Skip to content

Commit d5fe3a7

Browse files
committed
Deprecate non-image and unsupported modes
1 parent ddbf08f commit d5fe3a7

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

Tests/test_imagecms.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ def test_auxiliary_channels_isolated() -> None:
663663

664664
def test_long_modes() -> None:
665665
p = ImageCms.getOpenProfile("Tests/icc/sGrey-v2-nano.icc")
666-
ImageCms.buildTransform(p, p, "ABCDEFGHI", "ABCDEFGHI")
666+
with pytest.warns(DeprecationWarning):
667+
ImageCms.buildTransform(p, p, "ABCDEFGHI", "ABCDEFGHI")
667668

668669

669670
@pytest.mark.parametrize("mode", ("RGB", "RGBA", "RGBX"))
@@ -684,3 +685,9 @@ def test_deprecation() -> None:
684685
assert ImageCms.VERSION == "1.0.0 pil"
685686
with pytest.warns(DeprecationWarning):
686687
assert isinstance(ImageCms.FLAGS, dict)
688+
689+
profile = ImageCmsProfile(ImageCms.createProfile("sRGB"))
690+
with pytest.warns(DeprecationWarning):
691+
ImageCms.ImageCmsTransform(profile, profile, "RGBA;16B", "RGB")
692+
with pytest.warns(DeprecationWarning):
693+
ImageCms.ImageCmsTransform(profile, profile, "RGB", "RGBA;16B")

docs/deprecations.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ Support for LibTIFF earlier than 4
115115
Support for LibTIFF earlier than version 4 has been deprecated.
116116
Upgrade to a newer version of LibTIFF instead.
117117

118+
Non-image modes in ImageCms
119+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
120+
121+
.. deprecated:: 10.4.0
122+
123+
The use in ImageCms of input modes and output modes that are not Pillow image
124+
modes has been deprecated. Defaulting to "L" or "1" if the mode cannot be
125+
mapped is also deprecated.
126+
118127
Removed features
119128
----------------
120129

src/PIL/ImageCms.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,31 @@ def __init__(
299299
proof_intent: Intent = Intent.ABSOLUTE_COLORIMETRIC,
300300
flags: Flags = Flags.NONE,
301301
):
302+
supported_modes = (
303+
"RGB",
304+
"RGBA",
305+
"RGBX",
306+
"CMYK",
307+
"I;16",
308+
"I;16L",
309+
"I;16B",
310+
"YCbCr",
311+
"LAB",
312+
"L",
313+
"1",
314+
)
315+
for mode in (input_mode, output_mode):
316+
if mode not in supported_modes:
317+
deprecate(
318+
mode,
319+
12,
320+
{
321+
"L;16": "I;16 or I;16L",
322+
"L:16B": "I;16B",
323+
"YCCA": "YCbCr",
324+
"YCC": "YCbCr",
325+
}.get(mode),
326+
)
302327
if proof is None:
303328
self.transform = core.buildTransform(
304329
input.profile, output.profile, input_mode, output_mode, intent, flags

src/_imagingcms.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,21 @@ findLCMStype(char *PILmode) {
226226
if (strcmp(PILmode, "CMYK") == 0) {
227227
return TYPE_CMYK_8;
228228
}
229-
if (strcmp(PILmode, "L;16") == 0) {
229+
if (
230+
strcmp(PILmode, "I;16") == 0 ||
231+
strcmp(PILmode, "I;16L") == 0 ||
232+
strcmp(PILmode, "L;16") == 0
233+
) {
230234
return TYPE_GRAY_16;
231235
}
232-
if (strcmp(PILmode, "L;16B") == 0) {
236+
if (
237+
strcmp(PILmode, "I;16B") == 0 ||
238+
strcmp(PILmode, "L;16B") == 0
239+
) {
233240
return TYPE_GRAY_16_SE;
234241
}
235242
if (
243+
strcmp(PILmode, "YCbCr") == 0 ||
236244
strcmp(PILmode, "YCCA") == 0 ||
237245
strcmp(PILmode, "YCC") == 0
238246
) {
@@ -242,7 +250,7 @@ findLCMStype(char *PILmode) {
242250
// LabX equivalent like ALab, but not reversed -- no #define in lcms2
243251
return (COLORSPACE_SH(PT_LabV2) | CHANNELS_SH(3) | BYTES_SH(1) | EXTRA_SH(1));
244252
}
245-
/* presume "L" by default */
253+
/* presume "1" or "L" by default */
246254
return TYPE_GRAY_8;
247255
}
248256

0 commit comments

Comments
 (0)