From 0a8e6dbedb84b50ca2ca8762ae1279a66c385bad Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sat, 31 Aug 2024 20:41:37 +0400 Subject: [PATCH 01/58] Use im.has_transparency_data for webp._save_all Also: remove _VALID_WEBP_MODES and _VALID_WEBP_LEGACY_MODES consts RGBX is not faster RGB since demands more bandwidth Do not convert to str paths in tests --- Tests/test_file_webp.py | 27 ++++++++++++--------------- src/PIL/WebPImagePlugin.py | 25 +++++-------------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index e75e3ddd2..719831db9 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -72,7 +72,7 @@ class TestFileWebp: def _roundtrip( self, tmp_path: Path, mode: str, epsilon: float, args: dict[str, Any] = {} ) -> None: - temp_file = str(tmp_path / "temp.webp") + temp_file = tmp_path / "temp.webp" hopper(mode).save(temp_file, **args) with Image.open(temp_file) as image: @@ -116,7 +116,7 @@ class TestFileWebp: assert buffer_no_args.getbuffer() != buffer_method.getbuffer() def test_save_all(self, tmp_path: Path) -> None: - temp_file = str(tmp_path / "temp.webp") + temp_file = tmp_path / "temp.webp" im = Image.new("RGB", (1, 1)) im2 = Image.new("RGB", (1, 1), "#f00") im.save(temp_file, save_all=True, append_images=[im2]) @@ -151,18 +151,16 @@ class TestFileWebp: @pytest.mark.skipif(sys.maxsize <= 2**32, reason="Requires 64-bit system") def test_write_encoding_error_message(self, tmp_path: Path) -> None: - temp_file = str(tmp_path / "temp.webp") im = Image.new("RGB", (15000, 15000)) with pytest.raises(ValueError) as e: - im.save(temp_file, method=0) + im.save(tmp_path / "temp.webp", method=0) assert str(e.value) == "encoding error 6" @pytest.mark.skipif(sys.maxsize <= 2**32, reason="Requires 64-bit system") def test_write_encoding_error_bad_dimension(self, tmp_path: Path) -> None: - temp_file = str(tmp_path / "temp.webp") im = Image.new("L", (16384, 16384)) with pytest.raises(ValueError) as e: - im.save(temp_file) + im.save(tmp_path / "temp.webp") assert ( str(e.value) == "encoding error 5: Image size exceeds WebP limit of 16383 pixels" @@ -187,9 +185,8 @@ class TestFileWebp: def test_no_resource_warning(self, tmp_path: Path) -> None: file_path = "Tests/images/hopper.webp" with Image.open(file_path) as image: - temp_file = str(tmp_path / "temp.webp") with warnings.catch_warnings(): - image.save(temp_file) + image.save(tmp_path / "temp.webp") def test_file_pointer_could_be_reused(self) -> None: file_path = "Tests/images/hopper.webp" @@ -204,15 +201,16 @@ class TestFileWebp: def test_invalid_background( self, background: int | tuple[int, ...], tmp_path: Path ) -> None: - temp_file = str(tmp_path / "temp.webp") + temp_file = tmp_path / "temp.webp" im = hopper() with pytest.raises(OSError): im.save(temp_file, save_all=True, append_images=[im], background=background) def test_background_from_gif(self, tmp_path: Path) -> None: + out_webp = tmp_path / "temp.webp" + # Save L mode GIF with background with Image.open("Tests/images/no_palette_with_background.gif") as im: - out_webp = str(tmp_path / "temp.webp") im.save(out_webp, save_all=True) # Save P mode GIF with background @@ -220,11 +218,10 @@ class TestFileWebp: original_value = im.convert("RGB").getpixel((1, 1)) # Save as WEBP - out_webp = str(tmp_path / "temp.webp") im.save(out_webp, save_all=True) # Save as GIF - out_gif = str(tmp_path / "temp.gif") + out_gif = tmp_path / "temp.gif" with Image.open(out_webp) as im: im.save(out_gif) @@ -234,10 +231,10 @@ class TestFileWebp: assert difference < 5 def test_duration(self, tmp_path: Path) -> None: + out_webp = tmp_path / "temp.webp" + with Image.open("Tests/images/dispose_bgnd.gif") as im: assert im.info["duration"] == 1000 - - out_webp = str(tmp_path / "temp.webp") im.save(out_webp, save_all=True) with Image.open(out_webp) as reloaded: @@ -245,7 +242,7 @@ class TestFileWebp: assert reloaded.info["duration"] == 1000 def test_roundtrip_rgba_palette(self, tmp_path: Path) -> None: - temp_file = str(tmp_path / "temp.webp") + temp_file = tmp_path / "temp.webp" im = Image.new("RGBA", (1, 1)).convert("P") assert im.mode == "P" assert im.palette is not None diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index f8d6168ba..3754d784a 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -13,10 +13,6 @@ except ImportError: SUPPORTED = False -_VALID_WEBP_MODES = {"RGBX": True, "RGBA": True, "RGB": True} - -_VALID_WEBP_LEGACY_MODES = {"RGB": True, "RGBA": True} - _VP8_MODES_BY_IDENTIFIER = { b"VP8 ": "RGB", b"VP8X": "RGBA", @@ -247,27 +243,16 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: # Make sure image mode is supported frame = ims - rawmode = ims.mode - if ims.mode not in _VALID_WEBP_MODES: - alpha = ( - "A" in ims.mode - or "a" in ims.mode - or (ims.mode == "P" and "A" in ims.im.getpalettemode()) - ) - rawmode = "RGBA" if alpha else "RGB" - frame = ims.convert(rawmode) - - if rawmode == "RGB": - # For faster conversion, use RGBX - rawmode = "RGBX" + if frame.mode not in ("RGBX", "RGBA", "RGB"): + frame = frame.convert("RGBA" if im.has_transparency_data else "RGB") # Append the frame to the animation encoder enc.add( - frame.tobytes("raw", rawmode), + frame.tobytes(), round(timestamp), frame.size[0], frame.size[1], - rawmode, + frame.mode, lossless, quality, alpha_quality, @@ -310,7 +295,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: method = im.encoderinfo.get("method", 4) exact = 1 if im.encoderinfo.get("exact") else 0 - if im.mode not in _VALID_WEBP_LEGACY_MODES: + if im.mode not in ("RGB", "RGBA"): im = im.convert("RGBA" if im.has_transparency_data else "RGB") data = _webp.WebPEncode( From 8bb3134b1d2fa2a13111a6555e09bbc26b96ff7a Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 19:41:45 +0400 Subject: [PATCH 02/58] call _webp.WebPEncode with ptr --- src/PIL/WebPImagePlugin.py | 7 +--- src/_webp.c | 75 ++++++++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index 3754d784a..3eeba9400 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -295,17 +295,14 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: method = im.encoderinfo.get("method", 4) exact = 1 if im.encoderinfo.get("exact") else 0 - if im.mode not in ("RGB", "RGBA"): + if im.mode not in ("RGBX", "RGBA", "RGB"): im = im.convert("RGBA" if im.has_transparency_data else "RGB") data = _webp.WebPEncode( - im.tobytes(), - im.size[0], - im.size[1], + im.im.ptr, lossless, float(quality), float(alpha_quality), - im.mode, icc_profile, method, exact, diff --git a/src/_webp.c b/src/_webp.c index f59ad3036..bfd9de5c0 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -566,32 +566,65 @@ static PyTypeObject WebPAnimDecoder_Type = { 0, /*tp_getset*/ }; +/* -------------------------------------------------------------------- */ +/* Frame import */ +/* -------------------------------------------------------------------- */ + +static int +import_frame_libwebp(WebPPicture *frame, Imaging im) { + UINT32 mask = 0; + + if (strcmp(im->mode, "RGBA") && strcmp(im->mode, "RGB") && strcmp(im->mode, "RGBX")) { + PyErr_SetString(PyExc_ValueError, "unsupported image mode"); + return -1; + } + + if (strcmp(im->mode, "RGBA")) { + mask = MASK_UINT32_CHANNEL_3; + } + + frame->width = im->xsize; + frame->height = im->ysize; + frame->use_argb = 1; // Don't convert RGB pixels to YUV + + if (!WebPPictureAlloc(frame)) { + PyErr_SetString(PyExc_MemoryError, "can't allocate picture frame"); + return -2; + } + + for (int y = 0; y < im->ysize; ++y) { + UINT8 *src = (UINT8 *)im->image32[y]; + UINT32 *dst = frame->argb + frame->argb_stride * y; + for (int x = 0; x < im->xsize; ++x) { + UINT32 pix = MAKE_UINT32(src[x * 4 + 2], src[x * 4 + 1], src[x * 4], src[x * 4 + 3]); + dst[x] = pix | mask; + } + } + + return 0; +} + /* -------------------------------------------------------------------- */ /* Legacy WebP Support */ /* -------------------------------------------------------------------- */ PyObject * WebPEncode_wrapper(PyObject *self, PyObject *args) { - int width; - int height; int lossless; float quality_factor; float alpha_quality_factor; int method; int exact; - uint8_t *rgb; + Imaging im; + PyObject *i0; uint8_t *icc_bytes; uint8_t *exif_bytes; uint8_t *xmp_bytes; uint8_t *output; - char *mode; - Py_ssize_t size; Py_ssize_t icc_size; Py_ssize_t exif_size; Py_ssize_t xmp_size; size_t ret_size; - int rgba_mode; - int channels; int ok; ImagingSectionCookie cookie; WebPConfig config; @@ -600,15 +633,11 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple( args, - "y#iiiffss#iis#s#", - (char **)&rgb, - &size, - &width, - &height, + "Oiffs#iis#s#", + &i0, &lossless, &quality_factor, &alpha_quality_factor, - &mode, &icc_bytes, &icc_size, &method, @@ -621,15 +650,12 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) { return NULL; } - rgba_mode = strcmp(mode, "RGBA") == 0; - if (!rgba_mode && strcmp(mode, "RGB") != 0) { - Py_RETURN_NONE; + if (!PyCapsule_IsValid(i0, IMAGING_MAGIC)) { + PyErr_Format(PyExc_TypeError, "Expected '%s' Capsule", IMAGING_MAGIC); + return NULL; } - channels = rgba_mode ? 4 : 3; - if (size < width * height * channels) { - Py_RETURN_NONE; - } + im = (Imaging)PyCapsule_GetPointer(i0, IMAGING_MAGIC); // Setup config for this frame if (!WebPConfigInit(&config)) { @@ -652,14 +678,9 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) { PyErr_SetString(PyExc_ValueError, "could not initialise picture"); return NULL; } - pic.width = width; - pic.height = height; - pic.use_argb = 1; // Don't convert RGB pixels to YUV - if (rgba_mode) { - WebPPictureImportRGBA(&pic, rgb, channels * width); - } else { - WebPPictureImportRGB(&pic, rgb, channels * width); + if (import_frame_libwebp(&pic, im)) { + return NULL; } WebPMemoryWriterInit(&writer); From 0962b468b71ea9cdb99417d091c75e86c29f768a Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Tue, 3 Sep 2024 13:47:31 +0400 Subject: [PATCH 03/58] ImagingSectionEnter for WebPAnimEncoder --- src/_webp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/_webp.c b/src/_webp.c index bfd9de5c0..ede261df6 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -190,6 +190,7 @@ _anim_encoder_add(PyObject *self, PyObject *args) { float quality_factor; float alpha_quality_factor; int method; + ImagingSectionCookie cookie; WebPConfig config; WebPAnimEncoderObject *encp = (WebPAnimEncoderObject *)self; WebPAnimEncoder *enc = encp->enc; @@ -246,8 +247,11 @@ _anim_encoder_add(PyObject *self, PyObject *args) { WebPPictureImportRGB(frame, rgb, 3 * width); } - // Add the frame to the encoder - if (!WebPAnimEncoderAdd(enc, frame, timestamp, &config)) { + ImagingSectionEnter(&cookie); + int ok = WebPAnimEncoderAdd(enc, frame, timestamp, &config); + ImagingSectionLeave(&cookie); + + if (!ok) { PyErr_SetString(PyExc_RuntimeError, WebPAnimEncoderGetError(enc)); return NULL; } From 4d271c8ec87355962e0345a00d9e4032007a13c5 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Tue, 3 Sep 2024 13:58:40 +0400 Subject: [PATCH 04/58] import_frame for anim_encoder_add --- src/PIL/WebPImagePlugin.py | 7 +-- src/_webp.c | 114 ++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 65 deletions(-) diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index 3eeba9400..8251316d3 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -248,11 +248,8 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: # Append the frame to the animation encoder enc.add( - frame.tobytes(), + frame.im.ptr, round(timestamp), - frame.size[0], - frame.size[1], - frame.mode, lossless, quality, alpha_quality, @@ -270,7 +267,7 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: im.seek(cur_idx) # Force encoder to flush frames - enc.add(None, round(timestamp), 0, 0, "", lossless, quality, alpha_quality, 0) + enc.add(None, round(timestamp), lossless, quality, alpha_quality, 0) # Get the final output from the encoder data = enc.assemble(icc_profile, exif, xmp) diff --git a/src/_webp.c b/src/_webp.c index ede261df6..9717b9bc0 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -83,6 +83,46 @@ HandleMuxError(WebPMuxError err, char *chunk) { return NULL; } +/* -------------------------------------------------------------------- */ +/* Frame import */ +/* -------------------------------------------------------------------- */ + +static int +import_frame_libwebp(WebPPicture *frame, Imaging im) { + UINT32 mask = 0; + + if (strcmp(im->mode, "RGBA") && strcmp(im->mode, "RGB") && + strcmp(im->mode, "RGBX")) { + PyErr_SetString(PyExc_ValueError, "unsupported image mode"); + return -1; + } + + if (strcmp(im->mode, "RGBA")) { + mask = MASK_UINT32_CHANNEL_3; + } + + frame->width = im->xsize; + frame->height = im->ysize; + frame->use_argb = 1; // Don't convert RGB pixels to YUV + + if (!WebPPictureAlloc(frame)) { + PyErr_SetString(PyExc_MemoryError, "can't allocate picture frame"); + return -2; + } + + for (int y = 0; y < im->ysize; ++y) { + UINT8 *src = (UINT8 *)im->image32[y]; + UINT32 *dst = frame->argb + frame->argb_stride * y; + for (int x = 0; x < im->xsize; ++x) { + UINT32 pix = + MAKE_UINT32(src[x * 4 + 2], src[x * 4 + 1], src[x * 4], src[x * 4 + 3]); + dst[x] = pix | mask; + } + } + + return 0; +} + /* -------------------------------------------------------------------- */ /* WebP Animation Support */ /* -------------------------------------------------------------------- */ @@ -180,12 +220,9 @@ _anim_encoder_dealloc(PyObject *self) { PyObject * _anim_encoder_add(PyObject *self, PyObject *args) { - uint8_t *rgb; - Py_ssize_t size; + PyObject *i0; + Imaging im; int timestamp; - int width; - int height; - char *mode; int lossless; float quality_factor; float alpha_quality_factor; @@ -198,13 +235,9 @@ _anim_encoder_add(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple( args, - "z#iiisiffi", - (char **)&rgb, - &size, + "Oiiffi", + &i0, ×tamp, - &width, - &height, - &mode, &lossless, &quality_factor, &alpha_quality_factor, @@ -214,11 +247,18 @@ _anim_encoder_add(PyObject *self, PyObject *args) { } // Check for NULL frame, which sets duration of final frame - if (!rgb) { + if (i0 == Py_None) { WebPAnimEncoderAdd(enc, NULL, timestamp, NULL); Py_RETURN_NONE; } + if (!PyCapsule_IsValid(i0, IMAGING_MAGIC)) { + PyErr_Format(PyExc_TypeError, "Expected '%s' Capsule", IMAGING_MAGIC); + return NULL; + } + + im = (Imaging)PyCapsule_GetPointer(i0, IMAGING_MAGIC); + // Setup config for this frame if (!WebPConfigInit(&config)) { PyErr_SetString(PyExc_RuntimeError, "failed to initialize config!"); @@ -235,16 +275,8 @@ _anim_encoder_add(PyObject *self, PyObject *args) { return NULL; } - // Populate the frame with raw bytes passed to us - frame->width = width; - frame->height = height; - frame->use_argb = 1; // Don't convert RGB pixels to YUV - if (strcmp(mode, "RGBA") == 0) { - WebPPictureImportRGBA(frame, rgb, 4 * width); - } else if (strcmp(mode, "RGBX") == 0) { - WebPPictureImportRGBX(frame, rgb, 4 * width); - } else { - WebPPictureImportRGB(frame, rgb, 3 * width); + if (import_frame_libwebp(frame, im)) { + return NULL; } ImagingSectionEnter(&cookie); @@ -570,44 +602,6 @@ static PyTypeObject WebPAnimDecoder_Type = { 0, /*tp_getset*/ }; -/* -------------------------------------------------------------------- */ -/* Frame import */ -/* -------------------------------------------------------------------- */ - -static int -import_frame_libwebp(WebPPicture *frame, Imaging im) { - UINT32 mask = 0; - - if (strcmp(im->mode, "RGBA") && strcmp(im->mode, "RGB") && strcmp(im->mode, "RGBX")) { - PyErr_SetString(PyExc_ValueError, "unsupported image mode"); - return -1; - } - - if (strcmp(im->mode, "RGBA")) { - mask = MASK_UINT32_CHANNEL_3; - } - - frame->width = im->xsize; - frame->height = im->ysize; - frame->use_argb = 1; // Don't convert RGB pixels to YUV - - if (!WebPPictureAlloc(frame)) { - PyErr_SetString(PyExc_MemoryError, "can't allocate picture frame"); - return -2; - } - - for (int y = 0; y < im->ysize; ++y) { - UINT8 *src = (UINT8 *)im->image32[y]; - UINT32 *dst = frame->argb + frame->argb_stride * y; - for (int x = 0; x < im->xsize; ++x) { - UINT32 pix = MAKE_UINT32(src[x * 4 + 2], src[x * 4 + 1], src[x * 4], src[x * 4 + 3]); - dst[x] = pix | mask; - } - } - - return 0; -} - /* -------------------------------------------------------------------- */ /* Legacy WebP Support */ /* -------------------------------------------------------------------- */ From d1f40a94ffe783aceb7050d85fa5c17ecc4961a7 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Mon, 16 Sep 2024 10:52:06 +0200 Subject: [PATCH 05/58] Use Image.getim() instead of ImagingCore.ptr --- src/PIL/WebPImagePlugin.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index 8251316d3..ab545563f 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -239,7 +239,6 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: for idx in range(nfr): ims.seek(idx) - ims.load() # Make sure image mode is supported frame = ims @@ -248,7 +247,7 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: # Append the frame to the animation encoder enc.add( - frame.im.ptr, + frame.getim(), round(timestamp), lossless, quality, @@ -296,7 +295,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: im = im.convert("RGBA" if im.has_transparency_data else "RGB") data = _webp.WebPEncode( - im.im.ptr, + im.getim(), lossless, float(quality), float(alpha_quality), From 31d36e6b70e1e835bcc6d70f363cda49d3bc9e98 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Mon, 16 Sep 2024 11:04:00 +0200 Subject: [PATCH 06/58] Use current frame for transparency detection --- Tests/test_file_webp.py | 2 +- src/PIL/WebPImagePlugin.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index 719831db9..e7c887279 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -208,7 +208,7 @@ class TestFileWebp: def test_background_from_gif(self, tmp_path: Path) -> None: out_webp = tmp_path / "temp.webp" - + # Save L mode GIF with background with Image.open("Tests/images/no_palette_with_background.gif") as im: im.save(out_webp, save_all=True) diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index ab545563f..1a714d7ea 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -243,7 +243,9 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: # Make sure image mode is supported frame = ims if frame.mode not in ("RGBX", "RGBA", "RGB"): - frame = frame.convert("RGBA" if im.has_transparency_data else "RGB") + frame = frame.convert( + "RGBA" if frame.has_transparency_data else "RGB" + ) # Append the frame to the animation encoder enc.add( From 1d5b330758c1e9210a8c00c457b03a1f19903939 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Mon, 16 Sep 2024 15:37:57 +0200 Subject: [PATCH 07/58] Move common conversion in _convert_frame --- src/PIL/WebPImagePlugin.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index 1a714d7ea..64188f28c 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -149,6 +149,13 @@ class WebPImageFile(ImageFile.ImageFile): return self.__logical_frame +def _convert_frame(im: Image.Image) -> Image.Image: + # Make sure image mode is supported + if im.mode not in ("RGBX", "RGBA", "RGB"): + im = im.convert("RGBA" if im.has_transparency_data else "RGB") + return im + + def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: encoderinfo = im.encoderinfo.copy() append_images = list(encoderinfo.get("append_images", [])) @@ -240,12 +247,7 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: for idx in range(nfr): ims.seek(idx) - # Make sure image mode is supported - frame = ims - if frame.mode not in ("RGBX", "RGBA", "RGB"): - frame = frame.convert( - "RGBA" if frame.has_transparency_data else "RGB" - ) + frame = _convert_frame(ims) # Append the frame to the animation encoder enc.add( @@ -293,8 +295,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: method = im.encoderinfo.get("method", 4) exact = 1 if im.encoderinfo.get("exact") else 0 - if im.mode not in ("RGBX", "RGBA", "RGB"): - im = im.convert("RGBA" if im.has_transparency_data else "RGB") + im = _convert_frame(im) data = _webp.WebPEncode( im.getim(), From a988750595af555e07af0e937ab6f6697a5bb1e1 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Mon, 16 Sep 2024 16:37:39 +0200 Subject: [PATCH 08/58] Try fix bigendian --- src/_webp.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/_webp.c b/src/_webp.c index 9717b9bc0..92d5c20fe 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -89,7 +89,7 @@ HandleMuxError(WebPMuxError err, char *chunk) { static int import_frame_libwebp(WebPPicture *frame, Imaging im) { - UINT32 mask = 0; + int drop_alpha = strcmp(im->mode, "RGBA"); if (strcmp(im->mode, "RGBA") && strcmp(im->mode, "RGB") && strcmp(im->mode, "RGBX")) { @@ -97,10 +97,6 @@ import_frame_libwebp(WebPPicture *frame, Imaging im) { return -1; } - if (strcmp(im->mode, "RGBA")) { - mask = MASK_UINT32_CHANNEL_3; - } - frame->width = im->xsize; frame->height = im->ysize; frame->use_argb = 1; // Don't convert RGB pixels to YUV @@ -113,10 +109,18 @@ import_frame_libwebp(WebPPicture *frame, Imaging im) { for (int y = 0; y < im->ysize; ++y) { UINT8 *src = (UINT8 *)im->image32[y]; UINT32 *dst = frame->argb + frame->argb_stride * y; - for (int x = 0; x < im->xsize; ++x) { - UINT32 pix = - MAKE_UINT32(src[x * 4 + 2], src[x * 4 + 1], src[x * 4], src[x * 4 + 3]); - dst[x] = pix | mask; + if (drop_alpha) { + for (int x = 0; x < im->xsize; ++x) { + dst[x] = + ((UINT32)(src[x * 4 + 2]) | ((UINT32)(src[x * 4 + 1]) << 8) | + ((UINT32)(src[x * 4]) << 16) | (0xff << 24)); + } + } else { + for (int x = 0; x < im->xsize; ++x) { + dst[x] = + ((UINT32)(src[x * 4 + 2]) | ((UINT32)(src[x * 4 + 1]) << 8) | + ((UINT32)(src[x * 4]) << 16) | ((UINT32)(src[x * 4 + 3]) << 24)); + } } } From e33d8bb32bd04c5b29afa3dca52bce9cb2bbffbd Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:19:53 +0300 Subject: [PATCH 09/58] Generate and upload attestations to PyPI --- .github/workflows/wheels.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 11564c142..35ea0496d 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -296,3 +296,5 @@ jobs: merge-multiple: true - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + attestations: true From e57da68190ee685ae8aac898623d3c52963816d2 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 20 Sep 2024 19:20:53 +1000 Subject: [PATCH 10/58] Check image value before use --- src/libImaging/Geometry.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libImaging/Geometry.c b/src/libImaging/Geometry.c index 84aa442f0..1e2abd7e7 100644 --- a/src/libImaging/Geometry.c +++ b/src/libImaging/Geometry.c @@ -791,15 +791,15 @@ ImagingGenericTransform( char *out; double xx, yy; + if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) { + return (Imaging)ImagingError_ModeError(); + } + ImagingTransformFilter filter = getfilter(imIn, filterid); if (!filter) { return (Imaging)ImagingError_ValueError("bad filter number"); } - if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) { - return (Imaging)ImagingError_ModeError(); - } - ImagingCopyPalette(imOut, imIn); ImagingSectionEnter(&cookie); From 83c7043471df575e446c44a4d384df56cd76538b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 21 Sep 2024 15:54:27 +1000 Subject: [PATCH 11/58] Rename variable, since alpha channel is not dropped --- src/_webp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/_webp.c b/src/_webp.c index 92d5c20fe..dfda7048d 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -89,8 +89,6 @@ HandleMuxError(WebPMuxError err, char *chunk) { static int import_frame_libwebp(WebPPicture *frame, Imaging im) { - int drop_alpha = strcmp(im->mode, "RGBA"); - if (strcmp(im->mode, "RGBA") && strcmp(im->mode, "RGB") && strcmp(im->mode, "RGBX")) { PyErr_SetString(PyExc_ValueError, "unsupported image mode"); @@ -106,10 +104,11 @@ import_frame_libwebp(WebPPicture *frame, Imaging im) { return -2; } + int ignore_fourth_channel = strcmp(im->mode, "RGBA"); for (int y = 0; y < im->ysize; ++y) { UINT8 *src = (UINT8 *)im->image32[y]; UINT32 *dst = frame->argb + frame->argb_stride * y; - if (drop_alpha) { + if (ignore_fourth_channel) { for (int x = 0; x < im->xsize; ++x) { dst[x] = ((UINT32)(src[x * 4 + 2]) | ((UINT32)(src[x * 4 + 1]) << 8) | From 75cb1c1b87ae4be028f3e15141c14c28dd0d04a0 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 21 Sep 2024 16:02:23 +1000 Subject: [PATCH 12/58] Test unsupported image mode --- Tests/test_file_webp.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index e7c887279..79f6bb4e0 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -127,6 +127,11 @@ class TestFileWebp: reloaded.seek(1) assert_image_similar(im2, reloaded, 1) + def test_unsupported_image_mode(self) -> None: + im = Image.new("1", (1, 1)) + with pytest.raises(ValueError): + _webp.WebPEncode(im.getim(), False, 0, 0, "", 4, 0, b"", "") + def test_icc_profile(self, tmp_path: Path) -> None: self._roundtrip(tmp_path, self.rgb_mode, 12.5, {"icc_profile": None}) self._roundtrip( From d8e3572caad2f3dce65db6951909f161a4021687 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 26 Sep 2024 08:52:29 +1000 Subject: [PATCH 13/58] Updated fribidi to 1.0.16 --- winbuild/build_prepare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index 84ad6417e..026d9d306 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -111,7 +111,7 @@ ARCHITECTURES = { V = { "BROTLI": "1.1.0", "FREETYPE": "2.13.3", - "FRIBIDI": "1.0.15", + "FRIBIDI": "1.0.16", "HARFBUZZ": "10.0.1", "JPEGTURBO": "3.0.4", "LCMS2": "2.16", From 4ca2b92503ed0250d7e48bf4c187c4fd1dbbdc54 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 27 Sep 2024 14:59:27 +1000 Subject: [PATCH 14/58] Use $IS_ALPINE instead of $MB_ML_LIBC --- .github/workflows/wheels-dependencies.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index b5fbdc421..5175a2a92 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -156,12 +156,10 @@ if [[ -n "$IS_MACOS" ]]; then fi brew install meson pkg-config -elif [[ "$MB_ML_LIBC" == "manylinux" ]]; then - if [[ "$HARFBUZZ_VERSION" != 8.5.0 ]]; then - yum install -y meson - fi -else +elif [[ -n "$IS_ALPINE" ]]; then apk add meson +elif [[ "$HARFBUZZ_VERSION" != 8.5.0 ]]; then + yum install -y meson fi wrap_wheel_builder build From 71da6d8952c174fa0a465fa6caf98989d6eff9c9 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 27 Sep 2024 16:37:10 +1000 Subject: [PATCH 15/58] Downgrade harfbuzz on OSS Fuzz --- .github/workflows/wheels-dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index 5175a2a92..4289afdf3 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -16,7 +16,7 @@ ARCHIVE_SDIR=pillow-depends-main # Package versions for fresh source builds FREETYPE_VERSION=2.13.2 -if [[ "$MB_ML_VER" != 2014 ]]; then +if [[ "$MB_ML_VER" != 2014 ]] && [[ -z "$SANITIZER" ]]; then HARFBUZZ_VERSION=10.0.1 else HARFBUZZ_VERSION=8.5.0 From fb8db83122a2f942958fc93103ad7b043cca3a3b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 27 Sep 2024 17:35:06 +1000 Subject: [PATCH 16/58] Updated harfbuzz to 10.0.1 on macOS --- .github/workflows/wheels-dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index 4289afdf3..bb0f8a307 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -16,7 +16,7 @@ ARCHIVE_SDIR=pillow-depends-main # Package versions for fresh source builds FREETYPE_VERSION=2.13.2 -if [[ "$MB_ML_VER" != 2014 ]] && [[ -z "$SANITIZER" ]]; then +if [[ -n "$IS_MACOS" ]] || ([[ "$MB_ML_VER" != 2014 ]] && [[ -z "$SANITIZER" ]]); then HARFBUZZ_VERSION=10.0.1 else HARFBUZZ_VERSION=8.5.0 From 485a062010d0942f88686dbf7ece6a765d329e53 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 27 Sep 2024 23:13:03 +1000 Subject: [PATCH 17/58] Update CHANGES.rst [ci skip] --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index ae7370a79..6ff35ea4f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,9 @@ Changelog (Pillow) 11.0.0 (unreleased) ------------------- +- Use Capsule for WebP saving #8386 + [homm, radarhere] + - Fixed writing multiple StripOffsets to TIFF #8317 [Yay295, radarhere] From bda62c1ac52f6a843263d2e195025d204a094f78 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 27 Sep 2024 22:11:03 +1000 Subject: [PATCH 18/58] Revert "Temporarily disable cifuzz" This reverts commit 31469407166026ec6d74d2df07196ef2d4e32ab4. --- .github/workflows/cifuzz.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index 033ff98ce..eb73fc6a7 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -24,8 +24,6 @@ concurrency: jobs: Fuzzing: - # Disabled until google/oss-fuzz#11419 upgrades Python to 3.9+ - if: false runs-on: ubuntu-latest steps: - name: Build Fuzzers From 04a00d273c6fe72f8a2f4099950831deb8ad5407 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 28 Sep 2024 14:27:40 +1000 Subject: [PATCH 19/58] Support all resampling filters when resizing I;16* images --- Tests/test_image_resize.py | 16 ++++++-- src/_imaging.c | 10 ++--- src/libImaging/Resample.c | 84 +++++++++++++++++++++++++++++++++++++- 3 files changed, 99 insertions(+), 11 deletions(-) diff --git a/Tests/test_image_resize.py b/Tests/test_image_resize.py index d9ddf5009..1cd9c3800 100644 --- a/Tests/test_image_resize.py +++ b/Tests/test_image_resize.py @@ -44,9 +44,19 @@ class TestImagingCoreResize: self.resize(hopper("1"), (15, 12), Image.Resampling.BILINEAR) with pytest.raises(ValueError): self.resize(hopper("P"), (15, 12), Image.Resampling.BILINEAR) - with pytest.raises(ValueError): - self.resize(hopper("I;16"), (15, 12), Image.Resampling.BILINEAR) - for mode in ["L", "I", "F", "RGB", "RGBA", "CMYK", "YCbCr"]: + for mode in [ + "L", + "I", + "I;16", + "I;16L", + "I;16B", + "I;16N", + "F", + "RGB", + "RGBA", + "CMYK", + "YCbCr", + ]: im = hopper(mode) r = self.resize(im, (15, 12), Image.Resampling.BILINEAR) assert r.mode == mode diff --git a/src/_imaging.c b/src/_imaging.c index 07d9a64cc..426036335 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -1579,16 +1579,12 @@ _putdata(ImagingObject *self, PyObject *args) { int bigendian = 0; if (image->type == IMAGING_TYPE_SPECIAL) { // I;16* - if (strcmp(image->mode, "I;16N") == 0) { + if (strcmp(image->mode, "I;16B") == 0 #ifdef WORDS_BIGENDIAN - bigendian = 1; -#else - bigendian = 0; + || strcmp(image->mode, "I;16N") == 0 #endif - } else if (strcmp(image->mode, "I;16B") == 0) { + ) { bigendian = 1; - } else { - bigendian = 0; } } for (i = x = y = 0; i < n; i++) { diff --git a/src/libImaging/Resample.c b/src/libImaging/Resample.c index 222d6bca4..f5e386dc2 100644 --- a/src/libImaging/Resample.c +++ b/src/libImaging/Resample.c @@ -460,6 +460,83 @@ ImagingResampleVertical_8bpc( ImagingSectionLeave(&cookie); } +void +ImagingResampleHorizontal_16bpc( + Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk +) { + ImagingSectionCookie cookie; + double ss; + int xx, yy, x, xmin, xmax, ss_int; + double *k; + + int bigendian = 0; + if (strcmp(imIn->mode, "I;16N") == 0 +#ifdef WORDS_BIGENDIAN + || strcmp(imIn->mode, "I;16B") == 0 +#endif + ) { + bigendian = 1; + } + + ImagingSectionEnter(&cookie); + for (yy = 0; yy < imOut->ysize; yy++) { + for (xx = 0; xx < imOut->xsize; xx++) { + xmin = bounds[xx * 2 + 0]; + xmax = bounds[xx * 2 + 1]; + k = &kk[xx * ksize]; + ss = 0.0; + for (x = 0; x < xmax; x++) { + ss += (imIn->image8[yy + offset][(x + xmin) * 2 + (bigendian ? 1 : 0)] + + (imIn->image8[yy + offset][(x + xmin) * 2 + (bigendian ? 0 : 1)] + << 8)) * + k[x]; + } + ss_int = ROUND_UP(ss); + imOut->image8[yy][xx * 2 + (bigendian ? 1 : 0)] = CLIP8(ss_int % 256); + imOut->image8[yy][xx * 2 + (bigendian ? 0 : 1)] = CLIP8(ss_int >> 8); + } + } + ImagingSectionLeave(&cookie); +} + +void +ImagingResampleVertical_16bpc( + Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk +) { + ImagingSectionCookie cookie; + double ss; + int xx, yy, y, ymin, ymax, ss_int; + double *k; + + int bigendian = 0; + if (strcmp(imIn->mode, "I;16N") == 0 +#ifdef WORDS_BIGENDIAN + || strcmp(imIn->mode, "I;16B") == 0 +#endif + ) { + bigendian = 1; + } + + ImagingSectionEnter(&cookie); + for (yy = 0; yy < imOut->ysize; yy++) { + ymin = bounds[yy * 2 + 0]; + ymax = bounds[yy * 2 + 1]; + k = &kk[yy * ksize]; + for (xx = 0; xx < imOut->xsize; xx++) { + ss = 0.0; + for (y = 0; y < ymax; y++) { + ss += (imIn->image8[y + ymin][xx * 2 + (bigendian ? 1 : 0)] + + (imIn->image8[y + ymin][xx * 2 + (bigendian ? 0 : 1)] << 8)) * + k[y]; + } + ss_int = ROUND_UP(ss); + imOut->image8[yy][xx * 2 + (bigendian ? 1 : 0)] = CLIP8(ss_int % 256); + imOut->image8[yy][xx * 2 + (bigendian ? 0 : 1)] = CLIP8(ss_int >> 8); + } + } + ImagingSectionLeave(&cookie); +} + void ImagingResampleHorizontal_32bpc( Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk @@ -574,7 +651,12 @@ ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4]) { } if (imIn->type == IMAGING_TYPE_SPECIAL) { - return (Imaging)ImagingError_ModeError(); + if (strncmp(imIn->mode, "I;16", 4) == 0) { + ResampleHorizontal = ImagingResampleHorizontal_16bpc; + ResampleVertical = ImagingResampleVertical_16bpc; + } else { + return (Imaging)ImagingError_ModeError(); + } } else if (imIn->image8) { ResampleHorizontal = ImagingResampleHorizontal_8bpc; ResampleVertical = ImagingResampleVertical_8bpc; From e306546bf18b01c9bfa68ea397f2f5d5690113e0 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 28 Sep 2024 15:10:16 +1000 Subject: [PATCH 20/58] Use ruff check --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 94f7565d8..ec4159627 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,7 @@ lint-fix: python3 -c "import black" > /dev/null 2>&1 || python3 -m pip install black python3 -m black . python3 -c "import ruff" > /dev/null 2>&1 || python3 -m pip install ruff - python3 -m ruff --fix . + python3 -m ruff check --fix . .PHONY: mypy mypy: From 2e73ffe7034457461b13da71b05645999dd3c0ef Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 28 Sep 2024 15:29:09 +1000 Subject: [PATCH 21/58] Exclude multibuild from black and ruff --- pyproject.toml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 228c344e8..0d0a6f170 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -97,9 +97,13 @@ config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable" test-command = "cd {project} && .github/workflows/wheels-test.sh" test-extras = "tests" -[tool.ruff] -fix = true +[tool.black] +exclude = "wheels/multibuild" +[tool.ruff] +exclude = [ "wheels/multibuild" ] + +fix = true lint.select = [ "C4", # flake8-comprehensions "E", # pycodestyle errors From d33270ab51f6b62710b227394f2dadf913370d96 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 28 Sep 2024 15:35:42 +1000 Subject: [PATCH 22/58] Set default resize sampling for I;16* images to BICUBIC --- Tests/test_image_resize.py | 8 ++++---- docs/releasenotes/11.0.0.rst | 7 ++++--- src/PIL/Image.py | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Tests/test_image_resize.py b/Tests/test_image_resize.py index 1cd9c3800..8548fb5da 100644 --- a/Tests/test_image_resize.py +++ b/Tests/test_image_resize.py @@ -315,14 +315,14 @@ class TestImageResize: im = im.resize((64, 64)) assert im.size == (64, 64) - @pytest.mark.parametrize("mode", ("L", "RGB", "I", "F")) + @pytest.mark.parametrize( + "mode", ("L", "RGB", "I", "I;16", "I;16L", "I;16B", "I;16N", "F") + ) def test_default_filter_bicubic(self, mode: str) -> None: im = hopper(mode) assert im.resize((20, 20), Image.Resampling.BICUBIC) == im.resize((20, 20)) - @pytest.mark.parametrize( - "mode", ("1", "P", "I;16", "I;16L", "I;16B", "BGR;15", "BGR;16") - ) + @pytest.mark.parametrize("mode", ("1", "P", "BGR;15", "BGR;16")) def test_default_filter_nearest(self, mode: str) -> None: im = hopper(mode) assert im.resize((20, 20), Image.Resampling.NEAREST) == im.resize((20, 20)) diff --git a/docs/releasenotes/11.0.0.rst b/docs/releasenotes/11.0.0.rst index 36334e39f..1218c5014 100644 --- a/docs/releasenotes/11.0.0.rst +++ b/docs/releasenotes/11.0.0.rst @@ -119,10 +119,11 @@ Specific WebP Feature Checks API Changes =========== -TODO -^^^^ +Default resampling filter for I;16* image modes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -TODO +The default resampling filter for I;16, I;16L, I;16B and I;16N has been changed from +``Image.NEAREST`` to ``Image.BICUBIC``, to match the majority of modes. API Additions ============= diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 3f94cef38..bf9079f8b 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2278,8 +2278,8 @@ class Image: :py:data:`Resampling.BILINEAR`, :py:data:`Resampling.HAMMING`, :py:data:`Resampling.BICUBIC` or :py:data:`Resampling.LANCZOS`. If the image has mode "1" or "P", it is always set to - :py:data:`Resampling.NEAREST`. If the image mode specifies a number - of bits, such as "I;16", then the default filter is + :py:data:`Resampling.NEAREST`. If the image mode is "BGR;15", + "BGR;16" or "BGR;24", then the default filter is :py:data:`Resampling.NEAREST`. Otherwise, the default filter is :py:data:`Resampling.BICUBIC`. See: :ref:`concept-filters`. :param box: An optional 4-tuple of floats providing @@ -2302,8 +2302,8 @@ class Image: """ if resample is None: - type_special = ";" in self.mode - resample = Resampling.NEAREST if type_special else Resampling.BICUBIC + bgr = self.mode.startswith("BGR;") + resample = Resampling.NEAREST if bgr else Resampling.BICUBIC elif resample not in ( Resampling.NEAREST, Resampling.BILINEAR, From 30fca7a1d62a8b41f3536adb35355f5aa81c6a2f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 28 Sep 2024 18:38:45 +1000 Subject: [PATCH 23/58] Install meson through pip --- .github/workflows/wheels-dependencies.sh | 36 ++++++++---------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index bb0f8a307..b3996d5a1 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -16,11 +16,7 @@ ARCHIVE_SDIR=pillow-depends-main # Package versions for fresh source builds FREETYPE_VERSION=2.13.2 -if [[ -n "$IS_MACOS" ]] || ([[ "$MB_ML_VER" != 2014 ]] && [[ -z "$SANITIZER" ]]); then - HARFBUZZ_VERSION=10.0.1 -else - HARFBUZZ_VERSION=8.5.0 -fi +HARFBUZZ_VERSION=10.0.1 LIBPNG_VERSION=1.6.44 JPEGTURBO_VERSION=3.0.4 OPENJPEG_VERSION=2.5.2 @@ -65,21 +61,15 @@ function build_brotli { } function build_harfbuzz { - if [[ "$HARFBUZZ_VERSION" == 8.5.0 ]]; then - export FREETYPE_LIBS=-lfreetype - export FREETYPE_CFLAGS=-I/usr/local/include/freetype2/ - build_simple harfbuzz $HARFBUZZ_VERSION https://github.com/harfbuzz/harfbuzz/releases/download/$HARFBUZZ_VERSION tar.xz --with-freetype=yes --with-glib=no - export FREETYPE_LIBS="" - export FREETYPE_CFLAGS="" - else - local out_dir=$(fetch_unpack https://github.com/harfbuzz/harfbuzz/releases/download/$HARFBUZZ_VERSION/$HARFBUZZ_VERSION.tar.xz harfbuzz-$HARFBUZZ_VERSION.tar.xz) - (cd $out_dir \ - && meson setup build --buildtype=release -Dfreetype=enabled -Dglib=disabled) - (cd $out_dir/build \ - && meson install) - if [[ "$MB_ML_LIBC" == "manylinux" ]]; then - cp /usr/local/lib64/libharfbuzz* /usr/local/lib - fi + python3 -m pip install meson ninja + + local out_dir=$(fetch_unpack https://github.com/harfbuzz/harfbuzz/releases/download/$HARFBUZZ_VERSION/$HARFBUZZ_VERSION.tar.xz harfbuzz-$HARFBUZZ_VERSION.tar.xz) + (cd $out_dir \ + && meson setup build --buildtype=release -Dfreetype=enabled -Dglib=disabled) + (cd $out_dir/build \ + && meson install) + if [[ "$MB_ML_LIBC" == "manylinux" ]]; then + cp /usr/local/lib64/libharfbuzz* /usr/local/lib fi } @@ -155,11 +145,7 @@ if [[ -n "$IS_MACOS" ]]; then brew remove --ignore-dependencies webp fi - brew install meson pkg-config -elif [[ -n "$IS_ALPINE" ]]; then - apk add meson -elif [[ "$HARFBUZZ_VERSION" != 8.5.0 ]]; then - yum install -y meson + brew install pkg-config fi wrap_wheel_builder build From e976096c2eda0a41c49e0f06e6f84f6b3d0c99b0 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 28 Sep 2024 20:39:04 +1000 Subject: [PATCH 24/58] Allow libimagequant shared library path to change --- depends/install_imagequant.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/depends/install_imagequant.sh b/depends/install_imagequant.sh index 060d9840e..8d62d5ac7 100755 --- a/depends/install_imagequant.sh +++ b/depends/install_imagequant.sh @@ -23,19 +23,14 @@ else cargo cinstall --prefix=/usr --destdir=. # Copy into place - if [ -d "usr/lib64" ]; then - lib="lib64" - else - lib="lib" - fi - sudo cp usr/$lib/libimagequant.so* /usr/lib/ + sudo find usr -name libimagequant.so* -exec cp {} /usr/lib/ \; sudo cp usr/include/libimagequant.h /usr/include/ if [ -n "$GITHUB_ACTIONS" ]; then # Copy to cache rm -rf ~/cache-$archive_name mkdir ~/cache-$archive_name - cp usr/lib/libimagequant.so* ~/cache-$archive_name/ + find usr -name libimagequant.so* -exec cp {} ~/cache-$archive_name/ \; cp usr/include/libimagequant.h ~/cache-$archive_name/ fi From ed143f5fec816c7164ff2d8a76deef6a8abfaf77 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 29 Sep 2024 06:40:50 +1000 Subject: [PATCH 25/58] Update CHANGES.rst [ci skip] --- CHANGES.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 6ff35ea4f..b4644c541 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,15 +5,15 @@ Changelog (Pillow) 11.0.0 (unreleased) ------------------- +- Improved copying imagequant libraries #8420 + [radarhere] + - Use Capsule for WebP saving #8386 [homm, radarhere] - Fixed writing multiple StripOffsets to TIFF #8317 [Yay295, radarhere] -- Shared imagequant libraries may be located within usr/lib64 #8407 - [radarhere] - - Fix dereference before checking for NULL in ImagingTransformAffine #8398 [PavlNekrasov] From 3a734b5d4b2ee9d602e4d7d3e89530498bac5e68 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 29 Sep 2024 05:19:39 +0000 Subject: [PATCH 26/58] Update scientific-python/upload-nightly-action action to v0.6.0 --- .github/workflows/wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index d3c2ac44c..ee0c33166 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -278,7 +278,7 @@ jobs: path: dist merge-multiple: true - name: Upload wheels to scientific-python-nightly-wheels - uses: scientific-python/upload-nightly-action@b67d7fcc0396e1128a474d1ab2b48aa94680f9fc # 0.5.0 + uses: scientific-python/upload-nightly-action@ccf29c805b5d0c1dc31fa97fcdb962be074cade3 # 0.6.0 with: artifacts_path: dist anaconda_nightly_upload_token: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }} From 21ab53e0c0f81427c45e4b4205d5d6d07008ee81 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 30 Sep 2024 12:38:13 +1000 Subject: [PATCH 27/58] Updated test environment documentation --- docs/installation/platform-support.rst | 2 +- winbuild/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/installation/platform-support.rst b/docs/installation/platform-support.rst index f2ef9cacb..9216248a0 100644 --- a/docs/installation/platform-support.rst +++ b/docs/installation/platform-support.rst @@ -48,7 +48,7 @@ These platforms are built and tested for every change. | Ubuntu Linux 24.04 LTS (Noble) | 3.12 | x86-64, ppc64le, | | | | s390x | +----------------------------------+----------------------------+---------------------+ -| Windows Server 2016 | 3.9 | x86-64 | +| Windows Server 2019 | 3.9 | x86-64 | +----------------------------------+----------------------------+---------------------+ | Windows Server 2022 | 3.9, 3.10, 3.11, | x86-64 | | | 3.12, 3.13, PyPy3 | | diff --git a/winbuild/README.md b/winbuild/README.md index c8048bcc9..f6111c79b 100644 --- a/winbuild/README.md +++ b/winbuild/README.md @@ -11,7 +11,7 @@ For more extensive info, see the [Windows build instructions](build.rst). * Requires Microsoft Visual Studio 2017 or newer with C++ component. * Requires NASM for libjpeg-turbo, a required dependency when using this script. * Requires CMake 3.15 or newer (available as Visual Studio component). -* Tested on Windows Server 2016 with Visual Studio 2017 Community, and Windows Server 2019 with Visual Studio 2022 Community (AppVeyor). +* Tested on Windows Server 2019 with Visual Studio 2019 Community and Visual Studio 2022 Community (AppVeyor). * Tested on Windows Server 2022 with Visual Studio 2022 Enterprise (GitHub Actions). The following is a simplified version of the script used on AppVeyor: From 7a62c788edb77e6c0c11f31a180018411d3955f6 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 30 Sep 2024 12:42:39 +1000 Subject: [PATCH 28/58] Updated tested Python versions --- docs/installation/platform-support.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/installation/platform-support.rst b/docs/installation/platform-support.rst index 9216248a0..4cd3f2814 100644 --- a/docs/installation/platform-support.rst +++ b/docs/installation/platform-support.rst @@ -17,13 +17,13 @@ These platforms are built and tested for every change. +----------------------------------+----------------------------+---------------------+ | Operating system | Tested Python versions | Tested architecture | +==================================+============================+=====================+ -| Alpine | 3.9 | x86-64 | +| Alpine | 3.12 | x86-64 | +----------------------------------+----------------------------+---------------------+ | Amazon Linux 2 | 3.9 | x86-64 | +----------------------------------+----------------------------+---------------------+ | Amazon Linux 2023 | 3.9 | x86-64 | +----------------------------------+----------------------------+---------------------+ -| Arch | 3.9 | x86-64 | +| Arch | 3.12 | x86-64 | +----------------------------------+----------------------------+---------------------+ | CentOS Stream 9 | 3.9 | x86-64 | +----------------------------------+----------------------------+---------------------+ @@ -33,7 +33,7 @@ These platforms are built and tested for every change. +----------------------------------+----------------------------+---------------------+ | Fedora 40 | 3.12 | x86-64 | +----------------------------------+----------------------------+---------------------+ -| Gentoo | 3.9 | x86-64 | +| Gentoo | 3.12 | x86-64 | +----------------------------------+----------------------------+---------------------+ | macOS 13 Ventura | 3.9 | x86-64 | +----------------------------------+----------------------------+---------------------+ From b94c5c5e3474f915e817d77cd984f62f8fd4399b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 30 Sep 2024 19:32:21 +1000 Subject: [PATCH 29/58] Updated macOS tested Pillow versions --- docs/installation/platform-support.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/installation/platform-support.rst b/docs/installation/platform-support.rst index f2ef9cacb..28f749867 100644 --- a/docs/installation/platform-support.rst +++ b/docs/installation/platform-support.rst @@ -75,6 +75,8 @@ These platforms have been reported to work at the versions mentioned. | Operating system | | Tested Python | | Latest tested | | Tested | | | | versions | | Pillow version | | processors | +==================================+============================+==================+==============+ +| macOS 15 Sequoia | 3.8, 3.9, 3.10, 3.11, 3.12 | 10.4.0 |arm | ++----------------------------------+----------------------------+------------------+--------------+ | macOS 14 Sonoma | 3.8, 3.9, 3.10, 3.11, 3.12 | 10.4.0 |arm | +----------------------------------+----------------------------+------------------+--------------+ | macOS 13 Ventura | 3.8, 3.9, 3.10, 3.11 | 10.0.1 |arm | From cc0b6b9de94e7c632efb0a10cf985dd7aab74e2a Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 24 Sep 2024 07:56:45 +1000 Subject: [PATCH 30/58] Cast int before potentially exceeding INT_MAX --- src/libImaging/SgiRleDecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libImaging/SgiRleDecode.c b/src/libImaging/SgiRleDecode.c index a8db11740..a4ee2e10d 100644 --- a/src/libImaging/SgiRleDecode.c +++ b/src/libImaging/SgiRleDecode.c @@ -183,7 +183,7 @@ ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t each with 4 bytes per element of tablen Check here before we allocate any memory */ - if (c->bufsize < 8 * c->tablen) { + if (c->bufsize < 8 * (int64_t)c->tablen) { state->errcode = IMAGING_CODEC_OVERRUN; return -1; } From fc65e437cfc6ccc381792ca1f35c6afb44c66ec3 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 23 Sep 2024 23:25:42 +1000 Subject: [PATCH 31/58] Prevent division by zero --- src/libImaging/FliDecode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libImaging/FliDecode.c b/src/libImaging/FliDecode.c index 6b2518d35..130ecb7f7 100644 --- a/src/libImaging/FliDecode.c +++ b/src/libImaging/FliDecode.c @@ -224,7 +224,7 @@ ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt break; case 16: /* COPY chunk */ - if (INT32_MAX / state->xsize < state->ysize) { + if (INT32_MAX < (uint64_t)state->xsize * state->ysize) { /* Integer overflow, bail */ state->errcode = IMAGING_CODEC_OVERRUN; return -1; From 851449edfc1746a3ad63260db825ab3a2b23d331 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 24 Sep 2024 19:14:26 +1000 Subject: [PATCH 32/58] Free memory on early return --- src/libImaging/SgiRleDecode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libImaging/SgiRleDecode.c b/src/libImaging/SgiRleDecode.c index a8db11740..c285637dd 100644 --- a/src/libImaging/SgiRleDecode.c +++ b/src/libImaging/SgiRleDecode.c @@ -195,6 +195,7 @@ ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t } _imaging_seek_pyFd(state->fd, SGI_HEADER_SIZE, SEEK_SET); if (_imaging_read_pyFd(state->fd, (char *)ptr, c->bufsize) != c->bufsize) { + free(ptr); state->errcode = IMAGING_CODEC_UNKNOWN; return -1; } From a99361a38f4c0830205ccbe5d58f1f0ba6c7312c Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 13 Sep 2024 23:21:35 +1000 Subject: [PATCH 33/58] Raise an error if path is compacted during mapping --- Tests/test_imagepath.py | 11 +++++++++++ src/path.c | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py index cda2584e7..76bdf1e5f 100644 --- a/Tests/test_imagepath.py +++ b/Tests/test_imagepath.py @@ -204,6 +204,17 @@ def test_overflow_segfault() -> None: x[i] = b"0" * 16 +def test_compact_within_map() -> None: + p = ImagePath.Path([0, 1]) + + def map_func(x: float, y: float) -> tuple[float, float]: + p.compact() + return 0, 0 + + with pytest.raises(ValueError): + p.map(map_func) + + class Evil: def __init__(self) -> None: self.corrupt = Image.core.path(0x4000000000000000) diff --git a/src/path.c b/src/path.c index f4f4287f3..067f42f62 100644 --- a/src/path.c +++ b/src/path.c @@ -44,6 +44,7 @@ PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view); typedef struct { PyObject_HEAD Py_ssize_t count; double *xy; + int mapping; } PyPathObject; static PyTypeObject PyPathType; @@ -91,6 +92,7 @@ path_new(Py_ssize_t count, double *xy, int duplicate) { path->count = count; path->xy = xy; + path->mapping = 0; return path; } @@ -276,6 +278,10 @@ path_compact(PyPathObject *self, PyObject *args) { double cityblock = 2.0; + if (self->mapping) { + PyErr_SetString(PyExc_ValueError, "Path compacted during mapping"); + return NULL; + } if (!PyArg_ParseTuple(args, "|d:compact", &cityblock)) { return NULL; } @@ -393,11 +399,13 @@ path_map(PyPathObject *self, PyObject *args) { xy = self->xy; /* apply function to coordinate set */ + self->mapping = 1; for (i = 0; i < self->count; i++) { double x = xy[i + i]; double y = xy[i + i + 1]; PyObject *item = PyObject_CallFunction(function, "dd", x, y); if (!item || !PyArg_ParseTuple(item, "dd", &x, &y)) { + self->mapping = 0; Py_XDECREF(item); return NULL; } @@ -405,6 +413,7 @@ path_map(PyPathObject *self, PyObject *args) { xy[i + i + 1] = y; Py_DECREF(item); } + self->mapping = 0; Py_INCREF(Py_None); return Py_None; From c6b08ef32c39dc6517e9140c92dde7e10999da5e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 30 Sep 2024 22:13:24 +1000 Subject: [PATCH 34/58] Update CHANGES.rst [ci skip] --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index b4644c541..08c2f26bc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,9 @@ Changelog (Pillow) 11.0.0 (unreleased) ------------------- +- Check image value before use #8400 + [radarhere] + - Improved copying imagequant libraries #8420 [radarhere] From 6fe4375f28015f0c1a7c3cb6fbc9ea3c4f405679 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Sat, 3 Aug 2024 11:13:38 -0500 Subject: [PATCH 35/58] move eps test images to their own folder Co-authored-by: Andrew Murray --- Tests/images/{ => eps}/1.eps | Bin Tests/images/{ => eps}/binary_preview_map.eps | Bin Tests/images/{ => eps}/create_eps.gnuplot | 0 Tests/images/{ => eps}/illu10_no_preview.eps | Bin Tests/images/{ => eps}/illu10_preview.eps | Bin Tests/images/{ => eps}/illuCS6_no_preview.eps | Bin Tests/images/{ => eps}/illuCS6_preview.eps | Bin Tests/images/{ => eps}/non_zero_bb.eps | Bin Tests/images/{ => eps}/non_zero_bb.png | Bin Tests/images/{ => eps}/non_zero_bb_scale2.png | Bin Tests/images/{ => eps}/pil_sample_cmyk.eps | Bin Tests/images/{ => eps}/reqd_showpage.eps | Bin Tests/images/{ => eps}/reqd_showpage.png | Bin .../{ => eps}/reqd_showpage_transparency.png | Bin ...75703545fee17acab56e5fec644c19979175de.eps | Bin Tests/images/{ => eps}/zero_bb.eps | Bin Tests/images/{ => eps}/zero_bb.png | Bin Tests/images/{ => eps}/zero_bb_emptyline.eps | Bin .../zero_bb_eof_before_boundingbox.eps | Bin Tests/images/{ => eps}/zero_bb_scale2.png | Bin Tests/images/{ => eps}/zero_bb_trailer.eps | Bin Tests/test_file_eps.py | 48 +++++++++--------- Tests/test_pickle.py | 8 +-- 23 files changed, 29 insertions(+), 27 deletions(-) rename Tests/images/{ => eps}/1.eps (100%) rename Tests/images/{ => eps}/binary_preview_map.eps (100%) rename Tests/images/{ => eps}/create_eps.gnuplot (100%) rename Tests/images/{ => eps}/illu10_no_preview.eps (100%) rename Tests/images/{ => eps}/illu10_preview.eps (100%) rename Tests/images/{ => eps}/illuCS6_no_preview.eps (100%) rename Tests/images/{ => eps}/illuCS6_preview.eps (100%) rename Tests/images/{ => eps}/non_zero_bb.eps (100%) rename Tests/images/{ => eps}/non_zero_bb.png (100%) rename Tests/images/{ => eps}/non_zero_bb_scale2.png (100%) rename Tests/images/{ => eps}/pil_sample_cmyk.eps (100%) rename Tests/images/{ => eps}/reqd_showpage.eps (100%) rename Tests/images/{ => eps}/reqd_showpage.png (100%) rename Tests/images/{ => eps}/reqd_showpage_transparency.png (100%) rename Tests/images/{ => eps}/timeout-d675703545fee17acab56e5fec644c19979175de.eps (100%) rename Tests/images/{ => eps}/zero_bb.eps (100%) rename Tests/images/{ => eps}/zero_bb.png (100%) rename Tests/images/{ => eps}/zero_bb_emptyline.eps (100%) rename Tests/images/{ => eps}/zero_bb_eof_before_boundingbox.eps (100%) rename Tests/images/{ => eps}/zero_bb_scale2.png (100%) rename Tests/images/{ => eps}/zero_bb_trailer.eps (100%) diff --git a/Tests/images/1.eps b/Tests/images/eps/1.eps similarity index 100% rename from Tests/images/1.eps rename to Tests/images/eps/1.eps diff --git a/Tests/images/binary_preview_map.eps b/Tests/images/eps/binary_preview_map.eps similarity index 100% rename from Tests/images/binary_preview_map.eps rename to Tests/images/eps/binary_preview_map.eps diff --git a/Tests/images/create_eps.gnuplot b/Tests/images/eps/create_eps.gnuplot similarity index 100% rename from Tests/images/create_eps.gnuplot rename to Tests/images/eps/create_eps.gnuplot diff --git a/Tests/images/illu10_no_preview.eps b/Tests/images/eps/illu10_no_preview.eps similarity index 100% rename from Tests/images/illu10_no_preview.eps rename to Tests/images/eps/illu10_no_preview.eps diff --git a/Tests/images/illu10_preview.eps b/Tests/images/eps/illu10_preview.eps similarity index 100% rename from Tests/images/illu10_preview.eps rename to Tests/images/eps/illu10_preview.eps diff --git a/Tests/images/illuCS6_no_preview.eps b/Tests/images/eps/illuCS6_no_preview.eps similarity index 100% rename from Tests/images/illuCS6_no_preview.eps rename to Tests/images/eps/illuCS6_no_preview.eps diff --git a/Tests/images/illuCS6_preview.eps b/Tests/images/eps/illuCS6_preview.eps similarity index 100% rename from Tests/images/illuCS6_preview.eps rename to Tests/images/eps/illuCS6_preview.eps diff --git a/Tests/images/non_zero_bb.eps b/Tests/images/eps/non_zero_bb.eps similarity index 100% rename from Tests/images/non_zero_bb.eps rename to Tests/images/eps/non_zero_bb.eps diff --git a/Tests/images/non_zero_bb.png b/Tests/images/eps/non_zero_bb.png similarity index 100% rename from Tests/images/non_zero_bb.png rename to Tests/images/eps/non_zero_bb.png diff --git a/Tests/images/non_zero_bb_scale2.png b/Tests/images/eps/non_zero_bb_scale2.png similarity index 100% rename from Tests/images/non_zero_bb_scale2.png rename to Tests/images/eps/non_zero_bb_scale2.png diff --git a/Tests/images/pil_sample_cmyk.eps b/Tests/images/eps/pil_sample_cmyk.eps similarity index 100% rename from Tests/images/pil_sample_cmyk.eps rename to Tests/images/eps/pil_sample_cmyk.eps diff --git a/Tests/images/reqd_showpage.eps b/Tests/images/eps/reqd_showpage.eps similarity index 100% rename from Tests/images/reqd_showpage.eps rename to Tests/images/eps/reqd_showpage.eps diff --git a/Tests/images/reqd_showpage.png b/Tests/images/eps/reqd_showpage.png similarity index 100% rename from Tests/images/reqd_showpage.png rename to Tests/images/eps/reqd_showpage.png diff --git a/Tests/images/reqd_showpage_transparency.png b/Tests/images/eps/reqd_showpage_transparency.png similarity index 100% rename from Tests/images/reqd_showpage_transparency.png rename to Tests/images/eps/reqd_showpage_transparency.png diff --git a/Tests/images/timeout-d675703545fee17acab56e5fec644c19979175de.eps b/Tests/images/eps/timeout-d675703545fee17acab56e5fec644c19979175de.eps similarity index 100% rename from Tests/images/timeout-d675703545fee17acab56e5fec644c19979175de.eps rename to Tests/images/eps/timeout-d675703545fee17acab56e5fec644c19979175de.eps diff --git a/Tests/images/zero_bb.eps b/Tests/images/eps/zero_bb.eps similarity index 100% rename from Tests/images/zero_bb.eps rename to Tests/images/eps/zero_bb.eps diff --git a/Tests/images/zero_bb.png b/Tests/images/eps/zero_bb.png similarity index 100% rename from Tests/images/zero_bb.png rename to Tests/images/eps/zero_bb.png diff --git a/Tests/images/zero_bb_emptyline.eps b/Tests/images/eps/zero_bb_emptyline.eps similarity index 100% rename from Tests/images/zero_bb_emptyline.eps rename to Tests/images/eps/zero_bb_emptyline.eps diff --git a/Tests/images/zero_bb_eof_before_boundingbox.eps b/Tests/images/eps/zero_bb_eof_before_boundingbox.eps similarity index 100% rename from Tests/images/zero_bb_eof_before_boundingbox.eps rename to Tests/images/eps/zero_bb_eof_before_boundingbox.eps diff --git a/Tests/images/zero_bb_scale2.png b/Tests/images/eps/zero_bb_scale2.png similarity index 100% rename from Tests/images/zero_bb_scale2.png rename to Tests/images/eps/zero_bb_scale2.png diff --git a/Tests/images/zero_bb_trailer.eps b/Tests/images/eps/zero_bb_trailer.eps similarity index 100% rename from Tests/images/zero_bb_trailer.eps rename to Tests/images/eps/zero_bb_trailer.eps diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index d54deb515..89471fb5a 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -19,18 +19,18 @@ from .helper import ( HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript() # Our two EPS test files (they are identical except for their bounding boxes) -FILE1 = "Tests/images/zero_bb.eps" -FILE2 = "Tests/images/non_zero_bb.eps" +FILE1 = "Tests/images/eps/zero_bb.eps" +FILE2 = "Tests/images/eps/non_zero_bb.eps" # Due to palletization, we'll need to convert these to RGB after load -FILE1_COMPARE = "Tests/images/zero_bb.png" -FILE1_COMPARE_SCALE2 = "Tests/images/zero_bb_scale2.png" +FILE1_COMPARE = "Tests/images/eps/zero_bb.png" +FILE1_COMPARE_SCALE2 = "Tests/images/eps/zero_bb_scale2.png" -FILE2_COMPARE = "Tests/images/non_zero_bb.png" -FILE2_COMPARE_SCALE2 = "Tests/images/non_zero_bb_scale2.png" +FILE2_COMPARE = "Tests/images/eps/non_zero_bb.png" +FILE2_COMPARE_SCALE2 = "Tests/images/eps/non_zero_bb_scale2.png" # EPS test files with binary preview -FILE3 = "Tests/images/binary_preview_map.eps" +FILE3 = "Tests/images/eps/binary_preview_map.eps" # Three unsigned 32bit little-endian values: # 0xC6D3D0C5 magic number @@ -187,7 +187,7 @@ def test_load_long_binary_data(prefix: bytes) -> None: ) @pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available") def test_cmyk() -> None: - with Image.open("Tests/images/pil_sample_cmyk.eps") as cmyk_image: + with Image.open("Tests/images/eps/pil_sample_cmyk.eps") as cmyk_image: assert cmyk_image.mode == "CMYK" assert cmyk_image.size == (100, 100) assert cmyk_image.format == "EPS" @@ -204,8 +204,8 @@ def test_cmyk() -> None: @pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available") def test_showpage() -> None: # See https://github.com/python-pillow/Pillow/issues/2615 - with Image.open("Tests/images/reqd_showpage.eps") as plot_image: - with Image.open("Tests/images/reqd_showpage.png") as target: + with Image.open("Tests/images/eps/reqd_showpage.eps") as plot_image: + with Image.open("Tests/images/eps/reqd_showpage.png") as target: # should not crash/hang plot_image.load() # fonts could be slightly different @@ -214,11 +214,11 @@ def test_showpage() -> None: @pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available") def test_transparency() -> None: - with Image.open("Tests/images/reqd_showpage.eps") as plot_image: + with Image.open("Tests/images/eps/reqd_showpage.eps") as plot_image: plot_image.load(transparency=True) assert plot_image.mode == "RGBA" - with Image.open("Tests/images/reqd_showpage_transparency.png") as target: + with Image.open("Tests/images/eps/reqd_showpage_transparency.png") as target: # fonts could be slightly different assert_image_similar(plot_image, target, 6) @@ -246,7 +246,7 @@ def test_bytesio_object() -> None: def test_1_mode() -> None: - with Image.open("Tests/images/1.eps") as im: + with Image.open("Tests/images/eps/1.eps") as im: assert im.mode == "1" @@ -302,7 +302,9 @@ def test_render_scale2() -> None: @pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available") -@pytest.mark.parametrize("filename", (FILE1, FILE2, "Tests/images/illu10_preview.eps")) +@pytest.mark.parametrize( + "filename", (FILE1, FILE2, "Tests/images/eps/illu10_preview.eps") +) def test_resize(filename: str) -> None: with Image.open(filename) as im: new_size = (100, 100) @@ -344,10 +346,10 @@ def test_readline(prefix: bytes, line_ending: bytes) -> None: @pytest.mark.parametrize( "filename", ( - "Tests/images/illu10_no_preview.eps", - "Tests/images/illu10_preview.eps", - "Tests/images/illuCS6_no_preview.eps", - "Tests/images/illuCS6_preview.eps", + "Tests/images/eps/illu10_no_preview.eps", + "Tests/images/eps/illu10_preview.eps", + "Tests/images/eps/illuCS6_no_preview.eps", + "Tests/images/eps/illuCS6_preview.eps", ), ) def test_open_eps(filename: str) -> None: @@ -359,7 +361,7 @@ def test_open_eps(filename: str) -> None: @pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available") def test_emptyline() -> None: # Test file includes an empty line in the header data - emptyline_file = "Tests/images/zero_bb_emptyline.eps" + emptyline_file = "Tests/images/eps/zero_bb_emptyline.eps" with Image.open(emptyline_file) as image: image.load() @@ -371,7 +373,7 @@ def test_emptyline() -> None: @pytest.mark.timeout(timeout=5) @pytest.mark.parametrize( "test_file", - ["Tests/images/timeout-d675703545fee17acab56e5fec644c19979175de.eps"], + ["Tests/images/eps/timeout-d675703545fee17acab56e5fec644c19979175de.eps"], ) def test_timeout(test_file: str) -> None: with open(test_file, "rb") as f: @@ -384,7 +386,7 @@ def test_bounding_box_in_trailer() -> None: # Check bounding boxes are parsed in the same way # when specified in the header and the trailer with ( - Image.open("Tests/images/zero_bb_trailer.eps") as trailer_image, + Image.open("Tests/images/eps/zero_bb_trailer.eps") as trailer_image, Image.open(FILE1) as header_image, ): assert trailer_image.size == header_image.size @@ -392,12 +394,12 @@ def test_bounding_box_in_trailer() -> None: def test_eof_before_bounding_box() -> None: with pytest.raises(OSError): - with Image.open("Tests/images/zero_bb_eof_before_boundingbox.eps"): + with Image.open("Tests/images/eps/zero_bb_eof_before_boundingbox.eps"): pass def test_invalid_data_after_eof() -> None: - with open("Tests/images/illuCS6_preview.eps", "rb") as f: + with open("Tests/images/eps/illuCS6_preview.eps", "rb") as f: img_bytes = io.BytesIO(f.read() + b"\r\n%" + (b" " * 255)) with Image.open(img_bytes) as img: diff --git a/Tests/test_pickle.py b/Tests/test_pickle.py index be143e9c6..d250ba369 100644 --- a/Tests/test_pickle.py +++ b/Tests/test_pickle.py @@ -56,10 +56,10 @@ def helper_pickle_string(protocol: int, test_file: str, mode: str | None) -> Non ), ("Tests/images/hopper.tif", None), ("Tests/images/test-card.png", None), - ("Tests/images/zero_bb.png", None), - ("Tests/images/zero_bb_scale2.png", None), - ("Tests/images/non_zero_bb.png", None), - ("Tests/images/non_zero_bb_scale2.png", None), + ("Tests/images/eps/zero_bb.png", None), + ("Tests/images/eps/zero_bb_scale2.png", None), + ("Tests/images/eps/non_zero_bb.png", None), + ("Tests/images/eps/non_zero_bb_scale2.png", None), ("Tests/images/p_trns_single.png", None), ("Tests/images/pil123p.png", None), ("Tests/images/itxt_chunks.png", None), From 283b41afa033c64ce5baf9643356599240ff6367 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Sat, 3 Aug 2024 11:47:34 -0500 Subject: [PATCH 36/58] test 1.eps size and data --- Tests/images/eps/1.bmp | Bin 0 -> 1202 bytes Tests/test_file_eps.py | 6 ++++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 Tests/images/eps/1.bmp diff --git a/Tests/images/eps/1.bmp b/Tests/images/eps/1.bmp new file mode 100644 index 0000000000000000000000000000000000000000..194c85784c51ac3e30ea62381102eeca429fe63e GIT binary patch literal 1202 zcmZ|PZERCj7zgnGIlJA?O3~Y{V_O;Vu5@!VzEn35gb%0fWo&GkZt!8mC3a&%L`cAw z1RcgpH?TFE>7*Jn&33my7z%Mgqr{h_4ieBQ8H?zQi7CbpMh&1W;e#yoIc59k={>jS z_dL(ZxjpBm;m6Nt$hSD%_fYSl9-+?Yqgrq=uf}|_1G%M3g>&J}?a!;hVv|b)`u@Lh zz9g5+AzgDm72)2kpOgz`P;_7dVXhsT9<6leYq;=)k=*&2tGlEmND;rgC2p1%Ze9D* zRH-TmYa(_)9A05`1VXA5z^^6B(}_LI(p%m zVoCNl6^sjC`zujrc9qK8kPfYR;$)yQtB4Fu=`8rwbK`hwmn1tehLNB%J+=N#wH+w7 zMTy?A{~9Z<>etENz$n8bT6*l(I>RP2Lqy82W$O9#Ss3IM7CX&fJ$i{HSBHr3OIWe% zK41G;bD6RWiDZq-SND41zGKQCjk&uj%zrM*i9~}kEWNAh#d|LItgL-sQB={bbM5ua zTW^S{vd+ZkBJxFlKtv@OhHhMCqq!a2UOLJCHul72(i!K6KPQHs%PIr9Bf>{-ub1y;2om(3L|qHsOC@$nWg&jA+QaVd?4R8m z%^Tb4AfE31VECZQOK5V9zIs>oPxRVkhPr_r=6!$s_)~~alEHY&m(Wk$FhhO8yftC| z((=TW-%c`18C-taQuJ?8Vrax73A#K7!w&^MKKGy?1Of`JKlZN2vRbA$`Tu<0-`3Evk+i91Sz` zEkRiIMCf)wlbvC$63naCqw{gKkF9Z9IA+;oX&_W~YFRbqYKe$LIDGFF_{q9*Y@i!; z&fzXX-jYGzkKu%bNaq6(JORy1rFlB&kKw7{Dvj(=^Mlmm=$Fz$g>n|bBNpv4H9bEe z8L|Z4F-2Ij3<_rG5d}w;VX3nK+73sxIiP{!w3R@Y1-%1(l~Jmb None: assert_image_similar(img, image1_scale1_compare, 5) -def test_1_mode() -> None: +@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available") +def test_1() -> None: with Image.open("Tests/images/eps/1.eps") as im: - assert im.mode == "1" + assert_image_equal_tofile(im, "Tests/images/eps/1.bmp") def test_image_mode_not_supported(tmp_path: Path) -> None: From 3ccecd91cea6625612ef7e05d485058a7783bf07 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Sat, 3 Aug 2024 18:04:05 -0500 Subject: [PATCH 37/58] convert eps using pnmraw instead of ppmraw This lets Ghostscript choose the best device to use (pbmraw, pgmraw, ppmraw) based on the image data. --- Tests/test_file_eps.py | 2 +- src/PIL/EpsImagePlugin.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index f0f235f81..bca516a78 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -178,7 +178,7 @@ def test_load_long_binary_data(prefix: bytes) -> None: data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_long_binary_data)) with Image.open(data) as img: img.load() - assert img.mode == "RGB" + assert img.mode == "1" assert img.size == (100, 100) assert img.format == "EPS" diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index dd6ae4a77..f6c1ea2a5 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -121,7 +121,13 @@ def Ghostscript( lengthfile -= len(s) f.write(s) - device = "pngalpha" if transparency else "ppmraw" + if transparency: + # "RGBA" + device = "pngalpha" + else: + # "pnmraw" automatically chooses between + # PBM ("1"), PGM ("L"), and PPM ("RGB"). + device = "pnmraw" # Build Ghostscript command command = [ From 00bbd4a5b99447aad9def172a05ab768fe428dd6 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Sun, 4 Aug 2024 00:48:12 -0500 Subject: [PATCH 38/58] use "with Image" instead of closing manually --- src/PIL/EpsImagePlugin.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index f6c1ea2a5..cbf48de18 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -157,8 +157,9 @@ def Ghostscript( startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW subprocess.check_call(command, startupinfo=startupinfo) - out_im = Image.open(outfile) - out_im.load() + with Image.open(outfile) as out_im: + out_im.load() + return out_im.im.copy() finally: try: os.unlink(outfile) @@ -167,10 +168,6 @@ def Ghostscript( except OSError: pass - im = out_im.im.copy() - out_im.close() - return im - def _accept(prefix: bytes) -> bool: return prefix[:4] == b"%!PS" or (len(prefix) >= 4 and i32(prefix) == 0xC6D3D0C5) From 6b168a3e2bafe1c957de8e9705ec9a17dd62fd84 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Tue, 6 Aug 2024 21:02:46 -0500 Subject: [PATCH 39/58] add EPS test for image with ImageData and BoundingBox (atend) --- Tests/images/eps/1_atend.eps | Bin 0 -> 45867 bytes Tests/test_file_eps.py | 40 +++++++++++++-------- src/PIL/EpsImagePlugin.py | 65 ++++++++++++++++++++++------------- 3 files changed, 66 insertions(+), 39 deletions(-) create mode 100644 Tests/images/eps/1_atend.eps diff --git a/Tests/images/eps/1_atend.eps b/Tests/images/eps/1_atend.eps new file mode 100644 index 0000000000000000000000000000000000000000..08f8c4681a90908a2ca3d7695d19f150a5787816 GIT binary patch literal 45867 zcmeHw349b)x^Dvl8d=;$MePK`o^;pN)fGrWS64S{7Dz(E8ahd5F`e$v-GKlD+&lMP zy^hXs@j5!V3@)Q6q6mm6jBs@nHXX<1yleZMn=F>q_gLZ=9xW=qVzKe#hg&Yj(-oHUmWwRi%o^Q# zu=F@QcQev6VlfhX@YsJQU5sry}nyd*6#u2 z-(aMVAwATn-yLbLTX#z`?oIgcNMD8f0JI%{TQ`gI28(4R(lxj1I9x*m#r4nUk}Q`E zX}!BDLS=qyesw4sid2W{t-O%VTZiWO%4>p@GYpXJJfC5AW^jTP-=dPiJ1tIie9lD| zF@PllyG^(BxFL0Hr|&=={|9!@w_G$KZ(Q!c?y}`#-p)DgBF_!%KHAcY<9S|ESRbjZ zkIM!=RMF$XJAU*u1o8~Ks>J@THg@GV^7M^Z@ZVSo-dVYSmJfYjm%EO`h;%Yx8 z7d%-LtTM^hj|!#$Cp8p}hUx;LU=?+XtB+YiC?w?fHS?#`R8=PyTxu2ow|IS$jvhxD zz{@NZxOaoV8FwZ*gIQTW_RYSs|H-2BTVM7_l6@1ad0pG*9^bR)OV~HQpl8t65aLa6 zx*--|Sk{)5X`FAnk3lv*MnAeXVj6_iy`D;Xc<|MWQpQEIL3m$m@mTUL1(s4vjwR2M zi;pRSMn&UhupfJ(c5F5it0Y!1^IHYW5^M;N#FK9ARTgRpRz%wIb$OIS8AF?xAx?2* zwwp1F+B&lgjVY}YN2v9R1Zv9tk*R@6#CqM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?rUGc0!u{vuSym@@AyUqy0CzLY)3R+m{hBzKgzc+lkOQ None: EpsImagePlugin.EpsImageFile(data) +@pytest.mark.parametrize("prefix", (b"", simple_binary_header)) +def test_simple_eps_file(prefix: bytes) -> None: + data = io.BytesIO(prefix + b"\n".join(simple_eps_file)) + with Image.open(data) as img: + assert img.mode == "RGB" + assert img.size == (100, 100) + assert img.format == "EPS" + + @pytest.mark.parametrize("prefix", (b"", simple_binary_header)) def test_missing_version_comment(prefix: bytes) -> None: data = io.BytesIO(prefix + b"\n".join(simple_eps_file_without_version)) @@ -142,23 +151,19 @@ def test_missing_boundingbox_comment(prefix: bytes) -> None: @pytest.mark.parametrize("prefix", (b"", simple_binary_header)) -def test_invalid_boundingbox_comment(prefix: bytes) -> None: - data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_invalid_boundingbox)) +@pytest.mark.parametrize( + "file_lines", + ( + simple_eps_file_with_invalid_boundingbox, + simple_eps_file_with_invalid_boundingbox_valid_imagedata, + ), +) +def test_invalid_boundingbox_comment(prefix: bytes, file_lines: list[bytes]) -> None: + data = io.BytesIO(prefix + b"\n".join(file_lines)) with pytest.raises(OSError, match="cannot determine EPS bounding box"): EpsImagePlugin.EpsImageFile(data) -@pytest.mark.parametrize("prefix", (b"", simple_binary_header)) -def test_invalid_boundingbox_comment_valid_imagedata_comment(prefix: bytes) -> None: - data = io.BytesIO( - prefix + b"\n".join(simple_eps_file_with_invalid_boundingbox_valid_imagedata) - ) - with Image.open(data) as img: - assert img.mode == "RGB" - assert img.size == (100, 100) - assert img.format == "EPS" - - @pytest.mark.parametrize("prefix", (b"", simple_binary_header)) def test_ascii_comment_too_long(prefix: bytes) -> None: data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_long_ascii_comment)) @@ -247,8 +252,13 @@ def test_bytesio_object() -> None: @pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available") -def test_1() -> None: - with Image.open("Tests/images/eps/1.eps") as im: +@pytest.mark.parametrize( + # These images have an "ImageData" descriptor. + "filename", + ("Tests/images/eps/1.eps", "Tests/images/eps/1_atend.eps"), +) +def test_1(filename: str) -> None: + with Image.open(filename) as im: assert_image_equal_tofile(im, "Tests/images/eps/1.bmp") diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index cbf48de18..ce8e54908 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -194,6 +194,11 @@ class EpsImageFile(ImageFile.ImageFile): self._mode = "RGB" + # When reading header comments, the first comment is used. + # When reading trailer comments, the last comment is used. + bounding_box: list[int] | None = None + imagedata_size: tuple[int, int] | None = None + byte_arr = bytearray(255) bytes_mv = memoryview(byte_arr) bytes_read = 0 @@ -214,8 +219,8 @@ class EpsImageFile(ImageFile.ImageFile): msg = 'EPS header missing "%%BoundingBox" comment' raise SyntaxError(msg) - def _read_comment(s: str) -> bool: - nonlocal reading_trailer_comments + def read_comment(s: str) -> bool: + nonlocal bounding_box, reading_trailer_comments try: m = split.match(s) except re.error as e: @@ -230,18 +235,12 @@ class EpsImageFile(ImageFile.ImageFile): if k == "BoundingBox": if v == "(atend)": reading_trailer_comments = True - elif not self.tile or (trailer_reached and reading_trailer_comments): + elif not bounding_box or (trailer_reached and reading_trailer_comments): try: # Note: The DSC spec says that BoundingBox # fields should be integers, but some drivers # put floating point values there anyway. - box = [int(float(i)) for i in v.split()] - self._size = box[2] - box[0], box[3] - box[1] - self.tile = [ - ImageFile._Tile( - "eps", (0, 0) + self.size, offset, (length, box) - ) - ] + bounding_box = [int(float(i)) for i in v.split()] except Exception: pass return True @@ -292,7 +291,7 @@ class EpsImageFile(ImageFile.ImageFile): continue s = str(bytes_mv[:bytes_read], "latin-1") - if not _read_comment(s): + if not read_comment(s): m = field.match(s) if m: k = m.group(1) @@ -326,32 +325,50 @@ class EpsImageFile(ImageFile.ImageFile): int(value) for value in image_data_values[:4] ) - if bit_depth == 1: - self._mode = "1" - elif bit_depth == 8: - try: - self._mode = self.mode_map[mode_id] - except ValueError: - break - else: - break + if not imagedata_size: + imagedata_size = columns, rows - self._size = columns, rows - return + if bit_depth == 1: + self._mode = "1" + elif bit_depth == 8: + try: + self._mode = self.mode_map[mode_id] + except ValueError: + pass elif bytes_mv[:5] == b"%%EOF": break elif trailer_reached and reading_trailer_comments: # Load EPS trailer s = str(bytes_mv[:bytes_read], "latin-1") - _read_comment(s) + read_comment(s) elif bytes_mv[:9] == b"%%Trailer": trailer_reached = True bytes_read = 0 - if not self.tile: + # A "BoundingBox" is always required, + # even if an "ImageData" descriptor size exists. + if not bounding_box: msg = "cannot determine EPS bounding box" raise OSError(msg) + # An "ImageData" size takes precedence over the "BoundingBox". + if imagedata_size: + self._size = imagedata_size + else: + self._size = ( + bounding_box[2] - bounding_box[0], + bounding_box[3] - bounding_box[1], + ) + + self.tile = [ + ImageFile._Tile( + codec_name="eps", + extents=(0, 0) + self._size, + offset=offset, + args=(length, bounding_box), + ) + ] + def _find_offset(self, fp: IO[bytes]) -> tuple[int, int]: s = fp.read(4) From 56e4ad0dea6bcfcfa5ce8e0af07a512fd7f5a392 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Mon, 19 Aug 2024 19:24:30 -0500 Subject: [PATCH 40/58] don't name positional arguments --- src/PIL/EpsImagePlugin.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index ce8e54908..44391fcb1 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -361,12 +361,7 @@ class EpsImageFile(ImageFile.ImageFile): ) self.tile = [ - ImageFile._Tile( - codec_name="eps", - extents=(0, 0) + self._size, - offset=offset, - args=(length, bounding_box), - ) + ImageFile._Tile("eps", (0, 0) + self._size, offset, (length, bounding_box)) ] def _find_offset(self, fp: IO[bytes]) -> tuple[int, int]: From f3fe22d2f2345ed0e3eed9dc89a0cd1df728af9e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 3 Sep 2024 23:22:35 +1000 Subject: [PATCH 41/58] Break if the bit depth or mode id are unknown --- src/PIL/EpsImagePlugin.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index 44391fcb1..c7b1f2164 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -320,21 +320,26 @@ class EpsImageFile(ImageFile.ImageFile): # binary/ascii (1: binary, 2: ascii) # data start identifier (the image data follows after a single line # consisting only of this quoted value) + if imagedata_size: + bytes_read = 0 + continue + image_data_values = byte_arr[11:bytes_read].split(None, 7) columns, rows, bit_depth, mode_id = ( int(value) for value in image_data_values[:4] ) - if not imagedata_size: - imagedata_size = columns, rows + if bit_depth == 1: + self._mode = "1" + elif bit_depth == 8: + try: + self._mode = self.mode_map[mode_id] + except ValueError: + break + else: + break - if bit_depth == 1: - self._mode = "1" - elif bit_depth == 8: - try: - self._mode = self.mode_map[mode_id] - except ValueError: - pass + imagedata_size = columns, rows elif bytes_mv[:5] == b"%%EOF": break elif trailer_reached and reading_trailer_comments: From 75286a4e408f363ee8befc36d0ba082fa25fbd32 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Tue, 3 Sep 2024 09:03:37 -0500 Subject: [PATCH 42/58] add some comments --- src/PIL/EpsImagePlugin.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index c7b1f2164..da0bf3153 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -310,6 +310,12 @@ class EpsImageFile(ImageFile.ImageFile): # Check for an "ImageData" descriptor # https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577413_pgfId-1035096 + # If we've already read an "ImageData" descriptor, + # don't read another one. + if imagedata_size: + bytes_read = 0 + continue + # Values: # columns # rows @@ -320,10 +326,6 @@ class EpsImageFile(ImageFile.ImageFile): # binary/ascii (1: binary, 2: ascii) # data start identifier (the image data follows after a single line # consisting only of this quoted value) - if imagedata_size: - bytes_read = 0 - continue - image_data_values = byte_arr[11:bytes_read].split(None, 7) columns, rows, bit_depth, mode_id = ( int(value) for value in image_data_values[:4] @@ -339,6 +341,8 @@ class EpsImageFile(ImageFile.ImageFile): else: break + # Read the columns and rows after checking the bit depth and mode + # in case the bit depth and/or mode are invalid. imagedata_size = columns, rows elif bytes_mv[:5] == b"%%EOF": break From 782f0e8a5a8e61073ea2686e722e0575bbe09b6b Mon Sep 17 00:00:00 2001 From: Yay295 Date: Tue, 10 Sep 2024 08:31:01 -0500 Subject: [PATCH 43/58] change "Read" to "Parse" in comment Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- src/PIL/EpsImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index da0bf3153..1c1b6e0b5 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -341,7 +341,7 @@ class EpsImageFile(ImageFile.ImageFile): else: break - # Read the columns and rows after checking the bit depth and mode + # Parse the columns and rows after checking the bit depth and mode # in case the bit depth and/or mode are invalid. imagedata_size = columns, rows elif bytes_mv[:5] == b"%%EOF": From 4bfc77a1b12198d1f8b688fc2037e26059f80ab3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 20:19:02 +0000 Subject: [PATCH 44/58] Update scientific-python/upload-nightly-action action to v0.6.1 --- .github/workflows/wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index ee0c33166..1f5265bf5 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -278,7 +278,7 @@ jobs: path: dist merge-multiple: true - name: Upload wheels to scientific-python-nightly-wheels - uses: scientific-python/upload-nightly-action@ccf29c805b5d0c1dc31fa97fcdb962be074cade3 # 0.6.0 + uses: scientific-python/upload-nightly-action@82396a2ed4269ba06c6b2988bb4fd568ef3c3d6b # 0.6.1 with: artifacts_path: dist anaconda_nightly_upload_token: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }} From 749bec097ca48bb70f12bf3b5a78cd4d64e91fc9 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 1 Oct 2024 07:11:24 +1000 Subject: [PATCH 45/58] Do not convert image unnecessarily --- src/PIL/ImageEnhance.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/PIL/ImageEnhance.py b/src/PIL/ImageEnhance.py index d7e99a968..0e7e6dd8a 100644 --- a/src/PIL/ImageEnhance.py +++ b/src/PIL/ImageEnhance.py @@ -55,7 +55,9 @@ class Color(_Enhance): if "A" in image.getbands(): self.intermediate_mode = "LA" - self.degenerate = image.convert(self.intermediate_mode).convert(image.mode) + if self.intermediate_mode != image.mode: + image = image.convert(self.intermediate_mode).convert(image.mode) + self.degenerate = image class Contrast(_Enhance): @@ -68,11 +70,15 @@ class Contrast(_Enhance): def __init__(self, image: Image.Image) -> None: self.image = image - mean = int(ImageStat.Stat(image.convert("L")).mean[0] + 0.5) - self.degenerate = Image.new("L", image.size, mean).convert(image.mode) + if image.mode != "L": + image = image.convert("L") + mean = int(ImageStat.Stat(image).mean[0] + 0.5) + self.degenerate = Image.new("L", image.size, mean) + if self.degenerate.mode != self.image.mode: + self.degenerate = self.degenerate.convert(self.image.mode) - if "A" in image.getbands(): - self.degenerate.putalpha(image.getchannel("A")) + if "A" in self.image.getbands(): + self.degenerate.putalpha(self.image.getchannel("A")) class Brightness(_Enhance): From 84b167dfd53fe726a61953040ddbfa0e4e3e3359 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 1 Oct 2024 21:11:56 +1000 Subject: [PATCH 46/58] Update CHANGES.rst [ci skip] --- CHANGES.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 08c2f26bc..36266421a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,15 @@ Changelog (Pillow) 11.0.0 (unreleased) ------------------- +- Support all resampling filters when resizing I;16* images #8422 + [radarhere] + +- Free memory on early return #8413 + [radarhere] + +- Cast int before potentially exceeding INT_MAX #8402 + [radarhere] + - Check image value before use #8400 [radarhere] From c0d04e8b34f759797e45bccac74f49bddfaa7a41 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Tue, 1 Oct 2024 09:33:33 -0500 Subject: [PATCH 47/58] use .size instead of ._size Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- src/PIL/EpsImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index 1c1b6e0b5..27582f2a8 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -370,7 +370,7 @@ class EpsImageFile(ImageFile.ImageFile): ) self.tile = [ - ImageFile._Tile("eps", (0, 0) + self._size, offset, (length, bounding_box)) + ImageFile._Tile("eps", (0, 0) + self.size, offset, (length, bounding_box)) ] def _find_offset(self, fp: IO[bytes]) -> tuple[int, int]: From f9c69deaae2e029601dddba48268fadf630a18eb Mon Sep 17 00:00:00 2001 From: Yay295 Date: Tue, 1 Oct 2024 09:35:22 -0500 Subject: [PATCH 48/58] simplify setting self._size Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- src/PIL/EpsImagePlugin.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index 27582f2a8..fb1e301c0 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -361,13 +361,10 @@ class EpsImageFile(ImageFile.ImageFile): raise OSError(msg) # An "ImageData" size takes precedence over the "BoundingBox". - if imagedata_size: - self._size = imagedata_size - else: - self._size = ( - bounding_box[2] - bounding_box[0], - bounding_box[3] - bounding_box[1], - ) + self._size = imagedata_size or ( + bounding_box[2] - bounding_box[0], + bounding_box[3] - bounding_box[1], + ) self.tile = [ ImageFile._Tile("eps", (0, 0) + self.size, offset, (length, bounding_box)) From baf2d8160a5c1ec0c1ce1c64ea70ded2e5581495 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 2 Oct 2024 09:48:09 +1000 Subject: [PATCH 49/58] Updated xz to 5.6.3 --- .github/workflows/wheels-dependencies.sh | 2 +- winbuild/build_prepare.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index b3996d5a1..19eb91cbb 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -20,7 +20,7 @@ HARFBUZZ_VERSION=10.0.1 LIBPNG_VERSION=1.6.44 JPEGTURBO_VERSION=3.0.4 OPENJPEG_VERSION=2.5.2 -XZ_VERSION=5.6.2 +XZ_VERSION=5.6.3 TIFF_VERSION=4.6.0 LCMS2_VERSION=2.16 if [[ -n "$IS_MACOS" ]]; then diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index 026d9d306..a21fbef91 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -119,7 +119,7 @@ V = { "LIBWEBP": "1.4.0", "OPENJPEG": "2.5.2", "TIFF": "4.6.0", - "XZ": "5.6.2", + "XZ": "5.6.3", "ZLIB": "1.3.1", } V["LIBPNG_DOTLESS"] = V["LIBPNG"].replace(".", "") @@ -185,7 +185,7 @@ DEPS: dict[str, dict[str, Any]] = { cmd_copy(r"src\liblzma\api\lzma\*.h", r"{inc_dir}\lzma"), ], "headers": [r"src\liblzma\api\lzma.h"], - "libs": [r"liblzma.lib"], + "libs": [r"lzma.lib"], }, "libwebp": { "url": f"http://downloads.webmproject.org/releases/webp/libwebp-{V['LIBWEBP']}.tar.gz", @@ -216,8 +216,8 @@ DEPS: dict[str, dict[str, Any]] = { "license": "LICENSE.md", "patch": { r"libtiff\tif_lzma.c": { - # link against liblzma.lib - "#ifdef LZMA_SUPPORT": '#ifdef LZMA_SUPPORT\n#pragma comment(lib, "liblzma.lib")', # noqa: E501 + # link against lzma.lib + "#ifdef LZMA_SUPPORT": '#ifdef LZMA_SUPPORT\n#pragma comment(lib, "lzma.lib")', # noqa: E501 }, r"libtiff\tif_webp.c": { # link against libwebp.lib From 547e7dcc5df0e9bbd05119c9accc9295bfaa0cec Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 2 Oct 2024 19:17:13 +1000 Subject: [PATCH 50/58] Test cifuzz when wheel dependencies change --- .github/workflows/cifuzz.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml index eb73fc6a7..0456bbaba 100644 --- a/.github/workflows/cifuzz.yml +++ b/.github/workflows/cifuzz.yml @@ -6,11 +6,13 @@ on: - "**" paths: - ".github/workflows/cifuzz.yml" + - ".github/workflows/wheels-dependencies.sh" - "**.c" - "**.h" pull_request: paths: - ".github/workflows/cifuzz.yml" + - ".github/workflows/wheels-dependencies.sh" - "**.c" - "**.h" workflow_dispatch: From 33f065eb5e458724cdd76dc6074445b4fad9fd7f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 00:41:31 +0000 Subject: [PATCH 51/58] Update dependency cibuildwheel to v2.21.2 --- .ci/requirements-cibw.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/requirements-cibw.txt b/.ci/requirements-cibw.txt index 7dc3a53fe..a1424ecc0 100644 --- a/.ci/requirements-cibw.txt +++ b/.ci/requirements-cibw.txt @@ -1 +1 @@ -cibuildwheel==2.21.1 +cibuildwheel==2.21.2 From 8e6d518ea89035077fb4a855f61f3b5bab26a9c4 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Sat, 5 Oct 2024 08:05:00 -0500 Subject: [PATCH 52/58] change parameter type from list to tuple Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- Tests/test_file_eps.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 94ab5d327..7ae0900fd 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -158,7 +158,9 @@ def test_missing_boundingbox_comment(prefix: bytes) -> None: simple_eps_file_with_invalid_boundingbox_valid_imagedata, ), ) -def test_invalid_boundingbox_comment(prefix: bytes, file_lines: list[bytes]) -> None: +def test_invalid_boundingbox_comment( + prefix: bytes, file_lines: tuple[bytes, ...] +) -> None: data = io.BytesIO(prefix + b"\n".join(file_lines)) with pytest.raises(OSError, match="cannot determine EPS bounding box"): EpsImagePlugin.EpsImageFile(data) From d4fedc852c2a78b9dc93b67f93d6211f7337ca43 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 5 Oct 2024 15:21:42 +1000 Subject: [PATCH 53/58] Rename test image --- ..._atend.eps => 1_boundingbox_after_imagedata.eps} | Bin Tests/test_file_eps.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename Tests/images/eps/{1_atend.eps => 1_boundingbox_after_imagedata.eps} (100%) diff --git a/Tests/images/eps/1_atend.eps b/Tests/images/eps/1_boundingbox_after_imagedata.eps similarity index 100% rename from Tests/images/eps/1_atend.eps rename to Tests/images/eps/1_boundingbox_after_imagedata.eps diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 7ae0900fd..0a69ee6e5 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -257,7 +257,7 @@ def test_bytesio_object() -> None: @pytest.mark.parametrize( # These images have an "ImageData" descriptor. "filename", - ("Tests/images/eps/1.eps", "Tests/images/eps/1_atend.eps"), + ("Tests/images/eps/1.eps", "Tests/images/eps/1_boundingbox_after_imagedata.eps"), ) def test_1(filename: str) -> None: with Image.open(filename) as im: From a9cbf6d5a71013124305f05d09b344e3698f2c0c Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 18 Aug 2024 20:41:01 +0300 Subject: [PATCH 54/58] Test Python 3.13 on AppVeyor --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 41a5725b2..781ad4a4b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -18,7 +18,7 @@ environment: TEST_OPTIONS: DEPLOY: YES matrix: - - PYTHON: C:/Python312 + - PYTHON: C:/Python313 ARCHITECTURE: x86 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 - PYTHON: C:/Python39-x64 From 1b57b32caf99f7fb5b9c6b83e439832f5a55dc83 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 6 Oct 2024 08:02:17 +1100 Subject: [PATCH 55/58] Test ignoring second ImageData --- Tests/images/eps/1_second_imagedata.eps | Bin 0 -> 45834 bytes Tests/test_file_eps.py | 6 +++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Tests/images/eps/1_second_imagedata.eps diff --git a/Tests/images/eps/1_second_imagedata.eps b/Tests/images/eps/1_second_imagedata.eps new file mode 100644 index 0000000000000000000000000000000000000000..e6309a3b4ede316d83a2bb84388f1d29140b433f GIT binary patch literal 45834 zcmeHw349b)x^Dvl8d=;$MePK`o^)4LS65dc30+-XtXUul32W#ioyByzLw5%P3~=w< zd-Xax!^P|9;4-+3qKG0OqA0Cbc6tb(C`19s_Jw?)cEe3_j~vK zQqWze&hnk_eCONFcdAcb|MRZxb8fO&R^MZZUwE`A_=?5Gj~{Ni7*AJN&RZ_BbTeyo z>%r3F@Z8N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fF(l5VW9KvKXGjiRk_A{e!4dMwijC6= zjcSzD$|;M%NPu8+MEo4ew)()(w6?fZV**>%6l3bva}T*h*9YTaEX*7rrdE)nv%Jn9 zbW)2=A; zHFL%lqz#Eg&|vZyv9Kz&E@^1tjD}nDTp^b&wK6b`yCqy)KJ}I{H6!yUWKYa3PD!0L zd{DAFcFwfqtQ=d(2wBZbsYq8MWy$H&ZNcK4Dlv~_` zC3Q@`G;7x2@;Uj*%8=4fdh(3Q;?(4nTT5qo?AgfgdVNKtKRd5|wnP8PlO^6;{(~!W92TKIckfAe@lZ(f>l7=SNjjFB6_cS=_YH9|Ra;1}IPIWla?A20uf;%mF zcG$4n3A zWfgmdH;nU)8a%cZ0JUPQZH#-}hqzvUt{A0)Eme`_! z3F(v599r?L6!);%b7w`SmrBvBq+ug62WN=o%7nS8)q}@|a)!()o|K;D&zx8^J2*{B zPM@a0m&K&2hx8{tQFtVX+%7kQB`m~%OV>2Sj*`?E5NyAb`+UF+Mxra`%XXm*_ z4OO!FV1C*7YJSATz;N%Nf+=Nr-Xd>}b3|EDy*HV+dwlpyWrJr46Mb62>{*U6DM?wA z=R_KCnwMjGMu9YQa!OIEI=47`&IEUIN|DQ(Vsj488Z{|r%*2{OxtYORgtBOboH~6< z*f(@qP0@r=bEC78GRI9G=}Wm)bGcKiQnO~eM*Gt8C*w~EPfr<_Uz=p7F6o|c(>OH{6%BYKDBj=^7q${16o&GJ None: @pytest.mark.parametrize( # These images have an "ImageData" descriptor. "filename", - ("Tests/images/eps/1.eps", "Tests/images/eps/1_boundingbox_after_imagedata.eps"), + ( + "Tests/images/eps/1.eps", + "Tests/images/eps/1_boundingbox_after_imagedata.eps", + "Tests/images/eps/1_second_imagedata.eps", + ), ) def test_1(filename: str) -> None: with Image.open(filename) as im: From e2f996e2bd9b933a7a88b9ed47e6065a6d5a28b8 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 6 Oct 2024 08:55:15 +1100 Subject: [PATCH 56/58] Updated CI target --- docs/installation/platform-support.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation/platform-support.rst b/docs/installation/platform-support.rst index 0e46ef0c7..00dec41d1 100644 --- a/docs/installation/platform-support.rst +++ b/docs/installation/platform-support.rst @@ -53,7 +53,7 @@ These platforms are built and tested for every change. | Windows Server 2022 | 3.9, 3.10, 3.11, | x86-64 | | | 3.12, 3.13, PyPy3 | | | +----------------------------+---------------------+ -| | 3.12 | x86 | +| | 3.13 | x86 | | +----------------------------+---------------------+ | | 3.9 (MinGW) | x86-64 | | +----------------------------+---------------------+ From b77cd009e210cefae9424206f80ed5dc65b53fdf Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 6 Oct 2024 11:30:27 +1100 Subject: [PATCH 57/58] Use transparency when combining P frames --- Tests/test_file_apng.py | 4 ++-- src/PIL/PngImagePlugin.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_apng.py b/Tests/test_file_apng.py index e95850212..ee6c867c3 100644 --- a/Tests/test_file_apng.py +++ b/Tests/test_file_apng.py @@ -258,8 +258,8 @@ def test_apng_mode() -> None: assert im.mode == "P" im.seek(im.n_frames - 1) im = im.convert("RGBA") - assert im.getpixel((0, 0)) == (255, 0, 0, 0) - assert im.getpixel((64, 32)) == (255, 0, 0, 0) + assert im.getpixel((0, 0)) == (0, 255, 0, 255) + assert im.getpixel((64, 32)) == (0, 255, 0, 255) with Image.open("Tests/images/apng/mode_palette_1bit_alpha.png") as im: assert im.mode == "P" diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 28ade293e..4e1227204 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -1063,6 +1063,12 @@ class PngImageFile(ImageFile.ImageFile): "RGBA", self.info["transparency"] ) else: + if self.im.mode == "P" and "transparency" in self.info: + t = self.info["transparency"] + if isinstance(t, bytes): + updated.putpalettealphas(t) + elif isinstance(t, int): + updated.putpalettealpha(t) mask = updated.convert("RGBA") self._prev_im.paste(updated, self.dispose_extent, mask) self.im = self._prev_im From 27c1bb265432cb5a1138e39165f0610e2d8a4e94 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 7 Oct 2024 07:48:32 +1100 Subject: [PATCH 58/58] Update CHANGES.rst [ci skip] --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 36266421a..cc891ed1d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,12 @@ Changelog (Pillow) 11.0.0 (unreleased) ------------------- +- Updated EPS mode when opening images without transparency #8281 + [Yay295, radarhere] + +- Use transparency when combining P frames from APNGs #8443 + [radarhere] + - Support all resampling filters when resizing I;16* images #8422 [radarhere]