1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

WebP: Add test for vertical ALPH chunk filtering_method

This commit is contained in:
Nico Weber 2023-06-08 18:28:11 -04:00 committed by Tim Flynn
parent a77b6c470a
commit 52d17afd7e
Notes: sideshowbarker 2024-07-17 01:28:15 +09:00
2 changed files with 24 additions and 1 deletions

View file

@ -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.

View file

@ -290,7 +290,6 @@ static ErrorOr<void> 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) {