~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to _imagingcms.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "Python.h"
27
27
#include "lcms.h"
28
28
#include "Imaging.h"
29
 
 
30
 
#if PY_VERSION_HEX < 0x01060000
31
 
#define PyObject_New PyObject_NEW
32
 
#define PyObject_Del PyMem_DEL
33
 
#endif
 
29
#include "py3.h"
34
30
 
35
31
#if LCMS_VERSION < 117
36
32
#define LCMSBOOL BOOL
83
79
    cmsHPROFILE profile;
84
80
} CmsProfileObject;
85
81
 
86
 
staticforward PyTypeObject CmsProfile_Type;
 
82
static PyTypeObject CmsProfile_Type;
87
83
 
88
 
#define CmsProfile_Check(op) ((op)->ob_type == &CmsProfile_Type)
 
84
#define CmsProfile_Check(op) (Py_TYPE(op) == &CmsProfile_Type)
89
85
 
90
86
static PyObject*
91
87
cms_profile_new(cmsHPROFILE profile)
128
124
 
129
125
    char* pProfile;
130
126
    int nProfile;
 
127
#if PY_VERSION_HEX >= 0x03000000
 
128
    if (!PyArg_ParseTuple(args, "y#:profile_frombytes", &pProfile, &nProfile))
 
129
        return NULL;
 
130
#else
131
131
    if (!PyArg_ParseTuple(args, "s#:profile_fromstring", &pProfile, &nProfile))
132
132
        return NULL;
 
133
#endif
133
134
 
134
135
    cmsErrorAction(LCMS_ERROR_IGNORE);
135
136
 
136
137
    hProfile = cmsOpenProfileFromMem(pProfile, nProfile);
137
 
    if (!hProfile)
 
138
    if (!hProfile) {
138
139
        PyErr_SetString(PyExc_IOError, "cannot open profile from string");
 
140
        return NULL;
 
141
    }
139
142
 
140
143
    return cms_profile_new(hProfile);
141
144
}
156
159
    cmsHTRANSFORM transform;
157
160
} CmsTransformObject;
158
161
 
159
 
staticforward PyTypeObject CmsTransform_Type;
 
162
static PyTypeObject CmsTransform_Type;
160
163
 
161
 
#define CmsTransform_Check(op) ((op)->ob_type == &CmsTransform_Type)
 
164
#define CmsTransform_Check(op) (Py_TYPE(op) == &CmsTransform_Type)
162
165
 
163
166
static PyObject*
164
167
cms_transform_new(cmsHTRANSFORM transform, char* mode_in, char* mode_out)
493
496
static PyMethodDef pyCMSdll_methods[] = {
494
497
 
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},
 
502
#endif
497
503
 
498
504
    /* profile and transform functions */
499
505
    {"buildTransform", buildTransform, 1},
513
519
    {NULL, NULL} /* sentinel */
514
520
};
515
521
 
516
 
static PyObject*  
517
 
cms_profile_getattr(CmsProfileObject* self, char* name)
518
 
{
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) */
532
 
 
533
 
    return Py_FindMethod(cms_profile_methods, (PyObject*) self, name);
534
 
}
535
 
 
536
 
statichere PyTypeObject CmsProfile_Type = {
537
 
    PyObject_HEAD_INIT(NULL)
538
 
    0, "CmsProfile", sizeof(CmsProfileObject), 0,
 
522
static PyObject*
 
523
cms_profile_getattr_product_name(CmsProfileObject* self, void* closure)
 
524
{
 
525
    return PyUnicode_DecodeFSDefault(cmsTakeProductName(self->profile));
 
526
}
 
527
 
 
528
static PyObject*
 
529
cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure)
 
530
{
 
531
    return PyUnicode_DecodeFSDefault(cmsTakeProductDesc(self->profile));
 
532
}
 
533
 
 
534
static PyObject*
 
535
cms_profile_getattr_product_info(CmsProfileObject* self, void* closure)
 
536
{
 
537
    return PyUnicode_DecodeFSDefault(cmsTakeProductInfo(self->profile));
 
538
}
 
539
 
 
540
static PyObject*
 
541
cms_profile_getattr_rendering_intent(CmsProfileObject* self, void* closure)
 
542
{
 
543
    return PyInt_FromLong(cmsTakeRenderingIntent(self->profile));
 
544
}
 
545
 
 
546
static PyObject*
 
547
cms_profile_getattr_pcs(CmsProfileObject* self, void* closure)
 
548
{
 
549
    return PyUnicode_DecodeFSDefault(findICmode(cmsGetPCS(self->profile)));
 
550
}
 
551
 
 
552
static PyObject*
 
553
cms_profile_getattr_color_space(CmsProfileObject* self, void* closure)
 
554
{
 
555
    return PyUnicode_DecodeFSDefault(findICmode(cmsGetColorSpace(self->profile)));
 
556
}
 
557
 
 
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 },
 
566
    { NULL }
 
567
};
 
568
 
 
569
static PyTypeObject CmsProfile_Type = {
 
570
    PyVarObject_HEAD_INIT(NULL, 0)
 
571
    "CmsProfile", sizeof(CmsProfileObject), 0,
539
572
    /* methods */
540
573
    (destructor) cms_profile_dealloc, /*tp_dealloc*/
541
574
    0, /*tp_print*/
542
 
    (getattrfunc) cms_profile_getattr, /*tp_getattr*/
543
 
    0, /*tp_setattr*/
544
 
    0, /*tp_compare*/
545
 
    0, /*tp_repr*/
546
 
    0, /*tp_as_number */
547
 
    0, /*tp_as_sequence */
548
 
    0, /*tp_as_mapping */
549
 
    0 /*tp_hash*/
 
575
    0,                          /*tp_getattr*/
 
576
    0,                          /*tp_setattr*/
 
577
    0,                          /*tp_compare*/
 
578
    0,                          /*tp_repr*/
 
579
    0,                          /*tp_as_number */
 
580
    0,                          /*tp_as_sequence */
 
581
    0,                          /*tp_as_mapping */
 
582
    0,                          /*tp_hash*/
 
583
    0,                          /*tp_call*/
 
584
    0,                          /*tp_str*/
 
585
    0,                          /*tp_getattro*/
 
586
    0,                          /*tp_setattro*/
 
587
    0,                          /*tp_as_buffer*/
 
588
    Py_TPFLAGS_DEFAULT,         /*tp_flags*/
 
589
    0,                          /*tp_doc*/
 
590
    0,                          /*tp_traverse*/
 
591
    0,                          /*tp_clear*/
 
592
    0,                          /*tp_richcompare*/
 
593
    0,                          /*tp_weaklistoffset*/
 
594
    0,                          /*tp_iter*/
 
595
    0,                          /*tp_iternext*/
 
596
    cms_profile_methods,        /*tp_methods*/
 
597
    0,                          /*tp_members*/
 
598
    cms_profile_getsetters,     /*tp_getset*/
550
599
};
551
600
 
552
601
static struct PyMethodDef cms_transform_methods[] = {
554
603
    {NULL, NULL} /* sentinel */
555
604
};
556
605
 
557
 
static PyObject*  
558
 
cms_transform_getattr(CmsTransformObject* self, char* name)
559
 
{
560
 
    if (!strcmp(name, "inputMode"))
561
 
        return PyString_FromString(self->mode_in);
562
 
    if (!strcmp(name, "outputMode"))
563
 
        return PyString_FromString(self->mode_out);
564
 
 
565
 
    return Py_FindMethod(cms_transform_methods, (PyObject*) self, name);
566
 
}
567
 
 
568
 
statichere PyTypeObject CmsTransform_Type = {
569
 
    PyObject_HEAD_INIT(NULL)
570
 
    0, "CmsTransform", sizeof(CmsTransformObject), 0,
 
606
static PyObject*
 
607
cms_transform_getattr_inputMode(CmsTransformObject* self, void* closure)
 
608
{
 
609
    return PyUnicode_FromString(self->mode_in);
 
610
}
 
611
 
 
612
static PyObject*
 
613
cms_transform_getattr_outputMode(CmsTransformObject* self, void* closure)
 
614
{
 
615
    return PyUnicode_FromString(self->mode_out);
 
616
}
 
617
 
 
618
static struct PyGetSetDef cms_transform_getsetters[] = {
 
619
    { "inputMode",      (getter) cms_transform_getattr_inputMode },
 
620
    { "outputMode",     (getter) cms_transform_getattr_outputMode },
 
621
    { NULL }
 
622
};
 
623
 
 
624
static PyTypeObject CmsTransform_Type = {
 
625
    PyVarObject_HEAD_INIT(NULL, 0)
 
626
    "CmsTransform", sizeof(CmsTransformObject), 0,
571
627
    /* methods */
572
628
    (destructor) cms_transform_dealloc, /*tp_dealloc*/
573
629
    0, /*tp_print*/
574
 
    (getattrfunc) cms_transform_getattr, /*tp_getattr*/
575
 
    0, /*tp_setattr*/
576
 
    0, /*tp_compare*/
577
 
    0, /*tp_repr*/
578
 
    0, /*tp_as_number */
579
 
    0, /*tp_as_sequence */
580
 
    0, /*tp_as_mapping */
581
 
    0 /*tp_hash*/
 
630
    0,                          /*tp_getattr*/
 
631
    0,                          /*tp_setattr*/
 
632
    0,                          /*tp_compare*/
 
633
    0,                          /*tp_repr*/
 
634
    0,                          /*tp_as_number */
 
635
    0,                          /*tp_as_sequence */
 
636
    0,                          /*tp_as_mapping */
 
637
    0,                          /*tp_hash*/
 
638
    0,                          /*tp_call*/
 
639
    0,                          /*tp_str*/
 
640
    0,                          /*tp_getattro*/
 
641
    0,                          /*tp_setattro*/
 
642
    0,                          /*tp_as_buffer*/
 
643
    Py_TPFLAGS_DEFAULT,         /*tp_flags*/
 
644
    0,                          /*tp_doc*/
 
645
    0,                          /*tp_traverse*/
 
646
    0,                          /*tp_clear*/
 
647
    0,                          /*tp_richcompare*/
 
648
    0,                          /*tp_weaklistoffset*/
 
649
    0,                          /*tp_iter*/
 
650
    0,                          /*tp_iternext*/
 
651
    cms_transform_methods,      /*tp_methods*/
 
652
    0,                          /*tp_members*/
 
653
    cms_transform_getsetters,   /*tp_getset*/
582
654
};
583
655
 
584
 
DL_EXPORT(void)
585
 
init_imagingcms(void)
586
 
{
587
 
    PyObject *m;
 
656
static int
 
657
setup_module(PyObject* m) {
588
658
    PyObject *d;
589
659
    PyObject *v;
590
660
 
591
 
    /* Patch up object types */
592
 
    CmsProfile_Type.ob_type = &PyType_Type;
593
 
    CmsTransform_Type.ob_type = &PyType_Type;
594
 
 
595
 
    m = Py_InitModule("_imagingcms", pyCMSdll_methods);
596
 
    d = PyModule_GetDict(m);
597
 
 
598
 
#if PY_VERSION_HEX >= 0x02020000
599
 
    v = PyString_FromFormat("%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
600
 
#else
601
 
    {
602
 
        char buffer[100];
603
 
        sprintf(buffer, "%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
604
 
        v = PyString_FromString(buffer);
605
 
    }
606
 
#endif
 
661
    d = PyModule_GetDict(m);
 
662
 
 
663
    /* Ready object types */
 
664
    PyType_Ready(&CmsProfile_Type);
 
665
    PyType_Ready(&CmsTransform_Type);
 
666
 
 
667
    d = PyModule_GetDict(m);
 
668
 
 
669
    v = PyUnicode_FromFormat("%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
607
670
    PyDict_SetItemString(d, "littlecms_version", v);
608
 
}
 
671
 
 
672
    return 0;
 
673
}
 
674
 
 
675
#if PY_VERSION_HEX >= 0x03000000
 
676
PyMODINIT_FUNC
 
677
PyInit__imagingcms(void) {
 
678
    PyObject* m;
 
679
 
 
680
    static PyModuleDef module_def = {
 
681
        PyModuleDef_HEAD_INIT,
 
682
        "_imagingcms",      /* m_name */
 
683
        NULL,               /* m_doc */
 
684
        -1,                 /* m_size */
 
685
        pyCMSdll_methods,   /* m_methods */
 
686
    };
 
687
 
 
688
    m = PyModule_Create(&module_def);
 
689
 
 
690
    if (setup_module(m) < 0)
 
691
        return NULL;
 
692
 
 
693
    return m;
 
694
}
 
695
#else
 
696
PyMODINIT_FUNC
 
697
init_imagingcms(void)
 
698
{
 
699
    PyObject *m = Py_InitModule("_imagingcms", pyCMSdll_methods);
 
700
    setup_module(m);
 
701
}
 
702
#endif
 
703