mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
Fixed ability to create LAB profiles with color temperatures
This commit is contained in:
parent
9042f8c61f
commit
b506e2ad44
|
@ -566,10 +566,10 @@ def createProfile(colorSpace, colorTemp=-1):
|
||||||
raise PyCMSError("Color space not supported for on-the-fly profile creation (%s)" % colorSpace)
|
raise PyCMSError("Color space not supported for on-the-fly profile creation (%s)" % colorSpace)
|
||||||
|
|
||||||
if colorSpace == "LAB":
|
if colorSpace == "LAB":
|
||||||
if isinstance(colorTemp, float):
|
try:
|
||||||
colorTemp = int(colorTemp + 0.5)
|
colorTemp = float(colorTemp)
|
||||||
if not isinstance(colorTemp, int):
|
except:
|
||||||
raise PyCMSError("Color temperature must be a positive integer, \"%s\" not valid" % colorTemp)
|
raise PyCMSError("Color temperature must be numeric, \"%s\" not valid" % colorTemp)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return core.createProfile(colorSpace, colorTemp)
|
return core.createProfile(colorSpace, colorTemp)
|
||||||
|
|
|
@ -89,3 +89,18 @@ def test_exceptions():
|
||||||
def test_display_profile():
|
def test_display_profile():
|
||||||
# try fetching the profile for the current display device
|
# try fetching the profile for the current display device
|
||||||
assert_no_exception(lambda: ImageCms.get_display_profile())
|
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)
|
||||||
|
|
|
@ -389,7 +389,7 @@ createProfile(PyObject *self, PyObject *args)
|
||||||
char *sColorSpace;
|
char *sColorSpace;
|
||||||
cmsHPROFILE hProfile;
|
cmsHPROFILE hProfile;
|
||||||
cmsFloat64Number dColorTemp = 0.0;
|
cmsFloat64Number dColorTemp = 0.0;
|
||||||
cmsCIExyY *whitePoint = NULL;
|
cmsCIExyY whitePoint;
|
||||||
cmsBool result;
|
cmsBool result;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s|d:createProfile", &sColorSpace, &dColorTemp))
|
if (!PyArg_ParseTuple(args, "s|d:createProfile", &sColorSpace, &dColorTemp))
|
||||||
|
@ -397,12 +397,12 @@ createProfile(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
if (strcmp(sColorSpace, "LAB") == 0) {
|
if (strcmp(sColorSpace, "LAB") == 0) {
|
||||||
if (dColorTemp > 0.0) {
|
if (dColorTemp > 0.0) {
|
||||||
result = cmsWhitePointFromTemp(whitePoint, dColorTemp);
|
result = cmsWhitePointFromTemp(&whitePoint, dColorTemp);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
PyErr_SetString(PyExc_ValueError, "ERROR: Could not calculate white point from color temperature provided, must be float in degrees Kelvin");
|
PyErr_SetString(PyExc_ValueError, "ERROR: Could not calculate white point from color temperature provided, must be float in degrees Kelvin");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
hProfile = cmsCreateLab2Profile(whitePoint);
|
hProfile = cmsCreateLab2Profile(&whitePoint);
|
||||||
} else {
|
} else {
|
||||||
hProfile = cmsCreateLab2Profile(NULL);
|
hProfile = cmsCreateLab2Profile(NULL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user