From a2d6b1afe828b2e0405f824ada79a6a14ca4e9bf Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 25 Dec 2023 19:35:01 +1100 Subject: [PATCH] other --- src/PIL/Image.py | 3 +++ src/PIL/ImageChops.py | 48 +++++++++++++++++++++---------------------- src/PIL/__init__.py | 4 ---- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 1cb484b8528..bdc595f2cdb 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -40,6 +40,9 @@ from collections.abc import Callable, MutableMapping from enum import IntEnum from pathlib import Path +from typing import TypeAlias + +ImageType: TypeAlias = Image.Image try: from defusedxml import ElementTree diff --git a/src/PIL/ImageChops.py b/src/PIL/ImageChops.py index 571016228d0..cf32915d7a8 100644 --- a/src/PIL/ImageChops.py +++ b/src/PIL/ImageChops.py @@ -17,10 +17,10 @@ from __future__ import annotations -from . import Image, ImageType +from . import Image -def constant(image: ImageType, value: int) -> ImageType: +def constant(image: Image.ImageType, value: int) -> Image.ImageType: """Fill a channel with a given gray level. :rtype: :py:class:`~PIL.Image.Image` @@ -29,7 +29,7 @@ def constant(image: ImageType, value: int) -> ImageType: return Image.new("L", image.size, value) -def duplicate(image: ImageType) -> ImageType: +def duplicate(image: Image.ImageType) -> Image.ImageType: """Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`. :rtype: :py:class:`~PIL.Image.Image` @@ -38,7 +38,7 @@ def duplicate(image: ImageType) -> ImageType: return image.copy() -def invert(image: ImageType) -> ImageType: +def invert(image: Image.ImageType) -> Image.ImageType: """ Invert an image (channel). :: @@ -51,7 +51,7 @@ def invert(image: ImageType) -> ImageType: return image._new(image.im.chop_invert()) -def lighter(image1: ImageType, image2: ImageType) -> ImageType: +def lighter(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """ Compares the two images, pixel by pixel, and returns a new image containing the lighter values. :: @@ -66,7 +66,7 @@ def lighter(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_lighter(image2.im)) -def darker(image1: ImageType, image2: ImageType) -> ImageType: +def darker(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """ Compares the two images, pixel by pixel, and returns a new image containing the darker values. :: @@ -81,7 +81,7 @@ def darker(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_darker(image2.im)) -def difference(image1: ImageType, image2: ImageType) -> ImageType: +def difference(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """ Returns the absolute value of the pixel-by-pixel difference between the two images. :: @@ -96,7 +96,7 @@ def difference(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_difference(image2.im)) -def multiply(image1: ImageType, image2: ImageType) -> ImageType: +def multiply(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """ Superimposes two images on top of each other. @@ -113,7 +113,7 @@ def multiply(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_multiply(image2.im)) -def screen(image1: ImageType, image2: ImageType) -> ImageType: +def screen(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """ Superimposes two inverted images on top of each other. :: @@ -127,7 +127,7 @@ def screen(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_screen(image2.im)) -def soft_light(image1: ImageType, image2: ImageType) -> ImageType: +def soft_light(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """ Superimposes two images on top of each other using the Soft Light algorithm @@ -139,7 +139,7 @@ def soft_light(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_soft_light(image2.im)) -def hard_light(image1: ImageType, image2: ImageType) -> ImageType: +def hard_light(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """ Superimposes two images on top of each other using the Hard Light algorithm @@ -151,7 +151,7 @@ def hard_light(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_hard_light(image2.im)) -def overlay(image1: ImageType, image2: ImageType) -> ImageType: +def overlay(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """ Superimposes two images on top of each other using the Overlay algorithm @@ -164,8 +164,8 @@ def overlay(image1: ImageType, image2: ImageType) -> ImageType: def add( - image1: ImageType, image2: ImageType, scale: float = 1.0, offset: float = 0 -) -> ImageType: + image1: Image.ImageType, image2: Image.ImageType, scale: float = 1.0, offset: float = 0 +) -> Image.ImageType: """ Adds two images, dividing the result by scale and adding the offset. If omitted, scale defaults to 1.0, and offset to 0.0. :: @@ -181,8 +181,8 @@ def add( def subtract( - image1: ImageType, image2: ImageType, scale: float = 1.0, offset: float = 0 -) -> ImageType: + image1: Image.ImageType, image2: Image.ImageType, scale: float = 1.0, offset: float = 0 +) -> Image.ImageType: """ Subtracts two images, dividing the result by scale and adding the offset. If omitted, scale defaults to 1.0, and offset to 0.0. :: @@ -197,7 +197,7 @@ def subtract( return image1._new(image1.im.chop_subtract(image2.im, scale, offset)) -def add_modulo(image1: ImageType, image2: ImageType) -> ImageType: +def add_modulo(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """Add two images, without clipping the result. :: out = ((image1 + image2) % MAX) @@ -210,7 +210,7 @@ def add_modulo(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_add_modulo(image2.im)) -def subtract_modulo(image1: ImageType, image2: ImageType) -> ImageType: +def subtract_modulo(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """Subtract two images, without clipping the result. :: out = ((image1 - image2) % MAX) @@ -223,7 +223,7 @@ def subtract_modulo(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_subtract_modulo(image2.im)) -def logical_and(image1: ImageType, image2: ImageType) -> ImageType: +def logical_and(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """Logical AND between two images. Both of the images must have mode "1". If you would like to perform a @@ -241,7 +241,7 @@ def logical_and(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_and(image2.im)) -def logical_or(image1: ImageType, image2: ImageType) -> ImageType: +def logical_or(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """Logical OR between two images. Both of the images must have mode "1". :: @@ -256,7 +256,7 @@ def logical_or(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_or(image2.im)) -def logical_xor(image1: ImageType, image2: ImageType) -> ImageType: +def logical_xor(image1: Image.ImageType, image2: Image.ImageType) -> Image.ImageType: """Logical XOR between two images. Both of the images must have mode "1". :: @@ -271,7 +271,7 @@ def logical_xor(image1: ImageType, image2: ImageType) -> ImageType: return image1._new(image1.im.chop_xor(image2.im)) -def blend(image1: ImageType, image2: ImageType, alpha: float) -> ImageType: +def blend(image1: Image.ImageType, image2: Image.ImageType, alpha: float) -> Image.ImageType: """Blend images using constant transparency weight. Alias for :py:func:`PIL.Image.blend`. @@ -281,7 +281,7 @@ def blend(image1: ImageType, image2: ImageType, alpha: float) -> ImageType: return Image.blend(image1, image2, alpha) -def composite(image1: ImageType, image2: ImageType, mask: ImageType) -> ImageType: +def composite(image1: Image.ImageType, image2: Image.ImageType, mask: Image.ImageType) -> Image.ImageType: """Create composite using transparency mask. Alias for :py:func:`PIL.Image.composite`. @@ -291,7 +291,7 @@ def composite(image1: ImageType, image2: ImageType, mask: ImageType) -> ImageTyp return Image.composite(image1, image2, mask) -def offset(image: ImageType, xoffset: int, yoffset: int | None = None) -> ImageType: +def offset(image: Image.ImageType, xoffset: int, yoffset: int | None = None) -> Image.ImageType: """Returns a copy of the image where data has been offset by the given distances. Data wraps around the edges. If ``yoffset`` is omitted, it is assumed to be equal to ``xoffset``. diff --git a/src/PIL/__init__.py b/src/PIL/__init__.py index e20189adb47..eb9fd6cfa92 100644 --- a/src/PIL/__init__.py +++ b/src/PIL/__init__.py @@ -14,12 +14,8 @@ """ from __future__ import annotations -from typing import TypeAlias - from . import Image, _version -ImageType: TypeAlias = Image.Image - # VERSION was removed in Pillow 6.0.0. # PILLOW_VERSION was removed in Pillow 9.0.0. # Use __version__ instead.