[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#858156: Improved patch



Hello,

This is a patch that improve the support for legacy icon format.

Now also correctly render:
xcalc/xman (1 bpp, without mask)
xclock/oclock/xlogo (1 bpp, with mask)

This patch apply to marco source package.
Thanks
diff -pur a/src/core/iconcache.c b/src/core/iconcache.c
--- a/src/core/iconcache.c	2018-12-19 14:47:57.000000000 -0500
+++ b/src/core/iconcache.c	2021-01-17 11:10:55.427118807 -0500
@@ -334,12 +334,28 @@ apply_mask (GdkPixbuf *pixbuf,
   guchar *dest;
   int src_stride;
   int dest_stride;
+  int has_alpha, has_mask;
 
-  w = MIN (gdk_pixbuf_get_width (mask), gdk_pixbuf_get_width (pixbuf));
-  h = MIN (gdk_pixbuf_get_height (mask), gdk_pixbuf_get_height (pixbuf));
+  has_mask = mask != NULL;
+  if (!has_mask)
+    mask = pixbuf;
 
   with_alpha = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0);
 
+  /* make sure we have the proper pixel format before proceeding */
+  if (gdk_pixbuf_get_n_channels (with_alpha) != 4 ||
+      gdk_pixbuf_get_bits_per_sample (with_alpha) != 8 ||
+      gdk_pixbuf_get_has_alpha (with_alpha) != 1 ||
+      gdk_pixbuf_get_n_channels (mask) != 4 ||
+      gdk_pixbuf_get_bits_per_sample (mask) != 8 ||
+      gdk_pixbuf_get_has_alpha (mask) != 1)
+    return with_alpha; /* wrong pixel format: no alpha */
+
+  has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
+
+  w = MIN (gdk_pixbuf_get_width (mask), gdk_pixbuf_get_width (with_alpha));
+  h = MIN (gdk_pixbuf_get_height (mask), gdk_pixbuf_get_height (with_alpha));
+
   dest = gdk_pixbuf_get_pixels (with_alpha);
   src = gdk_pixbuf_get_pixels (mask);
 
@@ -352,14 +368,13 @@ apply_mask (GdkPixbuf *pixbuf,
       j = 0;
       while (j < w)
         {
-          guchar *s = src + i * src_stride + j * 3;
+          guchar *s = src + i * src_stride + j * 4;
           guchar *d = dest + i * dest_stride + j * 4;
 
-          /* s[0] == s[1] == s[2], they are 255 if the bit was set, 0
-           * otherwise
-           */
-          if (s[0] == 0)
-            d[3] = 0;   /* transparent */
+          if (has_alpha)
+            d[0] = d[1] = d[2] = d[3];
+          if (has_mask)
+            d[3] = s[3];
           else
             d[3] = 255; /* opaque */
 
@@ -385,6 +400,7 @@ try_pixmap_and_mask (MetaDisplay *displa
 {
   GdkPixbuf *unscaled = NULL;
   GdkPixbuf *mask = NULL;
+  GdkPixbuf *masked;
   int w, h;
 
   if (src_pixmap == None)
@@ -410,14 +426,12 @@ try_pixmap_and_mask (MetaDisplay *displa
 
   meta_error_trap_pop (display, FALSE);
 
+  masked = apply_mask (unscaled, mask);
+  g_object_unref (G_OBJECT (unscaled));
+  unscaled = masked;
+
   if (mask)
     {
-      GdkPixbuf *masked;
-
-      masked = apply_mask (unscaled, mask);
-      g_object_unref (G_OBJECT (unscaled));
-      unscaled = masked;
-
       g_object_unref (G_OBJECT (mask));
       mask = NULL;
     }

Reply to: