Mercurial > geeqie
comparison src/pixbuf_util.c @ 82:a4c1b7014e6e
Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
* image.c, typedefs.h: Add ALTER_DESATURATE alteration type.
* img-view.c, layout_image.c, layout_util.c, menu.c: Allow to grayscale
the display of current image with [Shift]+[G] kyboard shortcut and
'adjust' submenu item.
* pixbuf_util.[ch] (pixbuf_desaturate_rect): Implement grayscale
function.
author | gqview |
---|---|
date | Thu, 19 Oct 2006 19:27:20 +0000 |
parents | 6281cc38e5ca |
children | d063f97503b7 |
comparison
equal
deleted
inserted
replaced
81:0ef72a64930b | 82:a4c1b7014e6e |
---|---|
1175 r, g, b, a); | 1175 r, g, b, a); |
1176 } | 1176 } |
1177 } | 1177 } |
1178 | 1178 |
1179 | 1179 |
1180 /* | |
1181 *----------------------------------------------------------------------------- | |
1182 * pixbuf color alterations | |
1183 *----------------------------------------------------------------------------- | |
1184 */ | |
1185 | |
1186 void pixbuf_desaturate_rect(GdkPixbuf *pb, | |
1187 gint x, gint y, gint w, gint h) | |
1188 { | |
1189 gint p_alpha; | |
1190 gint pw, ph, prs; | |
1191 guchar *p_pix; | |
1192 guchar *pp; | |
1193 gint i, j; | |
1194 | |
1195 if (!pb) return; | |
1196 | |
1197 pw = gdk_pixbuf_get_width(pb); | |
1198 ph = gdk_pixbuf_get_height(pb); | |
1199 | |
1200 if (x < 0 || x + w > pw) return; | |
1201 if (y < 0 || y + h > ph) return; | |
1202 | |
1203 p_alpha = gdk_pixbuf_get_has_alpha(pb); | |
1204 prs = gdk_pixbuf_get_rowstride(pb); | |
1205 p_pix = gdk_pixbuf_get_pixels(pb); | |
1206 | |
1207 for (i = 0; i < h; i++) | |
1208 { | |
1209 pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3)); | |
1210 for (j = 0; j < w; j++) | |
1211 { | |
1212 guint8 grey; | |
1213 | |
1214 grey = (pp[0] + pp[1] + pp[2]) / 3; | |
1215 *pp = grey; | |
1216 pp++; | |
1217 *pp = grey; | |
1218 pp++; | |
1219 *pp = grey; | |
1220 pp++; | |
1221 if (p_alpha) pp++; | |
1222 } | |
1223 } | |
1224 } | |
1225 | |
1226 |