~ubuntu-branches/ubuntu/saucy/python-imaging/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/git-updates.diff/_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:
 
1
/* 
 
2
 * pyCMS
 
3
 * a Python / PIL interface to the littleCMS ICC Color Management System
 
4
 * Copyright (C) 2002-2003 Kevin Cazabon
 
5
 * kevin@cazabon.com
 
6
 * http://www.cazabon.com
 
7
 * Adapted/reworked for PIL by Fredrik Lundh
 
8
 * Copyright (c) 2009 Fredrik Lundh
 
9
 * 
 
10
 * pyCMS home page:  http://www.cazabon.com/pyCMS
 
11
 * littleCMS home page:  http://www.littlecms.com
 
12
 * (littleCMS is Copyright (C) 1998-2001 Marti Maria)
 
13
 * 
 
14
 * Originally released under LGPL.  Graciously donated to PIL in
 
15
 * March 2009, for distribution under the standard PIL license
 
16
 */
 
17
 
 
18
#define COPYRIGHTINFO "\
 
19
pyCMS\n\
 
20
a Python / PIL interface to the littleCMS ICC Color Management System\n\
 
21
Copyright (C) 2002-2003 Kevin Cazabon\n\
 
22
kevin@cazabon.com\n\
 
23
http://www.cazabon.com\n\
 
24
"
 
25
 
 
26
#include "Python.h"
 
27
#include "lcms.h"
 
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
 
34
 
 
35
#if LCMS_VERSION < 117
 
36
#define LCMSBOOL BOOL
 
37
#endif
 
38
 
 
39
#ifdef WIN32
 
40
#include <wingdi.h>
 
41
#endif
 
42
 
 
43
#define PYCMSVERSION "0.1.0 pil"
 
44
 
 
45
/* version history */
 
46
 
 
47
/*
 
48
  0.1.0 pil integration & refactoring
 
49
  0.0.2 alpha:  Minor updates, added interfaces to littleCMS features, Jan 6, 2003
 
50
  - fixed some memory holes in how transforms/profiles were created and passed back to Python
 
51
  due to improper destructor setup for PyCObjects
 
52
  - added buildProofTransformFromOpenProfiles() function
 
53
  - eliminated some code redundancy, centralizing several common tasks with internal functions
 
54
 
 
55
  0.0.1 alpha:  First public release Dec 26, 2002
 
56
 
 
57
*/
 
58
 
 
59
/* known to-do list with current version:
 
60
 
 
61
   Verify that PILmode->littleCMStype conversion in findLCMStype is correct for all PIL modes (it probably isn't for the more obscure ones)
 
62
  
 
63
   Add support for creating custom RGB profiles on the fly
 
64
   Add support for checking presence of a specific tag in a profile
 
65
   Add support for other littleCMS features as required
 
66
 
 
67
*/
 
68
 
 
69
/*
 
70
  INTENT_PERCEPTUAL                 0
 
71
  INTENT_RELATIVE_COLORIMETRIC      1
 
72
  INTENT_SATURATION                 2
 
73
  INTENT_ABSOLUTE_COLORIMETRIC      3
 
74
*/
 
75
 
 
76
/* -------------------------------------------------------------------- */
 
77
/* wrapper classes */
 
78
 
 
79
/* a profile represents the ICC characteristics for a specific device */
 
80
 
 
81
typedef struct {
 
82
    PyObject_HEAD
 
83
    cmsHPROFILE profile;
 
84
} CmsProfileObject;
 
85
 
 
86
staticforward PyTypeObject CmsProfile_Type;
 
87
 
 
88
#define CmsProfile_Check(op) ((op)->ob_type == &CmsProfile_Type)
 
89
 
 
90
static PyObject*
 
91
cms_profile_new(cmsHPROFILE profile)
 
92
{
 
93
    CmsProfileObject* self;
 
94
 
 
95
    self = PyObject_New(CmsProfileObject, &CmsProfile_Type);
 
96
    if (!self)
 
97
        return NULL;
 
98
 
 
99
    self->profile = profile;
 
100
 
 
101
    return (PyObject*) self;
 
102
}
 
103
 
 
104
static PyObject*
 
105
cms_profile_open(PyObject* self, PyObject* args)
 
106
{
 
107
    cmsHPROFILE hProfile;
 
108
 
 
109
    char* sProfile;
 
110
    if (!PyArg_ParseTuple(args, "s:profile_open", &sProfile))
 
111
        return NULL;
 
112
 
 
113
    cmsErrorAction(LCMS_ERROR_IGNORE);
 
114
 
 
115
    hProfile = cmsOpenProfileFromFile(sProfile, "r");
 
116
    if (!hProfile) {
 
117
        PyErr_SetString(PyExc_IOError, "cannot open profile file");
 
118
        return NULL;
 
119
    }
 
120
 
 
121
    return cms_profile_new(hProfile);
 
122
}
 
123
 
 
124
static PyObject*
 
125
cms_profile_fromstring(PyObject* self, PyObject* args)
 
126
{
 
127
    cmsHPROFILE hProfile;
 
128
 
 
129
    char* pProfile;
 
130
    int nProfile;
 
131
    if (!PyArg_ParseTuple(args, "s#:profile_fromstring", &pProfile, &nProfile))
 
132
        return NULL;
 
133
 
 
134
    cmsErrorAction(LCMS_ERROR_IGNORE);
 
135
 
 
136
    hProfile = cmsOpenProfileFromMem(pProfile, nProfile);
 
137
    if (!hProfile)
 
138
        PyErr_SetString(PyExc_IOError, "cannot open profile from string");
 
139
 
 
140
    return cms_profile_new(hProfile);
 
141
}
 
142
 
 
143
static void
 
144
cms_profile_dealloc(CmsProfileObject* self)
 
145
{
 
146
    (void) cmsCloseProfile(self->profile);
 
147
    PyObject_Del(self);
 
148
}
 
149
 
 
150
/* a transform represents the mapping between two profiles */
 
151
 
 
152
typedef struct {
 
153
    PyObject_HEAD
 
154
    char mode_in[8];
 
155
    char mode_out[8];
 
156
    cmsHTRANSFORM transform;
 
157
} CmsTransformObject;
 
158
 
 
159
staticforward PyTypeObject CmsTransform_Type;
 
160
 
 
161
#define CmsTransform_Check(op) ((op)->ob_type == &CmsTransform_Type)
 
162
 
 
163
static PyObject*
 
164
cms_transform_new(cmsHTRANSFORM transform, char* mode_in, char* mode_out)
 
165
{
 
166
    CmsTransformObject* self;
 
167
 
 
168
    self = PyObject_New(CmsTransformObject, &CmsTransform_Type);
 
169
    if (!self)
 
170
        return NULL;
 
171
 
 
172
    self->transform = transform;
 
173
 
 
174
    strcpy(self->mode_in, mode_in);
 
175
    strcpy(self->mode_out, mode_out);
 
176
 
 
177
    return (PyObject*) self;
 
178
}
 
179
 
 
180
static void
 
181
cms_transform_dealloc(CmsTransformObject* self)
 
182
{
 
183
    cmsDeleteTransform(self->transform);
 
184
    PyObject_Del(self);
 
185
}
 
186
 
 
187
/* -------------------------------------------------------------------- */
 
188
/* internal functions */
 
189
 
 
190
static const char*
 
191
findICmode(icColorSpaceSignature cs)
 
192
{
 
193
    switch (cs) {
 
194
    case icSigXYZData: return "XYZ";
 
195
    case icSigLabData: return "LAB";
 
196
    case icSigLuvData: return "LUV";
 
197
    case icSigYCbCrData: return "YCbCr";
 
198
    case icSigYxyData: return "YXY";
 
199
    case icSigRgbData: return "RGB";
 
200
    case icSigGrayData: return "L";
 
201
    case icSigHsvData: return "HSV";
 
202
    case icSigHlsData: return "HLS";
 
203
    case icSigCmykData: return "CMYK";
 
204
    case icSigCmyData: return "CMY";
 
205
    default: return ""; /* other TBA */
 
206
    }
 
207
}
 
208
 
 
209
static DWORD 
 
210
findLCMStype(char* PILmode)
 
211
{
 
212
    if (strcmp(PILmode, "RGB") == 0) {
 
213
        return TYPE_RGBA_8;
 
214
    }
 
215
    else if (strcmp(PILmode, "RGBA") == 0) {
 
216
        return TYPE_RGBA_8;
 
217
    }
 
218
    else if (strcmp(PILmode, "RGBX") == 0) {
 
219
        return TYPE_RGBA_8;
 
220
    }
 
221
    else if (strcmp(PILmode, "RGBA;16B") == 0) {
 
222
        return TYPE_RGBA_16;
 
223
    }
 
224
    else if (strcmp(PILmode, "CMYK") == 0) {
 
225
        return TYPE_CMYK_8;
 
226
    }
 
227
    else if (strcmp(PILmode, "L") == 0) {
 
228
        return TYPE_GRAY_8;
 
229
    }
 
230
    else if (strcmp(PILmode, "L;16") == 0) {
 
231
        return TYPE_GRAY_16;
 
232
    }
 
233
    else if (strcmp(PILmode, "L;16B") == 0) {
 
234
        return TYPE_GRAY_16_SE;
 
235
    }
 
236
    else if (strcmp(PILmode, "YCCA") == 0) {
 
237
        return TYPE_YCbCr_8;
 
238
    }
 
239
    else if (strcmp(PILmode, "YCC") == 0) {
 
240
        return TYPE_YCbCr_8;
 
241
    }
 
242
 
 
243
    else {
 
244
        /* take a wild guess... but you probably should fail instead. */
 
245
        return TYPE_GRAY_8; /* so there's no buffer overrun... */
 
246
    }
 
247
}
 
248
 
 
249
static int
 
250
pyCMSdoTransform(Imaging im, Imaging imOut, cmsHTRANSFORM hTransform)
 
251
{
 
252
    int i;
 
253
 
 
254
    if (im->xsize > imOut->xsize || im->ysize > imOut->ysize)
 
255
        return -1;
 
256
 
 
257
    Py_BEGIN_ALLOW_THREADS
 
258
 
 
259
    for (i = 0; i < im->ysize; i++)
 
260
        cmsDoTransform(hTransform, im->image[i], imOut->image[i], im->xsize);
 
261
 
 
262
    Py_END_ALLOW_THREADS
 
263
 
 
264
    return 0;
 
265
}
 
266
 
 
267
static cmsHTRANSFORM
 
268
_buildTransform(cmsHPROFILE hInputProfile, cmsHPROFILE hOutputProfile, char *sInMode, char *sOutMode, int iRenderingIntent, DWORD cmsFLAGS)
 
269
{
 
270
    cmsHTRANSFORM hTransform;
 
271
 
 
272
    cmsErrorAction(LCMS_ERROR_IGNORE);
 
273
 
 
274
    Py_BEGIN_ALLOW_THREADS
 
275
 
 
276
    /* create the transform */
 
277
    hTransform = cmsCreateTransform(hInputProfile,
 
278
                                    findLCMStype(sInMode),
 
279
                                    hOutputProfile,
 
280
                                    findLCMStype(sOutMode),
 
281
                                    iRenderingIntent, cmsFLAGS);
 
282
 
 
283
    Py_END_ALLOW_THREADS
 
284
 
 
285
    if (!hTransform)
 
286
        PyErr_SetString(PyExc_ValueError, "cannot build transform");
 
287
 
 
288
    return hTransform; /* if NULL, an exception is set */
 
289
}
 
290
 
 
291
static cmsHTRANSFORM
 
292
_buildProofTransform(cmsHPROFILE hInputProfile, cmsHPROFILE hOutputProfile, cmsHPROFILE hProofProfile, char *sInMode, char *sOutMode, int iRenderingIntent, int iProofIntent, DWORD cmsFLAGS)
 
293
{
 
294
    cmsHTRANSFORM hTransform;
 
295
 
 
296
    cmsErrorAction(LCMS_ERROR_IGNORE);
 
297
 
 
298
    Py_BEGIN_ALLOW_THREADS
 
299
 
 
300
    /* create the transform */
 
301
    hTransform =  cmsCreateProofingTransform(hInputProfile,
 
302
                                             findLCMStype(sInMode),
 
303
                                             hOutputProfile,
 
304
                                             findLCMStype(sOutMode),
 
305
                                             hProofProfile,
 
306
                                             iRenderingIntent,
 
307
                                             iProofIntent,
 
308
                                             cmsFLAGS);
 
309
 
 
310
    Py_END_ALLOW_THREADS
 
311
 
 
312
    if (!hTransform)
 
313
        PyErr_SetString(PyExc_ValueError, "cannot build proof transform");
 
314
 
 
315
    return hTransform; /* if NULL, an exception is set */
 
316
}
 
317
 
 
318
/* -------------------------------------------------------------------- */
 
319
/* Python callable functions */
 
320
 
 
321
static PyObject *
 
322
buildTransform(PyObject *self, PyObject *args) {
 
323
    CmsProfileObject *pInputProfile;
 
324
    CmsProfileObject *pOutputProfile;
 
325
    char *sInMode;
 
326
    char *sOutMode;
 
327
    int iRenderingIntent = 0;
 
328
    int cmsFLAGS = 0;
 
329
 
 
330
    cmsHTRANSFORM transform = NULL;
 
331
 
 
332
    if (!PyArg_ParseTuple(args, "O!O!ss|ii:buildTransform", &CmsProfile_Type, &pInputProfile, &CmsProfile_Type, &pOutputProfile, &sInMode, &sOutMode, &iRenderingIntent, &cmsFLAGS))
 
333
        return NULL;
 
334
 
 
335
    cmsErrorAction(LCMS_ERROR_IGNORE);
 
336
 
 
337
    transform = _buildTransform(pInputProfile->profile, pOutputProfile->profile, sInMode, sOutMode, iRenderingIntent, cmsFLAGS);
 
338
 
 
339
    if (!transform)
 
340
        return NULL;
 
341
 
 
342
    return cms_transform_new(transform, sInMode, sOutMode);
 
343
}
 
344
 
 
345
static PyObject *
 
346
buildProofTransform(PyObject *self, PyObject *args)
 
347
{
 
348
    CmsProfileObject *pInputProfile;
 
349
    CmsProfileObject *pOutputProfile;
 
350
    CmsProfileObject *pProofProfile;
 
351
    char *sInMode;
 
352
    char *sOutMode;
 
353
    int iRenderingIntent = 0;
 
354
    int iProofIntent = 0;
 
355
    int cmsFLAGS = 0;
 
356
 
 
357
    cmsHTRANSFORM transform = NULL;
 
358
 
 
359
    if (!PyArg_ParseTuple(args, "O!O!O!ss|iii:buildProofTransform", &CmsProfile_Type, &pInputProfile, &CmsProfile_Type, &pOutputProfile, &CmsProfile_Type, &pProofProfile, &sInMode, &sOutMode, &iRenderingIntent, &iProofIntent, &cmsFLAGS))
 
360
        return NULL;
 
361
 
 
362
    cmsErrorAction(LCMS_ERROR_IGNORE);
 
363
 
 
364
    transform = _buildProofTransform(pInputProfile->profile, pOutputProfile->profile, pProofProfile->profile, sInMode, sOutMode, iRenderingIntent, iProofIntent, cmsFLAGS);
 
365
  
 
366
    if (!transform)
 
367
        return NULL;
 
368
 
 
369
    return cms_transform_new(transform, sInMode, sOutMode);
 
370
 
 
371
}
 
372
 
 
373
static PyObject *
 
374
cms_transform_apply(CmsTransformObject *self, PyObject *args)
 
375
{
 
376
    long idIn;
 
377
    long idOut;
 
378
    Imaging im;
 
379
    Imaging imOut;
 
380
 
 
381
    int result;
 
382
 
 
383
    if (!PyArg_ParseTuple(args, "ll:apply", &idIn, &idOut))
 
384
        return NULL;
 
385
 
 
386
    im = (Imaging) idIn;
 
387
    imOut = (Imaging) idOut;
 
388
 
 
389
    cmsErrorAction(LCMS_ERROR_IGNORE);
 
390
 
 
391
    result = pyCMSdoTransform(im, imOut, self->transform);
 
392
 
 
393
    return Py_BuildValue("i", result);
 
394
}
 
395
 
 
396
/* -------------------------------------------------------------------- */
 
397
/* Python-Callable On-The-Fly profile creation functions */
 
398
 
 
399
static PyObject *
 
400
createProfile(PyObject *self, PyObject *args)
 
401
{
 
402
    char *sColorSpace;
 
403
    cmsHPROFILE hProfile;
 
404
    int iColorTemp = 0;
 
405
    LPcmsCIExyY whitePoint = NULL;
 
406
    LCMSBOOL result;
 
407
 
 
408
    if (!PyArg_ParseTuple(args, "s|i:createProfile", &sColorSpace, &iColorTemp))
 
409
        return NULL;
 
410
 
 
411
    cmsErrorAction(LCMS_ERROR_IGNORE);
 
412
 
 
413
    if (strcmp(sColorSpace, "LAB") == 0) {
 
414
        if (iColorTemp > 0) {
 
415
            result = cmsWhitePointFromTemp(iColorTemp, whitePoint);
 
416
            if (!result) {
 
417
                PyErr_SetString(PyExc_ValueError, "ERROR: Could not calculate white point from color temperature provided, must be integer in degrees Kelvin");
 
418
                return NULL;
 
419
            }
 
420
            hProfile = cmsCreateLabProfile(whitePoint);
 
421
        } else
 
422
            hProfile = cmsCreateLabProfile(NULL);
 
423
    }
 
424
    else if (strcmp(sColorSpace, "XYZ") == 0)
 
425
        hProfile = cmsCreateXYZProfile();
 
426
    else if (strcmp(sColorSpace, "sRGB") == 0)
 
427
        hProfile = cmsCreate_sRGBProfile();
 
428
    else
 
429
        hProfile = NULL;
 
430
 
 
431
    if (!hProfile) {
 
432
        PyErr_SetString(PyExc_ValueError, "failed to create requested color space");
 
433
        return NULL;
 
434
    }
 
435
 
 
436
    return cms_profile_new(hProfile);
 
437
}
 
438
 
 
439
/* -------------------------------------------------------------------- */
 
440
/* profile methods */
 
441
 
 
442
static PyObject *
 
443
cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args)
 
444
{
 
445
    LCMSBOOL result;
 
446
 
 
447
    int intent;
 
448
    int direction;
 
449
    if (!PyArg_ParseTuple(args, "ii:is_intent_supported", &intent, &direction))
 
450
        return NULL;
 
451
 
 
452
    result = cmsIsIntentSupported(self->profile, intent, direction);
 
453
 
 
454
    /* printf("cmsIsIntentSupported(%p, %d, %d) => %d\n", self->profile, intent, direction, result); */
 
455
 
 
456
    return PyInt_FromLong(result != 0);
 
457
}
 
458
 
 
459
#ifdef WIN32
 
460
static PyObject *
 
461
cms_get_display_profile_win32(PyObject* self, PyObject* args)
 
462
{
 
463
    char filename[MAX_PATH];
 
464
    DWORD filename_size;
 
465
    BOOL ok;
 
466
 
 
467
    int handle = 0;
 
468
    int is_dc = 0;
 
469
    if (!PyArg_ParseTuple(args, "|ii:get_display_profile", &handle, &is_dc))
 
470
        return NULL;
 
471
 
 
472
    filename_size = sizeof(filename);
 
473
 
 
474
    if (is_dc) {
 
475
        ok = GetICMProfile((HDC) handle, &filename_size, filename);
 
476
    } else {
 
477
        HDC dc = GetDC((HWND) handle);
 
478
        ok = GetICMProfile(dc, &filename_size, filename);
 
479
        ReleaseDC((HWND) handle, dc);
 
480
    }
 
481
 
 
482
    if (ok)
 
483
        return PyString_FromStringAndSize(filename, filename_size-1);
 
484
 
 
485
    Py_INCREF(Py_None);
 
486
    return Py_None;
 
487
}
 
488
#endif
 
489
 
 
490
/* -------------------------------------------------------------------- */
 
491
/* Python interface setup */
 
492
 
 
493
static PyMethodDef pyCMSdll_methods[] = {
 
494
 
 
495
    {"profile_open", cms_profile_open, 1},
 
496
    {"profile_fromstring", cms_profile_fromstring, 1},
 
497
 
 
498
    /* profile and transform functions */
 
499
    {"buildTransform", buildTransform, 1},
 
500
    {"buildProofTransform", buildProofTransform, 1},
 
501
    {"createProfile", createProfile, 1},
 
502
 
 
503
    /* platform specific tools */
 
504
#ifdef WIN32
 
505
    {"get_display_profile_win32", cms_get_display_profile_win32, 1},
 
506
#endif
 
507
 
 
508
    {NULL, NULL}
 
509
};
 
510
 
 
511
static struct PyMethodDef cms_profile_methods[] = {
 
512
    {"is_intent_supported", (PyCFunction) cms_profile_is_intent_supported, 1},
 
513
    {NULL, NULL} /* sentinel */
 
514
};
 
515
 
 
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,
 
539
    /* methods */
 
540
    (destructor) cms_profile_dealloc, /*tp_dealloc*/
 
541
    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*/
 
550
};
 
551
 
 
552
static struct PyMethodDef cms_transform_methods[] = {
 
553
    {"apply", (PyCFunction) cms_transform_apply, 1},
 
554
    {NULL, NULL} /* sentinel */
 
555
};
 
556
 
 
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,
 
571
    /* methods */
 
572
    (destructor) cms_transform_dealloc, /*tp_dealloc*/
 
573
    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*/
 
582
};
 
583
 
 
584
DL_EXPORT(void)
 
585
init_imagingcms(void)
 
586
{
 
587
    PyObject *m;
 
588
    PyObject *d;
 
589
    PyObject *v;
 
590
 
 
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
 
607
    PyDict_SetItemString(d, "littlecms_version", v);
 
608
}