Skip to content

Commit 4d6dff3

Browse files
authored
Merge pull request #8031 from radarhere/imagingcms_modes
2 parents 70b3815 + eea3ac7 commit 4d6dff3

File tree

5 files changed

+55
-5
lines changed

5 files changed

+55
-5
lines changed

Tests/test_imagecms.py

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

680680
def test_long_modes() -> None:
681681
p = ImageCms.getOpenProfile("Tests/icc/sGrey-v2-nano.icc")
682-
ImageCms.buildTransform(p, p, "ABCDEFGHI", "ABCDEFGHI")
682+
with pytest.warns(DeprecationWarning):
683+
ImageCms.buildTransform(p, p, "ABCDEFGHI", "ABCDEFGHI")
683684

684685

685686
@pytest.mark.parametrize("mode", ("RGB", "RGBA", "RGBX"))
@@ -700,3 +701,9 @@ def test_deprecation() -> None:
700701
assert ImageCms.VERSION == "1.0.0 pil"
701702
with pytest.warns(DeprecationWarning):
702703
assert isinstance(ImageCms.FLAGS, dict)
704+
705+
profile = ImageCmsProfile(ImageCms.createProfile("sRGB"))
706+
with pytest.warns(DeprecationWarning):
707+
ImageCms.ImageCmsTransform(profile, profile, "RGBA;16B", "RGB")
708+
with pytest.warns(DeprecationWarning):
709+
ImageCms.ImageCmsTransform(profile, profile, "RGB", "RGBA;16B")

docs/deprecations.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ BGR;15, BGR 16 and BGR;24
107107

108108
The experimental BGR;15, BGR;16 and BGR;24 modes have been deprecated.
109109

110+
Non-image modes in ImageCms
111+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
112+
113+
.. deprecated:: 10.4.0
114+
115+
The use in :py:mod:`.ImageCms` of input modes and output modes that are not Pillow
116+
image modes has been deprecated. Defaulting to "L" or "1" if the mode cannot be mapped
117+
is also deprecated.
118+
110119
Support for LibTIFF earlier than 4
111120
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112121

docs/releasenotes/10.4.0.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ BGR;15, BGR 16 and BGR;24
2828

2929
The experimental BGR;15, BGR;16 and BGR;24 modes have been deprecated.
3030

31+
Non-image modes in ImageCms
32+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
34+
The use in :py:mod:`.ImageCms` of input modes and output modes that are not Pillow
35+
image modes has been deprecated. Defaulting to "L" or "1" if the mode cannot be mapped
36+
is also deprecated.
37+
3138
Support for LibTIFF earlier than 4
3239
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3340

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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,22 @@ findLCMStype(char *PILmode) {
223223
if (strcmp(PILmode, "CMYK") == 0) {
224224
return TYPE_CMYK_8;
225225
}
226-
if (strcmp(PILmode, "L;16") == 0) {
226+
if (strcmp(PILmode, "I;16") == 0 || strcmp(PILmode, "I;16L") == 0 ||
227+
strcmp(PILmode, "L;16") == 0) {
227228
return TYPE_GRAY_16;
228229
}
229-
if (strcmp(PILmode, "L;16B") == 0) {
230+
if (strcmp(PILmode, "I;16B") == 0 || strcmp(PILmode, "L;16B") == 0) {
230231
return TYPE_GRAY_16_SE;
231232
}
232-
if (strcmp(PILmode, "YCCA") == 0 || strcmp(PILmode, "YCC") == 0) {
233+
if (strcmp(PILmode, "YCbCr") == 0 || strcmp(PILmode, "YCCA") == 0 ||
234+
strcmp(PILmode, "YCC") == 0) {
233235
return TYPE_YCbCr_8;
234236
}
235237
if (strcmp(PILmode, "LAB") == 0) {
236238
// LabX equivalent like ALab, but not reversed -- no #define in lcms2
237239
return (COLORSPACE_SH(PT_LabV2) | CHANNELS_SH(3) | BYTES_SH(1) | EXTRA_SH(1));
238240
}
239-
/* presume "L" by default */
241+
/* presume "1" or "L" by default */
240242
return TYPE_GRAY_8;
241243
}
242244

0 commit comments

Comments
 (0)