From 7594902973d2e0efe44bb174ade31ddcb7d0956a Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 8 Mar 2024 21:17:20 -0500 Subject: [PATCH] LibPDF: In Filter::decode_jbig2(), invert bits See included comment. --- Userland/Libraries/LibPDF/Filter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibPDF/Filter.cpp b/Userland/Libraries/LibPDF/Filter.cpp index 88e57ca8455bb7..7a3a098d4db9e4 100644 --- a/Userland/Libraries/LibPDF/Filter.cpp +++ b/Userland/Libraries/LibPDF/Filter.cpp @@ -346,7 +346,14 @@ PDFErrorOr Filter::decode_jbig2(Document* document, ReadonlyBytes by } segments.append(bytes); - return TRY(Gfx::JBIG2ImageDecoderPlugin::decode_embedded(segments)); + auto decoded = TRY(Gfx::JBIG2ImageDecoderPlugin::decode_embedded(segments)); + + // JBIG2 treats `1` as "ink present" (black) and `0` as "no ink" (white). + // PDF treats `1` as "light present" (white) and `1` as "no light" (black). + // So we have to invert. + invert_bits(decoded); + + return decoded; } PDFErrorOr Filter::decode_dct(ReadonlyBytes bytes)