mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 13:14:27 +03:00
add type hints for ImageCms.{ImageCmsProfile,ImageCmsTransform}
This commit is contained in:
parent
24ed5db2d1
commit
0630ef061f
|
@ -23,7 +23,7 @@ import operator
|
||||||
import sys
|
import sys
|
||||||
from enum import IntEnum, IntFlag
|
from enum import IntEnum, IntFlag
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from typing import Any
|
from typing import Any, BinaryIO
|
||||||
|
|
||||||
from . import Image, __version__
|
from . import Image, __version__
|
||||||
from ._deprecate import deprecate
|
from ._deprecate import deprecate
|
||||||
|
@ -237,7 +237,7 @@ _FLAGS = {
|
||||||
|
|
||||||
|
|
||||||
class ImageCmsProfile:
|
class ImageCmsProfile:
|
||||||
def __init__(self, profile):
|
def __init__(self, profile: str | BinaryIO | core.CmsProfile) -> None:
|
||||||
"""
|
"""
|
||||||
:param profile: Either a string representing a filename,
|
:param profile: Either a string representing a filename,
|
||||||
a file like object containing a profile or a
|
a file like object containing a profile or a
|
||||||
|
@ -260,16 +260,16 @@ class ImageCmsProfile:
|
||||||
elif isinstance(profile, _imagingcms.CmsProfile):
|
elif isinstance(profile, _imagingcms.CmsProfile):
|
||||||
self._set(profile)
|
self._set(profile)
|
||||||
else:
|
else:
|
||||||
msg = "Invalid type for Profile"
|
msg = "Invalid type for Profile" # type: ignore[unreachable]
|
||||||
raise TypeError(msg)
|
raise TypeError(msg)
|
||||||
|
|
||||||
def _set(self, profile, filename=None):
|
def _set(self, profile: core.CmsProfile, filename: str | None = None) -> None:
|
||||||
self.profile = profile
|
self.profile = profile
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.product_name = None # profile.product_name
|
self.product_name = None # profile.product_name
|
||||||
self.product_info = None # profile.product_info
|
self.product_info = None # profile.product_info
|
||||||
|
|
||||||
def tobytes(self):
|
def tobytes(self) -> bytes:
|
||||||
"""
|
"""
|
||||||
Returns the profile in a format suitable for embedding in
|
Returns the profile in a format suitable for embedding in
|
||||||
saved images.
|
saved images.
|
||||||
|
@ -290,14 +290,14 @@ class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
input,
|
input: ImageCmsProfile,
|
||||||
output,
|
output: ImageCmsProfile,
|
||||||
input_mode,
|
input_mode: str,
|
||||||
output_mode,
|
output_mode: str,
|
||||||
intent=Intent.PERCEPTUAL,
|
intent: Intent = Intent.PERCEPTUAL,
|
||||||
proof=None,
|
proof: ImageCmsProfile | None = None,
|
||||||
proof_intent=Intent.ABSOLUTE_COLORIMETRIC,
|
proof_intent: Intent = Intent.ABSOLUTE_COLORIMETRIC,
|
||||||
flags=Flags.NONE,
|
flags: Flags | int = Flags.NONE,
|
||||||
):
|
):
|
||||||
if proof is None:
|
if proof is None:
|
||||||
self.transform = core.buildTransform(
|
self.transform = core.buildTransform(
|
||||||
|
@ -320,10 +320,10 @@ class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
|
|
||||||
self.output_profile = output
|
self.output_profile = output
|
||||||
|
|
||||||
def point(self, im):
|
def point(self, im: Image.Image) -> Image.Image:
|
||||||
return self.apply(im)
|
return self.apply(im)
|
||||||
|
|
||||||
def apply(self, im, imOut=None):
|
def apply(self, im: Image.Image, imOut: Image.Image | None = None) -> Image.Image:
|
||||||
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)
|
||||||
|
@ -331,7 +331,7 @@ class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
imOut.info["icc_profile"] = self.output_profile.tobytes()
|
imOut.info["icc_profile"] = self.output_profile.tobytes()
|
||||||
return imOut
|
return imOut
|
||||||
|
|
||||||
def apply_in_place(self, im):
|
def apply_in_place(self, im: Image.Image) -> Image.Image:
|
||||||
im.load()
|
im.load()
|
||||||
if im.mode != self.output_mode:
|
if im.mode != self.output_mode:
|
||||||
msg = "mode mismatch"
|
msg = "mode mismatch"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user