LibPDF: Read CCITT decode params

We don't do anything with them yet, so no behavior change.
This commit is contained in:
Nico Weber 2024-02-12 19:36:33 -05:00 committed by Andreas Kling
parent 454a10774e
commit c201825cc8
Notes: sideshowbarker 2024-07-17 01:51:00 +09:00
3 changed files with 48 additions and 3 deletions

View File

@ -22,6 +22,7 @@
X(BaseFont) \
X(BitsPerComponent) \
X(BitsPerSample) \
X(BlackIs1) \
X(BlackPoint) \
X(Bounds) \
X(C) \
@ -51,6 +52,7 @@
X(D) \
X(DCTDecode) \
X(DW) \
X(DamagedRowsBeforeError) \
X(Decode) \
X(DecodeParms) \
X(DescendantFonts) \
@ -65,9 +67,12 @@
X(E) \
X(EarlyChange) \
X(Encode) \
X(EncodedByteAlign) \
X(Encoding) \
X(Encrypt) \
X(EncryptMetadata) \
X(EndOfBlock) \
X(EndOfLine) \
X(ExtGState) \
X(F) \
X(FL) \
@ -106,6 +111,7 @@
X(Intent) \
X(JBIG2Decode) \
X(JPXDecode) \
X(K) \
X(Keywords) \
X(Kids) \
X(L) \
@ -152,6 +158,7 @@
X(Registry) \
X(Resources) \
X(Root) \
X(Rows) \
X(Rotate) \
X(RunLengthDecode) \
X(S) \

View File

@ -30,7 +30,7 @@ PDFErrorOr<ByteBuffer> Filter::decode(ReadonlyBytes bytes, DeprecatedFlyString c
if (encoding_type == CommonNames::RunLengthDecode)
return decode_run_length(bytes);
if (encoding_type == CommonNames::CCITTFaxDecode)
return decode_ccitt(bytes);
return decode_ccitt(bytes, decode_parms);
if (encoding_type == CommonNames::JBIG2Decode)
return decode_jbig2(bytes);
if (encoding_type == CommonNames::DCTDecode)
@ -275,8 +275,46 @@ PDFErrorOr<ByteBuffer> Filter::decode_run_length(ReadonlyBytes bytes)
return TRY(Compress::PackBits::decode_all(bytes, OptionalNone {}, Compress::PackBits::CompatibilityMode::PDF));
}
PDFErrorOr<ByteBuffer> Filter::decode_ccitt(ReadonlyBytes)
PDFErrorOr<ByteBuffer> Filter::decode_ccitt(ReadonlyBytes, RefPtr<DictObject> decode_parms)
{
// Table 3.9 Optional parameters for the CCITTFaxDecode filter
int k = 0;
bool require_end_of_line = false;
bool encoded_byte_align = false;
int columns = 1728;
int rows = 0;
bool end_of_block = true;
bool black_is_1 = false;
int damaged_rows_before_error = 0;
if (decode_parms) {
if (decode_parms->contains(CommonNames::K))
k = decode_parms->get_value(CommonNames::K).get<int>();
if (decode_parms->contains(CommonNames::EndOfLine))
require_end_of_line = decode_parms->get_value(CommonNames::EndOfLine).get<bool>();
if (decode_parms->contains(CommonNames::EncodedByteAlign))
encoded_byte_align = decode_parms->get_value(CommonNames::EncodedByteAlign).get<bool>();
if (decode_parms->contains(CommonNames::Columns))
columns = decode_parms->get_value(CommonNames::Columns).get<int>();
if (decode_parms->contains(CommonNames::Rows))
rows = decode_parms->get_value(CommonNames::Rows).get<int>();
if (decode_parms->contains(CommonNames::EndOfBlock))
end_of_block = decode_parms->get_value(CommonNames::EndOfBlock).get<bool>();
if (decode_parms->contains(CommonNames::BlackIs1))
black_is_1 = decode_parms->get_value(CommonNames::BlackIs1).get<bool>();
if (decode_parms->contains(CommonNames::DamagedRowsBeforeError))
damaged_rows_before_error = decode_parms->get_value(CommonNames::DamagedRowsBeforeError).get<int>();
}
// FIXME: Do something with these.
(void)k;
(void)require_end_of_line;
(void)encoded_byte_align;
(void)columns;
(void)rows;
(void)end_of_block;
(void)black_is_1;
(void)damaged_rows_before_error;
return Error::rendering_unsupported_error("CCITTFaxDecode Filter is unsupported");
}

View File

@ -25,7 +25,7 @@ private:
static PDFErrorOr<ByteBuffer> decode_lzw(ReadonlyBytes bytes, RefPtr<DictObject> decode_parms);
static PDFErrorOr<ByteBuffer> decode_flate(ReadonlyBytes bytes, RefPtr<DictObject> decode_parms);
static PDFErrorOr<ByteBuffer> decode_run_length(ReadonlyBytes bytes);
static PDFErrorOr<ByteBuffer> decode_ccitt(ReadonlyBytes bytes);
static PDFErrorOr<ByteBuffer> decode_ccitt(ReadonlyBytes bytes, RefPtr<DictObject> decode_parms);
static PDFErrorOr<ByteBuffer> decode_jbig2(ReadonlyBytes bytes);
static PDFErrorOr<ByteBuffer> decode_dct(ReadonlyBytes bytes);
static PDFErrorOr<ByteBuffer> decode_jpx(ReadonlyBytes bytes);