diff --git a/Libraries/LibGfx/ImageFormats/PNGLoader.cpp b/Libraries/LibGfx/ImageFormats/PNGLoader.cpp index 6cc65ff92c..a4f4d061ea 100644 --- a/Libraries/LibGfx/ImageFormats/PNGLoader.cpp +++ b/Libraries/LibGfx/ImageFormats/PNGLoader.cpp @@ -301,6 +301,9 @@ ErrorOr PNGLoadingContext::read_frames(png_structp png_ptr, png_infop in auto decoded_frame_bitmap = TRY(decode_frame({ width, height })); + if (!has_fcTL) + continue; + RefPtr 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 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: diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index cacf10a841..3e6a064ec2 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -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))); diff --git a/Tests/LibGfx/test-inputs/png/apng-blend.png b/Tests/LibGfx/test-inputs/png/apng-blend.png new file mode 100644 index 0000000000..24f2a191df Binary files /dev/null and b/Tests/LibGfx/test-inputs/png/apng-blend.png differ