mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
LibGfx: Properly skip IDAT chunks without fcTL in APNG files
In the previous fix, we were still drawing IDAT data to the reference frame even when no fcTL was present. This would cause rendering issues when subsequent frames use APNG_BLEND_OP_OVER blending mode, as they would composite over the incorrect reference frame. This commit adds a simple check to properly skip any frame without an fcTL chunk.
This commit is contained in:
parent
e5944a4d9e
commit
7da2339c89
Notes:
github-actions[bot]
2025-05-09 19:49:13 +00:00
Author: https://github.com/aplefull
Commit: 7da2339c89
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4660
Reviewed-by: https://github.com/gmta ✅
3 changed files with 21 additions and 4 deletions
|
@ -301,6 +301,9 @@ ErrorOr<size_t> PNGLoadingContext::read_frames(png_structp png_ptr, png_infop in
|
|||
|
||||
auto decoded_frame_bitmap = TRY(decode_frame({ width, height }));
|
||||
|
||||
if (!has_fcTL)
|
||||
continue;
|
||||
|
||||
RefPtr<Bitmap> prev_output_buffer;
|
||||
if (dispose_op == PNG_DISPOSE_OP_PREVIOUS) // Only actually clone if it's necessary
|
||||
prev_output_buffer = TRY(output_buffer->clone());
|
||||
|
@ -318,10 +321,8 @@ ErrorOr<size_t> PNGLoadingContext::read_frames(png_structp png_ptr, png_infop in
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (has_fcTL) {
|
||||
animation_frame_count++;
|
||||
frame_descriptors.append({ TRY(output_buffer->clone()), duration_ms() });
|
||||
}
|
||||
animation_frame_count++;
|
||||
frame_descriptors.append({ TRY(output_buffer->clone()), duration_ms() });
|
||||
|
||||
switch (dispose_op) {
|
||||
case PNG_DISPOSE_OP_NONE:
|
||||
|
|
|
@ -421,6 +421,22 @@ TEST_CASE(test_apng)
|
|||
EXPECT_EQ(frame.image->size(), Gfx::IntSize(128, 64));
|
||||
}
|
||||
|
||||
TEST_CASE(test_apng_idat_not_affecting_next_frame)
|
||||
{
|
||||
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("png/apng-blend.png"sv)));
|
||||
EXPECT(Gfx::PNGImageDecoderPlugin::sniff(file->bytes()));
|
||||
auto plugin_decoder = TRY_OR_FAIL(Gfx::PNGImageDecoderPlugin::create(file->bytes()));
|
||||
|
||||
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
|
||||
EXPECT_EQ(plugin_decoder->loop_count(), 0u);
|
||||
|
||||
auto frame = TRY_OR_FAIL(plugin_decoder->frame(0));
|
||||
|
||||
EXPECT_EQ(frame.duration, 1000);
|
||||
EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::Transparent);
|
||||
EXPECT_EQ(frame.image->size(), Gfx::IntSize(100, 100));
|
||||
}
|
||||
|
||||
TEST_CASE(test_exif)
|
||||
{
|
||||
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("png/exif.png"sv)));
|
||||
|
|
BIN
Tests/LibGfx/test-inputs/png/apng-blend.png
Normal file
BIN
Tests/LibGfx/test-inputs/png/apng-blend.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 464 B |
Loading…
Add table
Add a link
Reference in a new issue