Skip to content

Commit

Permalink
Deprecate non-image and unsupported modes
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Apr 30, 2024
1 parent ddbf08f commit d5fe3a7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Tests/test_imagecms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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")
9 changes: 9 additions & 0 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------

Expand Down
25 changes: 25 additions & 0 deletions src/PIL/ImageCms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/_imagingcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand All @@ -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;
}

Expand Down

0 comments on commit d5fe3a7

Please sign in to comment.