From 624a98c1d6a2a50acbad07a75953c9285db386d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kerbiriou?= Date: Fri, 11 Oct 2024 05:11:13 +0200 Subject: [PATCH] decode threads is a module constant (#76) Also adds num_threads to the signatures in pyi --- pillow_jxl/JpegXLImagePlugin.py | 3 ++- pillow_jxl/__init__.pyi | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pillow_jxl/JpegXLImagePlugin.py b/pillow_jxl/JpegXLImagePlugin.py index 58f4e69..705f557 100644 --- a/pillow_jxl/JpegXLImagePlugin.py +++ b/pillow_jxl/JpegXLImagePlugin.py @@ -8,6 +8,7 @@ from pillow_jxl import Decoder, Encoder _VALID_JXL_MODES = {"RGB", "RGBA", "L", "LA"} +DECODE_THREADS = -1 # -1 detect available cpu cores, 0 disables parallelism def _accept(data): @@ -26,7 +27,7 @@ class JXLImageFile(ImageFile.ImageFile): def _open(self): self.fc = self.fp.read() - self._decoder = Decoder() + self._decoder = Decoder(num_threads=DECODE_THREADS) self.jpeg, self._jxlinfo, self._data, icc_profile = self._decoder(self.fc) # FIXME (Isotr0py): Maybe slow down jpeg reconstruction diff --git a/pillow_jxl/__init__.pyi b/pillow_jxl/__init__.pyi index 055561d..fe4f9c7 100644 --- a/pillow_jxl/__init__.pyi +++ b/pillow_jxl/__init__.pyi @@ -15,7 +15,8 @@ class Encoder: parallel: bool = True, has_alpha: bool = False, lossless: bool = True, - quality: float = 0.0): ... + quality: float = 0.0, + num_threads: int = -1): ... def __call__(self, data: bytes, width: int, height: int, jpeg_encode: bool) -> bytes: ... ''' @@ -37,7 +38,7 @@ class Decoder: parallel(`bool`): enable parallel decoding ''' - def __init__(self, parallel: bool = True): ... + def __init__(self, num_threads: int = -1): ... def __call__(self, data: bytes) -> (bool, ImageInfo, bytes): ... '''