mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +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)
|
||||
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user