From 2fefed89d96d8367d33b926f9b1f4f167c79f7e1 Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Wed, 24 Jul 2024 10:26:54 +0100 Subject: [PATCH 1/2] STY: Simplify paeth_predictor --- pypdf/_utils.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pypdf/_utils.py b/pypdf/_utils.py index 38c0d67d7..9587a0728 100644 --- a/pypdf/_utils.py +++ b/pypdf/_utils.py @@ -396,12 +396,7 @@ def paeth_predictor(left: int, up: int, up_left: int) -> int: dist_up = abs(p - up) dist_up_left = abs(p - up_left) - if dist_left <= dist_up and dist_left <= dist_up_left: - return left - elif dist_up <= dist_up_left: - return up - else: - return up_left + return min((left, dist_left), (up, dist_up), (up_left, dist_up_left), key=lambda x: x[1])[0] def deprecate(msg: str, stacklevel: int = 3) -> None: From 413f3d00fdc860a4e69df593fd52778b5ecaa00e Mon Sep 17 00:00:00 2001 From: j-t-1 <120829237+j-t-1@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:41:34 +0100 Subject: [PATCH 2/2] DEP: Remove paeth_predictor This function is unused. --- pypdf/_utils.py | 9 --------- tests/test_utils.py | 18 ------------------ 2 files changed, 27 deletions(-) diff --git a/pypdf/_utils.py b/pypdf/_utils.py index 9587a0728..6569707b6 100644 --- a/pypdf/_utils.py +++ b/pypdf/_utils.py @@ -390,15 +390,6 @@ def ord_(b: Union[int, str, bytes]) -> Union[int, bytes]: WHITESPACES_AS_REGEXP = b"[" + WHITESPACES_AS_BYTES + b"]" -def paeth_predictor(left: int, up: int, up_left: int) -> int: - p = left + up - up_left - dist_left = abs(p - left) - dist_up = abs(p - up) - dist_up_left = abs(p - up_left) - - return min((left, dist_left), (up, dist_up), (up_left, dist_up_left), key=lambda x: x[1])[0] - - def deprecate(msg: str, stacklevel: int = 3) -> None: warnings.warn(msg, DeprecationWarning, stacklevel=stacklevel) diff --git a/tests/test_utils.py b/tests/test_utils.py index 81fcf9fb4..856bedd86 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -132,24 +132,6 @@ def test_deprecate_no_replacement(): assert warn[0].message.args[0] == error_msg -@pytest.mark.parametrize( - ("left", "up", "upleft", "expected"), - [ - (0, 0, 0, 0), - (1, 0, 0, 1), - (0, 1, 0, 1), - (0, 0, 1, 0), - (1, 2, 3, 1), - (2, 1, 3, 1), - (1, 3, 2, 2), - (3, 1, 2, 2), - (3, 2, 1, 3), - ], -) -def test_paeth_predictor(left, up, upleft, expected): - assert pypdf._utils.paeth_predictor(left, up, upleft) == expected - - @pytest.mark.parametrize( ("dat", "pos", "to_read", "expected", "expected_pos"), [