Merge pull request #145 from radarhere/use-ptr

Use getim()
This commit is contained in:
Alexander Karpinsky 2024-09-16 10:26:49 +02:00 committed by GitHub
commit 3b09f436bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 14 deletions

View File

@ -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())

View File

@ -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

View File

@ -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

View File

@ -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"""

View File

@ -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

View File

@ -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: ...