diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index bf629fa79cc..a96b5f0e726 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -663,7 +663,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")) @@ -684,3 +685,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 b2cd968fee3..49a3c80cb32 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -115,6 +115,15 @@ Support for LibTIFF earlier than 4 Support for LibTIFF earlier than version 4 has been deprecated. Upgrade to a newer version of LibTIFF instead. +Non-image modes in ImageCms +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. deprecated:: 10.4.0 + +The use in 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. + Removed features ---------------- diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index 5f5c5df54e7..cc130f2c3d7 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -299,6 +299,31 @@ def __init__( 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 63d78f84daa..c47e3866ddc 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -226,13 +226,21 @@ 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, "YCbCr") == 0 || strcmp(PILmode, "YCCA") == 0 || strcmp(PILmode, "YCC") == 0 ) { @@ -242,7 +250,7 @@ findLCMStype(char *PILmode) { // 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; }