From 2825323e84aff1c6005506fb1d6e78373a356486 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 31 Dec 2023 16:46:24 +0200 Subject: [PATCH 1/5] Release notes: add ImageColor and ImageMode optimisations, and type hints --- docs/PIL.rst | 9 ++++++++ docs/releasenotes/10.2.0.rst | 40 ++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/docs/PIL.rst b/docs/PIL.rst index fa036b9ccfe..493d0bde368 100644 --- a/docs/PIL.rst +++ b/docs/PIL.rst @@ -69,6 +69,15 @@ can be found here. :undoc-members: :show-inheritance: +:mod:`~PIL.ImageMode` Module +----------------------------- + +.. automodule:: PIL.ImageMode + :members: + :member-order: bysource + :undoc-members: + :show-inheritance: + :mod:`~PIL.ImageTransform` Module --------------------------------- diff --git a/docs/releasenotes/10.2.0.rst b/docs/releasenotes/10.2.0.rst index 6ab139b560b..f82d20176cc 100644 --- a/docs/releasenotes/10.2.0.rst +++ b/docs/releasenotes/10.2.0.rst @@ -1,14 +1,6 @@ 10.2.0 ------ -Backwards Incompatible Changes -============================== - -TODO -^^^^ - -TODO - Deprecations ============ @@ -20,11 +12,6 @@ ImageFile.raise_oserror error codes returned by a codec's ``decode()`` method, which ImageFile already does automatically. -TODO -^^^^ - -TODO - API Changes =========== @@ -92,6 +79,21 @@ Support has been added to read the BC4U format of DDS images. Support has also been added to read DX10 BC1 and BC4, whether UNORM or TYPELESS. +Optimized ImageColor.getrgb and getcolor +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The color calculations of :py:attr:`~PIL.ImageColor.getrgb` and +:py:attr:`~PIL.ImageColor.getcolor` are now cached using +:py:func:`functools.lru_cache`. Cached calls of ``getrgb`` are 3.1 - 91.4 times +as fast and ``getcolor`` are 5.1 - 19.6 times as fast. + +Optimized ImageMode.getmode +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The lookups made by :py:attr:`~PIL.ImageMode.getmode` are now cached using +:py:func:`functools.lru_cache` instead of a custom cache. Cached calls are 20% +faster. + Optimized ImageStat.Stat count and extrema ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -105,3 +107,15 @@ Encoder errors now report error detail as string :py:exc:`OSError` exceptions from image encoders now include a textual description of the error instead of a numeric error code. + +Type hints +^^^^^^^^^^ + +Work has begun to add type annotations to Pillow, including: + +* :py:class:`~PIL.ContainerIO` +* :py:class:`~PIL.FontFile` and subclasses +* :py:class:`~PIL.ImageChops` +* :py:class:`~PIL.ImageMode` +* :py:class:`~PIL.ImageSequence` +* :py:class:`~PIL.TarIO` From 129a4936d33f775e2122b5f21d49ceeeb601e0b5 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 31 Dec 2023 09:53:59 -0700 Subject: [PATCH 2/5] Update docs/releasenotes/10.2.0.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ondrej Baranovič --- docs/releasenotes/10.2.0.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/releasenotes/10.2.0.rst b/docs/releasenotes/10.2.0.rst index f82d20176cc..c08a85c2c10 100644 --- a/docs/releasenotes/10.2.0.rst +++ b/docs/releasenotes/10.2.0.rst @@ -113,9 +113,9 @@ Type hints Work has begun to add type annotations to Pillow, including: -* :py:class:`~PIL.ContainerIO` -* :py:class:`~PIL.FontFile` and subclasses -* :py:class:`~PIL.ImageChops` -* :py:class:`~PIL.ImageMode` -* :py:class:`~PIL.ImageSequence` -* :py:class:`~PIL.TarIO` +* :py:mod:`~PIL.ContainerIO` +* :py:mod:`~PIL.FontFile` and subclasses +* :py:mod:`~PIL.ImageChops` +* :py:mod:`~PIL.ImageMode` +* :py:mod:`~PIL.ImageSequence` +* :py:mod:`~PIL.TarIO` From 9bcd4770582ecd0e66479671e271c91b5926a80b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 1 Jan 2024 14:19:16 +1100 Subject: [PATCH 3/5] Use consistent language --- docs/releasenotes/10.2.0.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/releasenotes/10.2.0.rst b/docs/releasenotes/10.2.0.rst index c08a85c2c10..46cfe1599aa 100644 --- a/docs/releasenotes/10.2.0.rst +++ b/docs/releasenotes/10.2.0.rst @@ -91,16 +91,16 @@ Optimized ImageMode.getmode ^^^^^^^^^^^^^^^^^^^^^^^^^^^ The lookups made by :py:attr:`~PIL.ImageMode.getmode` are now cached using -:py:func:`functools.lru_cache` instead of a custom cache. Cached calls are 20% -faster. +:py:func:`functools.lru_cache` instead of a custom cache. Cached calls are 1.2 times as +fast. Optimized ImageStat.Stat count and extrema ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Calculating the :py:attr:`~PIL.ImageStat.Stat.count` and :py:attr:`~PIL.ImageStat.Stat.extrema` statistics is now faster. After the -histogram is created in ``st = ImageStat.Stat(im)``, ``st.count`` is 3x as fast -on average and ``st.extrema`` is 12x as fast on average. +histogram is created in ``st = ImageStat.Stat(im)``, ``st.count`` is 3 times as fast on +average and ``st.extrema`` is 12 times as fast on average. Encoder errors now report error detail as string ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 681f8183f3e7b0755f345e8cbf12237af51d5492 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 1 Jan 2024 10:01:42 +0200 Subject: [PATCH 4/5] Remove member-order Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- docs/PIL.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/PIL.rst b/docs/PIL.rst index 493d0bde368..b617d920577 100644 --- a/docs/PIL.rst +++ b/docs/PIL.rst @@ -74,7 +74,6 @@ can be found here. .. automodule:: PIL.ImageMode :members: - :member-order: bysource :undoc-members: :show-inheritance: From c08426b8343d1b84e02068df877e24e294cc9cbd Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 1 Jan 2024 10:02:22 +0200 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- docs/PIL.rst | 2 +- docs/releasenotes/10.2.0.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/PIL.rst b/docs/PIL.rst index b617d920577..b6944e234a5 100644 --- a/docs/PIL.rst +++ b/docs/PIL.rst @@ -70,7 +70,7 @@ can be found here. :show-inheritance: :mod:`~PIL.ImageMode` Module ------------------------------ +---------------------------- .. automodule:: PIL.ImageMode :members: diff --git a/docs/releasenotes/10.2.0.rst b/docs/releasenotes/10.2.0.rst index 46cfe1599aa..75ed461ba11 100644 --- a/docs/releasenotes/10.2.0.rst +++ b/docs/releasenotes/10.2.0.rst @@ -114,7 +114,7 @@ Type hints Work has begun to add type annotations to Pillow, including: * :py:mod:`~PIL.ContainerIO` -* :py:mod:`~PIL.FontFile` and subclasses +* :py:mod:`~PIL.FontFile`, :py:mod:`~PIL.BdfFontFile` and :py:mod:`~PIL.PcfFontFile` * :py:mod:`~PIL.ImageChops` * :py:mod:`~PIL.ImageMode` * :py:mod:`~PIL.ImageSequence`