diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2022-03-27 10:50:29 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2022-03-27 10:50:29 +0100 |
commit | d33af429113159b1a1d7cf62f5d8894a015c6efb (patch) | |
tree | 1b17783a348982773737df4f5404ef42b6377c45 /content/handlers/image | |
parent | 41995c3999521ea4486326fba27460d0f17c8f68 (diff) | |
download | netsurf-d33af429113159b1a1d7cf62f5d8894a015c6efb.tar.gz netsurf-d33af429113159b1a1d7cf62f5d8894a015c6efb.tar.bz2 |
Image: WebP: Decode to client bitmap format where possible.
Diffstat (limited to 'content/handlers/image')
-rw-r--r-- | content/handlers/image/webp.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/content/handlers/image/webp.c b/content/handlers/image/webp.c index b8748593b..4087f4cfe 100644 --- a/content/handlers/image/webp.c +++ b/content/handlers/image/webp.c @@ -98,6 +98,9 @@ webp_cache_convert(struct content *c) uint8_t *decoded; size_t rowstride; struct bitmap *bitmap = NULL; + bitmap_fmt_t webp_fmt = { + .layout = bitmap_fmt.layout, + }; source_data = content__get_source_data(c, &source_size); @@ -131,20 +134,33 @@ webp_cache_convert(struct content *c) rowstride = guit->bitmap->get_rowstride(bitmap); - decoded = WebPDecodeRGBAInto(source_data, - source_size, - pixels, - rowstride * webpfeatures.height, - rowstride); + switch (webp_fmt.layout) { + default: + /* WebP has no ABGR function, fall back to default. */ + webp_fmt.layout = BITMAP_LAYOUT_R8G8B8A8; + /* Fall through. */ + case BITMAP_LAYOUT_R8G8B8A8: + decoded = WebPDecodeRGBAInto(source_data, source_size, pixels, + rowstride * webpfeatures.height, rowstride); + break; + + case BITMAP_LAYOUT_B8G8R8A8: + decoded = WebPDecodeBGRAInto(source_data, source_size, pixels, + rowstride * webpfeatures.height, rowstride); + break; + + case BITMAP_LAYOUT_A8R8G8B8: + decoded = WebPDecodeARGBInto(source_data, source_size, pixels, + rowstride * webpfeatures.height, rowstride); + break; + } if (decoded == NULL) { /* decode failed */ guit->bitmap->destroy(bitmap); return NULL; } - bitmap_format_to_client(bitmap, &(bitmap_fmt_t) { - .layout = BITMAP_LAYOUT_R8G8B8A8, - }); + bitmap_format_to_client(bitmap, &webp_fmt); guit->bitmap->modified(bitmap); return bitmap; |