From 4307230331cba76e3bae99e76021c9991a522b97 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 28 Mar 2022 15:59:26 +0100 Subject: [PATCH] PNG: Allow support for premultiplied alpha. LibPNG doesn't support premultiplied alpha, so now that the core supports it, we can't just say that the decoded PNG is in the core bitmap format. So we now say it's in the core pixel layout, and if it's opaque we say it has the same premultipled alpha setting as core bitmaps because the conversion is costly and makes no difference. On the other hand if it is not opaque we now admit that it is not premultipled alpha so it gets converted if needed. --- content/handlers/image/png.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/content/handlers/image/png.c b/content/handlers/image/png.c index 30ff3be5a..520b72834 100644 --- a/content/handlers/image/png.c +++ b/content/handlers/image/png.c @@ -538,8 +538,13 @@ png_cache_convert_error: } if (bitmap != NULL) { - bitmap_format_to_client((struct bitmap *)bitmap, &bitmap_fmt); - guit->bitmap->modified((struct bitmap *)bitmap); + bool opaque = guit->bitmap->test_opaque((void *)bitmap); + guit->bitmap->set_opaque((void *)bitmap, opaque); + bitmap_format_to_client((void *)bitmap, &(bitmap_fmt_t) { + .layout = bitmap_fmt.layout, + .pma = opaque ? bitmap_fmt.pma : false, + }); + guit->bitmap->modified((void *)bitmap); } return (struct bitmap *)bitmap; @@ -566,8 +571,12 @@ static bool nspng_convert(struct content *c) } if (png_c->bitmap != NULL) { - guit->bitmap->set_opaque(png_c->bitmap, guit->bitmap->test_opaque(png_c->bitmap)); - bitmap_format_to_client(png_c->bitmap, &bitmap_fmt); + bool opaque = guit->bitmap->test_opaque(png_c->bitmap); + guit->bitmap->set_opaque(png_c->bitmap, opaque); + bitmap_format_to_client(png_c->bitmap, &(bitmap_fmt_t) { + .layout = bitmap_fmt.layout, + .pma = opaque ? bitmap_fmt.pma : false, + }); guit->bitmap->modified(png_c->bitmap); }