static PyObject* cms_profile_fromstring(PyObject* self, PyObject* args) { cmsHPROFILE hProfile; char* pProfile; int nProfile; #if PY_VERSION_HEX >= 0x03000000 if (!PyArg_ParseTuple(args, "y#:profile_frombytes", &pProfile, &nProfile)) return NULL; #else if (!PyArg_ParseTuple(args, "s#:profile_fromstring", &pProfile, &nProfile)) return NULL; #endif cmsErrorAction(LCMS_ERROR_IGNORE); hProfile = cmsOpenProfileFromMem(pProfile, nProfile); if (!hProfile) { PyErr_SetString(PyExc_IOError, "cannot open profile from string"); return NULL; } return cms_profile_new(hProfile); }
static PyObject* cms_profile_open(PyObject* self, PyObject* args) { cmsHPROFILE hProfile; char* sProfile; if (!PyArg_ParseTuple(args, "s:profile_open", &sProfile)) return NULL; hProfile = cmsOpenProfileFromFile(sProfile, "r"); if (!hProfile) { PyErr_SetString(PyExc_IOError, "cannot open profile file"); return NULL; } return cms_profile_new(hProfile); }
static PyObject* cms_profile_fromstring(PyObject* self, PyObject* args) { cmsHPROFILE hProfile; char* pProfile; int nProfile; if (!PyArg_ParseTuple(args, "s#:profile_fromstring", &pProfile, &nProfile)) return NULL; cmsErrorAction(LCMS_ERROR_IGNORE); hProfile = cmsOpenProfileFromMem(pProfile, nProfile); if (!hProfile) PyErr_SetString(PyExc_IOError, "cannot open profile from string"); return cms_profile_new(hProfile); }
static PyObject * createProfile(PyObject *self, PyObject *args) { char *sColorSpace; cmsHPROFILE hProfile; int iColorTemp = 0; LPcmsCIExyY whitePoint = NULL; LCMSBOOL result; if (!PyArg_ParseTuple(args, "s|i:createProfile", &sColorSpace, &iColorTemp)) return NULL; cmsErrorAction(LCMS_ERROR_IGNORE); if (strcmp(sColorSpace, "LAB") == 0) { if (iColorTemp > 0) { result = cmsWhitePointFromTemp(iColorTemp, whitePoint); if (!result) { PyErr_SetString(PyExc_ValueError,"ERROR: Could not calculate "\ "white point from color temperature provided, must be "\ "integer in degrees Kelvin"); return NULL; } hProfile = cmsCreateLabProfile(whitePoint); } else hProfile = cmsCreateLabProfile(NULL); } else if (strcmp(sColorSpace, "XYZ") == 0) hProfile = cmsCreateXYZProfile(); else if (strcmp(sColorSpace, "sRGB") == 0) hProfile = cmsCreate_sRGBProfile(); else hProfile = NULL; if (!hProfile) { PyErr_SetString(PyExc_ValueError, "failed to create requested color space"); return NULL; } return cms_profile_new(hProfile); }
static PyObject * createProfile(PyObject *self, PyObject *args) { char *sColorSpace; cmsHPROFILE hProfile; cmsFloat64Number dColorTemp = 0.0; cmsCIExyY whitePoint; cmsBool result; if (!PyArg_ParseTuple(args, "s|d:createProfile", &sColorSpace, &dColorTemp)) return NULL; if (strcmp(sColorSpace, "LAB") == 0) { if (dColorTemp > 0.0) { 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); } else { hProfile = cmsCreateLab2Profile(NULL); } } else if (strcmp(sColorSpace, "XYZ") == 0) { hProfile = cmsCreateXYZProfile(); } else if (strcmp(sColorSpace, "sRGB") == 0) { hProfile = cmsCreate_sRGBProfile(); } else { hProfile = NULL; } if (!hProfile) { PyErr_SetString(PyExc_ValueError, "failed to create requested color space"); return NULL; } return cms_profile_new(hProfile); }