Mercurial > cpython-lru_cache-weakref
annotate Modules/imgfile.c @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | fd25030223b0 |
| children |
| rev | line source |
|---|---|
| 691 | 1 |
|
1022
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
2 /* IMGFILE module - Interface to sgi libimage */ |
| 691 | 3 |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13514
diff
changeset
|
4 /* XXX This module should be done better at some point. It should return |
| 691 | 5 ** an object of image file class, and have routines to manipulate these |
| 6 ** image files in a neater way (so you can get rgb images off a greyscale | |
| 7 ** file, for instance, or do a straight display without having to get the | |
| 8 ** image bits into python, etc). | |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
9 ** |
|
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
10 ** Warning: this module is very non-reentrant (esp. the readscaled stuff) |
| 691 | 11 */ |
| 12 | |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
13 #include "Python.h" |
| 691 | 14 |
| 15 #include <gl/image.h> | |
| 16 | |
|
1188
584c4142c537
Use full path for izoom.h include file
Jack Jansen <jack.jansen@cwi.nl>
parents:
1187
diff
changeset
|
17 #include "/usr/people/4Dgifts/iristools/include/izoom.h" |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
18 |
|
4624
b11d96c8075c
Added a bunch of extern void decls, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
19 /* Bunch of missing extern decls; keep gcc -Wall happy... */ |
|
b11d96c8075c
Added a bunch of extern void decls, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
20 extern void i_seterror(); |
|
b11d96c8075c
Added a bunch of extern void decls, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
21 extern void iclose(); |
|
b11d96c8075c
Added a bunch of extern void decls, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
22 extern void filterzoom(); |
|
b11d96c8075c
Added a bunch of extern void decls, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
23 extern void putrow(); |
|
b11d96c8075c
Added a bunch of extern void decls, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
24 extern void getrow(); |
|
b11d96c8075c
Added a bunch of extern void decls, to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
25 |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
26 static PyObject * ImgfileError; /* Exception we raise for various trouble */ |
| 691 | 27 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
28 static int top_to_bottom; /* True if we want top-to-bottom images */ |
| 691 | 29 |
|
1022
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
30 /* The image library does not always call the error hander :-(, |
|
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
31 therefore we have a global variable indicating that it was called. |
|
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
32 It is cleared by imgfile_open(). */ |
| 691 | 33 |
|
713
862457e0237c
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
691
diff
changeset
|
34 static int error_called; |
|
862457e0237c
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
691
diff
changeset
|
35 |
|
1022
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
36 |
|
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
37 /* The error handler */ |
|
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
38 |
| 4600 | 39 static void |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
40 imgfile_error(char *str) |
|
713
862457e0237c
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
691
diff
changeset
|
41 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
42 PyErr_SetString(ImgfileError, str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
43 error_called = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
44 return; /* To imglib, which will return a failure indicator */ |
|
713
862457e0237c
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
691
diff
changeset
|
45 } |
| 691 | 46 |
|
1022
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
47 |
|
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
48 /* Open an image file and return a pointer to it. |
|
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
49 Make sure we raise an exception if we fail. */ |
|
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
50 |
|
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
51 static IMAGE * |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
52 imgfile_open(char *fname) |
|
886
9a05e2bfa74c
added readscaled() function.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
53 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
54 IMAGE *image; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
55 i_seterror(imgfile_error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
56 error_called = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
57 errno = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
58 if ( (image = iopen(fname, "r")) == NULL ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
59 /* Error may already be set by imgfile_error */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
60 if ( !error_called ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
61 if (errno) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
62 PyErr_SetFromErrno(ImgfileError); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
63 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
64 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
65 "Can't open image file"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
66 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
67 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
68 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
69 return image; |
| 691 | 70 } |
| 71 | |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
72 static PyObject * |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
73 imgfile_ttob(PyObject *self, PyObject *args) |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1313
diff
changeset
|
74 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
75 int newval; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
76 PyObject *rv; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
77 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
78 if (!PyArg_ParseTuple(args, "i:ttob", &newval)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
79 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
80 rv = PyInt_FromLong(top_to_bottom); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
81 top_to_bottom = newval; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
82 return rv; |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1313
diff
changeset
|
83 } |
|
1022
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
84 |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
85 static PyObject * |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
86 imgfile_read(PyObject *self, PyObject *args) |
| 691 | 87 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
88 char *fname; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
89 PyObject *rv; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
90 int xsize, ysize, zsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
91 char *cdatap; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
92 long *idatap; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
93 static short rs[8192], gs[8192], bs[8192]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
94 int x, y; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
95 IMAGE *image; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
96 int yfirst, ylast, ystep; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
97 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
98 if ( !PyArg_ParseTuple(args, "s:read", &fname) ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
99 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
100 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
101 if ( (image = imgfile_open(fname)) == NULL ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
102 return NULL; |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1313
diff
changeset
|
103 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
104 if ( image->colormap != CM_NORMAL ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
105 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
106 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
107 "Can only handle CM_NORMAL images"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
108 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
109 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
110 if ( BPP(image->type) != 1 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
111 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
112 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
113 "Can't handle imgfiles with bpp!=1"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
114 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
115 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
116 xsize = image->xsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
117 ysize = image->ysize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
118 zsize = image->zsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
119 if ( zsize != 1 && zsize != 3) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
120 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
121 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
122 "Can only handle 1 or 3 byte pixels"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
123 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
124 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
125 if ( xsize > 8192 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
126 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
127 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
128 "Can't handle image with > 8192 columns"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
129 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
130 } |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
131 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
132 if ( zsize == 3 ) zsize = 4; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
133 rv = PyString_FromStringAndSize((char *)NULL, xsize*ysize*zsize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
134 if ( rv == NULL ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
135 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
136 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
137 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
138 cdatap = PyString_AsString(rv); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
139 idatap = (long *)cdatap; |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
140 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
141 if (top_to_bottom) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
142 yfirst = ysize-1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
143 ylast = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
144 ystep = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
145 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
146 yfirst = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
147 ylast = ysize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
148 ystep = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
149 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
150 for ( y=yfirst; y != ylast && !error_called; y += ystep ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
151 if ( zsize == 1 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
152 getrow(image, rs, y, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
153 for(x=0; x<xsize; x++ ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
154 *cdatap++ = rs[x]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
155 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
156 getrow(image, rs, y, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
157 getrow(image, gs, y, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
158 getrow(image, bs, y, 2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
159 for(x=0; x<xsize; x++ ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
160 *idatap++ = (rs[x] & 0xff) | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
161 ((gs[x] & 0xff)<<8) | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
162 ((bs[x] & 0xff)<<16); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
163 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
164 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
165 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
166 if ( error_called ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
167 Py_DECREF(rv); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
168 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
169 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
170 return rv; |
| 691 | 171 } |
| 172 | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
173 static IMAGE *glob_image; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
174 static long *glob_datap; |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1313
diff
changeset
|
175 static int glob_width, glob_z, glob_ysize; |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
176 |
| 4600 | 177 static void |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
178 xs_get(short *buf, int y) |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
179 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
180 if (top_to_bottom) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
181 getrow(glob_image, buf, (glob_ysize-1-y), glob_z); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
182 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
183 getrow(glob_image, buf, y, glob_z); |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
184 } |
|
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
185 |
| 4600 | 186 static void |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
187 xs_put_c(short *buf, int y) |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
188 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
189 char *datap = (char *)glob_datap + y*glob_width; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
190 int width = glob_width; |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
191 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
192 while ( width-- ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
193 *datap++ = (*buf++) & 0xff; |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
194 } |
|
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
195 |
| 4600 | 196 static void |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
197 xs_put_0(short *buf, int y) |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
198 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
199 long *datap = glob_datap + y*glob_width; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
200 int width = glob_width; |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
201 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
202 while ( width-- ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
203 *datap++ = (*buf++) & 0xff; |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
204 } |
| 4600 | 205 static void |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
206 xs_put_12(short *buf, int y) |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
207 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
208 long *datap = glob_datap + y*glob_width; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
209 int width = glob_width; |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
210 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
211 while ( width-- ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
212 *datap++ |= ((*buf++) & 0xff) << (glob_z*8); |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
213 } |
|
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
214 |
|
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
215 static void |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
216 xscale(IMAGE *image, int xsize, int ysize, int zsize, |
|
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
217 long *datap, int xnew, int ynew, int fmode, double blur) |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
218 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
219 glob_image = image; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
220 glob_datap = datap; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
221 glob_width = xnew; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
222 glob_ysize = ysize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
223 if ( zsize == 1 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
224 glob_z = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
225 filterzoom(xs_get, xs_put_c, xsize, ysize, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
226 xnew, ynew, fmode, blur); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
227 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
228 glob_z = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
229 filterzoom(xs_get, xs_put_0, xsize, ysize, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
230 xnew, ynew, fmode, blur); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
231 glob_z = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
232 filterzoom(xs_get, xs_put_12, xsize, ysize, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
233 xnew, ynew, fmode, blur); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
234 glob_z = 2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
235 filterzoom(xs_get, xs_put_12, xsize, ysize, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
236 xnew, ynew, fmode, blur); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
237 } |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
238 } |
|
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
239 |
|
1022
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
240 |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
241 static PyObject * |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
242 imgfile_readscaled(PyObject *self, PyObject *args) |
|
886
9a05e2bfa74c
added readscaled() function.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
243 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
244 char *fname; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
245 PyObject *rv; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
246 int xsize, ysize, zsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
247 char *cdatap; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
248 long *idatap; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
249 static short rs[8192], gs[8192], bs[8192]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
250 int x, y; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
251 int xwtd, ywtd, xorig, yorig; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
252 float xfac, yfac; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
253 IMAGE *image; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
254 char *filter; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
255 double blur = 1.0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
256 int extended; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
257 int fmode = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
258 int yfirst, ylast, ystep; |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
259 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
260 /* |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
261 ** Parse args. Funny, since arg 4 and 5 are optional |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
262 ** (filter name and blur factor). Also, 4 or 5 arguments indicates |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
263 ** extended scale algorithm in stead of simple-minded pixel drop/dup. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
264 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
265 extended = PyTuple_Size(args) >= 4; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
266 if ( !PyArg_ParseTuple(args, "sii|sd", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
267 &fname, &xwtd, &ywtd, &filter, &blur) ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
268 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
269 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
270 /* |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
271 ** Check parameters, open file and check type, rows, etc. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
272 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
273 if ( extended ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
274 if ( strcmp(filter, "impulse") == 0 ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
275 fmode = IMPULSE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
276 else if ( strcmp( filter, "box") == 0 ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
277 fmode = BOX; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
278 else if ( strcmp( filter, "triangle") == 0 ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
279 fmode = TRIANGLE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
280 else if ( strcmp( filter, "quadratic") == 0 ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
281 fmode = QUADRATIC; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
282 else if ( strcmp( filter, "gaussian") == 0 ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
283 fmode = GAUSSIAN; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
284 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
285 PyErr_SetString(ImgfileError, "Unknown filter type"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
286 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
287 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
288 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
289 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
290 if ( (image = imgfile_open(fname)) == NULL ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
291 return NULL; |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
292 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
293 if ( image->colormap != CM_NORMAL ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
294 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
295 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
296 "Can only handle CM_NORMAL images"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
297 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
298 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
299 if ( BPP(image->type) != 1 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
300 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
301 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
302 "Can't handle imgfiles with bpp!=1"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
303 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
304 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
305 xsize = image->xsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
306 ysize = image->ysize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
307 zsize = image->zsize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
308 if ( zsize != 1 && zsize != 3) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
309 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
310 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
311 "Can only handle 1 or 3 byte pixels"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
312 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
313 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
314 if ( xsize > 8192 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
315 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
316 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
317 "Can't handle image with > 8192 columns"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
318 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
319 } |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
320 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
321 if ( zsize == 3 ) zsize = 4; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
322 rv = PyString_FromStringAndSize(NULL, xwtd*ywtd*zsize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
323 if ( rv == NULL ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
324 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
325 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
326 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
327 PyFPE_START_PROTECT("readscaled", return 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
328 xfac = (float)xsize/(float)xwtd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
329 yfac = (float)ysize/(float)ywtd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
330 PyFPE_END_PROTECT(yfac) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
331 cdatap = PyString_AsString(rv); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
332 idatap = (long *)cdatap; |
|
886
9a05e2bfa74c
added readscaled() function.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
333 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
334 if ( extended ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
335 xscale(image, xsize, ysize, zsize, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
336 idatap, xwtd, ywtd, fmode, blur); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
337 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
338 if (top_to_bottom) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
339 yfirst = ywtd-1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
340 ylast = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
341 ystep = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
342 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
343 yfirst = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
344 ylast = ywtd; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
345 ystep = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
346 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
347 for ( y=yfirst; y != ylast && !error_called; y += ystep ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
348 yorig = (int)(y*yfac); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
349 if ( zsize == 1 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
350 getrow(image, rs, yorig, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
351 for(x=0; x<xwtd; x++ ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
352 *cdatap++ = rs[(int)(x*xfac)]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
353 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
354 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
355 getrow(image, rs, yorig, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
356 getrow(image, gs, yorig, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
357 getrow(image, bs, yorig, 2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
358 for(x=0; x<xwtd; x++ ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
359 xorig = (int)(x*xfac); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
360 *idatap++ = (rs[xorig] & 0xff) | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
361 ((gs[xorig] & 0xff)<<8) | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
362 ((bs[xorig] & 0xff)<<16); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
363 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
364 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
365 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
366 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
367 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
368 if ( error_called ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
369 Py_DECREF(rv); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
370 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
371 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
372 return rv; |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
373 } |
|
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
374 |
|
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
375 static PyObject * |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
376 imgfile_getsizes(PyObject *self, PyObject *args) |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
377 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
378 char *fname; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
379 PyObject *rv; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
380 IMAGE *image; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
381 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
382 if ( !PyArg_ParseTuple(args, "s:getsizes", &fname) ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
383 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
384 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
385 if ( (image = imgfile_open(fname)) == NULL ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
386 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
387 rv = Py_BuildValue("(iii)", image->xsize, image->ysize, image->zsize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
388 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
389 return rv; |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
390 } |
|
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
391 |
|
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
392 static PyObject * |
|
13514
5304b88fe3cc
ANSI-fication of the SGI modules (note that svmodule.c and sgimodule.c
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
393 imgfile_write(PyObject *self, PyObject *args) |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
394 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
395 IMAGE *image; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
396 char *fname; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
397 int xsize, ysize, zsize, len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
398 char *cdatap; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
399 long *idatap; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
400 short rs[8192], gs[8192], bs[8192]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
401 short r, g, b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
402 long rgb; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
403 int x, y; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
404 int yfirst, ylast, ystep; |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
405 |
|
886
9a05e2bfa74c
added readscaled() function.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
406 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
407 if ( !PyArg_ParseTuple(args, "ss#iii:write", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
408 &fname, &cdatap, &len, &xsize, &ysize, &zsize) ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
409 return NULL; |
|
1187
6a077c293986
Added (optional) better scaling to readscaled
Jack Jansen <jack.jansen@cwi.nl>
parents:
1022
diff
changeset
|
410 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
411 if ( zsize != 1 && zsize != 3 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
412 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
413 "Can only handle 1 or 3 byte pixels"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
414 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
415 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
416 if ( len != xsize * ysize * (zsize == 1 ? 1 : 4) ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
417 PyErr_SetString(ImgfileError, "Data does not match sizes"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
418 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
419 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
420 if ( xsize > 8192 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
421 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
422 "Can't handle image with > 8192 columns"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
423 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
424 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
425 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
426 error_called = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
427 errno = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
428 image =iopen(fname, "w", RLE(1), 3, xsize, ysize, zsize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
429 if ( image == 0 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
430 if ( ! error_called ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
431 if (errno) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
432 PyErr_SetFromErrno(ImgfileError); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
433 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
434 PyErr_SetString(ImgfileError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
435 "Can't create image file"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
436 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
437 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
438 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
439 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
440 idatap = (long *)cdatap; |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
441 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
442 if (top_to_bottom) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
443 yfirst = ysize-1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
444 ylast = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
445 ystep = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
446 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
447 yfirst = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
448 ylast = ysize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
449 ystep = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
450 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
451 for ( y=yfirst; y != ylast && !error_called; y += ystep ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
452 if ( zsize == 1 ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
453 for( x=0; x<xsize; x++ ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
454 rs[x] = *cdatap++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
455 putrow(image, rs, y, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
456 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
457 for( x=0; x<xsize; x++ ) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
458 rgb = *idatap++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
459 r = rgb & 0xff; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
460 g = (rgb >> 8 ) & 0xff; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
461 b = (rgb >> 16 ) & 0xff; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
462 rs[x] = r; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
463 gs[x] = g; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
464 bs[x] = b; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
465 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
466 putrow(image, rs, y, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
467 putrow(image, gs, y, 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
468 putrow(image, bs, y, 2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
469 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
470 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
471 iclose(image); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
472 if ( error_called ) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
473 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
474 Py_INCREF(Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
475 return Py_None; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
476 |
|
988
197a2cf3a662
Added method to write image files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
886
diff
changeset
|
477 } |
| 691 | 478 |
|
1022
9b566ac38c2b
Got rid the bogus cache code and fix some unchecked errors.
Guido van Rossum <guido@python.org>
parents:
992
diff
changeset
|
479 |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
480 static PyMethodDef imgfile_methods[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
481 { "getsizes", imgfile_getsizes, METH_VARARGS }, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
482 { "read", imgfile_read, METH_VARARGS }, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
483 { "readscaled", imgfile_readscaled, METH_VARARGS}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
484 { "write", imgfile_write, METH_VARARGS }, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
485 { "ttob", imgfile_ttob, METH_VARARGS }, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
486 { NULL, NULL } /* Sentinel */ |
| 691 | 487 }; |
| 488 | |
| 489 | |
| 490 void | |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
491 initimgfile(void) |
| 691 | 492 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
493 PyObject *m, *d; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
494 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
495 if (PyErr_WarnPy3k("the imgfile module has been removed in " |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
496 "Python 3.0", 2) < 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
497 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
498 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
499 m = Py_InitModule("imgfile", imgfile_methods); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
500 if (m == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
501 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
502 d = PyModule_GetDict(m); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
503 ImgfileError = PyErr_NewException("imgfile.error", NULL, NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
504 if (ImgfileError != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47527
diff
changeset
|
505 PyDict_SetItemString(d, "error", ImgfileError); |
| 691 | 506 } |
|
4809
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
507 |
|
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
508 |
|
6f8b5c3cd6cb
Renamed.
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4624
diff
changeset
|
509 |
