blob: 9c318be136c84d4104bea5fc2f7a494272024c3e [file] [log] [blame]
Guido van Rossumaa9de671992-03-04 16:40:03 +00001/***********************************************************
Guido van Rossum524b5881995-01-04 19:10:35 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossumaa9de671992-03-04 16:40:03 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossuma5f61381992-09-03 20:41:22 +000025/* IMGFILE module - Interface to sgi libimage */
Guido van Rossumaa9de671992-03-04 16:40:03 +000026
Guido van Rossum2c4be641992-06-03 17:06:36 +000027/* XXX This modele should be done better at some point. It should return
Guido van Rossumaa9de671992-03-04 16:40:03 +000028** 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).
Jack Jansen3c2eb5c1993-01-19 15:17:13 +000032**
33** Warning: this module is very non-reentrant (esp. the readscaled stuff)
Guido van Rossumaa9de671992-03-04 16:40:03 +000034*/
35
36#include "allobjects.h"
37#include "modsupport.h"
38
39#include <gl/image.h>
Guido van Rossuma5f61381992-09-03 20:41:22 +000040#include <errno.h>
Guido van Rossumaa9de671992-03-04 16:40:03 +000041
Jack Jansen09cbf9a1993-01-19 15:33:13 +000042#include "/usr/people/4Dgifts/iristools/include/izoom.h"
Jack Jansen3c2eb5c1993-01-19 15:17:13 +000043
Guido van Rossuma5f61381992-09-03 20:41:22 +000044static object * ImgfileError; /* Exception we raise for various trouble */
Guido van Rossumaa9de671992-03-04 16:40:03 +000045
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +000046static int top_to_bottom; /* True if we want top-to-bottom images */
Guido van Rossumaa9de671992-03-04 16:40:03 +000047
Guido van Rossuma5f61381992-09-03 20:41:22 +000048/* The image library does not always call the error hander :-(,
49 therefore we have a global variable indicating that it was called.
50 It is cleared by imgfile_open(). */
Guido van Rossumaa9de671992-03-04 16:40:03 +000051
Guido van Rossum3e941971992-03-23 18:21:32 +000052static int error_called;
53
Guido van Rossuma5f61381992-09-03 20:41:22 +000054
55/* The error handler */
56
Guido van Rossum3e941971992-03-23 18:21:32 +000057static imgfile_error(str)
58 char *str;
59{
60 err_setstr(ImgfileError, str);
61 error_called = 1;
Guido van Rossum9bfef441993-03-29 10:43:31 +000062 return; /* To imglib, which will return a failure indicator */
Guido van Rossum3e941971992-03-23 18:21:32 +000063}
Guido van Rossumaa9de671992-03-04 16:40:03 +000064
Guido van Rossuma5f61381992-09-03 20:41:22 +000065
66/* Open an image file and return a pointer to it.
67 Make sure we raise an exception if we fail. */
68
69static IMAGE *
Guido van Rossum2c4be641992-06-03 17:06:36 +000070imgfile_open(fname)
Guido van Rossumaa9de671992-03-04 16:40:03 +000071 char *fname;
Guido van Rossum2c4be641992-06-03 17:06:36 +000072{
Guido van Rossuma5f61381992-09-03 20:41:22 +000073 IMAGE *image;
Guido van Rossum3e941971992-03-23 18:21:32 +000074 i_seterror(imgfile_error);
75 error_called = 0;
Guido van Rossuma5f61381992-09-03 20:41:22 +000076 errno = 0;
77 if ( (image = iopen(fname, "r")) == NULL ) {
Guido van Rossum3e941971992-03-23 18:21:32 +000078 /* Error may already be set by imgfile_error */
Guido van Rossuma5f61381992-09-03 20:41:22 +000079 if ( !error_called ) {
80 if (errno)
81 err_errno(ImgfileError);
82 else
83 err_setstr(ImgfileError, "Can't open image file");
84 }
85 return NULL;
Guido van Rossumaa9de671992-03-04 16:40:03 +000086 }
Guido van Rossuma5f61381992-09-03 20:41:22 +000087 return image;
Guido van Rossumaa9de671992-03-04 16:40:03 +000088}
89
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +000090static object *
91imgfile_ttob(self, args)
92 object *self;
93 object *args;
94{
95 int newval;
96 object *rv;
97
98 if (!getargs(args, "i", &newval))
99 return NULL;
100 rv = newintobject(top_to_bottom);
101 top_to_bottom = newval;
102 return rv;
103}
Guido van Rossuma5f61381992-09-03 20:41:22 +0000104
Guido van Rossumaa9de671992-03-04 16:40:03 +0000105static object *
106imgfile_read(self, args)
107 object *self;
108 object *args;
109{
110 char *fname;
111 object *rv;
112 int xsize, ysize, zsize;
113 char *cdatap;
114 long *idatap;
115 static short rs[8192], gs[8192], bs[8192];
116 int x, y;
Guido van Rossuma5f61381992-09-03 20:41:22 +0000117 IMAGE *image;
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000118 int yfirst, ylast, ystep;
119
Guido van Rossum2c4be641992-06-03 17:06:36 +0000120 if ( !getargs(args, "s", &fname) )
Guido van Rossuma5f61381992-09-03 20:41:22 +0000121 return NULL;
Guido van Rossum2c4be641992-06-03 17:06:36 +0000122
Guido van Rossuma5f61381992-09-03 20:41:22 +0000123 if ( (image = imgfile_open(fname)) == NULL )
Guido van Rossumaa9de671992-03-04 16:40:03 +0000124 return NULL;
125
126 if ( image->colormap != CM_NORMAL ) {
Guido van Rossuma5f61381992-09-03 20:41:22 +0000127 iclose(image);
Guido van Rossumaa9de671992-03-04 16:40:03 +0000128 err_setstr(ImgfileError, "Can only handle CM_NORMAL images");
129 return NULL;
130 }
131 if ( BPP(image->type) != 1 ) {
Guido van Rossuma5f61381992-09-03 20:41:22 +0000132 iclose(image);
133 err_setstr(ImgfileError, "Can't handle imgfiles with bpp!=1");
Guido van Rossumaa9de671992-03-04 16:40:03 +0000134 return NULL;
135 }
136 xsize = image->xsize;
137 ysize = image->ysize;
138 zsize = image->zsize;
139 if ( zsize != 1 && zsize != 3) {
Guido van Rossuma5f61381992-09-03 20:41:22 +0000140 iclose(image);
Guido van Rossumaa9de671992-03-04 16:40:03 +0000141 err_setstr(ImgfileError, "Can only handle 1 or 3 byte pixels");
142 return NULL;
143 }
Guido van Rossuma5f61381992-09-03 20:41:22 +0000144 if ( xsize > 8192 ) {
145 iclose(image);
146 err_setstr(ImgfileError, "Can't handle image with > 8192 columns");
147 return NULL;
148 }
Guido van Rossumaa9de671992-03-04 16:40:03 +0000149
150 if ( zsize == 3 ) zsize = 4;
Guido van Rossuma5f61381992-09-03 20:41:22 +0000151 rv = newsizedstringobject((char *)NULL, xsize*ysize*zsize);
152 if ( rv == NULL ) {
153 iclose(image);
Guido van Rossumaa9de671992-03-04 16:40:03 +0000154 return NULL;
Guido van Rossuma5f61381992-09-03 20:41:22 +0000155 }
Guido van Rossumaa9de671992-03-04 16:40:03 +0000156 cdatap = getstringvalue(rv);
157 idatap = (long *)cdatap;
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000158
159 if (top_to_bottom) {
160 yfirst = ysize-1;
161 ylast = -1;
162 ystep = -1;
163 } else {
164 yfirst = 0;
165 ylast = ysize;
166 ystep = 1;
167 }
168 for ( y=yfirst; y != ylast && !error_called; y += ystep ) {
Guido van Rossumaa9de671992-03-04 16:40:03 +0000169 if ( zsize == 1 ) {
170 getrow(image, rs, y, 0);
171 for(x=0; x<xsize; x++ )
172 *cdatap++ = rs[x];
173 } else {
174 getrow(image, rs, y, 0);
175 getrow(image, gs, y, 1);
176 getrow(image, bs, y, 2);
177 for(x=0; x<xsize; x++ )
178 *idatap++ = (rs[x] & 0xff) |
179 ((gs[x] & 0xff)<<8) |
180 ((bs[x] & 0xff)<<16);
181 }
182 }
Jack Jansen3accf981992-08-20 11:54:27 +0000183 iclose(image);
Guido van Rossum3e941971992-03-23 18:21:32 +0000184 if ( error_called ) {
185 DECREF(rv);
186 return NULL;
187 }
Guido van Rossumaa9de671992-03-04 16:40:03 +0000188 return rv;
189}
190
Guido van Rossum234f9421993-06-17 12:35:49 +0000191static IMAGE *glob_image;
192static long *glob_datap;
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000193static int glob_width, glob_z, glob_ysize;
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000194
195static
196xs_get(buf, y)
197 short *buf;
198 int y;
199{
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000200 if (top_to_bottom)
201 getrow(glob_image, buf, (glob_ysize-1-y), glob_z);
202 else
203 getrow(glob_image, buf, y, glob_z);
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000204}
205
206static
207xs_put_c(buf, y)
208 short *buf;
209 int y;
210{
211 char *datap = (char *)glob_datap + y*glob_width;
212 int width = glob_width;
213
214 while ( width-- )
215 *datap++ = (*buf++) & 0xff;
216}
217
218static
219xs_put_0(buf, y)
220 short *buf;
221 int y;
222{
223 long *datap = glob_datap + y*glob_width;
224 int width = glob_width;
225
226 while ( width-- )
227 *datap++ = (*buf++) & 0xff;
228}
229static
230xs_put_12(buf, y)
231 short *buf;
232 int y;
233{
234 long *datap = glob_datap + y*glob_width;
235 int width = glob_width;
236
237 while ( width-- )
238 *datap++ |= ((*buf++) & 0xff) << (glob_z*8);
239}
240
241static void
242xscale(image, xsize, ysize, zsize, datap, xnew, ynew, fmode, blur)
243 IMAGE *image;
244 int xsize, ysize, zsize;
245 long *datap;
246 int xnew, ynew;
247 int fmode;
248 double blur;
249{
250 glob_image = image;
251 glob_datap = datap;
252 glob_width = xnew;
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000253 glob_ysize = ysize;
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000254 if ( zsize == 1 ) {
255 glob_z = 0;
256 filterzoom(xs_get, xs_put_c, xsize, ysize, xnew, ynew, fmode, blur);
257 } else {
258 glob_z = 0;
259 filterzoom(xs_get, xs_put_0, xsize, ysize, xnew, ynew, fmode, blur);
260 glob_z = 1;
261 filterzoom(xs_get, xs_put_12, xsize, ysize, xnew, ynew, fmode, blur);
262 glob_z = 2;
263 filterzoom(xs_get, xs_put_12, xsize, ysize, xnew, ynew, fmode, blur);
264 }
265}
266
Guido van Rossuma5f61381992-09-03 20:41:22 +0000267
Guido van Rossumaa9de671992-03-04 16:40:03 +0000268static object *
Guido van Rossum2c4be641992-06-03 17:06:36 +0000269imgfile_readscaled(self, args)
270 object *self;
271 object *args;
272{
273 char *fname;
274 object *rv;
275 int xsize, ysize, zsize;
276 char *cdatap;
277 long *idatap;
278 static short rs[8192], gs[8192], bs[8192];
279 int x, y;
280 int xwtd, ywtd, xorig, yorig;
281 float xfac, yfac;
282 int cnt;
Guido van Rossuma5f61381992-09-03 20:41:22 +0000283 IMAGE *image;
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000284 char *filter;
285 double blur;
286 int extended;
287 int fmode;
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000288 int yfirst, ylast, ystep;
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000289
290 /*
291 ** Parse args. Funny, since arg 4 and 5 are optional
292 ** (filter name and blur factor). Also, 4 or 5 arguments indicates
293 ** extended scale algorithm in stead of simple-minded pixel drop/dup.
294 */
295 extended = 0;
296 cnt = gettuplesize(args);
297 if ( cnt == 5 ) {
298 extended = 1;
299 if ( !getargs(args, "(siisd)", &fname, &xwtd, &ywtd, &filter, &blur) )
300 return NULL;
301 } else if ( cnt == 4 ) {
302 extended = 1;
303 if ( !getargs(args, "(siis)", &fname, &xwtd, &ywtd, &filter) )
304 return NULL;
305 blur = 1.0;
306 } else if ( !getargs(args, "(sii)", &fname, &xwtd, &ywtd) )
Guido van Rossuma5f61381992-09-03 20:41:22 +0000307 return NULL;
Guido van Rossum2c4be641992-06-03 17:06:36 +0000308
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000309 /*
310 ** Check parameters, open file and check type, rows, etc.
311 */
312 if ( extended ) {
313 if ( strcmp(filter, "impulse") == 0 ) fmode = IMPULSE;
314 else if ( strcmp( filter, "box") == 0 ) fmode = BOX;
315 else if ( strcmp( filter, "triangle") == 0 ) fmode = TRIANGLE;
316 else if ( strcmp( filter, "quadratic") == 0 ) fmode = QUADRATIC;
317 else if ( strcmp( filter, "gaussian") == 0 ) fmode = GAUSSIAN;
318 else {
319 err_setstr(ImgfileError, "Unknown filter type");
320 return NULL;
321 }
322 }
323
Guido van Rossuma5f61381992-09-03 20:41:22 +0000324 if ( (image = imgfile_open(fname)) == NULL )
Guido van Rossum2c4be641992-06-03 17:06:36 +0000325 return NULL;
326
327 if ( image->colormap != CM_NORMAL ) {
Guido van Rossuma5f61381992-09-03 20:41:22 +0000328 iclose(image);
Guido van Rossum2c4be641992-06-03 17:06:36 +0000329 err_setstr(ImgfileError, "Can only handle CM_NORMAL images");
330 return NULL;
331 }
332 if ( BPP(image->type) != 1 ) {
Guido van Rossuma5f61381992-09-03 20:41:22 +0000333 iclose(image);
334 err_setstr(ImgfileError, "Can't handle imgfiles with bpp!=1");
Guido van Rossum2c4be641992-06-03 17:06:36 +0000335 return NULL;
336 }
337 xsize = image->xsize;
338 ysize = image->ysize;
339 zsize = image->zsize;
340 if ( zsize != 1 && zsize != 3) {
Guido van Rossuma5f61381992-09-03 20:41:22 +0000341 iclose(image);
Guido van Rossum2c4be641992-06-03 17:06:36 +0000342 err_setstr(ImgfileError, "Can only handle 1 or 3 byte pixels");
343 return NULL;
344 }
Guido van Rossuma5f61381992-09-03 20:41:22 +0000345 if ( xsize > 8192 ) {
346 iclose(image);
347 err_setstr(ImgfileError, "Can't handle image with > 8192 columns");
348 return NULL;
349 }
Guido van Rossum2c4be641992-06-03 17:06:36 +0000350
351 if ( zsize == 3 ) zsize = 4;
352 rv = newsizedstringobject(NULL, xwtd*ywtd*zsize);
Guido van Rossuma5f61381992-09-03 20:41:22 +0000353 if ( rv == NULL ) {
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000354 iclose(image);
355 return NULL;
Guido van Rossuma5f61381992-09-03 20:41:22 +0000356 }
Guido van Rossum2c4be641992-06-03 17:06:36 +0000357 xfac = (float)xsize/(float)xwtd;
358 yfac = (float)ysize/(float)ywtd;
Guido van Rossum2c4be641992-06-03 17:06:36 +0000359 cdatap = getstringvalue(rv);
360 idatap = (long *)cdatap;
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000361
362 if ( extended ) {
363 xscale(image, xsize, ysize, zsize, idatap, xwtd, ywtd, fmode, blur);
364 } else {
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000365 if (top_to_bottom) {
366 yfirst = ywtd-1;
367 ylast = -1;
368 ystep = -1;
369 } else {
370 yfirst = 0;
371 ylast = ywtd;
372 ystep = 1;
373 }
374 for ( y=yfirst; y != ylast && !error_called; y += ystep ) {
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000375 yorig = (int)(y*yfac);
376 if ( zsize == 1 ) {
377 getrow(image, rs, yorig, 0);
378 for(x=0; x<xwtd; x++ ) {
379 *cdatap++ = rs[(int)(x*xfac)];
380 }
381 } else {
382 getrow(image, rs, yorig, 0);
383 getrow(image, gs, yorig, 1);
384 getrow(image, bs, yorig, 2);
385 for(x=0; x<xwtd; x++ ) {
386 xorig = (int)(x*xfac);
387 *idatap++ = (rs[xorig] & 0xff) |
388 ((gs[xorig] & 0xff)<<8) |
389 ((bs[xorig] & 0xff)<<16);
390 }
391 }
Guido van Rossum2c4be641992-06-03 17:06:36 +0000392 }
393 }
Guido van Rossuma5f61381992-09-03 20:41:22 +0000394 iclose(image);
Guido van Rossum2c4be641992-06-03 17:06:36 +0000395 if ( error_called ) {
396 DECREF(rv);
397 return NULL;
398 }
399 return rv;
400}
401
402static object *
Guido van Rossumaa9de671992-03-04 16:40:03 +0000403imgfile_getsizes(self, args)
404 object *self;
405 object *args;
406{
407 char *fname;
408 object *rv;
Guido van Rossuma5f61381992-09-03 20:41:22 +0000409 IMAGE *image;
Guido van Rossumaa9de671992-03-04 16:40:03 +0000410
Guido van Rossum2c4be641992-06-03 17:06:36 +0000411 if ( !getargs(args, "s", &fname) )
Guido van Rossuma5f61381992-09-03 20:41:22 +0000412 return NULL;
Guido van Rossum2c4be641992-06-03 17:06:36 +0000413
Guido van Rossuma5f61381992-09-03 20:41:22 +0000414 if ( (image = imgfile_open(fname)) == NULL )
Guido van Rossumaa9de671992-03-04 16:40:03 +0000415 return NULL;
Guido van Rossuma5f61381992-09-03 20:41:22 +0000416 rv = mkvalue("(iii)", image->xsize, image->ysize, image->zsize);
417 iclose(image);
Guido van Rossumaa9de671992-03-04 16:40:03 +0000418 return rv;
419}
420
Jack Jansen3accf981992-08-20 11:54:27 +0000421static object *
422imgfile_write(self, args)
423 object *self;
424 object *args;
425{
426 IMAGE *image;
427 char *fname;
428 int xsize, ysize, zsize, len;
429 char *cdatap;
430 long *idatap;
431 short rs[8192], gs[8192], bs[8192];
432 short r, g, b;
433 long rgb;
434 int x, y;
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000435 int yfirst, ylast, ystep;
436
Jack Jansen3accf981992-08-20 11:54:27 +0000437
438 if ( !getargs(args, "(ss#iii)",
439 &fname, &cdatap, &len, &xsize, &ysize, &zsize) )
Guido van Rossuma5f61381992-09-03 20:41:22 +0000440 return NULL;
Jack Jansen3accf981992-08-20 11:54:27 +0000441
442 if ( zsize != 1 && zsize != 3 ) {
443 err_setstr(ImgfileError, "Can only handle 1 or 3 byte pixels");
Guido van Rossuma5f61381992-09-03 20:41:22 +0000444 return NULL;
Jack Jansen3accf981992-08-20 11:54:27 +0000445 }
Guido van Rossuma5f61381992-09-03 20:41:22 +0000446 if ( len != xsize * ysize * (zsize == 1 ? 1 : 4) ) {
Jack Jansen3accf981992-08-20 11:54:27 +0000447 err_setstr(ImgfileError, "Data does not match sizes");
Guido van Rossuma5f61381992-09-03 20:41:22 +0000448 return NULL;
449 }
450 if ( xsize > 8192 ) {
451 err_setstr(ImgfileError, "Can't handle image with > 8192 columns");
452 return NULL;
Jack Jansen3accf981992-08-20 11:54:27 +0000453 }
454
Guido van Rossuma5f61381992-09-03 20:41:22 +0000455 error_called = 0;
456 errno = 0;
Jack Jansen3accf981992-08-20 11:54:27 +0000457 image =iopen(fname, "w", RLE(1), 3, xsize, ysize, zsize);
458 if ( image == 0 ) {
Guido van Rossuma5f61381992-09-03 20:41:22 +0000459 if ( ! error_called ) {
460 if (errno)
461 err_errno(ImgfileError);
462 else
463 err_setstr(ImgfileError, "Can't create image file");
464 }
465 return NULL;
Jack Jansen3accf981992-08-20 11:54:27 +0000466 }
467
468 idatap = (long *)cdatap;
469
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000470 if (top_to_bottom) {
471 yfirst = ysize-1;
472 ylast = -1;
473 ystep = -1;
474 } else {
475 yfirst = 0;
476 ylast = ysize;
477 ystep = 1;
478 }
479 for ( y=yfirst; y != ylast && !error_called; y += ystep ) {
Jack Jansen3accf981992-08-20 11:54:27 +0000480 if ( zsize == 1 ) {
481 for( x=0; x<xsize; x++ )
482 rs[x] = *cdatap++;
483 putrow(image, rs, y, 0);
484 } else {
485 for( x=0; x<xsize; x++ ) {
486 rgb = *idatap++;
487 r = rgb & 0xff;
488 g = (rgb >> 8 ) & 0xff;
489 b = (rgb >> 16 ) & 0xff;
490 rs[x] = r;
491 gs[x] = g;
492 bs[x] = b;
493 }
494 putrow(image, rs, y, 0);
495 putrow(image, gs, y, 1);
496 putrow(image, bs, y, 2);
497 }
498 }
499 iclose(image);
500 if ( error_called )
Guido van Rossuma5f61381992-09-03 20:41:22 +0000501 return NULL;
Jack Jansen3accf981992-08-20 11:54:27 +0000502 INCREF(None);
503 return None;
504
505}
Guido van Rossumaa9de671992-03-04 16:40:03 +0000506
Guido van Rossuma5f61381992-09-03 20:41:22 +0000507
Guido van Rossumaa9de671992-03-04 16:40:03 +0000508static struct methodlist imgfile_methods[] = {
Guido van Rossum2c4be641992-06-03 17:06:36 +0000509 { "getsizes", imgfile_getsizes },
510 { "read", imgfile_read },
Jack Jansen3c2eb5c1993-01-19 15:17:13 +0000511 { "readscaled", imgfile_readscaled, 1},
Jack Jansen3accf981992-08-20 11:54:27 +0000512 { "write", imgfile_write },
Sjoerd Mullendera9c3c221993-10-11 12:54:31 +0000513 { "ttob", imgfile_ttob },
Guido van Rossuma5f61381992-09-03 20:41:22 +0000514 { NULL, NULL } /* Sentinel */
Guido van Rossumaa9de671992-03-04 16:40:03 +0000515};
516
517
518void
519initimgfile()
520{
521 object *m, *d;
522 m = initmodule("imgfile", imgfile_methods);
523 d = getmoduledict(m);
524 ImgfileError = newstringobject("imgfile.error");
Guido van Rossuma5f61381992-09-03 20:41:22 +0000525 if ( ImgfileError == NULL || dictinsert(d, "error", ImgfileError) )
Guido van Rossumaa9de671992-03-04 16:40:03 +0000526 fatal("can't define imgfile.error");
527}