From 98b73009cc92575f7b361057265b0443e4234022 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 16 Nov 2023 23:01:26 +1100 Subject: [PATCH 1/7] Correct PDF palette size when saving --- src/PIL/PdfImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/PdfImagePlugin.py b/src/PIL/PdfImagePlugin.py index 09fc0c7e6..b6bb60911 100644 --- a/src/PIL/PdfImagePlugin.py +++ b/src/PIL/PdfImagePlugin.py @@ -96,7 +96,7 @@ def _write_image(im, filename, existing_pdf, image_refs): dict_obj["ColorSpace"] = [ PdfParser.PdfName("Indexed"), PdfParser.PdfName("DeviceRGB"), - 255, + len(palette) // 3 - 1, PdfParser.PdfBinary(palette), ] procset = "ImageI" # indexed color From f23d029d5f356a1636342a0dfb12d1d6083fa5b5 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 30 Nov 2023 07:41:02 +1100 Subject: [PATCH 2/7] Moved error from truetype() to FreeTypeFont --- src/PIL/ImageFont.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 0331a5c45..18de10375 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -188,6 +188,10 @@ class FreeTypeFont: def __init__(self, font=None, size=10, index=0, encoding="", layout_engine=None): # FIXME: use service provider instead + if size <= 0: + msg = "font size must be greater than 0" + raise ValueError(msg) + self.path = font self.size = size self.index = index @@ -791,10 +795,6 @@ def truetype(font=None, size=10, index=0, encoding="", layout_engine=None): :exception ValueError: If the font size is not greater than zero. """ - if size <= 0: - msg = "font size must be greater than 0" - raise ValueError(msg) - def freetype(font): return FreeTypeFont(font, size, index, encoding, layout_engine) From a04c6a27e8fc6c4c3abccfb69ce892095a908da6 Mon Sep 17 00:00:00 2001 From: Andreas Florath Date: Fri, 1 Dec 2023 16:01:23 +0100 Subject: [PATCH 3/7] Optimization of ImageStat.Stat._getcount method The new implementation uses "sum" instead of the construct "functools.reduce(operator.add, ...)". Test showed that the new function is about three times faster than the original. Also it is shorter and easier to read. Signed-off-by: Andreas Florath --- src/PIL/ImageStat.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/PIL/ImageStat.py b/src/PIL/ImageStat.py index b7ebddf06..10cb08b30 100644 --- a/src/PIL/ImageStat.py +++ b/src/PIL/ImageStat.py @@ -69,10 +69,7 @@ class Stat: def _getcount(self): """Get total number of pixels in each layer""" - v = [] - for i in range(0, len(self.h), 256): - v.append(functools.reduce(operator.add, self.h[i : i + 256])) - return v + return [sum(self.h[i: i + 256]) for i in range(0, len(self.h), 256)] def _getsum(self): """Get sum of all pixels in each layer""" From f7d40ce31cfc7ecfb166b74e45b1e5844b547b86 Mon Sep 17 00:00:00 2001 From: Andreas Florath Date: Fri, 1 Dec 2023 16:15:31 +0100 Subject: [PATCH 4/7] Removed functools and operator import which are not needed anymore Signed-off-by: Andreas Florath --- src/PIL/ImageStat.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/PIL/ImageStat.py b/src/PIL/ImageStat.py index 10cb08b30..8d7dd8615 100644 --- a/src/PIL/ImageStat.py +++ b/src/PIL/ImageStat.py @@ -21,9 +21,7 @@ # See the README file for information on usage and redistribution. # -import functools import math -import operator class Stat: From e01354a2c85c9cdb4ce5dc8a6ad3cd1c6087f16f Mon Sep 17 00:00:00 2001 From: Andreas Florath Date: Fri, 1 Dec 2023 16:19:39 +0100 Subject: [PATCH 5/7] Added space before colon Signed-off-by: Andreas Florath --- src/PIL/ImageStat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/ImageStat.py b/src/PIL/ImageStat.py index 8d7dd8615..c0f647024 100644 --- a/src/PIL/ImageStat.py +++ b/src/PIL/ImageStat.py @@ -67,7 +67,7 @@ class Stat: def _getcount(self): """Get total number of pixels in each layer""" - return [sum(self.h[i: i + 256]) for i in range(0, len(self.h), 256)] + return [sum(self.h[i : i + 256]) for i in range(0, len(self.h), 256)] def _getsum(self): """Get sum of all pixels in each layer""" From 2b734a33c765d6a9f12c64b534231c8c39761275 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 4 Dec 2023 08:32:39 +1100 Subject: [PATCH 6/7] Updated lcms2 to 2.16 --- .github/workflows/wheels-dependencies.sh | 2 +- docs/installation.rst | 2 +- winbuild/build_prepare.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index 2605664eb..3ec314873 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -22,7 +22,7 @@ JPEGTURBO_VERSION=3.0.1 OPENJPEG_VERSION=2.5.0 XZ_VERSION=5.4.5 TIFF_VERSION=4.6.0 -LCMS2_VERSION=2.15 +LCMS2_VERSION=2.16 if [[ -n "$IS_MACOS" ]]; then GIFLIB_VERSION=5.1.4 else diff --git a/docs/installation.rst b/docs/installation.rst index aa78a7a00..fbcfbb907 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -175,7 +175,7 @@ Many of Pillow's features require external libraries: * **littlecms** provides color management * Pillow version 2.2.1 and below uses liblcms1, Pillow 2.3.0 and - above uses liblcms2. Tested with **1.19** and **2.7-2.15**. + above uses liblcms2. Tested with **1.19** and **2.7-2.16**. * **libwebp** provides the WebP format. diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index c5c9441d4..f7e145fb9 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -279,10 +279,10 @@ DEPS = { "libs": [r"objs\{msbuild_arch}\Release Static\freetype.lib"], }, "lcms2": { - "url": SF_PROJECTS + "/lcms/files/lcms/2.15/lcms2-2.15.tar.gz/download", - "filename": "lcms2-2.15.tar.gz", - "dir": "lcms2-2.15", - "license": "COPYING", + "url": SF_PROJECTS + "/lcms/files/lcms/2.16/lcms2-2.16.tar.gz/download", + "filename": "lcms2-2.16.tar.gz", + "dir": "lcms2-2.16", + "license": "LICENSE", "patch": { r"Projects\VC2022\lcms2_static\lcms2_static.vcxproj": { # default is /MD for x86 and /MT for x64, we need /MD always From d7fa0b9d966a14b81c6bcc63ca94668465c0d9e3 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 4 Dec 2023 22:20:22 +1100 Subject: [PATCH 7/7] Update CHANGES.rst [ci skip] --- CHANGES.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 5f58a2cad..d1fa91bfc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,10 +5,13 @@ Changelog (Pillow) 10.2.0 (unreleased) ------------------- +- Correct PDF palette size when saving #7555 + [radarhere] + - Fixed closing file pointer with olefile 0.47 #7594 [radarhere] -- Raise ValueError when TrueType font size is not greater than zero #7584 +- Raise ValueError when TrueType font size is not greater than zero #7584, #7587 [akx, radarhere] - If absent, do not try to close fp when closing image #7557