mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-15 06:07:33 +03:00
Use getim()
This commit is contained in:
parent
6921f83629
commit
1f3fe6f733
|
@ -328,13 +328,13 @@ def test_wrong_mode() -> None:
|
||||||
iml = Image.new("L", (10, 10))
|
iml = Image.new("L", (10, 10))
|
||||||
|
|
||||||
with pytest.raises(RuntimeError):
|
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):
|
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):
|
with pytest.raises(RuntimeError):
|
||||||
_imagingmorph.match(bytes(lut), imrgb.im.ptr)
|
_imagingmorph.match(bytes(lut), imrgb.getim())
|
||||||
|
|
||||||
# Should not raise
|
# Should not raise
|
||||||
_imagingmorph.match(bytes(lut), iml.im.ptr)
|
_imagingmorph.match(bytes(lut), iml.getim())
|
||||||
|
|
|
@ -352,7 +352,7 @@ class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
im.load()
|
im.load()
|
||||||
if imOut is None:
|
if imOut is None:
|
||||||
imOut = Image.new(self.output_mode, im.size, 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()
|
imOut.info["icc_profile"] = self.output_profile.tobytes()
|
||||||
return imOut
|
return imOut
|
||||||
|
|
||||||
|
@ -361,7 +361,7 @@ class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
if im.mode != self.output_mode:
|
if im.mode != self.output_mode:
|
||||||
msg = "mode mismatch"
|
msg = "mode mismatch"
|
||||||
raise ValueError(msg) # wrong output mode
|
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()
|
im.info["icc_profile"] = self.output_profile.tobytes()
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class _Operand:
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
msg = f"bad operand type for '{op}'"
|
msg = f"bad operand type for '{op}'"
|
||||||
raise TypeError(msg) from e
|
raise TypeError(msg) from e
|
||||||
_imagingmath.unop(op, out.im.ptr, im_1.im.ptr)
|
_imagingmath.unop(op, out.getim(), im_1.getim())
|
||||||
else:
|
else:
|
||||||
# binary operation
|
# binary operation
|
||||||
im_2 = self.__fixup(im2)
|
im_2 = self.__fixup(im2)
|
||||||
|
@ -87,13 +87,12 @@ class _Operand:
|
||||||
im_2 = im_2.crop((0, 0) + size)
|
im_2 = im_2.crop((0, 0) + size)
|
||||||
out = Image.new(mode or im_1.mode, im_1.size, None)
|
out = Image.new(mode or im_1.mode, im_1.size, None)
|
||||||
im_1.load()
|
im_1.load()
|
||||||
im_2.load()
|
|
||||||
try:
|
try:
|
||||||
op = getattr(_imagingmath, f"{op}_{im_1.mode}")
|
op = getattr(_imagingmath, f"{op}_{im_1.mode}")
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
msg = f"bad operand type for '{op}'"
|
msg = f"bad operand type for '{op}'"
|
||||||
raise TypeError(msg) from e
|
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)
|
return _Operand(out)
|
||||||
|
|
||||||
# unary operators
|
# unary operators
|
||||||
|
|
|
@ -213,7 +213,7 @@ class MorphOp:
|
||||||
msg = "Image mode must be L"
|
msg = "Image mode must be L"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
outimage = Image.new(image.mode, image.size, None)
|
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
|
return count, outimage
|
||||||
|
|
||||||
def match(self, image: Image.Image) -> list[tuple[int, int]]:
|
def match(self, image: Image.Image) -> list[tuple[int, int]]:
|
||||||
|
@ -229,7 +229,7 @@ class MorphOp:
|
||||||
if image.mode != "L":
|
if image.mode != "L":
|
||||||
msg = "Image mode must be L"
|
msg = "Image mode must be L"
|
||||||
raise ValueError(msg)
|
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]]:
|
def get_on_pixels(self, image: Image.Image) -> list[tuple[int, int]]:
|
||||||
"""Get a list of all turned on pixels in a binary image
|
"""Get a list of all turned on pixels in a binary image
|
||||||
|
@ -240,7 +240,7 @@ class MorphOp:
|
||||||
if image.mode != "L":
|
if image.mode != "L":
|
||||||
msg = "Image mode must be L"
|
msg = "Image mode must be L"
|
||||||
raise ValueError(msg)
|
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:
|
def load_lut(self, filename: str) -> None:
|
||||||
"""Load an operator from an mrl file"""
|
"""Load an operator from an mrl file"""
|
||||||
|
|
|
@ -259,7 +259,7 @@ def getimage(photo: PhotoImage) -> Image.Image:
|
||||||
"""Copies the contents of a PhotoImage to a PIL image memory."""
|
"""Copies the contents of a PhotoImage to a PIL image memory."""
|
||||||
im = Image.new("RGBA", (photo.width(), photo.height()))
|
im = Image.new("RGBA", (photo.width(), photo.height()))
|
||||||
|
|
||||||
_pyimagingtkcall("PyImagingPhotoGet", photo, im.im.ptr)
|
_pyimagingtkcall("PyImagingPhotoGet", photo, im.getim())
|
||||||
|
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ import datetime
|
||||||
import sys
|
import sys
|
||||||
from typing import Literal, SupportsFloat, TypedDict
|
from typing import Literal, SupportsFloat, TypedDict
|
||||||
|
|
||||||
|
from ._typing import CapsuleType
|
||||||
|
|
||||||
littlecms_version: str | None
|
littlecms_version: str | None
|
||||||
|
|
||||||
_Tuple3f = tuple[float, float, float]
|
_Tuple3f = tuple[float, float, float]
|
||||||
|
@ -108,7 +110,7 @@ class CmsProfile:
|
||||||
def is_intent_supported(self, intent: int, direction: int, /) -> int: ...
|
def is_intent_supported(self, intent: int, direction: int, /) -> int: ...
|
||||||
|
|
||||||
class CmsTransform:
|
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_open(profile: str, /) -> CmsProfile: ...
|
||||||
def profile_frombytes(profile: bytes, /) -> CmsProfile: ...
|
def profile_frombytes(profile: bytes, /) -> CmsProfile: ...
|
||||||
|
|
Loading…
Reference in New Issue
Block a user