Mercurial > cpython-lru_cache-weakref
annotate Modules/imageop.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 65d2d8e67da3 |
| children | d36250aefb82 |
| rev | line source |
|---|---|
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
3 The Netherlands. |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 All Rights Reserved |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
15 permission. |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3344
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 ******************************************************************/ |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 /* imageopmodule - Various operations on pictures */ |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 #ifdef sun |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 #define signed |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 #endif |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 #include "allobjects.h" |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 #include "modsupport.h" |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 #define CHARP(cp, xmax, x, y) ((char *)(cp+y*xmax+x)) |
|
3344
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
42 #define SHORTP(cp, xmax, x, y) ((short *)(cp+2*(y*xmax+x))) |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 #define LONGP(cp, xmax, x, y) ((long *)(cp+4*(y*xmax+x))) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 static object *ImageopError; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 static object * |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 imageop_crop(self, args) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 object *self; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 object *args; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 char *cp, *ncp; |
|
3344
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
53 short *nsp; |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 long *nlp; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 int len, size, x, y, newx1, newx2, newy1, newy2; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 int ix, iy, xstep, ystep; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 object *rv; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 if ( !getargs(args, "(s#iiiiiii)", &cp, &len, &size, &x, &y, |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 &newx1, &newy1, &newx2, &newy2) ) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
|
3344
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
63 if ( size != 1 && size != 2 && size != 4 ) { |
|
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
64 err_setstr(ImageopError, "Size should be 1, 2 or 4"); |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 if ( len != size*x*y ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 err_setstr(ImageopError, "String has incorrect length"); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 xstep = (newx1 < newx2)? 1 : -1; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 ystep = (newy1 < newy2)? 1 : -1; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
74 rv = newsizedstringobject(NULL, |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
75 (abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size); |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 if ( rv == 0 ) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 ncp = (char *)getstringvalue(rv); |
|
3344
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
79 nsp = (short *)ncp; |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 nlp = (long *)ncp; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 newy2 += ystep; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 newx2 += xstep; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 for( iy = newy1; iy != newy2; iy+=ystep ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 for ( ix = newx1; ix != newx2; ix+=xstep ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 if ( iy < 0 || iy >= y || ix < 0 || ix >= x ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 if ( size == 1 ) *ncp++ = 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 else *nlp++ = 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 } else { |
|
3344
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
89 if ( size == 1 ) *ncp++ = *CHARP(cp, x, ix, iy); |
|
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
90 else if ( size == 2 ) *nsp++ = *SHORTP(cp, x, ix, iy); |
|
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
91 else *nlp++ = *LONGP(cp, x, ix, iy); |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 return rv; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 static object * |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 imageop_scale(self, args) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 object *self; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 object *args; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 char *cp, *ncp; |
|
3344
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
104 short *nsp; |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 long *nlp; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 int len, size, x, y, newx, newy; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 int ix, iy; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 int oix, oiy; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 object *rv; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 if ( !getargs(args, "(s#iiiii)", &cp, &len, &size, &x, &y, &newx, &newy) ) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 |
|
3344
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
114 if ( size != 1 && size != 2 && size != 4 ) { |
|
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
115 err_setstr(ImageopError, "Size should be 1, 2 or 4"); |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 if ( len != size*x*y ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 err_setstr(ImageopError, "String has incorrect length"); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 rv = newsizedstringobject(NULL, newx*newy*size); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 if ( rv == 0 ) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 ncp = (char *)getstringvalue(rv); |
|
3344
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
127 nsp = (short *)ncp; |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 nlp = (long *)ncp; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 for( iy = 0; iy < newy; iy++ ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 for ( ix = 0; ix < newx; ix++ ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 oix = ix * x / newx; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 oiy = iy * y / newy; |
|
3344
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
133 if ( size == 1 ) *ncp++ = *CHARP(cp, x, oix, oiy); |
|
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
134 else if ( size == 2 ) *nsp++ = *SHORTP(cp, x, oix, oiy); |
|
3b484812acf6
Added 16-bit pixel support for some operations.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2061
diff
changeset
|
135 else *nlp++ = *LONGP(cp, x, oix, oiy); |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 return rv; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 |
| 1194 | 141 /* Note: this routine can use a bit of optimizing */ |
| 142 | |
| 143 static object * | |
| 144 imageop_tovideo(self, args) | |
| 145 object *self; | |
| 146 object *args; | |
| 147 { | |
| 148 int maxx, maxy, x, y, len; | |
| 149 int i; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2020
diff
changeset
|
150 unsigned char *cp, *ncp; |
| 1194 | 151 int width; |
| 152 object *rv; | |
| 153 | |
| 154 | |
| 155 if ( !getargs(args, "(s#iii)", &cp, &len, &width, &maxx, &maxy) ) | |
| 156 return 0; | |
| 157 | |
| 158 if ( width != 1 && width != 4 ) { | |
| 159 err_setstr(ImageopError, "Size should be 1 or 4"); | |
| 160 return 0; | |
| 161 } | |
| 162 if ( maxx*maxy*width != len ) { | |
| 163 err_setstr(ImageopError, "String has incorrect length"); | |
| 164 return 0; | |
| 165 } | |
| 166 | |
| 167 rv = newsizedstringobject(NULL, len); | |
| 168 if ( rv == 0 ) | |
| 169 return 0; | |
| 170 ncp = (unsigned char *)getstringvalue(rv); | |
| 171 | |
| 172 if ( width == 1 ) { | |
|
1330
409ea74feb21
Minor fixes / changes for Mac compatibility.
Guido van Rossum <guido@python.org>
parents:
1233
diff
changeset
|
173 memcpy(ncp, cp, maxx); /* Copy first line */ |
| 1194 | 174 ncp += maxx; |
| 175 for (y=1; y<maxy; y++) { /* Interpolate other lines */ | |
| 176 for(x=0; x<maxx; x++) { | |
| 177 i = y*maxx + x; | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
178 *ncp++ = ((int)cp[i] + (int)cp[i-maxx]) >> 1; |
| 1194 | 179 } |
| 180 } | |
| 181 } else { | |
|
1330
409ea74feb21
Minor fixes / changes for Mac compatibility.
Guido van Rossum <guido@python.org>
parents:
1233
diff
changeset
|
182 memcpy(ncp, cp, maxx*4); /* Copy first line */ |
| 1194 | 183 ncp += maxx*4; |
| 184 for (y=1; y<maxy; y++) { /* Interpolate other lines */ | |
| 185 for(x=0; x<maxx; x++) { | |
| 186 i = (y*maxx + x)*4 + 1; | |
| 187 *ncp++ = 0; /* Skip alfa comp */ | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
188 *ncp++ = ((int)cp[i] + (int)cp[i-4*maxx]) >> 1; |
| 1194 | 189 i++; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
190 *ncp++ = ((int)cp[i] + (int)cp[i-4*maxx]) >> 1; |
| 1194 | 191 i++; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
192 *ncp++ = ((int)cp[i] + (int)cp[i-4*maxx]) >> 1; |
| 1194 | 193 } |
| 194 } | |
| 195 } | |
| 196 return rv; | |
| 197 } | |
| 198 | |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
199 static object * |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
200 imageop_grey2mono(self, args) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
201 object *self; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
202 object *args; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
203 { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
204 int tres, x, y, len; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
205 unsigned char *cp, *ncp; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
206 unsigned char ovalue; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
207 object *rv; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
208 int i, bit; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
209 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
210 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
211 if ( !getargs(args, "(s#iii)", &cp, &len, &x, &y, &tres) ) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
212 return 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
213 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
214 if ( x*y != len ) { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
215 err_setstr(ImageopError, "String has incorrect length"); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
216 return 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
217 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
218 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
219 rv = newsizedstringobject(NULL, (len+7)/8); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
220 if ( rv == 0 ) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
221 return 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
222 ncp = (unsigned char *)getstringvalue(rv); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
223 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
224 bit = 0x80; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
225 ovalue = 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
226 for ( i=0; i < len; i++ ) { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
227 if ( (int)cp[i] > tres ) |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
228 ovalue |= bit; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
229 bit >>= 1; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
230 if ( bit == 0 ) { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
231 *ncp++ = ovalue; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
232 bit = 0x80; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
233 ovalue = 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
234 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
235 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
236 if ( bit != 0x80 ) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
237 *ncp++ = ovalue; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
238 return rv; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
239 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
240 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
241 static object * |
|
1165
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
242 imageop_grey2grey4(self, args) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
243 object *self; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
244 object *args; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
245 { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
246 int x, y, len; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
247 unsigned char *cp, *ncp; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
248 unsigned char ovalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
249 object *rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
250 int i; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
251 int pos; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
252 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
253 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
254 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
255 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
256 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
257 if ( x*y != len ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
258 err_setstr(ImageopError, "String has incorrect length"); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
259 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
260 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
261 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
262 rv = newsizedstringobject(NULL, (len+1)/2); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
263 if ( rv == 0 ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
264 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
265 ncp = (unsigned char *)getstringvalue(rv); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
266 pos = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
267 ovalue = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
268 for ( i=0; i < len; i++ ) { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
269 ovalue |= ((int)cp[i] & 0xf0) >> pos; |
|
1165
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
270 pos += 4; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
271 if ( pos == 8 ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
272 *ncp++ = ovalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
273 ovalue = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
274 pos = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
275 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
276 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
277 if ( pos != 0 ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
278 *ncp++ = ovalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
279 return rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
280 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
281 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
282 static object * |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
283 imageop_grey2grey2(self, args) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
284 object *self; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
285 object *args; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
286 { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
287 int x, y, len; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
288 unsigned char *cp, *ncp; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
289 unsigned char ovalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
290 object *rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
291 int i; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
292 int pos; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
293 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
294 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
295 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
296 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
297 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
298 if ( x*y != len ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
299 err_setstr(ImageopError, "String has incorrect length"); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
300 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
301 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
302 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
303 rv = newsizedstringobject(NULL, (len+3)/4); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
304 if ( rv == 0 ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
305 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
306 ncp = (unsigned char *)getstringvalue(rv); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
307 pos = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
308 ovalue = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
309 for ( i=0; i < len; i++ ) { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
310 ovalue |= ((int)cp[i] & 0xc0) >> pos; |
|
1165
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
311 pos += 2; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
312 if ( pos == 8 ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
313 *ncp++ = ovalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
314 ovalue = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
315 pos = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
316 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
317 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
318 if ( pos != 0 ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
319 *ncp++ = ovalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
320 return rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
321 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
322 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
323 static object * |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
324 imageop_dither2mono(self, args) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
325 object *self; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
326 object *args; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
327 { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
328 int sum, x, y, len; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
329 unsigned char *cp, *ncp; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
330 unsigned char ovalue; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
331 object *rv; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
332 int i, bit; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
333 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
334 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
335 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
336 return 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
337 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
338 if ( x*y != len ) { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
339 err_setstr(ImageopError, "String has incorrect length"); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
340 return 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
341 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
342 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
343 rv = newsizedstringobject(NULL, (len+7)/8); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
344 if ( rv == 0 ) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
345 return 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
346 ncp = (unsigned char *)getstringvalue(rv); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
347 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
348 bit = 0x80; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
349 ovalue = 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
350 sum = 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
351 for ( i=0; i < len; i++ ) { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
352 sum += cp[i]; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
353 if ( sum >= 256 ) { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
354 sum -= 256; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
355 ovalue |= bit; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
356 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
357 bit >>= 1; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
358 if ( bit == 0 ) { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
359 *ncp++ = ovalue; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
360 bit = 0x80; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
361 ovalue = 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
362 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
363 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
364 if ( bit != 0x80 ) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
365 *ncp++ = ovalue; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
366 return rv; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
367 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
368 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
369 static object * |
|
1165
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
370 imageop_dither2grey2(self, args) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
371 object *self; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
372 object *args; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
373 { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
374 int x, y, len; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
375 unsigned char *cp, *ncp; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
376 unsigned char ovalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
377 object *rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
378 int i; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
379 int pos; |
|
2020
7bda0f2c170c
Added missing initialization
Jack Jansen <jack.jansen@cwi.nl>
parents:
1746
diff
changeset
|
380 int sum = 0, nvalue; |
|
1165
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
381 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
382 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
383 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
384 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
385 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
386 if ( x*y != len ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
387 err_setstr(ImageopError, "String has incorrect length"); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
388 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
389 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
390 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
391 rv = newsizedstringobject(NULL, (len+3)/4); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
392 if ( rv == 0 ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
393 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
394 ncp = (unsigned char *)getstringvalue(rv); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
395 pos = 1; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
396 ovalue = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
397 for ( i=0; i < len; i++ ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
398 sum += cp[i]; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
399 nvalue = sum & 0x180; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
400 sum -= nvalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
401 ovalue |= nvalue >> pos; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
402 pos += 2; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
403 if ( pos == 9 ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
404 *ncp++ = ovalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
405 ovalue = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
406 pos = 1; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
407 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
408 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
409 if ( pos != 0 ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
410 *ncp++ = ovalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
411 return rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
412 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
413 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
414 static object * |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
415 imageop_mono2grey(self, args) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
416 object *self; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
417 object *args; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
418 { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
419 int v0, v1, x, y, len, nlen; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
420 unsigned char *cp, *ncp; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
421 object *rv; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2020
diff
changeset
|
422 int i, bit; |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
423 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
424 if ( !getargs(args, "(s#iiii)", &cp, &len, &x, &y, &v0, &v1) ) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
425 return 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
426 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
427 nlen = x*y; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
428 if ( (nlen+7)/8 != len ) { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
429 err_setstr(ImageopError, "String has incorrect length"); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
430 return 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
431 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
432 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
433 rv = newsizedstringobject(NULL, nlen); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
434 if ( rv == 0 ) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
435 return 0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
436 ncp = (unsigned char *)getstringvalue(rv); |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
437 |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
438 bit = 0x80; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
439 for ( i=0; i < nlen; i++ ) { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
440 if ( *cp & bit ) |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
441 *ncp++ = v1; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
442 else |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
443 *ncp++ = v0; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
444 bit >>= 1; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
445 if ( bit == 0 ) { |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
446 bit = 0x80; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
447 cp++; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
448 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
449 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
450 return rv; |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
451 } |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
452 |
|
1165
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
453 static object * |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
454 imageop_grey22grey(self, args) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
455 object *self; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
456 object *args; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
457 { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
458 int x, y, len, nlen; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
459 unsigned char *cp, *ncp; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
460 object *rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
461 int i, pos, value, nvalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
462 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
463 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
464 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
465 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
466 nlen = x*y; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
467 if ( (nlen+3)/4 != len ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
468 err_setstr(ImageopError, "String has incorrect length"); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
469 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
470 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
471 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
472 rv = newsizedstringobject(NULL, nlen); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
473 if ( rv == 0 ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
474 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
475 ncp = (unsigned char *)getstringvalue(rv); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
476 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
477 pos = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
478 for ( i=0; i < nlen; i++ ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
479 if ( pos == 0 ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
480 value = *cp++; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
481 pos = 8; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
482 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
483 pos -= 2; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
484 nvalue = (value >> pos) & 0x03; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
485 *ncp++ = nvalue | (nvalue << 2) | (nvalue << 4) | (nvalue << 6); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
486 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
487 return rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
488 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
489 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
490 static object * |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
491 imageop_grey42grey(self, args) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
492 object *self; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
493 object *args; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
494 { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
495 int x, y, len, nlen; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
496 unsigned char *cp, *ncp; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
497 object *rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
498 int i, pos, value, nvalue; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
499 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
500 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
501 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
502 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
503 nlen = x*y; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
504 if ( (nlen+1)/2 != len ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
505 err_setstr(ImageopError, "String has incorrect length"); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
506 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
507 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
508 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
509 rv = newsizedstringobject(NULL, nlen); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
510 if ( rv == 0 ) |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
511 return 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
512 ncp = (unsigned char *)getstringvalue(rv); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
513 |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
514 pos = 0; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
515 for ( i=0; i < nlen; i++ ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
516 if ( pos == 0 ) { |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
517 value = *cp++; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
518 pos = 8; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
519 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
520 pos -= 4; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
521 nvalue = (value >> pos) & 0x0f; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
522 *ncp++ = nvalue | (nvalue << 4); |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
523 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
524 return rv; |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
525 } |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
526 |
|
1233
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
527 static object * |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
528 imageop_rgb2rgb8(self, args) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
529 object *self; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
530 object *args; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
531 { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
532 int x, y, len, nlen; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
533 unsigned long *cp; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
534 unsigned char *ncp; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
535 object *rv; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
536 int i, r, g, b; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
537 unsigned long value, nvalue; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
538 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
539 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
540 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
541 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
542 nlen = x*y; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
543 if ( nlen*4 != len ) { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
544 err_setstr(ImageopError, "String has incorrect length"); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
545 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
546 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
547 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
548 rv = newsizedstringobject(NULL, nlen); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
549 if ( rv == 0 ) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
550 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
551 ncp = (unsigned char *)getstringvalue(rv); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
552 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
553 for ( i=0; i < nlen; i++ ) { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
554 /* Bits in source: aaaaaaaa BBbbbbbb GGGggggg RRRrrrrr */ |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
555 value = *cp++; |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
556 #if 0 |
|
1233
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
557 r = (value >> 5) & 7; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
558 g = (value >> 13) & 7; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
559 b = (value >> 22) & 3; |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
560 #else |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
561 r = (int) ((value & 0xff) / 255. * 7. + .5); |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
562 g = (int) (((value >> 8) & 0xff) / 255. * 7. + .5); |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
563 b = (int) (((value >> 16) & 0xff) / 255. * 3. + .5); |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1330
diff
changeset
|
564 #endif |
|
1233
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
565 nvalue = (r<<5) | (b<<3) | g; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
566 *ncp++ = nvalue; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
567 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
568 return rv; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
569 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
570 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
571 static object * |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
572 imageop_rgb82rgb(self, args) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
573 object *self; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
574 object *args; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
575 { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
576 int x, y, len, nlen; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
577 unsigned char *cp; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
578 unsigned long *ncp; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
579 object *rv; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
580 int i, r, g, b; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
581 unsigned long value, nvalue; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
582 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
583 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
584 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
585 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
586 nlen = x*y; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
587 if ( nlen != len ) { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
588 err_setstr(ImageopError, "String has incorrect length"); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
589 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
590 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
591 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
592 rv = newsizedstringobject(NULL, nlen*4); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
593 if ( rv == 0 ) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
594 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
595 ncp = (unsigned long *)getstringvalue(rv); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
596 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
597 for ( i=0; i < nlen; i++ ) { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
598 /* Bits in source: RRRBBGGG |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
599 ** Red and Green are multiplied by 36.5, Blue by 85 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
600 */ |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
601 value = *cp++; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
602 r = (value >> 5) & 7; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
603 g = (value ) & 7; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
604 b = (value >> 3) & 3; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
605 r = (r<<5) | (r<<3) | (r>>1); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
606 g = (g<<5) | (g<<3) | (g>>1); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
607 b = (b<<6) | (b<<4) | (b<<2) | b; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
608 nvalue = r | (g<<8) | (b<<16); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
609 *ncp++ = nvalue; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
610 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
611 return rv; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
612 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
613 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
614 static object * |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
615 imageop_rgb2grey(self, args) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
616 object *self; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
617 object *args; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
618 { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
619 int x, y, len, nlen; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
620 unsigned long *cp; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
621 unsigned char *ncp; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
622 object *rv; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
623 int i, r, g, b; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
624 unsigned long value, nvalue; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
625 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
626 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
627 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
628 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
629 nlen = x*y; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
630 if ( nlen*4 != len ) { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
631 err_setstr(ImageopError, "String has incorrect length"); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
632 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
633 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
634 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
635 rv = newsizedstringobject(NULL, nlen); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
636 if ( rv == 0 ) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
637 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
638 ncp = (unsigned char *)getstringvalue(rv); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
639 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
640 for ( i=0; i < nlen; i++ ) { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
641 value = *cp++; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
642 r = (value ) & 0xff; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
643 g = (value >> 8) & 0xff; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
644 b = (value >> 16) & 0xff; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
645 nvalue = (int)(0.30*r + 0.59*g + 0.11*b); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
646 if ( nvalue > 255 ) nvalue = 255; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
647 *ncp++ = nvalue; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
648 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
649 return rv; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
650 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
651 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
652 static object * |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
653 imageop_grey2rgb(self, args) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
654 object *self; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
655 object *args; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
656 { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
657 int x, y, len, nlen; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
658 unsigned char *cp; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
659 unsigned long *ncp; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
660 object *rv; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
661 int i; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
662 unsigned long value; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
663 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
664 if ( !getargs(args, "(s#ii)", &cp, &len, &x, &y) ) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
665 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
666 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
667 nlen = x*y; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
668 if ( nlen != len ) { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
669 err_setstr(ImageopError, "String has incorrect length"); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
670 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
671 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
672 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
673 rv = newsizedstringobject(NULL, nlen*4); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
674 if ( rv == 0 ) |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
675 return 0; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
676 ncp = (unsigned long *)getstringvalue(rv); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
677 |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
678 for ( i=0; i < nlen; i++ ) { |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
679 value = *cp++; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
680 *ncp++ = value | (value << 8 ) | (value << 16); |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
681 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
682 return rv; |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
683 } |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
684 |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
685 /* |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
686 static object * |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
687 imageop_mul(self, args) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
688 object *self; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
689 object *args; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
691 char *cp, *ncp; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
692 int len, size, x, y; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
693 object *rv; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
694 int i; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
695 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
696 if ( !getargs(args, "(s#iii)", &cp, &len, &size, &x, &y) ) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
697 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
698 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
699 if ( size != 1 && size != 4 ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
700 err_setstr(ImageopError, "Size should be 1 or 4"); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
701 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
702 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
703 if ( len != size*x*y ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 err_setstr(ImageopError, "String has incorrect length"); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
705 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
706 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
707 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
708 rv = newsizedstringobject(NULL, XXXX); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
709 if ( rv == 0 ) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
710 return 0; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
711 ncp = (char *)getstringvalue(rv); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
712 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
713 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
714 for ( i=0; i < len; i += size ) { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
715 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
716 return rv; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
717 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
718 */ |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
719 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
720 static struct methodlist imageop_methods[] = { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
721 { "crop", imageop_crop }, |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
722 { "scale", imageop_scale }, |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
723 { "grey2mono", imageop_grey2mono }, |
|
1165
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
724 { "grey2grey2", imageop_grey2grey2 }, |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
725 { "grey2grey4", imageop_grey2grey4 }, |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
726 { "dither2mono", imageop_dither2mono }, |
|
1165
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
727 { "dither2grey2", imageop_dither2grey2 }, |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
1084
diff
changeset
|
728 { "mono2grey", imageop_mono2grey }, |
|
1165
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
729 { "grey22grey", imageop_grey22grey }, |
|
d990c2b8a1e6
Added 2 and 4 bits grey formats
Jack Jansen <jack.jansen@cwi.nl>
parents:
1132
diff
changeset
|
730 { "grey42grey", imageop_grey42grey }, |
| 1194 | 731 { "tovideo", imageop_tovideo }, |
|
1233
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
732 { "rgb2rgb8", imageop_rgb2rgb8 }, |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
733 { "rgb82rgb", imageop_rgb82rgb }, |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
734 { "rgb2grey", imageop_rgb2grey }, |
|
b3e6a435c48f
Added converters for rgb<->rgb8 and rgb<->grey
Jack Jansen <jack.jansen@cwi.nl>
parents:
1198
diff
changeset
|
735 { "grey2rgb", imageop_grey2rgb }, |
|
1084
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
736 { 0, 0 } |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
737 }; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
738 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
739 |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
740 void |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
741 initimageop() |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
742 { |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
743 object *m, *d; |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
744 m = initmodule("imageop", imageop_methods); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
745 d = getmoduledict(m); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
746 ImageopError = newstringobject("imageop.error"); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
747 if ( ImageopError == NULL || dictinsert(d,"error",ImageopError) ) |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
748 fatal("can't define imageop.error"); |
|
b755a46201f6
Added imageopmodule.c, also added them to Makefile and config.c.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
749 } |
