From b506e2ad443103f609a4a1cde3cd1832d9662fd0 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Thu, 10 Oct 2013 22:42:27 -0700 Subject: [PATCH] Fixed ability to create LAB profiles with color temperatures --- PIL/ImageCms.py | 8 ++++---- Tests/test_imagecms.py | 15 +++++++++++++++ _imagingcms.c | 6 +++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/PIL/ImageCms.py b/PIL/ImageCms.py index d9c69e909..20ba6a11f 100644 --- a/PIL/ImageCms.py +++ b/PIL/ImageCms.py @@ -566,10 +566,10 @@ def createProfile(colorSpace, colorTemp=-1): raise PyCMSError("Color space not supported for on-the-fly profile creation (%s)" % colorSpace) if colorSpace == "LAB": - if isinstance(colorTemp, float): - colorTemp = int(colorTemp + 0.5) - if not isinstance(colorTemp, int): - raise PyCMSError("Color temperature must be a positive integer, \"%s\" not valid" % colorTemp) + try: + colorTemp = float(colorTemp) + except: + raise PyCMSError("Color temperature must be numeric, \"%s\" not valid" % colorTemp) try: return core.createProfile(colorSpace, colorTemp) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index ad02ba836..6c4e0e702 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -89,3 +89,18 @@ def test_exceptions(): def test_display_profile(): # try fetching the profile for the current display device assert_no_exception(lambda: ImageCms.get_display_profile()) + + +def test_lab_color_profile(): + pLab = ImageCms.createProfile("LAB", 5000) + pLab = ImageCms.createProfile("LAB", 6500) + +def test_lab_color(): + pLab = ImageCms.createProfile("LAB") + t = ImageCms.buildTransform(SRGB, pLab, "RGB", "RGB") + i = ImageCms.applyTransform(lena(), t) + assert_image(i, "RGB", (128, 128)) + + target = Image.open('Tests/images/lena.Lab.tif') + + assert_image_similar(i,target, 1) diff --git a/_imagingcms.c b/_imagingcms.c index 20d740a08..d489eed60 100644 --- a/_imagingcms.c +++ b/_imagingcms.c @@ -389,7 +389,7 @@ createProfile(PyObject *self, PyObject *args) char *sColorSpace; cmsHPROFILE hProfile; cmsFloat64Number dColorTemp = 0.0; - cmsCIExyY *whitePoint = NULL; + cmsCIExyY whitePoint; cmsBool result; if (!PyArg_ParseTuple(args, "s|d:createProfile", &sColorSpace, &dColorTemp)) @@ -397,12 +397,12 @@ createProfile(PyObject *self, PyObject *args) if (strcmp(sColorSpace, "LAB") == 0) { if (dColorTemp > 0.0) { - result = cmsWhitePointFromTemp(whitePoint, dColorTemp); + result = cmsWhitePointFromTemp(&whitePoint, dColorTemp); if (!result) { PyErr_SetString(PyExc_ValueError, "ERROR: Could not calculate white point from color temperature provided, must be float in degrees Kelvin"); return NULL; } - hProfile = cmsCreateLab2Profile(whitePoint); + hProfile = cmsCreateLab2Profile(&whitePoint); } else { hProfile = cmsCreateLab2Profile(NULL); }