From ced21d8419281ff5ca5ad17c386a8540c46e886f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 20 Mar 2024 22:34:20 -0400 Subject: [PATCH] LibGfx/JBIG2: Call decode_immediate_text_region for lossless text region It seems to do the right thing already, and nothing in the spec says not to do this as far as I can tell. With this, we can finally decode the test input from #23659. See f391c7822dee7 for a similar change for generic regions and lossless generic regions. --- .../Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp index 63987401f19..e657c9bb792 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp @@ -1665,11 +1665,6 @@ static ErrorOr decode_immediate_text_region(JBIG2LoadingContext& context, return {}; } -static ErrorOr decode_immediate_lossless_text_region(JBIG2LoadingContext&, SegmentData const&) -{ - return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode immediate lossless text region yet"); -} - static ErrorOr decode_pattern_dictionary(JBIG2LoadingContext&, SegmentData const&) { return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode pattern dictionary yet"); @@ -1943,10 +1938,13 @@ static ErrorOr decode_data(JBIG2LoadingContext& context) TRY(decode_intermediate_text_region(context, segment)); break; case SegmentType::ImmediateTextRegion: - TRY(decode_immediate_text_region(context, segment)); - break; case SegmentType::ImmediateLosslessTextRegion: - TRY(decode_immediate_lossless_text_region(context, segment)); + // 7.4.3 Text region segment syntax + // "The data parts of all three of the text region segment types ("intermediate text region", "immediate text region" and + // "immediate lossless text region") are coded identically, but are acted upon differently, see 8.2." + // But 8.2 only describes a difference between intermediate and immediate regions as far as I can tell, + // and calling the immediate text region handler for immediate lossless text regions seems to do the right thing (?). + TRY(decode_immediate_text_region(context, segment)); break; case SegmentType::PatternDictionary: TRY(decode_pattern_dictionary(context, segment));