Browse Source

LibPDF: In Filter::decode_jbig2(), invert bits

See included comment.
Nico Weber 1 year ago
parent
commit
be9a6caa0a
1 changed files with 8 additions and 1 deletions
  1. 8 1
      Userland/Libraries/LibPDF/Filter.cpp

+ 8 - 1
Userland/Libraries/LibPDF/Filter.cpp

@@ -346,7 +346,14 @@ PDFErrorOr<ByteBuffer> 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<ByteBuffer> Filter::decode_dct(ReadonlyBytes bytes)