2 //#include "/usr/include/python2.3/Imaging.h"
8 /* redefine the ImagingObject struct defined in _imagingmodule.c */
9 /* there should be a better way to do this... */
15 int image_getWidth(PyObject
*_image
) {
16 if(strcmp(_image
->ob_type
->tp_name
, "ImagingCore")) {
17 PyErr_SetString(PyExc_Exception
, setError("not an image: %s", _image
->ob_type
->tp_name
));
20 ImagingObject
*image
= (ImagingObject
*)_image
;
21 return image
->image
->xsize
;
24 int image_getHeight(PyObject
*_image
) {
25 if(strcmp(_image
->ob_type
->tp_name
, "ImagingCore")) {
26 PyErr_SetString(PyExc_Exception
, setError("not an image: %s", _image
->ob_type
->tp_name
));
29 ImagingObject
*image
= (ImagingObject
*)_image
;
30 return image
->image
->ysize
;
33 int image_getBPP(PyObject
*_image
) {
34 if(strcmp(_image
->ob_type
->tp_name
, "ImagingCore")) {
35 PyErr_SetString(PyExc_Exception
, setError("not an image: %s", _image
->ob_type
->tp_name
));
38 ImagingObject
*image
= (ImagingObject
*)_image
;
39 if(!strcmp(image
->image
->mode
, "1") ||
40 !strcmp(image
->image
->mode
, "L") ||
41 !strcmp(image
->image
->mode
, "P")) {
44 if(!strcmp(image
->image
->mode
, "I") ||
45 !strcmp(image
->image
->mode
, "F")) {
48 if(!strcmp(image
->image
->mode
, "RGB") ||
49 !strcmp(image
->image
->mode
, "RGBA") ||
50 !strcmp(image
->image
->mode
, "CMYK") ||
51 !strcmp(image
->image
->mode
, "YCbCr")) {
54 PyErr_SetString(PyExc_Exception
, setError("Unknown image format (%s).", image
->image
->mode
));
58 RGBA
* image_toRGBA(PyObject
*_image
)
60 if(strcmp(_image
->ob_type
->tp_name
, "ImagingCore")) {
61 PyErr_SetString(PyExc_Exception
, setError("not an image: %s", _image
->ob_type
->tp_name
));
64 ImagingObject
*image
= (ImagingObject
*)_image
;
65 printf("mode: %s\n", image
->image
->mode
);
66 printf("depth: %d\n", image
->image
->depth
);
67 printf("bands: %d\n", image
->image
->bands
);
68 printf("xsize: %d\n", image
->image
->xsize
);
69 printf("ysize: %d\n", image
->image
->ysize
);
70 int bpp
= image_getBPP(_image
);
74 RGBA
*rgba
= (RGBA
*)malloc(image
->image
->xsize
* image
->image
->ysize
* sizeof(RGBA
));
76 if(!strcmp(image
->image
->mode
, "RGBA")) {
77 int y
,ymax
=image
->image
->ysize
;
78 int width
= image
->image
->xsize
;
81 U8
* src
= (U8
*)(image
->image
->image32
[y
]);
83 for(x
=0;x
<width
;x
++) {
84 dest
[x
].r
= src
[x
*4+0];
85 dest
[x
].g
= src
[x
*4+1];
86 dest
[x
].b
= src
[x
*4+2];
87 dest
[x
].a
= src
[x
*4+3];
94 PyErr_SetString(PyExc_Exception
, setError("Unsupported image format: %s (try .convert(\"RGBA\")", image
->image
->mode
));