From 2d6069650a68fecab70207c88b45604e2ea9d3da Mon Sep 17 00:00:00 2001 From: Khaled Lakehal Date: Mon, 19 Aug 2024 15:49:11 +0200 Subject: [PATCH] LibGfx: Enhance APNG format support Improve handling of APNG chunks by avoiding premature termination when encountering non-fcTL chunks. With this patch, the browser now passes additional APNG-related tests in the "png/" Web Platform Tests (WPT) suite. --- .../Libraries/LibGfx/ImageFormats/PNGLoader.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp index e64d0b46d2d..1f1fae48f46 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/PNGLoader.cpp @@ -244,15 +244,16 @@ ErrorOr PNGLoadingContext::read_frames(png_structp png_ptr, png_infop in u32 y = 0; u16 delay_num = 0; u16 delay_den = 0; - u8 dispose_op = 0; - u8 blend_op = 0; + u8 dispose_op = PNG_DISPOSE_OP_NONE; + u8 blend_op = PNG_BLEND_OP_SOURCE; - if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_fcTL)) { - return Error::from_string_literal("Missing fcTL chunk in APNG frame"); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_fcTL)) { + png_get_next_frame_fcTL(png_ptr, info_ptr, &width, &height, &x, &y, &delay_num, &delay_den, &dispose_op, &blend_op); + } else { + width = png_get_image_width(png_ptr, info_ptr); + height = png_get_image_height(png_ptr, info_ptr); } - png_get_next_frame_fcTL(png_ptr, info_ptr, &width, &height, &x, &y, &delay_num, &delay_den, &dispose_op, &blend_op); - decoded_frame_bitmap = TRY(Bitmap::create(BitmapFormat::BGRA8888, AlphaType::Unpremultiplied, IntSize { static_cast(width), static_cast(height) })); row_pointers.resize(height);