diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 55f72c3b9..dbbd46dcf 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -678,7 +678,8 @@ def test_auxiliary_channels_isolated() -> None: def test_long_modes() -> None: p = ImageCms.getOpenProfile("Tests/icc/sGrey-v2-nano.icc") - ImageCms.buildTransform(p, p, "ABCDEFGHI", "ABCDEFGHI") + with pytest.warns(DeprecationWarning): + ImageCms.buildTransform(p, p, "ABCDEFGHI", "ABCDEFGHI") @pytest.mark.parametrize("mode", ("RGB", "RGBA", "RGBX")) @@ -699,3 +700,9 @@ def test_deprecation() -> None: assert ImageCms.VERSION == "1.0.0 pil" with pytest.warns(DeprecationWarning): assert isinstance(ImageCms.FLAGS, dict) + + profile = ImageCmsProfile(ImageCms.createProfile("sRGB")) + with pytest.warns(DeprecationWarning): + ImageCms.ImageCmsTransform(profile, profile, "RGBA;16B", "RGB") + with pytest.warns(DeprecationWarning): + ImageCms.ImageCmsTransform(profile, profile, "RGB", "RGBA;16B") diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 627672e1f..e6566eae2 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -107,6 +107,15 @@ BGR;15, BGR 16 and BGR;24 The experimental BGR;15, BGR;16 and BGR;24 modes have been deprecated. +Non-image modes in ImageCms +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. deprecated:: 10.4.0 + +The use in :py:mod:`.ImageCms` of input modes and output modes that are not Pillow +image modes has been deprecated. Defaulting to "L" or "1" if the mode cannot be mapped +is also deprecated. + Support for LibTIFF earlier than 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/releasenotes/10.4.0.rst b/docs/releasenotes/10.4.0.rst index 44727efd4..96300c008 100644 --- a/docs/releasenotes/10.4.0.rst +++ b/docs/releasenotes/10.4.0.rst @@ -28,6 +28,13 @@ BGR;15, BGR 16 and BGR;24 The experimental BGR;15, BGR;16 and BGR;24 modes have been deprecated. +Non-image modes in ImageCms +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The use in :py:mod:`.ImageCms` of input modes and output modes that are not Pillow +image modes has been deprecated. Defaulting to "L" or "1" if the mode cannot be mapped +is also deprecated. + Support for LibTIFF earlier than 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index 19a79facc..ec10230f1 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -299,6 +299,31 @@ class ImageCmsTransform(Image.ImagePointHandler): proof_intent: Intent = Intent.ABSOLUTE_COLORIMETRIC, flags: Flags = Flags.NONE, ): + supported_modes = ( + "RGB", + "RGBA", + "RGBX", + "CMYK", + "I;16", + "I;16L", + "I;16B", + "YCbCr", + "LAB", + "L", + "1", + ) + for mode in (input_mode, output_mode): + if mode not in supported_modes: + deprecate( + mode, + 12, + { + "L;16": "I;16 or I;16L", + "L:16B": "I;16B", + "YCCA": "YCbCr", + "YCC": "YCbCr", + }.get(mode), + ) if proof is None: self.transform = core.buildTransform( input.profile, output.profile, input_mode, output_mode, intent, flags diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 2b9612db7..590e1b983 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -223,20 +223,22 @@ findLCMStype(char *PILmode) { if (strcmp(PILmode, "CMYK") == 0) { return TYPE_CMYK_8; } - if (strcmp(PILmode, "L;16") == 0) { + if (strcmp(PILmode, "I;16") == 0 || strcmp(PILmode, "I;16L") == 0 || + strcmp(PILmode, "L;16") == 0) { return TYPE_GRAY_16; } - if (strcmp(PILmode, "L;16B") == 0) { + if (strcmp(PILmode, "I;16B") == 0 || strcmp(PILmode, "L;16B") == 0) { return TYPE_GRAY_16_SE; } - if (strcmp(PILmode, "YCCA") == 0 || strcmp(PILmode, "YCC") == 0) { + if (strcmp(PILmode, "YCbCr") == 0 || strcmp(PILmode, "YCCA") == 0 || + strcmp(PILmode, "YCC") == 0) { return TYPE_YCbCr_8; } if (strcmp(PILmode, "LAB") == 0) { // LabX equivalent like ALab, but not reversed -- no #define in lcms2 return (COLORSPACE_SH(PT_LabV2) | CHANNELS_SH(3) | BYTES_SH(1) | EXTRA_SH(1)); } - /* presume "L" by default */ + /* presume "1" or "L" by default */ return TYPE_GRAY_8; }