aboutsummaryrefslogtreecommitdiff
path: root/webp.c
diff options
context:
space:
mode:
authorLeonardo Hernández Hernández <leohdz172@proton.me>2024-06-14 13:58:21 -0600
committerLeonardo Hernández Hernández <leohdz172@proton.me>2024-06-14 14:14:34 -0600
commitd9002dc181c95aa6f3358776420beda226ab2e2a (patch)
tree6a23e64bcdc253e9e446f4df971ee8b1475eb203 /webp.c
parent75e9e6e76d7a44ff7ea621747d6712d43855eb53 (diff)
downloadwbg-d9002dc181c95aa6f3358776420beda226ab2e2a.tar.gz
webp: do alpha pre-multiplication
libwebp returns the alpha as-is
Diffstat (limited to 'webp.c')
-rw-r--r--webp.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/webp.c b/webp.c
index 1028f6d..2749511 100644
--- a/webp.c
+++ b/webp.c
@@ -54,6 +54,29 @@ webp_load(FILE *fp, const char *path)
format = PIXMAN_x8b8g8r8;
stride = stride_for_format_and_width(format, width);
+ for (uint32_t *abgr = (uint32_t *)image_data;
+ abgr < (uint32_t *)(image_data + (size_t)width * (size_t)height * 4);
+ abgr++) {
+ uint8_t alpha = (*abgr >> 24) & 0xff;
+ uint8_t red = (*abgr >> 16) & 0xff;
+ uint8_t green = (*abgr >> 8) & 0xff;
+ uint8_t blue = (*abgr >> 0) & 0xff;
+
+ if (alpha == 0xff)
+ continue;
+
+ if (alpha == 0x00)
+ blue = green = red = 0x00;
+ else {
+ blue = blue * alpha / 0xff;
+ green = green * alpha / 0xff;
+ red = red * alpha / 0xff;
+ }
+
+ *abgr = (uint32_t)alpha << 24 | red << 16 | green << 8 | blue;
+ }
+
+
ok = NULL != (pix = pixman_image_create_bits_no_clear(
format, width, height, (uint32_t *)image_data, stride));