summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r--Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp20
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");
}