Pillow-6.0.0/src/_imagingcms.c
/* -------------------------------------------------------------------- */
/* Python-Callable On-The-Fly profile creation functions */
Python-Callable On-The-Fly profile creation functions
Python - Callable On - The - Fly profile creation functions
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);
}
static PyObject * createProfile ( PyObject * self , PyObject * args ) { char * sColorSpace ; cmsHPROFILE hProfile ; cmsFloat64Number dColorTemp = 0.0 ; cmsCIExyY whitePoint ; cmsBool result ; if ( ! PyArg_ParseTuple ( args , " " , & sColorSpace , & dColorTemp ) ) return NULL ; if ( strcmp ( sColorSpace , " " ) == 0 ) { if ( dColorTemp > 0.0 ) { result = cmsWhitePointFromTemp ( & whitePoint , dColorTemp ) ; if ( ! result ) { PyErr_SetString ( PyExc_ValueError , " " ) ; return NULL ; } hProfile = cmsCreateLab2Profile ( & whitePoint ) ; } else { hProfile = cmsCreateLab2Profile ( NULL ) ; } } else if ( strcmp ( sColorSpace , " " ) == 0 ) { hProfile = cmsCreateXYZProfile ( ) ; } else if ( strcmp ( sColorSpace , " " ) == 0 ) { hProfile = cmsCreate_sRGBProfile ( ) ; } else { hProfile = NULL ; } if ( ! hProfile ) { PyErr_SetString ( PyExc_ValueError , " " ) ; return NULL ; } return cms_profile_new ( hProfile ) ; }
Python-Callable On-The-Fly profile creation functions
Python - Callable On - The - Fly profile creation functions