1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:07:45 +00:00

LibPDF: Handle the BlackIs1 parameter of the CCITTFaxDecode Filter

This commit is contained in:
Lucas CHOLLET 2024-02-20 18:35:44 -05:00 committed by Andrew Kaster
parent 6b3bab5c8a
commit cb03ab4a5a

View file

@ -276,6 +276,12 @@ PDFErrorOr<ByteBuffer> Filter::decode_run_length(ReadonlyBytes bytes)
return TRY(Compress::PackBits::decode_all(bytes, OptionalNone {}, Compress::PackBits::CompatibilityMode::PDF));
}
static void invert_bits(ByteBuffer& decoded)
{
for (u8& byte : decoded.bytes())
byte = ~byte;
}
PDFErrorOr<ByteBuffer> Filter::decode_ccitt(ReadonlyBytes bytes, RefPtr<DictObject> decode_parms)
{
// Table 3.9 Optional parameters for the CCITTFaxDecode filter
@ -310,14 +316,21 @@ PDFErrorOr<ByteBuffer> Filter::decode_ccitt(ReadonlyBytes bytes, RefPtr<DictObje
// achieve to decode images that have it. Figure out what to do with it.
(void)end_of_block;
if (require_end_of_line || encoded_byte_align || black_is_1 || damaged_rows_before_error > 0 || rows == 0)
if (require_end_of_line || encoded_byte_align || damaged_rows_before_error > 0 || rows == 0)
return Error::rendering_unsupported_error("Unimplemented option for the CCITTFaxDecode Filter");
ByteBuffer decoded {};
if (k < 0)
return TRY(Gfx::CCITT::decode_ccitt_group4(bytes, columns, rows));
if (k == 0)
decoded = TRY(Gfx::CCITT::decode_ccitt_group4(bytes, columns, rows));
else if (k == 0)
return Error::rendering_unsupported_error("CCITTFaxDecode Filter Group 3, 1-D is unsupported");
return Error::rendering_unsupported_error("CCITTFaxDecode Filter Group 3, 2-D is unsupported");
else
return Error::rendering_unsupported_error("CCITTFaxDecode Filter Group 3, 2-D is unsupported");
if (!black_is_1)
invert_bits(decoded);
return decoded;
}
PDFErrorOr<ByteBuffer> Filter::decode_jbig2(ReadonlyBytes)