]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-image: Don't do alpha pre-multiplication for opaque pixels
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Mon, 8 Dec 2014 10:47:12 +0000 (11:47 +0100)
committerRay Strode <rstrode@redhat.com>
Thu, 26 Mar 2015 01:09:50 +0000 (21:09 -0400)
When transforming the output of libpng to ARG32 with pre-multiplied
alpha, only do the multiplications if the pixel isn't opaque. Otherwise
plymouth is just applying a very complicated identity function.

https://bugs.freedesktop.org/show_bug.cgi?id=87105

src/libply-splash-graphics/ply-image.c

index f838601a762508e93fbca4b9c4f9490b93dcd469..8b4697883add9abe1a4902a087931895d2c774f2 100644 (file)
@@ -99,10 +99,13 @@ transform_to_argb32 (png_struct   *png,
                 blue = data[i + 2];
                 alpha = data[i + 3];
 
-                red = (uint8_t) CLAMP (((red / 255.0) * (alpha / 255.0)) * 255.0, 0, 255.0);
-                green = (uint8_t) CLAMP (((green / 255.0) * (alpha / 255.0)) * 255.0,
-                                         0, 255.0);
-                blue = (uint8_t) CLAMP (((blue / 255.0) * (alpha / 255.0)) * 255.0, 0, 255.0);
+                /* pre-multiply the alpha if there's translucency */
+                if (alpha != 0xff) {
+                        red = (uint8_t) CLAMP (((red / 255.0) * (alpha / 255.0)) * 255.0, 0, 255.0);
+                        green = (uint8_t) CLAMP (((green / 255.0) * (alpha / 255.0)) * 255.0,
+                                                 0, 255.0);
+                        blue = (uint8_t) CLAMP (((blue / 255.0) * (alpha / 255.0)) * 255.0, 0, 255.0);
+                }
 
                 pixel_value = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
                 memcpy (data + i, &pixel_value, sizeof(uint32_t));