Mercurial > pygame
annotate src/pixelarray_methods.c @ 989:1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
| author | marcus |
|---|---|
| date | Fri, 04 Apr 2008 08:04:49 +0000 |
| parents | |
| children | 404e3a0be4f8 |
| rev | line source |
|---|---|
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
1 /* |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
2 pygame - Python Game Library |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
3 Copyright (C) 2007-2008 Marcus von Appen |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
4 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
9 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
13 Library General Public License for more details. |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
14 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
18 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
19 */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
20 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
21 /** |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
22 * Tries to retrieve a valid color for a Surface. |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
23 */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
24 static int |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
25 _get_color_from_object (PyObject *val, SDL_PixelFormat *format, Uint32 *color) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
26 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
27 Uint8 rgba[4]; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
28 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
29 if (!val) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
30 return 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
31 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
32 if (PyInt_Check (val)) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
33 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
34 long intval = PyInt_AsLong (val); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
35 if ((intval < INT_MIN) || (intval > INT_MAX)) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
36 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
37 if (!PyErr_Occurred ()) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
38 PyErr_SetString (PyExc_ValueError, "invalid color argument"); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
39 return 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
40 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
41 *color = (Uint32) intval; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
42 return 1; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
43 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
44 else if (PyLong_Check (val)) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
45 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
46 long long longval = PyLong_AsLong (val); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
47 if ((longval < INT_MIN) || (longval > INT_MAX)) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
48 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
49 PyErr_SetString(PyExc_ValueError, "invalid color argument"); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
50 return 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
51 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
52 *color = (Uint32) longval; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
53 return 1; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
54 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
55 else if (RGBAFromObj (val, rgba)) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
56 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
57 *color = (Uint32) SDL_MapRGBA |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
58 (format, rgba[0], rgba[1], rgba[2], rgba[3]); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
59 return 1; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
60 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
61 else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
62 PyErr_SetString (PyExc_ValueError, "invalid color argument"); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
63 return 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
64 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
65 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
66 /** |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
67 * Retrieves a single pixel located at index from the surface pixel |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
68 * array. |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
69 */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
70 static PyObject* |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
71 _get_single_pixel (Uint8 *pixels, int bpp, Uint32 _index, Uint32 row) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
72 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
73 Uint32 pixel; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
74 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
75 switch (bpp) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
76 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
77 case 1: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
78 pixel = (Uint32)*((Uint8 *) pixels + row + _index); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
79 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
80 case 2: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
81 pixel = (Uint32)*((Uint16 *) (pixels + row) + _index); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
82 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
83 case 3: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
84 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
85 Uint8 *px = ((Uint8 *) (pixels + row) + _index * 3); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
86 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
87 pixel = (px[0]) + (px[1] << 8) + (px[2] << 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
88 #else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
89 pixel = (px[2]) + (px[1] << 8) + (px[0] << 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
90 #endif |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
91 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
92 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
93 default: /* 4 bpp */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
94 pixel = *((Uint32 *) (pixels + row) + _index); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
95 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
96 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
97 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
98 return PyInt_FromLong ((long)pixel); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
99 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
100 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
101 /** |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
102 * Sets a single pixel located at index from the surface pixel array. |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
103 */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
104 static void |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
105 _set_single_pixel (Uint8 *pixels, int bpp, Uint32 _index, Uint32 row, |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
106 SDL_PixelFormat *format, Uint32 color) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
107 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
108 switch (bpp) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
109 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
110 case 1: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
111 *((Uint8 *) pixels + row + _index) = (Uint8) color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
112 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
113 case 2: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
114 *((Uint16 *) (pixels + row) + _index) = (Uint16) color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
115 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
116 case 3: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
117 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
118 *((Uint8 *) (pixels + row) + _index * 3 + (format->Rshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
119 (Uint8) (color >> 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
120 *((Uint8 *) (pixels + row) + _index * 3 + (format->Gshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
121 (Uint8) (color >> 8); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
122 *((Uint8 *) (pixels + row) + _index * 3 + (format->Bshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
123 (Uint8) color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
124 #else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
125 *((Uint8 *) (pixels + row) + _index * 3 + 2 - (format->Rshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
126 (Uint8) (color >> 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
127 *((Uint8 *) (pixels + row) + _index * 3 + 2 - (format->Gshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
128 (Uint8) (color >> 8); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
129 *((Uint8 *) (pixels + row) + _index * 3 + 2 - (format->Bshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
130 (Uint8) color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
131 #endif |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
132 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
133 default: /* 4 bpp */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
134 *((Uint32 *) (pixels + row) + _index) = color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
135 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
136 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
137 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
138 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
139 /** |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
140 * Creates a new surface using the currently applied dimensions, step |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
141 * size, etc. |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
142 */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
143 static PyObject* |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
144 _make_surface(PyPixelArray *array) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
145 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
146 PyObject *newsf; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
147 SDL_Surface *tmpsf; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
148 SDL_Surface *newsurf; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
149 Uint8 *pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
150 Uint8 *origpixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
151 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
152 SDL_Surface *surface; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
153 int bpp; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
154 Uint32 x = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
155 Uint32 y = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
156 Uint32 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
157 Uint32 vy = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
158 Uint32 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
159 Uint32 posy = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
160 Uint32 absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
161 Uint32 absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
162 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
163 surface = PySurface_AsSurface (array->surface); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
164 bpp = surface->format->BytesPerPixel; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
165 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
166 /* Create the second surface. */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
167 tmpsf = SDL_CreateRGBSurface (surface->flags, |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
168 (int) (array->xlen / ABS (array->xstep)), |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
169 (int) (array->ylen / ABS (array->ystep)), bpp, surface->format->Rmask, |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
170 surface->format->Gmask, surface->format->Bmask, surface->format->Amask); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
171 if (!tmpsf) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
172 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
173 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
174 /* Guarantee an identical format. */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
175 newsurf = SDL_ConvertSurface (tmpsf, surface->format, surface->flags); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
176 if (!newsurf) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
177 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
178 SDL_FreeSurface (tmpsf); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
179 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
180 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
181 SDL_FreeSurface (tmpsf); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
182 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
183 /* Acquire a temporary lock. */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
184 if (SDL_MUSTLOCK (newsurf) == 0) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
185 SDL_LockSurface (newsurf); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
186 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
187 pixels = (Uint8 *) newsurf->pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
188 origpixels = (Uint8 *) surface->pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
189 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
190 absxstep = ABS (array->xstep); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
191 absystep = ABS (array->ystep); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
192 y = array->ystart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
193 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
194 /* Single value assignment. */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
195 switch (bpp) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
196 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
197 case 1: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
198 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
199 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
200 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
201 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
202 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
203 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
204 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
205 *((Uint8 *) pixels + vy * newsurf->pitch + vx) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
206 (Uint8)*((Uint8 *) origpixels + y * array->padding + x); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
207 vx++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
208 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
209 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
210 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
211 vy++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
212 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
213 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
214 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
215 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
216 case 2: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
217 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
218 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
219 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
220 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
221 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
222 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
223 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
224 *((Uint16 *) (pixels + vy * newsurf->pitch) + vx) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
225 (Uint16)*((Uint16 *) (origpixels + y * array->padding) + x); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
226 vx++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
227 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
228 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
229 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
230 vy++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
231 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
232 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
233 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
234 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
235 case 3: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
236 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
237 Uint8 *px; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
238 Uint8 *vpx; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
239 SDL_PixelFormat *format = newsurf->format; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
240 SDL_PixelFormat *vformat = surface->format; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
241 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
242 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
243 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
244 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
245 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
246 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
247 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
248 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
249 px = (Uint8 *) (pixels + vy * newsurf->pitch) + vx * 3; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
250 vpx = (Uint8 *) ((Uint8*) origpixels + y * array->padding) + |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
251 x * 3; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
252 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
253 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
254 *(px + (format->Rshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
255 *(vpx + (vformat->Rshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
256 *(px + (format->Gshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
257 *(vpx + (vformat->Gshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
258 *(px + (format->Bshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
259 *(vpx + (vformat->Bshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
260 #else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
261 *(px + 2 - (format->Rshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
262 *(vpx + 2 - (vformat->Rshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
263 *(px + 2 - (format->Gshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
264 *(vpx + 2 - (vformat->Gshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
265 *(px + 2 - (format->Bshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
266 *(vpx + 2 - (vformat->Bshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
267 #endif |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
268 vx++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
269 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
270 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
271 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
272 vy++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
273 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
274 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
275 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
276 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
277 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
278 default: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
279 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
280 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
281 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
282 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
283 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
284 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
285 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
286 *((Uint32 *) (pixels + vy * newsurf->pitch) + vx) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
287 (Uint32)*((Uint32 *) (origpixels + y * array->padding) + x); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
288 vx++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
289 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
290 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
291 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
292 vy++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
293 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
294 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
295 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
296 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
297 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
298 if (SDL_MUSTLOCK (newsurf) == 0) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
299 SDL_UnlockSurface (newsurf); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
300 newsf = PySurface_New (newsurf); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
301 if (!newsf) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
302 return NULL; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
303 return newsf; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
304 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
305 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
306 static PyObject* |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
307 _replace_color (PyPixelArray *array, PyObject *args) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
308 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
309 PyObject *delcolor = NULL; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
310 PyObject *replcolor = NULL; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
311 Uint32 dcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
312 Uint32 rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
313 SDL_Surface *surface; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
314 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
315 Uint32 x = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
316 Uint32 y = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
317 Uint32 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
318 Uint32 posy = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
319 Sint32 absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
320 Sint32 absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
321 Uint8 *pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
322 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
323 if (!PyArg_ParseTuple (args, "OO", &delcolor, &replcolor)) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
324 return NULL; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
325 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
326 surface = PySurface_AsSurface (array->surface); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
327 if (!_get_color_from_object (delcolor, surface->format, &dcolor) || |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
328 !_get_color_from_object (replcolor, surface->format, &rcolor)) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
329 return NULL; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
330 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
331 surface = PySurface_AsSurface (array->surface); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
332 pixels = surface->pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
333 absxstep = ABS (array->xstep); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
334 absystep = ABS (array->ystep); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
335 y = array->ystart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
336 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
337 switch (surface->format->BytesPerPixel) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
338 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
339 case 1: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
340 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
341 Uint8 *pixel; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
342 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
343 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
344 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
345 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
346 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
347 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
348 pixel = ((Uint8 *) pixels + y * surface->pitch + x); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
349 if (*pixel == dcolor) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
350 *pixel = (Uint8) rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
351 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
352 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
353 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
354 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
355 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
356 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
357 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
358 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
359 case 2: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
360 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
361 Uint16 *pixel; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
362 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
363 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
364 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
365 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
366 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
367 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
368 pixel = ((Uint16 *) (pixels + y * surface->pitch) + x); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
369 if (*pixel == dcolor) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
370 *pixel = (Uint16) rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
371 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
372 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
373 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
374 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
375 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
376 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
377 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
378 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
379 case 3: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
380 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
381 Uint8 *px; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
382 Uint32 pxcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
383 SDL_PixelFormat *format = surface->format; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
384 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
385 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
386 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
387 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
388 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
389 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
390 px = (Uint8 *) (pixels + y * surface->pitch) + x * 3; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
391 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
392 pxcolor = (px[0]) + (px[1] << 8) + (px[2] << 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
393 if (pxcolor == dcolor) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
394 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
395 *(px + (format->Rshift >> 3)) = (Uint8) (rcolor >> 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
396 *(px + (format->Gshift >> 3)) = (Uint8) (rcolor >> 8); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
397 *(px + (format->Bshift >> 3)) = (Uint8) rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
398 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
399 #else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
400 pxcolor = (px[2]) + (px[1] << 8) + (px[0] << 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
401 if (pxcolor == dcolor) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
402 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
403 *(px + 2 - (format->Rshift >> 3)) = (Uint8) (rcolor >> 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
404 *(px + 2 - (format->Gshift >> 3)) = (Uint8) (rcolor >> 8); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
405 *(px + 2 - (format->Bshift >> 3)) = (Uint8) rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
406 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
407 #endif |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
408 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
409 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
410 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
411 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
412 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
413 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
414 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
415 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
416 default: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
417 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
418 Uint32 *pixel; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
419 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
420 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
421 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
422 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
423 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
424 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
425 pixel = ((Uint32 *) (pixels + y * surface->pitch) + x); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
426 if (*pixel == dcolor) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
427 *pixel = rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
428 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
429 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
430 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
431 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
432 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
433 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
434 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
435 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
436 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
437 Py_RETURN_NONE; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
438 } |
