summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-03-28 15:59:26 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2022-03-28 16:05:47 +0100
commit4307230331cba76e3bae99e76021c9991a522b97 (patch)
treedad4532bd9038ad1ef9e437fa06672d67db11fae /content
parentc93ed6d63a1a2bbb43db6e8f420ef2283dd54623 (diff)
downloadnetsurf-4307230331cba76e3bae99e76021c9991a522b97.tar.gz
netsurf-4307230331cba76e3bae99e76021c9991a522b97.tar.bz2
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.
Diffstat (limited to 'content')
-rw-r--r--content/handlers/image/png.c17
1 files 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);
}