From 6b3bab5c8a959a030374b93db6b0421f2c3807b9 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Tue, 20 Feb 2024 16:27:29 -0500 Subject: [PATCH] LibPDF: Plug in the CCITTFaxDecode filter to our CCITT decoder We only call the decoder for Group 4 images. We do support Group 3 images, but let's wait to find a PDF with these before adding support. --- Userland/Libraries/LibPDF/Filter.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibPDF/Filter.cpp b/Userland/Libraries/LibPDF/Filter.cpp index 8f9f524b4a..70e187f938 100644 --- a/Userland/Libraries/LibPDF/Filter.cpp +++ b/Userland/Libraries/LibPDF/Filter.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -275,7 +276,7 @@ PDFErrorOr Filter::decode_run_length(ReadonlyBytes bytes) return TRY(Compress::PackBits::decode_all(bytes, OptionalNone {}, Compress::PackBits::CompatibilityMode::PDF)); } -PDFErrorOr Filter::decode_ccitt(ReadonlyBytes, RefPtr decode_parms) +PDFErrorOr Filter::decode_ccitt(ReadonlyBytes bytes, RefPtr decode_parms) { // Table 3.9 Optional parameters for the CCITTFaxDecode filter int k = 0; @@ -305,17 +306,15 @@ PDFErrorOr Filter::decode_ccitt(ReadonlyBytes, RefPtr de damaged_rows_before_error = decode_parms->get_value(CommonNames::DamagedRowsBeforeError).get(); } - // FIXME: Do something with these. - (void)require_end_of_line; - (void)encoded_byte_align; - (void)columns; - (void)rows; + // FIXME: This parameter seems crucial when reading its description, but we still + // achieve to decode images that have it. Figure out what to do with it. (void)end_of_block; - (void)black_is_1; - (void)damaged_rows_before_error; + + if (require_end_of_line || encoded_byte_align || black_is_1 || damaged_rows_before_error > 0 || rows == 0) + return Error::rendering_unsupported_error("Unimplemented option for the CCITTFaxDecode Filter"); if (k < 0) - return Error::rendering_unsupported_error("CCITTFaxDecode Filter Group 4 is unsupported"); + return TRY(Gfx::CCITT::decode_ccitt_group4(bytes, columns, rows)); 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");