From 80f69ad32e077e041af3181f1f4b502722fe603f Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 28 Jan 2019 08:39:18 +0200 Subject: [PATCH 01/11] Convert tabs to spaces --- src/_imagingcms.c | 98 +++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 5e4196cb7..80cef2668 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -735,12 +735,12 @@ _xyz3_py(cmsCIEXYZ* XYZ) cmsXYZ2xyY(&xyY[2], &XYZ[2]); return Py_BuildValue("(((d,d,d),(d,d,d),(d,d,d)),((d,d,d),(d,d,d),(d,d,d)))", - XYZ[0].X, XYZ[0].Y, XYZ[0].Z, - XYZ[1].X, XYZ[1].Y, XYZ[1].Z, - XYZ[2].X, XYZ[2].Y, XYZ[2].Z, - xyY[0].x, xyY[0].y, xyY[0].Y, - xyY[1].x, xyY[1].y, xyY[1].Y, - xyY[2].x, xyY[2].y, xyY[2].Y); + XYZ[0].X, XYZ[0].Y, XYZ[0].Z, + XYZ[1].X, XYZ[1].Y, XYZ[1].Z, + XYZ[2].X, XYZ[2].Y, XYZ[2].Z, + xyY[0].x, xyY[0].y, xyY[0].Y, + xyY[1].x, xyY[1].y, xyY[1].Y, + xyY[2].x, xyY[2].y, xyY[2].Y); } static PyObject* @@ -783,9 +783,9 @@ _profile_read_ciexyy_triple(CmsProfileObject* self, cmsTagSignature info) /* Note: lcms does all the heavy lifting and error checking (nr of channels == 3). */ return Py_BuildValue("((d,d,d),(d,d,d),(d,d,d)),", - triple->Red.x, triple->Red.y, triple->Red.Y, - triple->Green.x, triple->Green.y, triple->Green.Y, - triple->Blue.x, triple->Blue.y, triple->Blue.Y); + triple->Red.x, triple->Red.y, triple->Red.Y, + triple->Green.x, triple->Green.y, triple->Green.Y, + triple->Blue.x, triple->Blue.y, triple->Blue.Y); } static PyObject* @@ -817,12 +817,12 @@ _profile_read_named_color_list(CmsProfileObject* self, cmsTagSignature info) for (i = 0; i < n; i++) { PyObject* str; cmsNamedColorInfo(ncl, i, name, NULL, NULL, NULL, NULL); - str = PyUnicode_FromString(name); - if (str == NULL) { - Py_DECREF(result); - Py_INCREF(Py_None); - return Py_None; - } + str = PyUnicode_FromString(name); + if (str == NULL) { + Py_DECREF(result); + Py_INCREF(Py_None); + return Py_None; + } PyList_SET_ITEM(result, i, str); } @@ -844,9 +844,9 @@ static cmsBool _calculate_rgb_primaries(CmsProfileObject* self, cmsCIEXYZTRIPLE* // transform from our profile to XYZ using doubles for highest precision hTransform = cmsCreateTransform(self->profile, TYPE_RGB_DBL, - hXYZ, TYPE_XYZ_DBL, - INTENT_RELATIVE_COLORIMETRIC, - cmsFLAGS_NOCACHE | cmsFLAGS_NOOPTIMIZE); + hXYZ, TYPE_XYZ_DBL, + INTENT_RELATIVE_COLORIMETRIC, + cmsFLAGS_NOCACHE | cmsFLAGS_NOOPTIMIZE); cmsCloseProfile(hXYZ); if (hTransform == NULL) return 0; @@ -885,31 +885,31 @@ _is_intent_supported(CmsProfileObject* self, int clut) n = cmsGetSupportedIntents(INTENTS, - intent_ids, - intent_descs); + intent_ids, + intent_descs); for (i = 0; i < n; i++) { int intent = (int) intent_ids[i]; PyObject* id; - PyObject* entry; + PyObject* entry; - /* Only valid for ICC Intents (otherwise we read invalid memory in lcms cmsio1.c). */ - if (!(intent == INTENT_PERCEPTUAL || intent == INTENT_RELATIVE_COLORIMETRIC - || intent == INTENT_SATURATION || intent == INTENT_ABSOLUTE_COLORIMETRIC)) - continue; + /* Only valid for ICC Intents (otherwise we read invalid memory in lcms cmsio1.c). */ + if (!(intent == INTENT_PERCEPTUAL || intent == INTENT_RELATIVE_COLORIMETRIC + || intent == INTENT_SATURATION || intent == INTENT_ABSOLUTE_COLORIMETRIC)) + continue; - id = PyInt_FromLong((long) intent); - entry = Py_BuildValue("(OOO)", - _check_intent(clut, self->profile, intent, LCMS_USED_AS_INPUT) ? Py_True : Py_False, - _check_intent(clut, self->profile, intent, LCMS_USED_AS_OUTPUT) ? Py_True : Py_False, - _check_intent(clut, self->profile, intent, LCMS_USED_AS_PROOF) ? Py_True : Py_False); - if (id == NULL || entry == NULL) { - Py_XDECREF(id); - Py_XDECREF(entry); - Py_XDECREF(result); - Py_INCREF(Py_None); - return Py_None; - } - PyDict_SetItem(result, id, entry); + id = PyInt_FromLong((long) intent); + entry = Py_BuildValue("(OOO)", + _check_intent(clut, self->profile, intent, LCMS_USED_AS_INPUT) ? Py_True : Py_False, + _check_intent(clut, self->profile, intent, LCMS_USED_AS_OUTPUT) ? Py_True : Py_False, + _check_intent(clut, self->profile, intent, LCMS_USED_AS_PROOF) ? Py_True : Py_False); + if (id == NULL || entry == NULL) { + Py_XDECREF(id); + Py_XDECREF(entry); + Py_XDECREF(result); + Py_INCREF(Py_None); + return Py_None; + } + PyDict_SetItem(result, id, entry); } return result; } @@ -1070,7 +1070,7 @@ cms_profile_getattr_creation_date(CmsProfileObject* self, void* closure) } return PyDateTime_FromDateAndTime(1900 + ct.tm_year, ct.tm_mon, ct.tm_mday, - ct.tm_hour, ct.tm_min, ct.tm_sec, 0); + ct.tm_hour, ct.tm_min, ct.tm_sec, 0); } static PyObject* @@ -1295,7 +1295,7 @@ cms_profile_getattr_green_primary(CmsProfileObject* self, void* closure) result = _calculate_rgb_primaries(self, &primaries); if (! result) { Py_INCREF(Py_None); - return Py_None; + return Py_None; } return _xyz_py(&primaries.Green); @@ -1311,7 +1311,7 @@ cms_profile_getattr_blue_primary(CmsProfileObject* self, void* closure) result = _calculate_rgb_primaries(self, &primaries); if (! result) { Py_INCREF(Py_None); - return Py_None; + return Py_None; } return _xyz_py(&primaries.Blue); @@ -1394,11 +1394,11 @@ cms_profile_getattr_icc_measurement_condition (CmsProfileObject* self, void* clo geo = "unknown"; return Py_BuildValue("{s:i,s:(ddd),s:s,s:d,s:s}", - "observer", mc->Observer, - "backing", mc->Backing.X, mc->Backing.Y, mc->Backing.Z, - "geo", geo, - "flare", mc->Flare, - "illuminant_type", _illu_map(mc->IlluminantType)); + "observer", mc->Observer, + "backing", mc->Backing.X, mc->Backing.Y, mc->Backing.Z, + "geo", geo, + "flare", mc->Flare, + "illuminant_type", _illu_map(mc->IlluminantType)); } static PyObject* @@ -1419,9 +1419,9 @@ cms_profile_getattr_icc_viewing_condition (CmsProfileObject* self, void* closure } return Py_BuildValue("{s:(ddd),s:(ddd),s:s}", - "illuminant", vc->IlluminantXYZ.X, vc->IlluminantXYZ.Y, vc->IlluminantXYZ.Z, - "surround", vc->SurroundXYZ.X, vc->SurroundXYZ.Y, vc->SurroundXYZ.Z, - "illuminant_type", _illu_map(vc->IlluminantType)); + "illuminant", vc->IlluminantXYZ.X, vc->IlluminantXYZ.Y, vc->IlluminantXYZ.Z, + "surround", vc->SurroundXYZ.X, vc->SurroundXYZ.Y, vc->SurroundXYZ.Z, + "illuminant_type", _illu_map(vc->IlluminantType)); } From e7eac4f80b5ef243573029c9c5fb89f28eecde7d Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 28 Jan 2019 09:01:02 +0200 Subject: [PATCH 02/11] Add warnings to deprecated CMS profile attributes --- Tests/test_imagecms.py | 12 ++++++++++-- src/_imagingcms.c | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index b4d53a2df..ee3a2b92e 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -309,7 +309,11 @@ class TestImageCms(PillowTestCase): 2: (False, False, True), 3: (False, False, True) }) - self.assertEqual(p.color_space, 'RGB') + + # p.color_space + result = self.assert_warning(DeprecationWarning, getattr, p, "color_space") + self.assertEqual(result, 'RGB') + self.assertIsNone(p.colorant_table) self.assertIsNone(p.colorant_table_out) self.assertIsNone(p.colorimetric_intent) @@ -361,7 +365,11 @@ class TestImageCms(PillowTestCase): (5000.722328847392,)) self.assertEqual(p.model, 'IEC 61966-2-1 Default RGB Colour Space - sRGB') - self.assertEqual(p.pcs, 'XYZ') + + # p.pcs + result = self.assert_warning(DeprecationWarning, getattr, p, "pcs") + self.assertEqual(result, 'XYZ') + self.assertIsNone(p.perceptual_rendering_intent_gamut) self.assertEqual(p.product_copyright, 'Copyright International Color Consortium, 2009') diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 80cef2668..51b987f8d 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -1005,12 +1005,16 @@ cms_profile_getattr_rendering_intent(CmsProfileObject* self, void* closure) static PyObject* cms_profile_getattr_pcs(CmsProfileObject* self, void* closure) { + PyErr_WarnEx(PyExc_DeprecationWarning, + "cms is deprecated. Use padded connection_space instead.", 1); return PyUnicode_DecodeFSDefault(findICmode(cmsGetPCS(self->profile))); } static PyObject* cms_profile_getattr_color_space(CmsProfileObject* self, void* closure) { + PyErr_WarnEx(PyExc_DeprecationWarning, + "color_space is deprecated. Use padded xcolor_space instead.", 1); return PyUnicode_DecodeFSDefault(findICmode(cmsGetColorSpace(self->profile))); } From 7d157bd825f5006cee78a7d3f7dc40530dd21407 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 28 Jan 2019 10:37:56 +0200 Subject: [PATCH 03/11] Add warnings to deprecated CMS profile attributes --- Tests/test_imagecms.py | 7 +++++-- docs/reference/ImageCms.rst | 10 +++++----- src/PIL/ImageCms.py | 4 ++-- src/_imagingcms.c | 2 ++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index ee3a2b92e..1eac4ad5f 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -377,8 +377,11 @@ class TestImageCms(PillowTestCase): self.assertEqual(p.product_description, 'sRGB IEC61966-2-1 black scaled') self.assertEqual(p.product_manufacturer, '') - self.assertEqual( - p.product_model, 'IEC 61966-2-1 Default RGB Colour Space - sRGB') + + # p.product_model + result = self.assert_warning(DeprecationWarning, getattr, p, "product_model") + self.assertEqual(result, "IEC 61966-2-1 Default RGB Colour Space - sRGB") + self.assertEqual( p.profile_description, 'sRGB IEC61966-2-1 black scaled') self.assertEqual( diff --git a/docs/reference/ImageCms.rst b/docs/reference/ImageCms.rst index 35f4acee6..ea6334708 100644 --- a/docs/reference/ImageCms.rst +++ b/docs/reference/ImageCms.rst @@ -132,21 +132,21 @@ can be easily displayed in a chromaticity diagram, for example). .. py:attribute:: manufacturer - The (english) display string for the device manufacturer (see + The (English) display string for the device manufacturer (see 9.2.22 of ICC.1:2010). :type: :py:class:`unicode` or ``None`` .. py:attribute:: model - The (english) display string for the device model of the device + The (English) display string for the device model of the device for which this profile is created (see 9.2.23 of ICC.1:2010). :type: :py:class:`unicode` or ``None`` .. py:attribute:: profile_description - The (english) display string for the profile description (see + The (English) display string for the profile description (see 9.2.41 of ICC.1:2010). :type: :py:class:`unicode` or ``None`` @@ -269,14 +269,14 @@ can be easily displayed in a chromaticity diagram, for example). .. py:attribute:: viewing_condition - The (english) display string for the viewing conditions (see + The (English) display string for the viewing conditions (see 9.2.48 of ICC.1:2010). :type: :py:class:`unicode` or ``None`` .. py:attribute:: screening_description - The (english) display string for the screening conditions. + The (English) display string for the screening conditions. This tag was available in ICC 3.2, but it is removed from version 4. diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index 29959a83a..ccb8aecf0 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -686,7 +686,7 @@ def getProfileName(profile): # // name was "%s - %s" (model, manufacturer) || Description , # // but if the Model and Manufacturer were the same or the model # // was long, Just the model, in 1.x - model = profile.profile.product_model + model = profile.profile.model manufacturer = profile.profile.product_manufacturer if not (model or manufacturer): @@ -819,7 +819,7 @@ def getProfileModel(profile): # add an extra newline to preserve pyCMS compatibility if not isinstance(profile, ImageCmsProfile): profile = ImageCmsProfile(profile) - return profile.profile.product_model + "\n" + return profile.profile.model + "\n" except (AttributeError, IOError, TypeError, ValueError) as v: raise PyCMSError(v) diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 51b987f8d..0def62e1b 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -981,6 +981,8 @@ cms_profile_getattr_product_description(CmsProfileObject* self, void* closure) static PyObject* cms_profile_getattr_product_model(CmsProfileObject* self, void* closure) { + PyErr_WarnEx(PyExc_DeprecationWarning, + "product_model is deprecated. Use Unicode model instead.", 1); return _profile_getattr(self, cmsInfoModel); } From a149c13d2eff7563097a331520c533724afbae97 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 28 Jan 2019 11:10:38 +0200 Subject: [PATCH 04/11] Add warnings to deprecated CMS profile attributes --- Tests/test_imagecms.py | 7 ++++++- src/PIL/ImageCms.py | 4 ++-- src/_imagingcms.c | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 1eac4ad5f..6bd27baf6 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -376,7 +376,12 @@ class TestImageCms(PillowTestCase): self.assertEqual(p.product_desc, 'sRGB IEC61966-2-1 black scaled') self.assertEqual(p.product_description, 'sRGB IEC61966-2-1 black scaled') - self.assertEqual(p.product_manufacturer, '') + + # p.product_manufacturer + result = self.assert_warning( + DeprecationWarning, getattr, p, "product_manufacturer" + ) + self.assertEqual(result, "") # p.product_model result = self.assert_warning(DeprecationWarning, getattr, p, "product_model") diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index ccb8aecf0..6188d71b4 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -687,7 +687,7 @@ def getProfileName(profile): # // but if the Model and Manufacturer were the same or the model # // was long, Just the model, in 1.x model = profile.profile.model - manufacturer = profile.profile.product_manufacturer + manufacturer = profile.profile.manufacturer if not (model or manufacturer): return profile.profile.product_description + "\n" @@ -790,7 +790,7 @@ def getProfileManufacturer(profile): # add an extra newline to preserve pyCMS compatibility if not isinstance(profile, ImageCmsProfile): profile = ImageCmsProfile(profile) - return profile.profile.product_manufacturer + "\n" + return (profile.profile.manufacturer or "") + "\n" except (AttributeError, IOError, TypeError, ValueError) as v: raise PyCMSError(v) diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 0def62e1b..006450a58 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -989,6 +989,8 @@ cms_profile_getattr_product_model(CmsProfileObject* self, void* closure) static PyObject* cms_profile_getattr_product_manufacturer(CmsProfileObject* self, void* closure) { + PyErr_WarnEx(PyExc_DeprecationWarning, + "product_manufacturer is deprecated. Use Unicode manufacturer instead.", 1); return _profile_getattr(self, cmsInfoManufacturer); } From e1381d21025ad9d310135d60435393fcfa122925 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 28 Jan 2019 11:16:55 +0200 Subject: [PATCH 05/11] Add warnings to deprecated CMS profile attributes --- Tests/test_imagecms.py | 9 +++++++-- src/PIL/ImageCms.py | 4 ++-- src/_imagingcms.c | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 6bd27baf6..3c5ced05c 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -371,8 +371,13 @@ class TestImageCms(PillowTestCase): self.assertEqual(result, 'XYZ') self.assertIsNone(p.perceptual_rendering_intent_gamut) - self.assertEqual(p.product_copyright, - 'Copyright International Color Consortium, 2009') + + # p.product_copyright + result = self.assert_warning( + DeprecationWarning, getattr, p, "product_copyright" + ) + self.assertEqual(result, "Copyright International Color Consortium, 2009") + self.assertEqual(p.product_desc, 'sRGB IEC61966-2-1 black scaled') self.assertEqual(p.product_description, 'sRGB IEC61966-2-1 black scaled') diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index 6188d71b4..e3f920f33 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -728,7 +728,7 @@ def getProfileInfo(profile): # so skipping. # info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint description = profile.profile.product_description - cpright = profile.profile.product_copyright + cpright = profile.profile.copyright arr = [] for elt in (description, cpright): if elt: @@ -762,7 +762,7 @@ def getProfileCopyright(profile): # add an extra newline to preserve pyCMS compatibility if not isinstance(profile, ImageCmsProfile): profile = ImageCmsProfile(profile) - return profile.profile.product_copyright + "\n" + return (profile.profile.copyright or "") + "\n" except (AttributeError, IOError, TypeError, ValueError) as v: raise PyCMSError(v) diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 006450a58..9f13f0c88 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -997,6 +997,8 @@ cms_profile_getattr_product_manufacturer(CmsProfileObject* self, void* closure) static PyObject* cms_profile_getattr_product_copyright(CmsProfileObject* self, void* closure) { + PyErr_WarnEx(PyExc_DeprecationWarning, + "product_copyright is deprecated. Use Unicode copyright instead.", 1); return _profile_getattr(self, cmsInfoCopyright); } From 34764743592482e0a4931a15bc53ba011b9632f3 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 28 Jan 2019 11:57:41 +0200 Subject: [PATCH 06/11] Add warnings to deprecated CMS profile attributes --- Tests/test_imagecms.py | 12 +++++++++--- src/PIL/ImageCms.py | 6 +++--- src/_imagingcms.c | 4 ++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 3c5ced05c..c25f71bf3 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -378,9 +378,15 @@ class TestImageCms(PillowTestCase): ) self.assertEqual(result, "Copyright International Color Consortium, 2009") - self.assertEqual(p.product_desc, 'sRGB IEC61966-2-1 black scaled') - self.assertEqual(p.product_description, - 'sRGB IEC61966-2-1 black scaled') + # p.product_desc + result = self.assert_warning(DeprecationWarning, getattr, p, "product_desc") + self.assertEqual(result, "sRGB IEC61966-2-1 black scaled") + + # p.product_description + result = self.assert_warning( + DeprecationWarning, getattr, p, "product_description" + ) + self.assertEqual(result, "sRGB IEC61966-2-1 black scaled") # p.product_manufacturer result = self.assert_warning( diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index e3f920f33..aee1ba624 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -690,7 +690,7 @@ def getProfileName(profile): manufacturer = profile.profile.manufacturer if not (model or manufacturer): - return profile.profile.product_description + "\n" + return (profile.profile.profile_description or "") + "\n" if not manufacturer or len(model) > 30: return model + "\n" return "%s - %s\n" % (model, manufacturer) @@ -727,7 +727,7 @@ def getProfileInfo(profile): # Python, not C. the white point bits weren't working well, # so skipping. # info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint - description = profile.profile.product_description + description = profile.profile.profile_description cpright = profile.profile.copyright arr = [] for elt in (description, cpright): @@ -848,7 +848,7 @@ def getProfileDescription(profile): # add an extra newline to preserve pyCMS compatibility if not isinstance(profile, ImageCmsProfile): profile = ImageCmsProfile(profile) - return profile.profile.product_description + "\n" + return (profile.profile.profile_description or "") + "\n" except (AttributeError, IOError, TypeError, ValueError) as v: raise PyCMSError(v) diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 9f13f0c88..13a013ced 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -966,6 +966,8 @@ _profile_getattr(CmsProfileObject* self, cmsInfoType field) static PyObject* cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure) { + PyErr_WarnEx(PyExc_DeprecationWarning, + "product_desc is deprecated. Use Unicode profile_description instead.", 1); // description was Description != 'Copyright' || or "%s - %s" (manufacturer, model) in 1.x return _profile_getattr(self, cmsInfoDescription); } @@ -975,6 +977,8 @@ cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure) static PyObject* cms_profile_getattr_product_description(CmsProfileObject* self, void* closure) { + PyErr_WarnEx(PyExc_DeprecationWarning, + "product_description is deprecated. Use Unicode profile_description instead.", 1); return _profile_getattr(self, cmsInfoDescription); } From a9070f3ca22d1331a7ee8a7508d0de51982ea917 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 28 Jan 2019 13:59:53 +0200 Subject: [PATCH 07/11] Group deprecation tests --- Tests/test_imagecms.py | 63 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index c25f71bf3..762df93db 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -310,10 +310,6 @@ class TestImageCms(PillowTestCase): 3: (False, False, True) }) - # p.color_space - result = self.assert_warning(DeprecationWarning, getattr, p, "color_space") - self.assertEqual(result, 'RGB') - self.assertIsNone(p.colorant_table) self.assertIsNone(p.colorant_table_out) self.assertIsNone(p.colorimetric_intent) @@ -366,11 +362,42 @@ class TestImageCms(PillowTestCase): self.assertEqual(p.model, 'IEC 61966-2-1 Default RGB Colour Space - sRGB') + self.assertIsNone(p.perceptual_rendering_intent_gamut) + + self.assertEqual( + p.profile_description, 'sRGB IEC61966-2-1 black scaled') + self.assertEqual( + p.profile_id, b')\xf8=\xde\xaf\xf2U\xaexB\xfa\xe4\xca\x839\r') + assert_truncated_tuple_equal( + p.red_colorant, + ((0.436065673828125, 0.2224884033203125, 0.013916015625), + (0.6484536316398539, 0.3308524880306778, 0.2224884033203125))) + assert_truncated_tuple_equal( + p.red_primary, + ((0.43606566581047446, 0.22248840582960838, 0.013916015621759925), + (0.6484536250319214, 0.3308524944738204, 0.22248840582960838))) + self.assertEqual(p.rendering_intent, 0) + self.assertIsNone(p.saturation_rendering_intent_gamut) + self.assertIsNone(p.screening_description) + self.assertIsNone(p.target) + self.assertEqual(p.technology, 'CRT ') + self.assertEqual(p.version, 2.0) + self.assertEqual(p.viewing_condition, + 'Reference Viewing Condition in IEC 61966-2-1') + self.assertEqual(p.xcolor_space, 'RGB ') + + def test_deprecations(self): + self.skip_missing() + o = ImageCms.getOpenProfile(SRGB) + p = o.profile + + # p.color_space + result = self.assert_warning(DeprecationWarning, getattr, p, "color_space") + self.assertEqual(result, "RGB") + # p.pcs result = self.assert_warning(DeprecationWarning, getattr, p, "pcs") - self.assertEqual(result, 'XYZ') - - self.assertIsNone(p.perceptual_rendering_intent_gamut) + self.assertEqual(result, "XYZ") # p.product_copyright result = self.assert_warning( @@ -398,28 +425,6 @@ class TestImageCms(PillowTestCase): result = self.assert_warning(DeprecationWarning, getattr, p, "product_model") self.assertEqual(result, "IEC 61966-2-1 Default RGB Colour Space - sRGB") - self.assertEqual( - p.profile_description, 'sRGB IEC61966-2-1 black scaled') - self.assertEqual( - p.profile_id, b')\xf8=\xde\xaf\xf2U\xaexB\xfa\xe4\xca\x839\r') - assert_truncated_tuple_equal( - p.red_colorant, - ((0.436065673828125, 0.2224884033203125, 0.013916015625), - (0.6484536316398539, 0.3308524880306778, 0.2224884033203125))) - assert_truncated_tuple_equal( - p.red_primary, - ((0.43606566581047446, 0.22248840582960838, 0.013916015621759925), - (0.6484536250319214, 0.3308524944738204, 0.22248840582960838))) - self.assertEqual(p.rendering_intent, 0) - self.assertIsNone(p.saturation_rendering_intent_gamut) - self.assertIsNone(p.screening_description) - self.assertIsNone(p.target) - self.assertEqual(p.technology, 'CRT ') - self.assertEqual(p.version, 2.0) - self.assertEqual(p.viewing_condition, - 'Reference Viewing Condition in IEC 61966-2-1') - self.assertEqual(p.xcolor_space, 'RGB ') - def test_profile_typesafety(self): """ Profile init type safety From a2a5ebfeb41b0df24e1dbe75f9849185a1093590 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 28 Jan 2019 14:10:37 +0200 Subject: [PATCH 08/11] Refactor --- Tests/test_imagecms.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 762df93db..996243df8 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -391,39 +391,34 @@ class TestImageCms(PillowTestCase): o = ImageCms.getOpenProfile(SRGB) p = o.profile + def helper_deprecated(attr, expected): + result = self.assert_warning(DeprecationWarning, getattr, p, attr) + self.assertEqual(result, expected) + # p.color_space - result = self.assert_warning(DeprecationWarning, getattr, p, "color_space") - self.assertEqual(result, "RGB") + helper_deprecated("color_space", "RGB") # p.pcs - result = self.assert_warning(DeprecationWarning, getattr, p, "pcs") - self.assertEqual(result, "XYZ") + helper_deprecated("pcs", "XYZ") # p.product_copyright - result = self.assert_warning( - DeprecationWarning, getattr, p, "product_copyright" + helper_deprecated( + "product_copyright", "Copyright International Color Consortium, 2009" ) - self.assertEqual(result, "Copyright International Color Consortium, 2009") # p.product_desc - result = self.assert_warning(DeprecationWarning, getattr, p, "product_desc") - self.assertEqual(result, "sRGB IEC61966-2-1 black scaled") + helper_deprecated("product_desc", "sRGB IEC61966-2-1 black scaled") # p.product_description - result = self.assert_warning( - DeprecationWarning, getattr, p, "product_description" - ) - self.assertEqual(result, "sRGB IEC61966-2-1 black scaled") + helper_deprecated("product_description", "sRGB IEC61966-2-1 black scaled") # p.product_manufacturer - result = self.assert_warning( - DeprecationWarning, getattr, p, "product_manufacturer" - ) - self.assertEqual(result, "") + helper_deprecated("product_manufacturer", "") # p.product_model - result = self.assert_warning(DeprecationWarning, getattr, p, "product_model") - self.assertEqual(result, "IEC 61966-2-1 Default RGB Colour Space - sRGB") + helper_deprecated( + "product_model", "IEC 61966-2-1 Default RGB Colour Space - sRGB" + ) def test_profile_typesafety(self): """ Profile init type safety From daee1d4b3d53816b3a5196f23e0b2db992844289 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 28 Jan 2019 14:30:27 +0200 Subject: [PATCH 09/11] Document deprecations --- docs/deprecations.rst | 20 ++++++++++++++++++++ docs/releasenotes/6.0.0.rst | 19 ++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index adbf0f85f..921e0ba39 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -34,6 +34,26 @@ Two version constants – ``VERSION`` (the old PIL version, always 1.1.7) and ``PILLOW_VERSION`` – have been deprecated and will be removed in the next major release. Use ``__version__`` instead. +ImageCms.CmsProfile attributes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 3.2.0 + +Some attributes in ``ImageCms.CmsProfile`` are deprecated. From 6.0.0, they issue a +``DeprecationWarning``: + +======================== =============================== +Deprecated Use instead +======================== =============================== +``color_space`` Padded ``xcolor_space`` +``pcs`` Padded ``connection_space`` +``product_copyright`` Unicode ``copyright`` +``product_desc`` Unicode ``profile_description`` +``product_description`` Unicode ``profile_description`` +``product_manufacturer`` Unicode ``manufacturer`` +``product_model`` Unicode ``model`` +======================== =============================== + Removed features ---------------- diff --git a/docs/releasenotes/6.0.0.rst b/docs/releasenotes/6.0.0.rst index f683d7c20..8ab264df7 100644 --- a/docs/releasenotes/6.0.0.rst +++ b/docs/releasenotes/6.0.0.rst @@ -29,10 +29,23 @@ and have now been removed: ``gaussian_blur``, ``gblur``, ``unsharp_mask``, ``usm API Changes =========== -TODO -^^^^ +Deprecations +^^^^^^^^^^^^ -TODO +Some attributes in ``ImageCms.CmsProfile`` have been deprecated since Pillow 3.2.0. From +6.0.0, they issue a ``DeprecationWarning``: + +======================== =============================== +Deprecated Use instead +======================== =============================== +``color_space`` Padded ``xcolor_space`` +``pcs`` Padded ``connection_space`` +``product_copyright`` Unicode ``copyright`` +``product_desc`` Unicode ``profile_description`` +``product_description`` Unicode ``profile_description`` +``product_manufacturer`` Unicode ``manufacturer`` +``product_model`` Unicode ``model`` +======================== =============================== API Additions ============= From e40e0093fb6aa11b9472f41f3692480e1111590f Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Sat, 16 Mar 2019 11:58:23 +0200 Subject: [PATCH 10/11] Fix typo Co-Authored-By: hugovk --- src/_imagingcms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 13a013ced..a79c0c1b5 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -1016,7 +1016,7 @@ static PyObject* cms_profile_getattr_pcs(CmsProfileObject* self, void* closure) { PyErr_WarnEx(PyExc_DeprecationWarning, - "cms is deprecated. Use padded connection_space instead.", 1); + "pcs is deprecated. Use padded connection_space instead.", 1); return PyUnicode_DecodeFSDefault(findICmode(cmsGetPCS(self->profile))); } From 75cce8d3aa3613cc40d8a604d912649e7ed16eac Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Wed, 27 Mar 2019 12:02:51 +0200 Subject: [PATCH 11/11] Default to "", like the others Co-Authored-By: hugovk --- src/PIL/ImageCms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index aee1ba624..544b7a60d 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -819,7 +819,7 @@ def getProfileModel(profile): # add an extra newline to preserve pyCMS compatibility if not isinstance(profile, ImageCmsProfile): profile = ImageCmsProfile(profile) - return profile.profile.model + "\n" + return (profile.profile.model or "") + "\n" except (AttributeError, IOError, TypeError, ValueError) as v: raise PyCMSError(v)