Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | bab9d03 | 1992-04-05 14:26:55 +0000 | [diff] [blame] | 2 | Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 3 | Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 25 | /* IMGFILE module - Interface to sgi libimage */ |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 27 | /* XXX This modele should be done better at some point. It should return |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 28 | ** an object of image file class, and have routines to manipulate these |
| 29 | ** image files in a neater way (so you can get rgb images off a greyscale |
| 30 | ** file, for instance, or do a straight display without having to get the |
| 31 | ** image bits into python, etc). |
| 32 | */ |
| 33 | |
| 34 | #include "allobjects.h" |
| 35 | #include "modsupport.h" |
| 36 | |
| 37 | #include <gl/image.h> |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 38 | #include <errno.h> |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 39 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 40 | static object * ImgfileError; /* Exception we raise for various trouble */ |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 41 | |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 42 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 43 | /* The image library does not always call the error hander :-(, |
| 44 | therefore we have a global variable indicating that it was called. |
| 45 | It is cleared by imgfile_open(). */ |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | 3e94197 | 1992-03-23 18:21:32 +0000 | [diff] [blame] | 47 | static int error_called; |
| 48 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 49 | |
| 50 | /* The error handler */ |
| 51 | |
Guido van Rossum | 3e94197 | 1992-03-23 18:21:32 +0000 | [diff] [blame] | 52 | static imgfile_error(str) |
| 53 | char *str; |
| 54 | { |
| 55 | err_setstr(ImgfileError, str); |
| 56 | error_called = 1; |
| 57 | return; /* To imglib, which will return a failure indictaor */ |
| 58 | } |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 59 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 60 | |
| 61 | /* Open an image file and return a pointer to it. |
| 62 | Make sure we raise an exception if we fail. */ |
| 63 | |
| 64 | static IMAGE * |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 65 | imgfile_open(fname) |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 66 | char *fname; |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 67 | { |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 68 | IMAGE *image; |
Guido van Rossum | 3e94197 | 1992-03-23 18:21:32 +0000 | [diff] [blame] | 69 | i_seterror(imgfile_error); |
| 70 | error_called = 0; |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 71 | errno = 0; |
| 72 | if ( (image = iopen(fname, "r")) == NULL ) { |
Guido van Rossum | 3e94197 | 1992-03-23 18:21:32 +0000 | [diff] [blame] | 73 | /* Error may already be set by imgfile_error */ |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 74 | if ( !error_called ) { |
| 75 | if (errno) |
| 76 | err_errno(ImgfileError); |
| 77 | else |
| 78 | err_setstr(ImgfileError, "Can't open image file"); |
| 79 | } |
| 80 | return NULL; |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 81 | } |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 82 | return image; |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 85 | |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 86 | static object * |
| 87 | imgfile_read(self, args) |
| 88 | object *self; |
| 89 | object *args; |
| 90 | { |
| 91 | char *fname; |
| 92 | object *rv; |
| 93 | int xsize, ysize, zsize; |
| 94 | char *cdatap; |
| 95 | long *idatap; |
| 96 | static short rs[8192], gs[8192], bs[8192]; |
| 97 | int x, y; |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 98 | IMAGE *image; |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 99 | |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 100 | if ( !getargs(args, "s", &fname) ) |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 101 | return NULL; |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 102 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 103 | if ( (image = imgfile_open(fname)) == NULL ) |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 104 | return NULL; |
| 105 | |
| 106 | if ( image->colormap != CM_NORMAL ) { |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 107 | iclose(image); |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 108 | err_setstr(ImgfileError, "Can only handle CM_NORMAL images"); |
| 109 | return NULL; |
| 110 | } |
| 111 | if ( BPP(image->type) != 1 ) { |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 112 | iclose(image); |
| 113 | err_setstr(ImgfileError, "Can't handle imgfiles with bpp!=1"); |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 114 | return NULL; |
| 115 | } |
| 116 | xsize = image->xsize; |
| 117 | ysize = image->ysize; |
| 118 | zsize = image->zsize; |
| 119 | if ( zsize != 1 && zsize != 3) { |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 120 | iclose(image); |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 121 | err_setstr(ImgfileError, "Can only handle 1 or 3 byte pixels"); |
| 122 | return NULL; |
| 123 | } |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 124 | if ( xsize > 8192 ) { |
| 125 | iclose(image); |
| 126 | err_setstr(ImgfileError, "Can't handle image with > 8192 columns"); |
| 127 | return NULL; |
| 128 | } |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 129 | |
| 130 | if ( zsize == 3 ) zsize = 4; |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 131 | rv = newsizedstringobject((char *)NULL, xsize*ysize*zsize); |
| 132 | if ( rv == NULL ) { |
| 133 | iclose(image); |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 134 | return NULL; |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 135 | } |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 136 | cdatap = getstringvalue(rv); |
| 137 | idatap = (long *)cdatap; |
Guido van Rossum | 3e94197 | 1992-03-23 18:21:32 +0000 | [diff] [blame] | 138 | for ( y=0; y < ysize && !error_called; y++ ) { |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 139 | if ( zsize == 1 ) { |
| 140 | getrow(image, rs, y, 0); |
| 141 | for(x=0; x<xsize; x++ ) |
| 142 | *cdatap++ = rs[x]; |
| 143 | } else { |
| 144 | getrow(image, rs, y, 0); |
| 145 | getrow(image, gs, y, 1); |
| 146 | getrow(image, bs, y, 2); |
| 147 | for(x=0; x<xsize; x++ ) |
| 148 | *idatap++ = (rs[x] & 0xff) | |
| 149 | ((gs[x] & 0xff)<<8) | |
| 150 | ((bs[x] & 0xff)<<16); |
| 151 | } |
| 152 | } |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 153 | iclose(image); |
Guido van Rossum | 3e94197 | 1992-03-23 18:21:32 +0000 | [diff] [blame] | 154 | if ( error_called ) { |
| 155 | DECREF(rv); |
| 156 | return NULL; |
| 157 | } |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 158 | return rv; |
| 159 | } |
| 160 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 161 | |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 162 | static object * |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 163 | imgfile_readscaled(self, args) |
| 164 | object *self; |
| 165 | object *args; |
| 166 | { |
| 167 | char *fname; |
| 168 | object *rv; |
| 169 | int xsize, ysize, zsize; |
| 170 | char *cdatap; |
| 171 | long *idatap; |
| 172 | static short rs[8192], gs[8192], bs[8192]; |
| 173 | int x, y; |
| 174 | int xwtd, ywtd, xorig, yorig; |
| 175 | float xfac, yfac; |
| 176 | int cnt; |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 177 | IMAGE *image; |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 178 | |
| 179 | if ( !getargs(args, "(sii)", &fname, &xwtd, &ywtd) ) |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 180 | return NULL; |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 181 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 182 | if ( (image = imgfile_open(fname)) == NULL ) |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 183 | return NULL; |
| 184 | |
| 185 | if ( image->colormap != CM_NORMAL ) { |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 186 | iclose(image); |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 187 | err_setstr(ImgfileError, "Can only handle CM_NORMAL images"); |
| 188 | return NULL; |
| 189 | } |
| 190 | if ( BPP(image->type) != 1 ) { |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 191 | iclose(image); |
| 192 | err_setstr(ImgfileError, "Can't handle imgfiles with bpp!=1"); |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 193 | return NULL; |
| 194 | } |
| 195 | xsize = image->xsize; |
| 196 | ysize = image->ysize; |
| 197 | zsize = image->zsize; |
| 198 | if ( zsize != 1 && zsize != 3) { |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 199 | iclose(image); |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 200 | err_setstr(ImgfileError, "Can only handle 1 or 3 byte pixels"); |
| 201 | return NULL; |
| 202 | } |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 203 | if ( xsize > 8192 ) { |
| 204 | iclose(image); |
| 205 | err_setstr(ImgfileError, "Can't handle image with > 8192 columns"); |
| 206 | return NULL; |
| 207 | } |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 208 | |
| 209 | if ( zsize == 3 ) zsize = 4; |
| 210 | rv = newsizedstringobject(NULL, xwtd*ywtd*zsize); |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 211 | if ( rv == NULL ) { |
| 212 | iclose(image); |
| 213 | return NULL; |
| 214 | } |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 215 | xfac = (float)xsize/(float)xwtd; |
| 216 | yfac = (float)ysize/(float)ywtd; |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 217 | cdatap = getstringvalue(rv); |
| 218 | idatap = (long *)cdatap; |
| 219 | for ( y=0; y < ywtd && !error_called; y++ ) { |
| 220 | yorig = (int)(y*yfac); |
| 221 | if ( zsize == 1 ) { |
| 222 | getrow(image, rs, yorig, 0); |
| 223 | for(x=0; x<xwtd; x++ ) { |
| 224 | *cdatap++ = rs[(int)(x*xfac)]; |
| 225 | } |
| 226 | } else { |
| 227 | getrow(image, rs, yorig, 0); |
| 228 | getrow(image, gs, yorig, 1); |
| 229 | getrow(image, bs, yorig, 2); |
| 230 | for(x=0; x<xwtd; x++ ) { |
| 231 | xorig = (int)(x*xfac); |
| 232 | *idatap++ = (rs[xorig] & 0xff) | |
| 233 | ((gs[xorig] & 0xff)<<8) | |
| 234 | ((bs[xorig] & 0xff)<<16); |
| 235 | } |
| 236 | } |
| 237 | } |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 238 | iclose(image); |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 239 | if ( error_called ) { |
| 240 | DECREF(rv); |
| 241 | return NULL; |
| 242 | } |
| 243 | return rv; |
| 244 | } |
| 245 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 246 | |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 247 | static object * |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 248 | imgfile_getsizes(self, args) |
| 249 | object *self; |
| 250 | object *args; |
| 251 | { |
| 252 | char *fname; |
| 253 | object *rv; |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 254 | IMAGE *image; |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 255 | |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 256 | if ( !getargs(args, "s", &fname) ) |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 257 | return NULL; |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 258 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 259 | if ( (image = imgfile_open(fname)) == NULL ) |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 260 | return NULL; |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 261 | rv = mkvalue("(iii)", image->xsize, image->ysize, image->zsize); |
| 262 | iclose(image); |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 263 | return rv; |
| 264 | } |
| 265 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 266 | |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 267 | static object * |
| 268 | imgfile_write(self, args) |
| 269 | object *self; |
| 270 | object *args; |
| 271 | { |
| 272 | IMAGE *image; |
| 273 | char *fname; |
| 274 | int xsize, ysize, zsize, len; |
| 275 | char *cdatap; |
| 276 | long *idatap; |
| 277 | short rs[8192], gs[8192], bs[8192]; |
| 278 | short r, g, b; |
| 279 | long rgb; |
| 280 | int x, y; |
| 281 | |
| 282 | if ( !getargs(args, "(ss#iii)", |
| 283 | &fname, &cdatap, &len, &xsize, &ysize, &zsize) ) |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 284 | return NULL; |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 285 | |
| 286 | if ( zsize != 1 && zsize != 3 ) { |
| 287 | err_setstr(ImgfileError, "Can only handle 1 or 3 byte pixels"); |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 288 | return NULL; |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 289 | } |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 290 | if ( len != xsize * ysize * (zsize == 1 ? 1 : 4) ) { |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 291 | err_setstr(ImgfileError, "Data does not match sizes"); |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 292 | return NULL; |
| 293 | } |
| 294 | if ( xsize > 8192 ) { |
| 295 | err_setstr(ImgfileError, "Can't handle image with > 8192 columns"); |
| 296 | return NULL; |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 299 | error_called = 0; |
| 300 | errno = 0; |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 301 | image =iopen(fname, "w", RLE(1), 3, xsize, ysize, zsize); |
| 302 | if ( image == 0 ) { |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 303 | if ( ! error_called ) { |
| 304 | if (errno) |
| 305 | err_errno(ImgfileError); |
| 306 | else |
| 307 | err_setstr(ImgfileError, "Can't create image file"); |
| 308 | } |
| 309 | return NULL; |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | idatap = (long *)cdatap; |
| 313 | |
| 314 | for( y=0; y<ysize && !error_called; y++ ) { |
| 315 | if ( zsize == 1 ) { |
| 316 | for( x=0; x<xsize; x++ ) |
| 317 | rs[x] = *cdatap++; |
| 318 | putrow(image, rs, y, 0); |
| 319 | } else { |
| 320 | for( x=0; x<xsize; x++ ) { |
| 321 | rgb = *idatap++; |
| 322 | r = rgb & 0xff; |
| 323 | g = (rgb >> 8 ) & 0xff; |
| 324 | b = (rgb >> 16 ) & 0xff; |
| 325 | rs[x] = r; |
| 326 | gs[x] = g; |
| 327 | bs[x] = b; |
| 328 | } |
| 329 | putrow(image, rs, y, 0); |
| 330 | putrow(image, gs, y, 1); |
| 331 | putrow(image, bs, y, 2); |
| 332 | } |
| 333 | } |
| 334 | iclose(image); |
| 335 | if ( error_called ) |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 336 | return NULL; |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 337 | INCREF(None); |
| 338 | return None; |
| 339 | |
| 340 | } |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 341 | |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 342 | |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 343 | static struct methodlist imgfile_methods[] = { |
Guido van Rossum | 2c4be64 | 1992-06-03 17:06:36 +0000 | [diff] [blame] | 344 | { "getsizes", imgfile_getsizes }, |
| 345 | { "read", imgfile_read }, |
| 346 | { "readscaled", imgfile_readscaled }, |
Jack Jansen | 3accf98 | 1992-08-20 11:54:27 +0000 | [diff] [blame] | 347 | { "write", imgfile_write }, |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 348 | { NULL, NULL } /* Sentinel */ |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | |
| 352 | void |
| 353 | initimgfile() |
| 354 | { |
| 355 | object *m, *d; |
| 356 | m = initmodule("imgfile", imgfile_methods); |
| 357 | d = getmoduledict(m); |
| 358 | ImgfileError = newstringobject("imgfile.error"); |
Guido van Rossum | a5f6138 | 1992-09-03 20:41:22 +0000 | [diff] [blame] | 359 | if ( ImgfileError == NULL || dictinsert(d, "error", ImgfileError) ) |
Guido van Rossum | aa9de67 | 1992-03-04 16:40:03 +0000 | [diff] [blame] | 360 | fatal("can't define imgfile.error"); |
| 361 | } |