diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 0dd9bd28c0..998804bacf 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -404,6 +404,30 @@ TEST_CASE(test_webp_extended_lossy_alpha_horizontal_filter) EXPECT_EQ(frame.image->get_pixel(131, 131), Gfx::Color(0x8f, 0x51, 0x2f, 0x4b)); } +TEST_CASE(test_webp_extended_lossy_alpha_vertical_filter) +{ + // Also lossy rgb + lossless alpha, but with a vertical alpha filtering method. + // The image should look like smolkling.webp, but with a vertical alpha gradient, and with a fully transparent first column. + auto file = MUST(Core::MappedFile::map(TEST_INPUT("smolkling-vertical-alpha.webp"sv))); + EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); + auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + MUST(plugin_decoder->initialize()); + + EXPECT_EQ(plugin_decoder->frame_count(), 1u); + EXPECT(!plugin_decoder->is_animated()); + EXPECT(!plugin_decoder->loop_count()); + + EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(264, 264)); + + auto frame = MUST(plugin_decoder->frame(0)); + EXPECT_EQ(frame.image->size(), Gfx::IntSize(264, 264)); + + // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't. + // So pixels changing by 1 or so below is fine if you change code. + // The important component in this test is alpha, and that shouldn't change even by 1 as it's losslessly compressed and doesn't use YUV. + EXPECT_EQ(frame.image->get_pixel(131, 131), Gfx::Color(0x94, 0x50, 0x32, 0x4c)); +} + TEST_CASE(test_webp_extended_lossy_alpha_gradient_filter) { // Also lossy rgb + lossless alpha, but with a gradient alpha filtering method. diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index 5e2417c1b4..1f9e4a9819 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -290,7 +290,6 @@ static ErrorOr decode_webp_chunk_ALPH(Chunk const& alph_chunk, Bitmap& bit // "Method 2: predictor = B" // "The top-left value at location (0, 0) uses 0 as predictor value. Otherwise, // For vertical or gradient filtering methods, the top-most pixels at location (x, 0) are predicted using the location (x-1, 0) on the left." - // FIXME: This branch is untested. for (int x = 1; x < bitmap.width(); ++x) alpha[x] += alpha[x - 1]; for (int y = 1; y < bitmap.height(); ++y) {