From 1f3fe6f73350aa9630b236a9f16370aa0c71258d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 16 Sep 2024 10:21:17 +1000 Subject: [PATCH] Use getim() --- Tests/test_imagemorph.py | 8 ++++---- src/PIL/ImageCms.py | 4 ++-- src/PIL/ImageMath.py | 5 ++--- src/PIL/ImageMorph.py | 6 +++--- src/PIL/ImageTk.py | 2 +- src/PIL/_imagingcms.pyi | 4 +++- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Tests/test_imagemorph.py b/Tests/test_imagemorph.py index 04860fd61..9da32aa01 100644 --- a/Tests/test_imagemorph.py +++ b/Tests/test_imagemorph.py @@ -328,13 +328,13 @@ def test_wrong_mode() -> None: iml = Image.new("L", (10, 10)) with pytest.raises(RuntimeError): - _imagingmorph.apply(bytes(lut), imrgb.im.ptr, iml.im.ptr) + _imagingmorph.apply(bytes(lut), imrgb.getim(), iml.getim()) with pytest.raises(RuntimeError): - _imagingmorph.apply(bytes(lut), iml.im.ptr, imrgb.im.ptr) + _imagingmorph.apply(bytes(lut), iml.getim(), imrgb.getim()) with pytest.raises(RuntimeError): - _imagingmorph.match(bytes(lut), imrgb.im.ptr) + _imagingmorph.match(bytes(lut), imrgb.getim()) # Should not raise - _imagingmorph.match(bytes(lut), iml.im.ptr) + _imagingmorph.match(bytes(lut), iml.getim()) diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index 5e256b0ab..f028f1775 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -352,7 +352,7 @@ class ImageCmsTransform(Image.ImagePointHandler): im.load() if imOut is None: imOut = Image.new(self.output_mode, im.size, None) - self.transform.apply(im.im.ptr, imOut.im.ptr) + self.transform.apply(im.getim(), imOut.getim()) imOut.info["icc_profile"] = self.output_profile.tobytes() return imOut @@ -361,7 +361,7 @@ class ImageCmsTransform(Image.ImagePointHandler): if im.mode != self.output_mode: msg = "mode mismatch" raise ValueError(msg) # wrong output mode - self.transform.apply(im.im.ptr, im.im.ptr) + self.transform.apply(im.getim(), im.getim()) im.info["icc_profile"] = self.output_profile.tobytes() return im diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py index b32742657..ff3014a8d 100644 --- a/src/PIL/ImageMath.py +++ b/src/PIL/ImageMath.py @@ -65,7 +65,7 @@ class _Operand: except AttributeError as e: msg = f"bad operand type for '{op}'" raise TypeError(msg) from e - _imagingmath.unop(op, out.im.ptr, im_1.im.ptr) + _imagingmath.unop(op, out.getim(), im_1.getim()) else: # binary operation im_2 = self.__fixup(im2) @@ -87,13 +87,12 @@ class _Operand: im_2 = im_2.crop((0, 0) + size) out = Image.new(mode or im_1.mode, im_1.size, None) im_1.load() - im_2.load() try: op = getattr(_imagingmath, f"{op}_{im_1.mode}") except AttributeError as e: msg = f"bad operand type for '{op}'" raise TypeError(msg) from e - _imagingmath.binop(op, out.im.ptr, im_1.im.ptr, im_2.im.ptr) + _imagingmath.binop(op, out.getim(), im_1.getim(), im_2.getim()) return _Operand(out) # unary operators diff --git a/src/PIL/ImageMorph.py b/src/PIL/ImageMorph.py index bc7ed66d3..f0a066b5b 100644 --- a/src/PIL/ImageMorph.py +++ b/src/PIL/ImageMorph.py @@ -213,7 +213,7 @@ class MorphOp: msg = "Image mode must be L" raise ValueError(msg) outimage = Image.new(image.mode, image.size, None) - count = _imagingmorph.apply(bytes(self.lut), image.im.ptr, outimage.im.ptr) + count = _imagingmorph.apply(bytes(self.lut), image.getim(), outimage.getim()) return count, outimage def match(self, image: Image.Image) -> list[tuple[int, int]]: @@ -229,7 +229,7 @@ class MorphOp: if image.mode != "L": msg = "Image mode must be L" raise ValueError(msg) - return _imagingmorph.match(bytes(self.lut), image.im.ptr) + return _imagingmorph.match(bytes(self.lut), image.getim()) def get_on_pixels(self, image: Image.Image) -> list[tuple[int, int]]: """Get a list of all turned on pixels in a binary image @@ -240,7 +240,7 @@ class MorphOp: if image.mode != "L": msg = "Image mode must be L" raise ValueError(msg) - return _imagingmorph.get_on_pixels(image.im.ptr) + return _imagingmorph.get_on_pixels(image.getim()) def load_lut(self, filename: str) -> None: """Load an operator from an mrl file""" diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index d01af364b..c36cf9b84 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -259,7 +259,7 @@ def getimage(photo: PhotoImage) -> Image.Image: """Copies the contents of a PhotoImage to a PIL image memory.""" im = Image.new("RGBA", (photo.width(), photo.height())) - _pyimagingtkcall("PyImagingPhotoGet", photo, im.im.ptr) + _pyimagingtkcall("PyImagingPhotoGet", photo, im.getim()) return im diff --git a/src/PIL/_imagingcms.pyi b/src/PIL/_imagingcms.pyi index 2abd6d0f7..ddcf93ab1 100644 --- a/src/PIL/_imagingcms.pyi +++ b/src/PIL/_imagingcms.pyi @@ -2,6 +2,8 @@ import datetime import sys from typing import Literal, SupportsFloat, TypedDict +from ._typing import CapsuleType + littlecms_version: str | None _Tuple3f = tuple[float, float, float] @@ -108,7 +110,7 @@ class CmsProfile: def is_intent_supported(self, intent: int, direction: int, /) -> int: ... class CmsTransform: - def apply(self, id_in: int, id_out: int) -> int: ... + def apply(self, id_in: CapsuleType, id_out: CapsuleType) -> int: ... def profile_open(profile: str, /) -> CmsProfile: ... def profile_frombytes(profile: bytes, /) -> CmsProfile: ...