From 8e9157d6ceac5428079fbb855c7d93e110fd8dae Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 21 Mar 2024 09:08:28 -0400 Subject: [PATCH] LibGfx/JBIG2: Implement decode_end_of_stripe() a bit This is enough to be able to decode 0000857.pdf p1-4 and 0000372.pdf p11. --- .../Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp index 3571fa12109..8f225ce766c 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp @@ -2049,9 +2049,18 @@ static ErrorOr decode_end_of_page(JBIG2LoadingContext&, SegmentData const& return {}; } -static ErrorOr decode_end_of_stripe(JBIG2LoadingContext&, SegmentData const&) +static ErrorOr decode_end_of_stripe(JBIG2LoadingContext&, SegmentData const& segment) { - return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode end of stripe yet"); + // 7.4.10 End of stripe segment syntax + // "The segment data of an end of stripe segment consists of one four-byte value, specifying the Y coordinate of the end row." + if (segment.data.size() != 4) + return Error::from_string_literal("JBIG2ImageDecoderPlugin: End of strip segment has wrong size"); + + // FIXME: Once we implement support for images with initially indeterminate height, we need these values to determine the height at the end. + u32 y_coordinate = *reinterpret_cast const*>(segment.data.data()); + dbgln_if(JBIG2_DEBUG, "End of stripe: y={}", y_coordinate); + + return {}; } static ErrorOr decode_end_of_file(JBIG2LoadingContext&, SegmentData const& segment)