Skip to content

Commit

Permalink
add warnings about jpeg reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
Isotr0py committed Sep 2, 2024
1 parent 284a7f0 commit 3c960be
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pillow_jxl/JpegXLImagePlugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from io import BytesIO
import warnings
from logging import getLogger

import PIL
from packaging.version import parse
Expand All @@ -8,6 +10,7 @@

_VALID_JXL_MODES = {"RGB", "RGBA", "L", "LA"}

logger = getLogger(__name__)

def _accept(data):
return (
Expand Down Expand Up @@ -94,6 +97,7 @@ def _save(im, fp, filename, save_all=False):
effort = info.get("effort", 7)
use_container = info.get("use_container", False)
use_original_profile = info.get("use_original_profile", False)
jpeg_encode = info.get("lossless_jpeg", True)

enc = Encoder(
mode=im.mode,
Expand All @@ -106,7 +110,12 @@ def _save(im, fp, filename, save_all=False):
)
# FIXME (Isotr0py): im.filename maybe None if parse stream
# TODO (Isotr0py): This part should be refactored in the near future
if im.format == "JPEG" and im.filename:
if im.format == "JPEG" and im.filename and jpeg_encode:
warnings.warn(
"Using JPEG reconstruction to create lossless JXL image from JPEG. "
"This is the default behavior for JPEG encode, if you want to "
"disable this, please set 'lossless_jpeg' to False."
)
with open(im.filename, "rb") as f:
data = enc(f.read(), im.width, im.height, jpeg_encode=True)
else:
Expand Down

0 comments on commit 3c960be

Please sign in to comment.