Remove single dispatch version of calculate_downsample
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from functools import singledispatch
|
||||
from math import floor, sqrt
|
||||
from typing import Optional, Tuple
|
||||
|
||||
@@ -43,8 +42,7 @@ def bytes_per_pixel(mode: str) -> int:
|
||||
return 4
|
||||
|
||||
|
||||
@singledispatch
|
||||
def calculate_downsample(
|
||||
def _calculate_downsample(
|
||||
image_size: Tuple[int, int],
|
||||
bytes_per_pixel: int,
|
||||
*,
|
||||
@@ -105,10 +103,8 @@ def calculate_downsample(
|
||||
return size
|
||||
|
||||
|
||||
@calculate_downsample.register
|
||||
def _(
|
||||
def calculate_downsample(
|
||||
image: Image.Image,
|
||||
arg: None = None,
|
||||
*,
|
||||
max_size: Optional[Tuple[int, int]] = None,
|
||||
max_pixels: Optional[int] = None,
|
||||
@@ -126,7 +122,7 @@ def _(
|
||||
max_bytes: The maximum number of bytes in the image. RGB is counted as 4
|
||||
bytes; all other modes are counted as 1 byte.
|
||||
"""
|
||||
return calculate_downsample(
|
||||
return _calculate_downsample(
|
||||
image.size,
|
||||
bytes_per_pixel(image.mode),
|
||||
max_size=max_size,
|
||||
|
||||
@@ -7,7 +7,12 @@ import hypothesis.strategies as st
|
||||
from hypothesis import given
|
||||
from PIL import Image
|
||||
|
||||
from ocrmypdf.imageops import bytes_per_pixel, calculate_downsample, downsample_image
|
||||
from ocrmypdf.imageops import (
|
||||
_calculate_downsample,
|
||||
bytes_per_pixel,
|
||||
calculate_downsample,
|
||||
downsample_image,
|
||||
)
|
||||
|
||||
|
||||
def test_bytes_per_pixel():
|
||||
@@ -34,7 +39,7 @@ def test_calculate_downsample():
|
||||
st.integers(min_value=64 * 64, max_value=1000000),
|
||||
)
|
||||
def test_calculate_downsample_hypothesis(mode, im_w, im_h, max_x, max_y, max_bytes):
|
||||
result = calculate_downsample(
|
||||
result = _calculate_downsample(
|
||||
(im_w, im_h),
|
||||
bytes_per_pixel(mode),
|
||||
max_size=(max_x, max_y),
|
||||
|
||||
Reference in New Issue
Block a user