Fix #344: Ignoring alpha channel
[geeqie.git] / src / pixbuf_util.c
index fc41487..9d10630 100644 (file)
@@ -1509,4 +1509,43 @@ void pixbuf_highlight_overunderexposed(GdkPixbuf *pb, gint x, gint y, gint w, gi
                        }
                }
 }
+
+/*
+ *-----------------------------------------------------------------------------
+ * pixbuf ignore alpha
+ *-----------------------------------------------------------------------------
+*/
+void pixbuf_ignore_alpha_rect(GdkPixbuf *pb,
+                 gint x, gint y, gint w, gint h)
+{
+   gboolean has_alpha;
+   gint pw, ph, prs;
+   guchar *p_pix;
+   guchar *pp;
+   gint i, j;
+
+   if (!pb) return;
+
+   pw = gdk_pixbuf_get_width(pb);
+   ph = gdk_pixbuf_get_height(pb);
+
+   if (x < 0 || x + w > pw) return;
+   if (y < 0 || y + h > ph) return;
+
+   has_alpha = gdk_pixbuf_get_has_alpha(pb);
+   if (!has_alpha) return;
+
+   prs = gdk_pixbuf_get_rowstride(pb);
+   p_pix = gdk_pixbuf_get_pixels(pb);
+
+   for (i = 0; i < h; i++)
+       {
+       pp = p_pix + (y + i) * prs + (x * 4 );
+       for (j = 0; j < w; j++)
+           {
+           pp[3] = 0xff;
+           pp+=4;
+           }
+       }
+}
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */