Skip to content

Commit

Permalink
decode threads is a module constant (#76)
Browse files Browse the repository at this point in the history
Also adds num_threads to the signatures in pyi
  • Loading branch information
Piezoid authored Oct 11, 2024
1 parent 58f14c2 commit 624a98c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pillow_jxl/JpegXLImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pillow_jxl/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
'''
Expand All @@ -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): ...
'''
Expand Down

0 comments on commit 624a98c

Please sign in to comment.