5 //#include "/usr/include/python2.3/Imaging.h"
6 #include "../../config.h"
7 #ifdef HAVE_PYTHON_IMAGING
12 #include "../rfxswf.h"
14 /* redefine the ImagingObject struct defined in _imagingmodule.c */
15 /* there should be a better way to do this... */
18 #ifdef HAVE_PYTHON_IMAGING
23 int image_getWidth(PyObject*_image) {
24 #ifdef HAVE_PYTHON_IMAGING
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->xsize;
32 PyErr_SetString(PyExc_Exception, "imaging not compiled in");
37 int image_getHeight(PyObject*_image) {
38 #ifdef HAVE_PYTHON_IMAGING
39 if(strcmp(_image->ob_type->tp_name, "ImagingCore")) {
40 PyErr_SetString(PyExc_Exception, setError("not an image: %s", _image->ob_type->tp_name));
43 ImagingObject*image = (ImagingObject*)_image;
44 return image->image->ysize;
46 PyErr_SetString(PyExc_Exception, "imaging not compiled in");
51 int image_getBPP(PyObject*_image) {
52 #ifdef HAVE_PYTHON_IMAGING
53 if(strcmp(_image->ob_type->tp_name, "ImagingCore")) {
54 PyErr_SetString(PyExc_Exception, setError("not an image: %s", _image->ob_type->tp_name));
57 ImagingObject*image = (ImagingObject*)_image;
58 if(!strcmp(image->image->mode, "1") ||
59 !strcmp(image->image->mode, "L") ||
60 !strcmp(image->image->mode, "P")) {
63 if(!strcmp(image->image->mode, "I") ||
64 !strcmp(image->image->mode, "F")) {
67 if(!strcmp(image->image->mode, "RGB") ||
68 !strcmp(image->image->mode, "RGBA") ||
69 !strcmp(image->image->mode, "CMYK") ||
70 !strcmp(image->image->mode, "YCbCr")) {
73 PyErr_SetString(PyExc_Exception, setError("Unknown image format (%s).", image->image->mode));
76 PyErr_SetString(PyExc_Exception, "imaging not compiled in");
81 RGBA* image_toRGBA(PyObject*_image)
83 #ifdef HAVE_PYTHON_IMAGING
84 if(strcmp(_image->ob_type->tp_name, "ImagingCore")) {
85 PyErr_SetString(PyExc_Exception, setError("not an image: %s", _image->ob_type->tp_name));
88 ImagingObject*image = (ImagingObject*)_image;
89 printf("mode: %s\n", image->image->mode);
90 printf("depth: %d\n", image->image->depth);
91 printf("bands: %d\n", image->image->bands);
92 printf("xsize: %d\n", image->image->xsize);
93 printf("ysize: %d\n", image->image->ysize);
94 int bpp = image_getBPP(_image);
98 RGBA*rgba = (RGBA*)malloc(image->image->xsize * image->image->ysize * sizeof(RGBA));
100 if(!strcmp(image->image->mode, "RGBA")) {
101 int y,ymax=image->image->ysize;
102 int width = image->image->xsize;
104 for(y=0;y<ymax;y++) {
105 U8* src = (U8*)(image->image->image32[y]);
107 for(x=0;x<width;x++) {
108 dest[x].r = src[x*4+0];
109 dest[x].g = src[x*4+1];
110 dest[x].b = src[x*4+2];
111 dest[x].a = src[x*4+3];
118 PyErr_SetString(PyExc_Exception, setError("Unsupported image format: %s (try .convert(\"RGBA\")", image->image->mode));
120 PyErr_SetString(PyExc_Exception, "imaging not compiled in");
125 #ifdef HAVE_PYTHON_IMAGING
126 extern PyObject*PyImagingNew(Imaging imOut);
129 PyObject* rgba_to_image(RGBA*rgba, int width, int height)
131 #ifdef HAVE_PYTHON_IMAGING
133 Imaging img = ImagingNew("RGBA", width, height);
136 fprintf(stderr, "No array allocated!\n");
139 for(y=0;y<height;y++) {
140 U8* dest = (U8*)(img->image32[y]);
141 RGBA* src = &rgba[width*y];
143 for(x=0;x<width;x++) {
144 dest[x+0] = src[x].r;
145 dest[x+1] = src[x].g;
146 dest[x+2] = src[x].b;
147 dest[x+3] = src[x].a;
151 return PyImagingNew(img);
153 fprintf(stderr, "This image extraction is not yet supported on non-linux systems\n");
157 PyErr_SetString(PyExc_Exception, "imaging not compiled in");