annotate Modules/rgbimgmodule.c @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 4c4621aa9e76
children 2c29b8982643
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
1 /*
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
2 * fastimg -
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
3 * Faster reading and writing of image files.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
4 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
5 * This code should work on machines with any byte order.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
6 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
7 * Could someone make this run real fast using multiple processors
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
8 * or how about using memory mapped files to speed it up?
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
9 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
10 * Paul Haeberli - 1991
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
11 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
12 * Changed to return sizes.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
13 * Sjoerd Mullender - 1993
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
14 * Changed to incorporate into Python.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
15 * Sjoerd Mullender - 1993
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
16 */
4686
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
17 #include "Python.h"
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
18
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1508
diff changeset
19 #ifdef HAVE_UNISTD_H
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
20 #include <unistd.h>
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1508
diff changeset
21 #endif
1447
4ff608c4caca ANSIfied somewhat.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1443
diff changeset
22 #include <string.h>
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
23
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
24 /*
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
25 * from image.h
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
26 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
27 */
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
28 typedef struct {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
29 unsigned short imagic; /* stuff saved on disk . . */
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
30 unsigned short type;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
31 unsigned short dim;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
32 unsigned short xsize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
33 unsigned short ysize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
34 unsigned short zsize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
35 unsigned long min;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
36 unsigned long max;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
37 unsigned long wastebytes;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
38 char name[80];
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
39 unsigned long colormap;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
40
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
41 long file; /* stuff used in core only */
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
42 unsigned short flags;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
43 short dorev;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
44 short x;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
45 short y;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
46 short z;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
47 short cnt;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
48 unsigned short *ptr;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
49 unsigned short *base;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
50 unsigned short *tmpbuf;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
51 unsigned long offset;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
52 unsigned long rleend; /* for rle images */
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
53 unsigned long *rowstart; /* for rle images */
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
54 long *rowsize; /* for rle images */
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
55 } IMAGE;
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
56
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
57 #define IMAGIC 0732
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
58
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
59 #define TYPEMASK 0xff00
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
60 #define BPPMASK 0x00ff
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
61 #define ITYPE_VERBATIM 0x0000
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
62 #define ITYPE_RLE 0x0100
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
63 #define ISRLE(type) (((type) & 0xff00) == ITYPE_RLE)
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
64 #define ISVERBATIM(type) (((type) & 0xff00) == ITYPE_VERBATIM)
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
65 #define BPP(type) ((type) & BPPMASK)
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
66 #define RLE(bpp) (ITYPE_RLE | (bpp))
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
67 #define VERBATIM(bpp) (ITYPE_VERBATIM | (bpp))
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
68 /*
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
69 * end of image.h stuff
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
70 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
71 */
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
72
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
73 #define RINTLUM (79)
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
74 #define GINTLUM (156)
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
75 #define BINTLUM (21)
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
76
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
77 #define ILUM(r,g,b) ((int)(RINTLUM*(r)+GINTLUM*(g)+BINTLUM*(b))>>8)
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
78
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
79 #define OFFSET_R 3 /* this is byte order dependent */
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
80 #define OFFSET_G 2
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
81 #define OFFSET_B 1
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
82 #define OFFSET_A 0
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
83
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
84 #define CHANOFFSET(z) (3-(z)) /* this is byte order dependent */
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
85
4686
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
86 static void expandrow Py_PROTO((unsigned char *, unsigned char *, int));
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
87 static void setalpha Py_PROTO((unsigned char *, int));
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
88 static void copybw Py_PROTO((long *, int));
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
89 static void interleaverow Py_PROTO((unsigned char*, unsigned char*, int, int));
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
90 static int compressrow Py_PROTO((unsigned char *, unsigned char *, int, int));
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
91 static void lumrow Py_PROTO((unsigned char *, unsigned char *, int));
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
92
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
93 #ifdef ADD_TAGS
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
94 #define TAGLEN (5)
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
95 #else
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
96 #define TAGLEN (0)
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
97 #endif
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
98
4686
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
99 static PyObject *ImgfileError;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
100
1454
3a5f2f110f70 Added function ttob.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1447
diff changeset
101 static int reverse_order;
3a5f2f110f70 Added function ttob.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1447
diff changeset
102
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
103 #ifdef ADD_TAGS
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
104 /*
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
105 * addlongimgtag -
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
106 * this is used to extract image data from core dumps.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
107 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
108 */
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
109 static void
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
110 addlongimgtag(dptr, xsize, ysize)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
111 unsigned long *dptr;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
112 int xsize, ysize;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
113 {
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
114 dptr = dptr + (xsize * ysize);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
115 dptr[0] = 0x12345678;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
116 dptr[1] = 0x59493333;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
117 dptr[2] = 0x69434222;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
118 dptr[3] = xsize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
119 dptr[4] = ysize;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
120 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
121 #endif
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
122
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
123 /*
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
124 * byte order independent read/write of shorts and longs.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
125 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
126 */
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
127 static unsigned short
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
128 getshort(inf)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
129 FILE *inf;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
130 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
131 unsigned char buf[2];
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
132
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
133 fread(buf, 2, 1, inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
134 return (buf[0] << 8) + (buf[1] << 0);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
135 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
136
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
137 static unsigned long
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
138 getlong(inf)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
139 FILE *inf;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
140 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
141 unsigned char buf[4];
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
142
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
143 fread(buf, 4, 1, inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
144 return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + (buf[3] << 0);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
145 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
146
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
147 static void
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
148 putshort(outf, val)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
149 FILE *outf;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
150 unsigned short val;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
151 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
152 unsigned char buf[2];
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
153
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
154 buf[0] = (val >> 8);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
155 buf[1] = (val >> 0);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
156 fwrite(buf, 2, 1, outf);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
157 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
158
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
159 static int
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
160 putlong(outf, val)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
161 FILE *outf;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
162 unsigned long val;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
163 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
164 unsigned char buf[4];
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
165
5318
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
166 buf[0] = (unsigned char) (val >> 24);
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
167 buf[1] = (unsigned char) (val >> 16);
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
168 buf[2] = (unsigned char) (val >> 8);
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
169 buf[3] = (unsigned char) (val >> 0);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
170 return fwrite(buf, 4, 1, outf);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
171 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
172
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
173 static void
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
174 readheader(inf, image)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
175 FILE *inf;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
176 IMAGE *image;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
177 {
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
178 memset(image ,0, sizeof(IMAGE));
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
179 image->imagic = getshort(inf);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
180 image->type = getshort(inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
181 image->dim = getshort(inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
182 image->xsize = getshort(inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
183 image->ysize = getshort(inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
184 image->zsize = getshort(inf);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
185 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
186
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
187 static int
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
188 writeheader(outf, image)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
189 FILE *outf;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
190 IMAGE *image;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
191 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
192 IMAGE t;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
193
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
194 memset(&t, 0, sizeof(IMAGE));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
195 fwrite(&t, sizeof(IMAGE), 1, outf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
196 fseek(outf, 0, SEEK_SET);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
197 putshort(outf, image->imagic);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
198 putshort(outf, image->type);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
199 putshort(outf, image->dim);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
200 putshort(outf, image->xsize);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
201 putshort(outf, image->ysize);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
202 putshort(outf, image->zsize);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
203 putlong(outf, image->min);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
204 putlong(outf, image->max);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
205 putlong(outf, 0);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
206 return fwrite("no name", 8, 1, outf);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
207 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
208
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
209 static int
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
210 writetab(outf, tab, len)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
211 FILE *outf;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
212 /*unsigned*/ long *tab;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
213 int len;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
214 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
215 int r = 0;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
216
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
217 while(len) {
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
218 r = putlong(outf, *tab++);
5594
4c4621aa9e76 Partial(?) 64bit patch (AMK).
Guido van Rossum <guido@python.org>
parents: 5318
diff changeset
219 len--;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
220 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
221 return r;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
222 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
223
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
224 static void
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
225 readtab(inf, tab, len)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
226 FILE *inf;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
227 /*unsigned*/ long *tab;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
228 int len;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
229 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
230 while(len) {
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
231 *tab++ = getlong(inf);
5594
4c4621aa9e76 Partial(?) 64bit patch (AMK).
Guido van Rossum <guido@python.org>
parents: 5318
diff changeset
232 len--;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
233 }
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
234 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
235
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
236 /*
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
237 * sizeofimage -
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
238 * return the xsize and ysize of an iris image file.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
239 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
240 */
4686
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
241 static PyObject *
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
242 sizeofimage(self, args)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
243 PyObject *self, *args;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
244 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
245 char *name;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
246 IMAGE image;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
247 FILE *inf;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
248
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
249 if (!PyArg_Parse(args, "s", &name))
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
250 return NULL;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
251
5309
e756b8e54c7c (Jack:) fopen arg typo (?) "rw" changed to "rb".
Guido van Rossum <guido@python.org>
parents: 5148
diff changeset
252 inf = fopen(name, "rb");
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
253 if (!inf) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
254 PyErr_SetString(ImgfileError, "can't open image file");
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
255 return NULL;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
256 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
257 readheader(inf, &image);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
258 fclose(inf);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
259 if (image.imagic != IMAGIC) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
260 PyErr_SetString(ImgfileError,
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
261 "bad magic number in image file");
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
262 return NULL;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
263 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
264 return Py_BuildValue("(ii)", image.xsize, image.ysize);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
265 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
266
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
267 /*
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
268 * longimagedata -
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
269 * read in a B/W RGB or RGBA iris image file and return a
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
270 * pointer to an array of longs.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
271 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
272 */
4686
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
273 static PyObject *
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
274 longimagedata(self, args)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
275 PyObject *self, *args;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
276 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
277 char *name;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
278 unsigned char *base, *lptr;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
279 unsigned char *rledat = NULL, *verdat = NULL;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
280 long *starttab = NULL, *lengthtab = NULL;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
281 FILE *inf = NULL;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
282 IMAGE image;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
283 int y, z, tablen;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
284 int xsize, ysize, zsize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
285 int bpp, rle, cur, badorder;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
286 int rlebuflen;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
287 PyObject *rv = NULL;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
288
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
289 if (!PyArg_Parse(args, "s", &name))
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
290 return NULL;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
291
5148
89edaa8ed50f Change all three fopen calls to use binary mode.
Guido van Rossum <guido@python.org>
parents: 4918
diff changeset
292 inf = fopen(name,"rb");
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
293 if (!inf) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
294 PyErr_SetString(ImgfileError, "can't open image file");
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
295 return NULL;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
296 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
297 readheader(inf,&image);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
298 if (image.imagic != IMAGIC) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
299 PyErr_SetString(ImgfileError,
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
300 "bad magic number in image file");
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
301 goto finally;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
302 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
303 rle = ISRLE(image.type);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
304 bpp = BPP(image.type);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
305 if (bpp != 1) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
306 PyErr_SetString(ImgfileError,
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
307 "image must have 1 byte per pix chan");
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
308 goto finally;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
309 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
310 xsize = image.xsize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
311 ysize = image.ysize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
312 zsize = image.zsize;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
313 if (rle) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
314 tablen = ysize * zsize * sizeof(long);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
315 starttab = (long *)malloc(tablen);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
316 lengthtab = (long *)malloc(tablen);
5318
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
317 rlebuflen = (int) (1.05 * xsize +10);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
318 rledat = (unsigned char *)malloc(rlebuflen);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
319 if (!starttab || !lengthtab || !rledat) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
320 PyErr_NoMemory();
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
321 goto finally;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
322 }
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
323
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
324 fseek(inf, 512, SEEK_SET);
5594
4c4621aa9e76 Partial(?) 64bit patch (AMK).
Guido van Rossum <guido@python.org>
parents: 5318
diff changeset
325 readtab(inf, starttab, ysize*zsize);
4c4621aa9e76 Partial(?) 64bit patch (AMK).
Guido van Rossum <guido@python.org>
parents: 5318
diff changeset
326 readtab(inf, lengthtab, ysize*zsize);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
327
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
328 /* check data order */
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
329 cur = 0;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
330 badorder = 0;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
331 for(y = 0; y < ysize; y++) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
332 for(z = 0; z < zsize; z++) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
333 if (starttab[y + z * ysize] < cur) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
334 badorder = 1;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
335 break;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
336 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
337 cur = starttab[y +z * ysize];
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
338 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
339 if (badorder)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
340 break;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
341 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
342
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
343 fseek(inf, 512 + 2 * tablen, SEEK_SET);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
344 cur = 512 + 2 * tablen;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
345 rv = PyString_FromStringAndSize((char *)NULL,
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
346 (xsize * ysize + TAGLEN) * sizeof(long));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
347 if (rv == NULL)
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
348 goto finally;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
349
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
350 base = (unsigned char *) PyString_AsString(rv);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
351 #ifdef ADD_TAGS
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
352 addlongimgtag(base,xsize,ysize);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
353 #endif
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
354 if (badorder) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
355 for (z = 0; z < zsize; z++) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
356 lptr = base;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
357 if (reverse_order)
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
358 lptr += (ysize - 1) * xsize
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
359 * sizeof(unsigned long);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
360 for (y = 0; y < ysize; y++) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
361 int idx = y + z * ysize;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
362 if (cur != starttab[idx]) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
363 fseek(inf,starttab[idx],
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
364 SEEK_SET);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
365 cur = starttab[idx];
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
366 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
367 if (lengthtab[idx] > rlebuflen) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
368 PyErr_SetString(ImgfileError,
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
369 "rlebuf is too small");
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
370 Py_DECREF(rv);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
371 rv = NULL;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
372 goto finally;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
373 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
374 fread(rledat, lengthtab[idx], 1, inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
375 cur += lengthtab[idx];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
376 expandrow(lptr, rledat, 3-z);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
377 if (reverse_order)
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
378 lptr -= xsize
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
379 * sizeof(unsigned long);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
380 else
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
381 lptr += xsize
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
382 * sizeof(unsigned long);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
383 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
384 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
385 } else {
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
386 lptr = base;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
387 if (reverse_order)
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
388 lptr += (ysize - 1) * xsize
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
389 * sizeof(unsigned long);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
390 for (y = 0; y < ysize; y++) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
391 for(z = 0; z < zsize; z++) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
392 int idx = y + z * ysize;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
393 if (cur != starttab[idx]) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
394 fseek(inf, starttab[idx],
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
395 SEEK_SET);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
396 cur = starttab[idx];
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
397 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
398 fread(rledat, lengthtab[idx], 1, inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
399 cur += lengthtab[idx];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
400 expandrow(lptr, rledat, 3-z);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
401 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
402 if (reverse_order)
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
403 lptr -= xsize * sizeof(unsigned long);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
404 else
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
405 lptr += xsize * sizeof(unsigned long);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
406 }
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
407 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
408 if (zsize == 3)
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
409 setalpha(base, xsize * ysize);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
410 else if (zsize < 3)
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
411 copybw((long *) base, xsize * ysize);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
412 }
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
413 else {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
414 rv = PyString_FromStringAndSize((char *) 0,
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
415 (xsize*ysize+TAGLEN)*sizeof(long));
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
416 if (rv == NULL)
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
417 goto finally;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
418
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
419 base = (unsigned char *) PyString_AsString(rv);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
420 #ifdef ADD_TAGS
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
421 addlongimgtag(base, xsize, ysize);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
422 #endif
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
423 verdat = (unsigned char *)malloc(xsize);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
424 fseek(inf, 512, SEEK_SET);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
425 for (z = 0; z < zsize; z++) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
426 lptr = base;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
427 if (reverse_order)
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
428 lptr += (ysize - 1) * xsize
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
429 * sizeof(unsigned long);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
430 for (y = 0; y < ysize; y++) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
431 fread(verdat, xsize, 1, inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
432 interleaverow(lptr, verdat, 3-z, xsize);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
433 if (reverse_order)
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
434 lptr -= xsize * sizeof(unsigned long);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
435 else
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
436 lptr += xsize * sizeof(unsigned long);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
437 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
438 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
439 if (zsize == 3)
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
440 setalpha(base, xsize * ysize);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
441 else if (zsize < 3)
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
442 copybw((long *) base, xsize * ysize);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
443 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
444 finally:
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
445 free(starttab);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
446 free(lengthtab);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
447 free(rledat);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
448 free(verdat);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
449 fclose(inf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
450 return rv;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
451 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
452
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
453 /* static utility functions for longimagedata */
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
454
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
455 static void
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
456 interleaverow(lptr, cptr, z, n)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
457 unsigned char *lptr, *cptr;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
458 int z, n;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
459 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
460 lptr += z;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
461 while (n--) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
462 *lptr = *cptr++;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
463 lptr += 4;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
464 }
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
465 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
466
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
467 static void
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
468 copybw(lptr, n)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
469 long *lptr;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
470 int n;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
471 {
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
472 while (n >= 8) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
473 lptr[0] = 0xff000000 + (0x010101 * (lptr[0] & 0xff));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
474 lptr[1] = 0xff000000 + (0x010101 * (lptr[1] & 0xff));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
475 lptr[2] = 0xff000000 + (0x010101 * (lptr[2] & 0xff));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
476 lptr[3] = 0xff000000 + (0x010101 * (lptr[3] & 0xff));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
477 lptr[4] = 0xff000000 + (0x010101 * (lptr[4] & 0xff));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
478 lptr[5] = 0xff000000 + (0x010101 * (lptr[5] & 0xff));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
479 lptr[6] = 0xff000000 + (0x010101 * (lptr[6] & 0xff));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
480 lptr[7] = 0xff000000 + (0x010101 * (lptr[7] & 0xff));
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
481 lptr += 8;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
482 n -= 8;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
483 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
484 while (n--) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
485 *lptr = 0xff000000 + (0x010101 * (*lptr&0xff));
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
486 lptr++;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
487 }
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
488 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
489
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
490 static void
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
491 setalpha(lptr, n)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
492 unsigned char *lptr;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
493 {
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
494 while (n >= 8) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
495 lptr[0 * 4] = 0xff;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
496 lptr[1 * 4] = 0xff;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
497 lptr[2 * 4] = 0xff;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
498 lptr[3 * 4] = 0xff;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
499 lptr[4 * 4] = 0xff;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
500 lptr[5 * 4] = 0xff;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
501 lptr[6 * 4] = 0xff;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
502 lptr[7 * 4] = 0xff;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
503 lptr += 4 * 8;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
504 n -= 8;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
505 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
506 while (n--) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
507 *lptr = 0xff;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
508 lptr += 4;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
509 }
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
510 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
511
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
512 static void
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
513 expandrow(optr, iptr, z)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
514 unsigned char *optr, *iptr;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
515 int z;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
516 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
517 unsigned char pixel, count;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
518
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
519 optr += z;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
520 while (1) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
521 pixel = *iptr++;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
522 if (!(count = (pixel & 0x7f)))
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
523 return;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
524 if (pixel & 0x80) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
525 while (count >= 8) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
526 optr[0 * 4] = iptr[0];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
527 optr[1 * 4] = iptr[1];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
528 optr[2 * 4] = iptr[2];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
529 optr[3 * 4] = iptr[3];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
530 optr[4 * 4] = iptr[4];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
531 optr[5 * 4] = iptr[5];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
532 optr[6 * 4] = iptr[6];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
533 optr[7 * 4] = iptr[7];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
534 optr += 8 * 4;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
535 iptr += 8;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
536 count -= 8;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
537 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
538 while (count--) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
539 *optr = *iptr++;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
540 optr += 4;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
541 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
542 }
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
543 else {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
544 pixel = *iptr++;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
545 while (count >= 8) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
546 optr[0 * 4] = pixel;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
547 optr[1 * 4] = pixel;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
548 optr[2 * 4] = pixel;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
549 optr[3 * 4] = pixel;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
550 optr[4 * 4] = pixel;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
551 optr[5 * 4] = pixel;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
552 optr[6 * 4] = pixel;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
553 optr[7 * 4] = pixel;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
554 optr += 8 * 4;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
555 count -= 8;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
556 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
557 while (count--) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
558 *optr = pixel;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
559 optr += 4;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
560 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
561 }
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
562 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
563 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
564
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
565 /*
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
566 * longstoimage -
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
567 * copy an array of longs to an iris image file. Each long
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
568 * represents one pixel. xsize and ysize specify the dimensions of
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
569 * the pixel array. zsize specifies what kind of image file to
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
570 * write out. if zsize is 1, the luminance of the pixels are
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
571 * calculated, and a sinlge channel black and white image is saved.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
572 * If zsize is 3, an RGB image file is saved. If zsize is 4, an
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
573 * RGBA image file is saved.
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
574 *
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
575 */
4686
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
576 static PyObject *
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
577 longstoimage(self, args)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
578 PyObject *self, *args;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
579 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
580 unsigned char *lptr;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
581 char *name;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
582 int xsize, ysize, zsize;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
583 FILE *outf = NULL;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
584 IMAGE image;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
585 int tablen, y, z, pos, len;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
586 long *starttab = NULL, *lengthtab = NULL;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
587 unsigned char *rlebuf = NULL;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
588 unsigned char *lumbuf = NULL;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
589 int rlebuflen, goodwrite;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
590 PyObject *retval = NULL;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
591
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
592 if (!PyArg_Parse(args, "(s#iiis)", &lptr, &len, &xsize, &ysize, &zsize,
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
593 &name))
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
594 return NULL;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
595
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
596 goodwrite = 1;
5148
89edaa8ed50f Change all three fopen calls to use binary mode.
Guido van Rossum <guido@python.org>
parents: 4918
diff changeset
597 outf = fopen(name, "wb");
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
598 if (!outf) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
599 PyErr_SetString(ImgfileError, "can't open output file");
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
600 return NULL;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
601 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
602 tablen = ysize * zsize * sizeof(long);
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
603
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
604 starttab = (long *)malloc(tablen);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
605 lengthtab = (long *)malloc(tablen);
5318
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
606 rlebuflen = (int) (1.05 * xsize + 10);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
607 rlebuf = (unsigned char *)malloc(rlebuflen);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
608 lumbuf = (unsigned char *)malloc(xsize * sizeof(long));
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
609 if (!starttab || !lengthtab || !rlebuf || !lumbuf) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
610 PyErr_NoMemory();
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
611 goto finally;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
612 }
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
613
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
614 memset(&image, 0, sizeof(IMAGE));
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
615 image.imagic = IMAGIC;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
616 image.type = RLE(1);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
617 if (zsize>1)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
618 image.dim = 3;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
619 else
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
620 image.dim = 2;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
621 image.xsize = xsize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
622 image.ysize = ysize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
623 image.zsize = zsize;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
624 image.min = 0;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
625 image.max = 255;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
626 goodwrite *= writeheader(outf, &image);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
627 pos = 512 + 2 * tablen;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
628 fseek(outf, pos, SEEK_SET);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
629 if (reverse_order)
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
630 lptr += (ysize - 1) * xsize * sizeof(unsigned long);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
631 for (y = 0; y < ysize; y++) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
632 for (z = 0; z < zsize; z++) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
633 if (zsize == 1) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
634 lumrow(lptr, lumbuf, xsize);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
635 len = compressrow(lumbuf, rlebuf,
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
636 CHANOFFSET(z), xsize);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
637 } else {
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
638 len = compressrow(lptr, rlebuf,
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
639 CHANOFFSET(z), xsize);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
640 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
641 if(len > rlebuflen) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
642 PyErr_SetString(ImgfileError,
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
643 "rlebuf is too small");
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
644 goto finally;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
645 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
646 goodwrite *= fwrite(rlebuf, len, 1, outf);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
647 starttab[y + z * ysize] = pos;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
648 lengthtab[y + z * ysize] = len;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
649 pos += len;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
650 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
651 if (reverse_order)
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
652 lptr -= xsize * sizeof(unsigned long);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
653 else
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
654 lptr += xsize * sizeof(unsigned long);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
655 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
656
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
657 fseek(outf, 512, SEEK_SET);
5594
4c4621aa9e76 Partial(?) 64bit patch (AMK).
Guido van Rossum <guido@python.org>
parents: 5318
diff changeset
658 goodwrite *= writetab(outf, starttab, ysize*zsize);
4c4621aa9e76 Partial(?) 64bit patch (AMK).
Guido van Rossum <guido@python.org>
parents: 5318
diff changeset
659 goodwrite *= writetab(outf, lengthtab, ysize*zsize);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
660 if (goodwrite) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
661 Py_INCREF(Py_None);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
662 retval = Py_None;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
663 } else
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
664 PyErr_SetString(ImgfileError, "not enough space for image");
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
665
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
666 finally:
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
667 fclose(outf);
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
668 free(starttab);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
669 free(lengthtab);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
670 free(rlebuf);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
671 free(lumbuf);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
672 return retval;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
673 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
674
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
675 /* static utility functions for longstoimage */
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
676
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
677 static void
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
678 lumrow(rgbptr, lumptr, n)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
679 unsigned char *rgbptr, *lumptr;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
680 int n;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
681 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
682 lumptr += CHANOFFSET(0);
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
683 while (n--) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
684 *lumptr = ILUM(rgbptr[OFFSET_R],
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
685 rgbptr[OFFSET_G],
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
686 rgbptr[OFFSET_B]);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
687 lumptr += 4;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
688 rgbptr += 4;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
689 }
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
690 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
691
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
692 static int
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
693 compressrow(lbuf, rlebuf, z, cnt)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
694 unsigned char *lbuf, *rlebuf;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
695 int z, cnt;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
696 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
697 unsigned char *iptr, *ibufend, *sptr, *optr;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
698 short todo, cc;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
699 long count;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
700
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
701 lbuf += z;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
702 iptr = lbuf;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
703 ibufend = iptr + cnt * 4;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
704 optr = rlebuf;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
705
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
706 while(iptr < ibufend) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
707 sptr = iptr;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
708 iptr += 8;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
709 while ((iptr<ibufend) &&
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
710 ((iptr[-8]!=iptr[-4]) ||(iptr[-4]!=iptr[0])))
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
711 {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
712 iptr += 4;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
713 }
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
714 iptr -= 8;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
715 count = (iptr - sptr) / 4;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
716 while (count) {
5318
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
717 todo = count > 126 ? 126 : (short)count;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
718 count -= todo;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
719 *optr++ = 0x80 | todo;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
720 while (todo > 8) {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
721 optr[0] = sptr[0 * 4];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
722 optr[1] = sptr[1 * 4];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
723 optr[2] = sptr[2 * 4];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
724 optr[3] = sptr[3 * 4];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
725 optr[4] = sptr[4 * 4];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
726 optr[5] = sptr[5 * 4];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
727 optr[6] = sptr[6 * 4];
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
728 optr[7] = sptr[7 * 4];
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
729 optr += 8;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
730 sptr += 8 * 4;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
731 todo -= 8;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
732 }
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
733 while (todo--) {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
734 *optr++ = *sptr;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
735 sptr += 4;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
736 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
737 }
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
738 sptr = iptr;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
739 cc = *iptr;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
740 iptr += 4;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
741 while ((iptr < ibufend) && (*iptr == cc))
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
742 iptr += 4;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
743 count = (iptr - sptr) / 4;
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
744 while (count) {
5318
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
745 todo = count > 126 ? 126 : (short)count;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
746 count -= todo;
5318
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
747 *optr++ = (unsigned char) todo;
2c4b802a3b5d Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5309
diff changeset
748 *optr++ = (unsigned char) cc;
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
749 }
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
750 }
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
751 *optr++ = 0;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
752 return optr - (unsigned char *)rlebuf;
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
753 }
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
754
4686
c046efaf1bd2 Grandly renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
755 static PyObject *
1454
3a5f2f110f70 Added function ttob.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1447
diff changeset
756 ttob(self, args)
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
757 PyObject *self;
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
758 PyObject *args;
1454
3a5f2f110f70 Added function ttob.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1447
diff changeset
759 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
760 int order, oldorder;
1454
3a5f2f110f70 Added function ttob.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1447
diff changeset
761
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
762 if (!PyArg_Parse(args, "i", &order))
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
763 return NULL;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
764 oldorder = reverse_order;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
765 reverse_order = order;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
766 return PyInt_FromLong(oldorder);
1454
3a5f2f110f70 Added function ttob.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1447
diff changeset
767 }
3a5f2f110f70 Added function ttob.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1447
diff changeset
768
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
769 static PyMethodDef
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
770 rgbimg_methods[] = {
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
771 {"sizeofimage", sizeofimage},
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
772 {"longimagedata", longimagedata},
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
773 {"longstoimage", longstoimage},
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
774 {"ttob", ttob},
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
775 {NULL, NULL} /* sentinel */
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
776 };
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
777
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
778
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
779 void
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
780 initrgbimg()
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
781 {
4872
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
782 PyObject *m, *d;
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
783 m = Py_InitModule("rgbimg", rgbimg_methods);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
784 d = PyModule_GetDict(m);
da53e48efea8 Reindented.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 4686
diff changeset
785 ImgfileError = PyString_FromString("rgbimg.error");
4918
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
786 if (ImgfileError)
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
787 PyDict_SetItemString(d, "error", ImgfileError);
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
788 if (PyErr_Occurred())
2a4d3d99b8a4 Primarily formatting changes, but I also plugged a couple of potential
Barry Warsaw <barry@python.org>
parents: 4872
diff changeset
789 Py_FatalError("can't initialize rgbimg module");
1443
2ec08a9d0325 rgbimgmodule.c, Makefile, config.c: new module to read RGB image files.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
790 }