Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoder num_threads as a module constant #76

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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