mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-28 02:04:36 +03:00
add LCMS2 flags to ImageCms
This commit is contained in:
parent
40a3f91af2
commit
90991428fa
|
@ -90,6 +90,16 @@ def test_sanity():
|
||||||
hopper().point(t)
|
hopper().point(t)
|
||||||
|
|
||||||
|
|
||||||
|
def test_flags():
|
||||||
|
assert ImageCms.Flags.NONE == 0
|
||||||
|
assert ImageCms.Flags.GRIDPOINTS(0) == ImageCms.Flags.NONE
|
||||||
|
assert ImageCms.Flags.GRIDPOINTS(256) == ImageCms.Flags.NONE
|
||||||
|
|
||||||
|
assert ImageCms.Flags.GRIDPOINTS(255) == (255 << 16)
|
||||||
|
assert ImageCms.Flags.GRIDPOINTS(-1) == ImageCms.Flags.GRIDPOINTS(255)
|
||||||
|
assert ImageCms.Flags.GRIDPOINTS(511) == ImageCms.Flags.GRIDPOINTS(255)
|
||||||
|
|
||||||
|
|
||||||
def test_name():
|
def test_name():
|
||||||
skip_missing()
|
skip_missing()
|
||||||
# get profile information for file
|
# get profile information for file
|
||||||
|
|
|
@ -16,8 +16,10 @@
|
||||||
# below for the original description.
|
# below for the original description.
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import operator
|
||||||
import sys
|
import sys
|
||||||
from enum import IntEnum
|
from enum import IntEnum, IntFlag
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
|
|
||||||
|
@ -119,6 +121,48 @@ class Direction(IntEnum):
|
||||||
#
|
#
|
||||||
# flags
|
# flags
|
||||||
|
|
||||||
|
|
||||||
|
class Flags(IntFlag):
|
||||||
|
# These are taken from lcms2.h (including comments)
|
||||||
|
NONE = 0
|
||||||
|
NOCACHE = 0x0040 # Inhibit 1-pixel cache
|
||||||
|
NOOPTIMIZE = 0x0100 # Inhibit optimizations
|
||||||
|
NULLTRANSFORM = 0x0200 # Don't transform anyway
|
||||||
|
GAMUTCHECK = 0x1000 # Out of Gamut alarm
|
||||||
|
SOFTPROOFING = 0x4000 # Do softproofing
|
||||||
|
BLACKPOINTCOMPENSATION = 0x2000
|
||||||
|
NOWHITEONWHITEFIXUP = 0x0004 # Don't fix scum dot
|
||||||
|
HIGHRESPRECALC = 0x0400 # Use more memory to give better accuracy
|
||||||
|
LOWRESPRECALC = 0x0800 # Use less memory to minimize resources
|
||||||
|
# this should be 8BITS_DEVICELINK, but that is not a valid name in Python:
|
||||||
|
USE_8BITS_DEVICELINK = 0x0008 # Create 8 bits devicelinks
|
||||||
|
GUESSDEVICECLASS = 0x0020 # Guess device class (for transform2devicelink)
|
||||||
|
KEEP_SEQUENCE = 0x0080 # Keep profile sequence for devicelink creation
|
||||||
|
FORCE_CLUT = 0x0002 # Force CLUT optimization
|
||||||
|
CLUT_POST_LINEARIZATION = 0x0001 # create postlinearization tables if possible
|
||||||
|
CLUT_PRE_LINEARIZATION = 0x0010 # create prelinearization tables if possible
|
||||||
|
NONEGATIVES = 0x8000 # Prevent negative numbers in floating point transforms
|
||||||
|
COPY_ALPHA = 0x04000000 # Alpha channels are copied on cmsDoTransform()
|
||||||
|
NODEFAULTRESOURCEDEF = 0x01000000
|
||||||
|
|
||||||
|
_GRIDPOINTS_1 = 1 << 16
|
||||||
|
_GRIDPOINTS_2 = 2 << 16
|
||||||
|
_GRIDPOINTS_4 = 4 << 16
|
||||||
|
_GRIDPOINTS_8 = 8 << 16
|
||||||
|
_GRIDPOINTS_16 = 16 << 16
|
||||||
|
_GRIDPOINTS_32 = 32 << 16
|
||||||
|
_GRIDPOINTS_64 = 64 << 16
|
||||||
|
_GRIDPOINTS_128 = 128 << 16
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def GRIDPOINTS(n: int) -> Flags:
|
||||||
|
# Fine-tune control over number of gridpoints
|
||||||
|
return Flags.NONE | ((n & 0xFF) << 16)
|
||||||
|
|
||||||
|
|
||||||
|
_MAX_FLAG = reduce(operator.or_, Flags)
|
||||||
|
|
||||||
|
|
||||||
FLAGS = {
|
FLAGS = {
|
||||||
"MATRIXINPUT": 1,
|
"MATRIXINPUT": 1,
|
||||||
"MATRIXOUTPUT": 2,
|
"MATRIXOUTPUT": 2,
|
||||||
|
@ -142,11 +186,6 @@ FLAGS = {
|
||||||
"GRIDPOINTS": lambda n: (n & 0xFF) << 16, # Gridpoints
|
"GRIDPOINTS": lambda n: (n & 0xFF) << 16, # Gridpoints
|
||||||
}
|
}
|
||||||
|
|
||||||
_MAX_FLAG = 0
|
|
||||||
for flag in FLAGS.values():
|
|
||||||
if isinstance(flag, int):
|
|
||||||
_MAX_FLAG = _MAX_FLAG | flag
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------.
|
# --------------------------------------------------------------------.
|
||||||
# Experimental PIL-level API
|
# Experimental PIL-level API
|
||||||
|
@ -218,7 +257,7 @@ class ImageCmsTransform(Image.ImagePointHandler):
|
||||||
intent=Intent.PERCEPTUAL,
|
intent=Intent.PERCEPTUAL,
|
||||||
proof=None,
|
proof=None,
|
||||||
proof_intent=Intent.ABSOLUTE_COLORIMETRIC,
|
proof_intent=Intent.ABSOLUTE_COLORIMETRIC,
|
||||||
flags=0,
|
flags=Flags.NONE,
|
||||||
):
|
):
|
||||||
if proof is None:
|
if proof is None:
|
||||||
self.transform = core.buildTransform(
|
self.transform = core.buildTransform(
|
||||||
|
@ -303,7 +342,7 @@ def profileToProfile(
|
||||||
renderingIntent=Intent.PERCEPTUAL,
|
renderingIntent=Intent.PERCEPTUAL,
|
||||||
outputMode=None,
|
outputMode=None,
|
||||||
inPlace=False,
|
inPlace=False,
|
||||||
flags=0,
|
flags=Flags.NONE,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Applies an ICC transformation to a given image, mapping from
|
(pyCMS) Applies an ICC transformation to a given image, mapping from
|
||||||
|
@ -420,7 +459,7 @@ def buildTransform(
|
||||||
inMode,
|
inMode,
|
||||||
outMode,
|
outMode,
|
||||||
renderingIntent=Intent.PERCEPTUAL,
|
renderingIntent=Intent.PERCEPTUAL,
|
||||||
flags=0,
|
flags=Flags.NONE,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Builds an ICC transform mapping from the ``inputProfile`` to the
|
(pyCMS) Builds an ICC transform mapping from the ``inputProfile`` to the
|
||||||
|
@ -482,7 +521,7 @@ def buildTransform(
|
||||||
raise PyCMSError(msg)
|
raise PyCMSError(msg)
|
||||||
|
|
||||||
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
||||||
msg = "flags must be an integer between 0 and %s" + _MAX_FLAG
|
msg = f"flags must be an integer between 0 and {_MAX_FLAG}"
|
||||||
raise PyCMSError(msg)
|
raise PyCMSError(msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -505,7 +544,7 @@ def buildProofTransform(
|
||||||
outMode,
|
outMode,
|
||||||
renderingIntent=Intent.PERCEPTUAL,
|
renderingIntent=Intent.PERCEPTUAL,
|
||||||
proofRenderingIntent=Intent.ABSOLUTE_COLORIMETRIC,
|
proofRenderingIntent=Intent.ABSOLUTE_COLORIMETRIC,
|
||||||
flags=FLAGS["SOFTPROOFING"],
|
flags=Flags.SOFTPROOFING,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
(pyCMS) Builds an ICC transform mapping from the ``inputProfile`` to the
|
(pyCMS) Builds an ICC transform mapping from the ``inputProfile`` to the
|
||||||
|
@ -586,7 +625,7 @@ def buildProofTransform(
|
||||||
raise PyCMSError(msg)
|
raise PyCMSError(msg)
|
||||||
|
|
||||||
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
|
||||||
msg = "flags must be an integer between 0 and %s" + _MAX_FLAG
|
msg = f"flags must be an integer between 0 and {_MAX_FLAG}"
|
||||||
raise PyCMSError(msg)
|
raise PyCMSError(msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user