diff options
author | Nico Weber <thakis@chromium.org> | 2023-04-03 19:53:38 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-04-07 09:47:04 +0200 |
commit | 8760376abefc4be57d9c8aebdf9bcf281d307e15 (patch) | |
tree | 7cceb90d1a7396463948b8790998bd30fef10a35 /Userland/Libraries/LibGfx | |
parent | cdc77f751266ba85f18359500453d41ff929452b (diff) | |
download | serenity-8760376abefc4be57d9c8aebdf9bcf281d307e15.zip |
LibGfx: Implement SUBTRACT_GREEN_TRANSFORM for webp lossless decoder
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r-- | Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index c480eea0dd..aca45e4980 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -636,6 +636,23 @@ public: Transform::~Transform() = default; +// https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#43_subtract_green_transform +class SubtractGreenTransform : public Transform { +public: + virtual ErrorOr<void> transform(Bitmap&) override; +}; + +ErrorOr<void> SubtractGreenTransform::transform(Bitmap& bitmap) +{ + for (ARGB32& pixel : bitmap) { + Color color = Color::from_argb(pixel); + u8 red = (color.red() + color.green()) & 0xff; + u8 blue = (color.blue() + color.green()) & 0xff; + pixel = Color(red, color.green(), blue, color.alpha()).value(); + } + return {}; +} + } // https://developers.google.com/speed/webp/docs/riff_container#simple_file_format_lossless @@ -702,7 +719,8 @@ static ErrorOr<void> decode_webp_chunk_VP8L(WebPLoadingContext& context, Chunk c case COLOR_TRANSFORM: return context.error("WebPImageDecoderPlugin: VP8L COLOR_TRANSFORM handling not yet implemented"); case SUBTRACT_GREEN_TRANSFORM: - return context.error("WebPImageDecoderPlugin: VP8L SUBTRACT_GREEN_TRANSFORM handling not yet implemented"); + TRY(transforms.try_append(TRY(try_make<SubtractGreenTransform>()))); + break; case COLOR_INDEXING_TRANSFORM: return context.error("WebPImageDecoderPlugin: VP8L COLOR_INDEXING_TRANSFORM handling not yet implemented"); } |