|
62 | 62 | from .errors import DependencyError, PdfReadError, PdfStreamError
|
63 | 63 | from .generic import (
|
64 | 64 | ArrayObject,
|
65 |
| - BooleanObject, |
66 | 65 | DictionaryObject,
|
67 | 66 | IndirectObject,
|
68 | 67 | NullObject,
|
@@ -518,12 +517,13 @@ class CCITTParameters:
|
518 | 517 | """§7.4.6, optional parameters for the CCITTFaxDecode filter."""
|
519 | 518 |
|
520 | 519 | K: int = 0
|
521 |
| - columns: int = 0 |
| 520 | + columns: int = 1728 |
522 | 521 | rows: int = 0
|
523 |
| - EndOfBlock: Union[int, None] = None |
524 |
| - EndOfLine: Union[int, None] = None |
525 |
| - EncodedByteAlign: Union[int, None] = None |
526 |
| - DamagedRowsBeforeError: Union[int, None] = None |
| 522 | + EndOfLine: Union[bool, None] = False |
| 523 | + EncodedByteAlign: Union[bool, None] = False |
| 524 | + EndOfBlock: Union[bool, None] = True |
| 525 | + BlackIs1: bool = False |
| 526 | + DamagedRowsBeforeError: Union[int, None] = 0 |
527 | 527 |
|
528 | 528 | @property
|
529 | 529 | def group(self) -> int:
|
@@ -565,26 +565,27 @@ def _get_parameters(
|
565 | 565 | parameters: Union[None, ArrayObject, DictionaryObject, IndirectObject],
|
566 | 566 | rows: Union[int, IndirectObject],
|
567 | 567 | ) -> CCITTParameters:
|
568 |
| - # §7.4.6, optional parameters for the CCITTFaxDecode filter |
569 |
| - k = 0 |
570 |
| - columns = 1728 |
| 568 | + ccitt_parameters = CCITTParameters(rows=int(rows)) |
571 | 569 | if parameters:
|
572 | 570 | parameters_unwrapped = cast(
|
573 | 571 | Union[ArrayObject, DictionaryObject], parameters.get_object()
|
574 | 572 | )
|
575 | 573 | if isinstance(parameters_unwrapped, ArrayObject):
|
576 | 574 | for decode_parm in parameters_unwrapped:
|
577 |
| - if CCITT.COLUMNS in decode_parm: |
578 |
| - columns = decode_parm[CCITT.COLUMNS].get_object() |
579 | 575 | if CCITT.K in decode_parm:
|
580 |
| - k = decode_parm[CCITT.K].get_object() |
| 576 | + ccitt_parameters.K = decode_parm[CCITT.K].get_object() |
| 577 | + if CCITT.COLUMNS in decode_parm: |
| 578 | + ccitt_parameters.columns = decode_parm[CCITT.COLUMNS].get_object() |
| 579 | + if CCITT.BLACK_IS_1 in decode_parm: |
| 580 | + ccitt_parameters.BlackIs1 = decode_parm[CCITT.BLACK_IS_1].get_object().value |
581 | 581 | else:
|
582 |
| - if CCITT.COLUMNS in parameters_unwrapped: |
583 |
| - columns = parameters_unwrapped[CCITT.COLUMNS].get_object() # type: ignore |
584 | 582 | if CCITT.K in parameters_unwrapped:
|
585 |
| - k = parameters_unwrapped[CCITT.K].get_object() # type: ignore |
586 |
| - |
587 |
| - return CCITTParameters(K=k, columns=columns, rows=int(rows)) |
| 583 | + ccitt_parameters.K = parameters_unwrapped[CCITT.K].get_object() # type: ignore |
| 584 | + if CCITT.COLUMNS in parameters_unwrapped: |
| 585 | + ccitt_parameters.columns = parameters_unwrapped[CCITT.COLUMNS].get_object() # type: ignore |
| 586 | + if CCITT.BLACK_IS_1 in parameters_unwrapped: |
| 587 | + ccitt_parameters.BlackIs1 = parameters_unwrapped[CCITT.BLACK_IS_1].get_object().value # type: ignore |
| 588 | + return ccitt_parameters |
588 | 589 |
|
589 | 590 | @staticmethod
|
590 | 591 | def decode(
|
@@ -622,7 +623,7 @@ def decode(
|
622 | 623 | 262, # Thresholding, SHORT, 1, 0 = BlackIs1
|
623 | 624 | 3,
|
624 | 625 | 1,
|
625 |
| - 0, |
| 626 | + int(params.BlackIs1), |
626 | 627 | 273, # StripOffsets, LONG, 1, length of header
|
627 | 628 | 4,
|
628 | 629 | 1,
|
@@ -922,10 +923,6 @@ def _apply_alpha(
|
922 | 923 | img, x_object, obj_as_text, image_format, extension
|
923 | 924 | )
|
924 | 925 |
|
925 |
| - if lfilters == FT.CCITT_FAX_DECODE and decode_parms.get("/BlackIs1", BooleanObject(False)).value is True: |
926 |
| - from PIL import ImageOps # noqa: PLC0415 |
927 |
| - img = ImageOps.invert(img) |
928 |
| - |
929 | 926 | # Save image to bytes
|
930 | 927 | img_byte_arr = BytesIO()
|
931 | 928 | try:
|
|
0 commit comments