127
#if PY_VERSION_HEX >= 0x03000000
128
if (!PyArg_ParseTuple(args, "y#:profile_frombytes", &pProfile, &nProfile))
131
131
if (!PyArg_ParseTuple(args, "s#:profile_fromstring", &pProfile, &nProfile))
134
135
cmsErrorAction(LCMS_ERROR_IGNORE);
136
137
hProfile = cmsOpenProfileFromMem(pProfile, nProfile);
138
139
PyErr_SetString(PyExc_IOError, "cannot open profile from string");
140
143
return cms_profile_new(hProfile);
493
496
static PyMethodDef pyCMSdll_methods[] = {
495
498
{"profile_open", cms_profile_open, 1},
499
{"profile_frombytes", cms_profile_fromstring, 1},
500
#if PY_VERSION_HEX < 0x03000000
496
501
{"profile_fromstring", cms_profile_fromstring, 1},
498
504
/* profile and transform functions */
499
505
{"buildTransform", buildTransform, 1},
513
519
{NULL, NULL} /* sentinel */
517
cms_profile_getattr(CmsProfileObject* self, char* name)
519
if (!strcmp(name, "product_name"))
520
return PyString_FromString(cmsTakeProductName(self->profile));
521
if (!strcmp(name, "product_desc"))
522
return PyString_FromString(cmsTakeProductDesc(self->profile));
523
if (!strcmp(name, "product_info"))
524
return PyString_FromString(cmsTakeProductInfo(self->profile));
525
if (!strcmp(name, "rendering_intent"))
526
return PyInt_FromLong(cmsTakeRenderingIntent(self->profile));
527
if (!strcmp(name, "pcs"))
528
return PyString_FromString(findICmode(cmsGetPCS(self->profile)));
529
if (!strcmp(name, "color_space"))
530
return PyString_FromString(findICmode(cmsGetColorSpace(self->profile)));
531
/* FIXME: add more properties (creation_datetime etc) */
533
return Py_FindMethod(cms_profile_methods, (PyObject*) self, name);
536
statichere PyTypeObject CmsProfile_Type = {
537
PyObject_HEAD_INIT(NULL)
538
0, "CmsProfile", sizeof(CmsProfileObject), 0,
523
cms_profile_getattr_product_name(CmsProfileObject* self, void* closure)
525
return PyUnicode_DecodeFSDefault(cmsTakeProductName(self->profile));
529
cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure)
531
return PyUnicode_DecodeFSDefault(cmsTakeProductDesc(self->profile));
535
cms_profile_getattr_product_info(CmsProfileObject* self, void* closure)
537
return PyUnicode_DecodeFSDefault(cmsTakeProductInfo(self->profile));
541
cms_profile_getattr_rendering_intent(CmsProfileObject* self, void* closure)
543
return PyInt_FromLong(cmsTakeRenderingIntent(self->profile));
547
cms_profile_getattr_pcs(CmsProfileObject* self, void* closure)
549
return PyUnicode_DecodeFSDefault(findICmode(cmsGetPCS(self->profile)));
553
cms_profile_getattr_color_space(CmsProfileObject* self, void* closure)
555
return PyUnicode_DecodeFSDefault(findICmode(cmsGetColorSpace(self->profile)));
558
/* FIXME: add more properties (creation_datetime etc) */
559
static struct PyGetSetDef cms_profile_getsetters[] = {
560
{ "product_name", (getter) cms_profile_getattr_product_name },
561
{ "product_desc", (getter) cms_profile_getattr_product_desc },
562
{ "product_info", (getter) cms_profile_getattr_product_info },
563
{ "rendering_intent", (getter) cms_profile_getattr_rendering_intent },
564
{ "pcs", (getter) cms_profile_getattr_pcs },
565
{ "color_space", (getter) cms_profile_getattr_color_space },
569
static PyTypeObject CmsProfile_Type = {
570
PyVarObject_HEAD_INIT(NULL, 0)
571
"CmsProfile", sizeof(CmsProfileObject), 0,
540
573
(destructor) cms_profile_dealloc, /*tp_dealloc*/
542
(getattrfunc) cms_profile_getattr, /*tp_getattr*/
547
0, /*tp_as_sequence */
548
0, /*tp_as_mapping */
580
0, /*tp_as_sequence */
581
0, /*tp_as_mapping */
588
Py_TPFLAGS_DEFAULT, /*tp_flags*/
592
0, /*tp_richcompare*/
593
0, /*tp_weaklistoffset*/
596
cms_profile_methods, /*tp_methods*/
598
cms_profile_getsetters, /*tp_getset*/
552
601
static struct PyMethodDef cms_transform_methods[] = {
554
603
{NULL, NULL} /* sentinel */
558
cms_transform_getattr(CmsTransformObject* self, char* name)
560
if (!strcmp(name, "inputMode"))
561
return PyString_FromString(self->mode_in);
562
if (!strcmp(name, "outputMode"))
563
return PyString_FromString(self->mode_out);
565
return Py_FindMethod(cms_transform_methods, (PyObject*) self, name);
568
statichere PyTypeObject CmsTransform_Type = {
569
PyObject_HEAD_INIT(NULL)
570
0, "CmsTransform", sizeof(CmsTransformObject), 0,
607
cms_transform_getattr_inputMode(CmsTransformObject* self, void* closure)
609
return PyUnicode_FromString(self->mode_in);
613
cms_transform_getattr_outputMode(CmsTransformObject* self, void* closure)
615
return PyUnicode_FromString(self->mode_out);
618
static struct PyGetSetDef cms_transform_getsetters[] = {
619
{ "inputMode", (getter) cms_transform_getattr_inputMode },
620
{ "outputMode", (getter) cms_transform_getattr_outputMode },
624
static PyTypeObject CmsTransform_Type = {
625
PyVarObject_HEAD_INIT(NULL, 0)
626
"CmsTransform", sizeof(CmsTransformObject), 0,
572
628
(destructor) cms_transform_dealloc, /*tp_dealloc*/
574
(getattrfunc) cms_transform_getattr, /*tp_getattr*/
579
0, /*tp_as_sequence */
580
0, /*tp_as_mapping */
635
0, /*tp_as_sequence */
636
0, /*tp_as_mapping */
643
Py_TPFLAGS_DEFAULT, /*tp_flags*/
647
0, /*tp_richcompare*/
648
0, /*tp_weaklistoffset*/
651
cms_transform_methods, /*tp_methods*/
653
cms_transform_getsetters, /*tp_getset*/
585
init_imagingcms(void)
657
setup_module(PyObject* m) {
591
/* Patch up object types */
592
CmsProfile_Type.ob_type = &PyType_Type;
593
CmsTransform_Type.ob_type = &PyType_Type;
595
m = Py_InitModule("_imagingcms", pyCMSdll_methods);
596
d = PyModule_GetDict(m);
598
#if PY_VERSION_HEX >= 0x02020000
599
v = PyString_FromFormat("%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
603
sprintf(buffer, "%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
604
v = PyString_FromString(buffer);
661
d = PyModule_GetDict(m);
663
/* Ready object types */
664
PyType_Ready(&CmsProfile_Type);
665
PyType_Ready(&CmsTransform_Type);
667
d = PyModule_GetDict(m);
669
v = PyUnicode_FromFormat("%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
607
670
PyDict_SetItemString(d, "littlecms_version", v);
675
#if PY_VERSION_HEX >= 0x03000000
677
PyInit__imagingcms(void) {
680
static PyModuleDef module_def = {
681
PyModuleDef_HEAD_INIT,
682
"_imagingcms", /* m_name */
685
pyCMSdll_methods, /* m_methods */
688
m = PyModule_Create(&module_def);
690
if (setup_module(m) < 0)
697
init_imagingcms(void)
699
PyObject *m = Py_InitModule("_imagingcms", pyCMSdll_methods);