Skip to content

Commit

Permalink
fix tiff predictor decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Fuchs committed Nov 7, 2024
1 parent 809f03f commit 6c19609
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pdfminer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ def shorten_str(s: str, size: int) -> str:


def compatible_encode_method(
bytesorstring: Union[bytes, str],
encoding: str = "utf-8",
erraction: str = "ignore",
bytesorstring: Union[bytes, str],
encoding: str = "utf-8",
erraction: str = "ignore",
) -> str:
"""When Py2 str.encode is called, it often means bytes.encode in Py3.
Expand Down Expand Up @@ -127,7 +127,7 @@ def paeth_predictor(left: int, above: int, upper_left: int) -> int:


def apply_tiff_predictor(
colors: int, columns: int, bitspercomponent: int, data: bytes
colors: int, columns: int, bitspercomponent: int, data: bytes
) -> bytes:
"""Reverse the effect of the TIFF predictor 2
Expand All @@ -139,7 +139,7 @@ def apply_tiff_predictor(
bpp = colors * (bitspercomponent // 8)
nbytes = columns * bpp
buf: list[int] = []
for scanline_i in range(0, len(data), nbytes + 1):
for scanline_i in range(0, len(data), nbytes):
raw: list[int] = []
for i in range(nbytes):
new_value = data[scanline_i + i]
Expand All @@ -153,11 +153,11 @@ def apply_tiff_predictor(


def apply_png_predictor(
pred: int,
colors: int,
columns: int,
bitspercomponent: int,
data: bytes,
pred: int,
colors: int,
columns: int,
bitspercomponent: int,
data: bytes,
) -> bytes:
"""Reverse the effect of the PNG predictor
Expand All @@ -173,7 +173,7 @@ def apply_png_predictor(
line_above = list(b"\x00" * columns)
for scanline_i in range(0, len(data), nbytes + 1):
filter_type = data[scanline_i]
line_encoded = data[scanline_i + 1 : scanline_i + 1 + nbytes]
line_encoded = data[scanline_i + 1: scanline_i + 1 + nbytes]
raw = []

if filter_type == 0:
Expand Down Expand Up @@ -360,9 +360,9 @@ def get_bound(pts: Iterable[Point]) -> Rect:


def pick(
seq: Iterable[_T],
func: Callable[[_T], float],
maxobj: Optional[_T] = None,
seq: Iterable[_T],
func: Callable[[_T], float],
maxobj: Optional[_T] = None,
) -> Optional[_T]:
"""Picks the object obj where func(obj) has the highest value."""
maxscore = None
Expand Down

0 comments on commit 6c19609

Please sign in to comment.