Mercurial > pygame
annotate src/pixelarray_methods.c @ 1849:301bc61643a9 math_module
merged changes from trunk
| author | lorenz |
|---|---|
| date | Mon, 16 Nov 2009 18:31:40 +0000 |
| parents | 902b98865c6c |
| children | 30fac6cc07ae |
| 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 |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
21 /* Simple weighted euclidian distance, which tries to get near to the |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
22 * human eye reception using the weights. |
| 993 | 23 * It receives RGB values in the range 0-255 and returns a distance |
| 24 * value between 0.0 and 1.0. | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
25 */ |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
26 #define COLOR_DIFF_RGB(wr,wg,wb,r1,g1,b1,r2,g2,b2) \ |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
27 (sqrt (wr * (r1 - r2) * (r1 - r2) + \ |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
28 wg * (g1 - g2) * (g1 - g2) + \ |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
29 wb * (b1 - b2) * (b1 - b2)) / 255.0) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
30 |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
31 #define WR_NTSC 0.299 |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
32 #define WG_NTSC 0.587 |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
33 #define WB_NTSC 0.114 |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
34 |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
35 /** |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
36 * 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
|
37 */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
38 static int |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
39 _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
|
40 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
41 Uint8 rgba[4]; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
42 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
43 if (!val) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
44 return 0; |
|
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 if (PyInt_Check (val)) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
47 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
48 long intval = PyInt_AsLong (val); |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1007
diff
changeset
|
49 if (intval == -1 && PyErr_Occurred ()) |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
50 { |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1007
diff
changeset
|
51 PyErr_SetString (PyExc_ValueError, "invalid color argument"); |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
52 return 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
53 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
54 *color = (Uint32) intval; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
55 return 1; |
|
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 else if (PyLong_Check (val)) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
58 { |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1007
diff
changeset
|
59 unsigned long longval = PyLong_AsUnsignedLong (val); |
|
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1007
diff
changeset
|
60 if (PyErr_Occurred ()) |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
61 { |
|
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 *color = (Uint32) longval; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
66 return 1; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
67 } |
| 1037 | 68 else if (RGBAFromColorObj (val, rgba)) |
|
989
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 *color = (Uint32) SDL_MapRGBA |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
71 (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
|
72 return 1; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
73 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
74 else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
75 PyErr_SetString (PyExc_ValueError, "invalid color argument"); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
76 return 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
77 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
78 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
79 /** |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
80 * 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
|
81 * array. |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
82 */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
83 static PyObject* |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
84 _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
|
85 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
86 Uint32 pixel; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
87 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
88 switch (bpp) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
89 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
90 case 1: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
91 pixel = (Uint32)*((Uint8 *) pixels + row + _index); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
92 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
93 case 2: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
94 pixel = (Uint32)*((Uint16 *) (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 case 3: |
|
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 Uint8 *px = ((Uint8 *) (pixels + row) + _index * 3); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
99 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
100 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
|
101 #else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
102 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
|
103 #endif |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
104 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
105 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
106 default: /* 4 bpp */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
107 pixel = *((Uint32 *) (pixels + row) + _index); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
108 break; |
|
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 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
111 return PyInt_FromLong ((long)pixel); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
112 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
113 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
114 /** |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
115 * 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
|
116 */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
117 static void |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
118 _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
|
119 SDL_PixelFormat *format, Uint32 color) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
120 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
121 switch (bpp) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
122 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
123 case 1: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
124 *((Uint8 *) pixels + row + _index) = (Uint8) color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
125 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
126 case 2: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
127 *((Uint16 *) (pixels + row) + _index) = (Uint16) color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
128 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
129 case 3: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
130 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
131 *((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
|
132 (Uint8) (color >> 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
133 *((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
|
134 (Uint8) (color >> 8); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
135 *((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
|
136 (Uint8) color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
137 #else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
138 *((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
|
139 (Uint8) (color >> 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
140 *((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
|
141 (Uint8) (color >> 8); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
142 *((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
|
143 (Uint8) color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
144 #endif |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
145 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
146 default: /* 4 bpp */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
147 *((Uint32 *) (pixels + row) + _index) = color; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
148 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
149 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
150 } |
|
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 /** |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
153 * 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
|
154 * size, etc. |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
155 */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
156 static PyObject* |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
157 _make_surface(PyPixelArray *array) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
158 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
159 PyObject *newsf; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
160 SDL_Surface *tmpsf; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
161 SDL_Surface *newsurf; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
162 Uint8 *pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
163 Uint8 *origpixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
164 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
165 SDL_Surface *surface; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
166 int bpp; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
167 Uint32 x = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
168 Uint32 y = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
169 Uint32 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
170 Uint32 vy = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
171 Uint32 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
172 Uint32 posy = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
173 Uint32 absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
174 Uint32 absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
175 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
176 surface = PySurface_AsSurface (array->surface); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
177 bpp = surface->format->BytesPerPixel; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
178 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
179 /* Create the second surface. */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
180 tmpsf = SDL_CreateRGBSurface (surface->flags, |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
181 (int) (array->xlen / ABS (array->xstep)), |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
182 (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
|
183 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
|
184 if (!tmpsf) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
185 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
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 /* Guarantee an identical format. */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
188 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
|
189 if (!newsurf) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
190 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
191 SDL_FreeSurface (tmpsf); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
192 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
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 SDL_FreeSurface (tmpsf); |
| 1007 | 195 |
| 196 newsf = PySurface_New (newsurf); | |
| 197 if (!newsf) | |
| 198 { | |
| 199 SDL_FreeSurface (newsurf); | |
| 200 return NULL; | |
| 201 } | |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
202 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
203 /* Acquire a temporary lock. */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
204 if (SDL_MUSTLOCK (newsurf) == 0) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
205 SDL_LockSurface (newsurf); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
206 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
207 pixels = (Uint8 *) newsurf->pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
208 origpixels = (Uint8 *) surface->pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
209 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
210 absxstep = ABS (array->xstep); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
211 absystep = ABS (array->ystep); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
212 y = array->ystart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
213 |
| 1001 | 214 Py_BEGIN_ALLOW_THREADS; |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
215 /* Single value assignment. */ |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
216 switch (bpp) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
217 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
218 case 1: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
219 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
220 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
221 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
222 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
223 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
224 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
225 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
226 *((Uint8 *) pixels + vy * newsurf->pitch + vx) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
227 (Uint8)*((Uint8 *) origpixels + y * array->padding + x); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
228 vx++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
229 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
230 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
231 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
232 vy++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
233 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
234 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
235 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
236 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
237 case 2: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
238 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
239 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
240 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
241 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
242 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
243 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
244 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
245 *((Uint16 *) (pixels + vy * newsurf->pitch) + vx) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
246 (Uint16)*((Uint16 *) (origpixels + y * array->padding) + x); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
247 vx++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
248 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
249 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
250 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
251 vy++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
252 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
253 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
254 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
255 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
256 case 3: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
257 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
258 Uint8 *px; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
259 Uint8 *vpx; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
260 SDL_PixelFormat *format = newsurf->format; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
261 SDL_PixelFormat *vformat = surface->format; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
262 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
263 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
264 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
265 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
266 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
267 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
268 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
269 { |
|
1023
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
270 px = ((Uint8 *) (pixels + vy * newsurf->pitch) + vx * 3); |
|
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
271 vpx = ((Uint8 *) (origpixels + y * array->padding) + x * 3); |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
272 |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
273 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
274 *(px + (format->Rshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
275 *(vpx + (vformat->Rshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
276 *(px + (format->Gshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
277 *(vpx + (vformat->Gshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
278 *(px + (format->Bshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
279 *(vpx + (vformat->Bshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
280 #else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
281 *(px + 2 - (format->Rshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
282 *(vpx + 2 - (vformat->Rshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
283 *(px + 2 - (format->Gshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
284 *(vpx + 2 - (vformat->Gshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
285 *(px + 2 - (format->Bshift >> 3)) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
286 *(vpx + 2 - (vformat->Bshift >> 3)); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
287 #endif |
|
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 default: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
299 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
300 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
301 vx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
302 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
303 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
304 while (posx < array->xlen) |
|
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 *((Uint32 *) (pixels + vy * newsurf->pitch) + vx) = |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
307 (Uint32)*((Uint32 *) (origpixels + y * array->padding) + x); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
308 vx++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
309 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
310 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
311 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
312 vy++; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
313 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
314 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
315 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
316 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
317 } |
| 1001 | 318 Py_END_ALLOW_THREADS; |
| 319 | |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
320 if (SDL_MUSTLOCK (newsurf) == 0) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
321 SDL_UnlockSurface (newsurf); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
322 return newsf; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
323 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
324 |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
325 static int |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
326 _get_weights (PyObject *weights, float *wr, float *wg, float *wb) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
327 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
328 int success = 1; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
329 float rgb[3] = { 0 }; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
330 |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
331 if (!weights) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
332 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
333 *wr = WR_NTSC; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
334 *wg = WG_NTSC; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
335 *wb = WB_NTSC; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
336 return 1; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
337 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
338 |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
339 if (!PySequence_Check (weights)) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
340 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
341 PyErr_SetString (PyExc_TypeError, "weights must be a sequence"); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
342 success = 0; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
343 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
344 else if (PySequence_Size (weights) < 3) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
345 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
346 PyErr_SetString (PyExc_TypeError, |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
347 "weights must contain at least 3 values"); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
348 success = 0; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
349 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
350 else |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
351 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
352 PyObject *item; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
353 int i; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
354 |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
355 for (i = 0; i < 3; i++) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
356 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
357 item = PySequence_GetItem (weights, i); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
358 if (PyNumber_Check (item)) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
359 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
360 PyObject *num = NULL; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
361 if ((num = PyNumber_Float (item)) != NULL) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
362 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
363 rgb[i] = (float) PyFloat_AsDouble (num); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
364 Py_DECREF (num); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
365 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
366 else if ((num = PyNumber_Int (item)) != NULL) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
367 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
368 rgb[i] = (float) PyInt_AsLong (num); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
369 if (rgb[i] == -1 && PyErr_Occurred ()) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
370 success = 0; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
371 Py_DECREF (num); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
372 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
373 else if ((num = PyNumber_Long (item)) != NULL) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
374 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
375 rgb[i] = (float) PyLong_AsLong (num); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
376 if (PyErr_Occurred () && |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
377 PyErr_ExceptionMatches (PyExc_OverflowError)) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
378 success = 0; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
379 Py_DECREF (num); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
380 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
381 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
382 else |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
383 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
384 PyErr_SetString (PyExc_TypeError, "invalid weights"); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
385 success = 0; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
386 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
387 Py_XDECREF (item); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
388 if (!success) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
389 break; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
390 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
391 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
392 |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
393 if (success) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
394 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
395 float sum = 0; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
396 |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
397 *wr = rgb[0]; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
398 *wg = rgb[1]; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
399 *wb = rgb[2]; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
400 if ((*wr < 0 || *wg < 0 || *wb < 0) || |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
401 (*wr == 0 && *wg == 0 && *wb == 0)) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
402 { |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
403 PyErr_SetString (PyExc_ValueError, |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
404 "weights must be positive and greater than 0"); |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
405 return 0; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
406 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
407 /* Build the average weight values. */ |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
408 sum = *wr + *wg + *wb; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
409 *wr = *wr / sum; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
410 *wg = *wg / sum; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
411 *wb = *wb / sum; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
412 |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
413 return success; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
414 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
415 return 0; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
416 } |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
417 |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
418 static PyObject* |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
419 _replace_color (PyPixelArray *array, PyObject *args, PyObject *kwds) |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
420 { |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
421 PyObject *weights = NULL; |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
422 PyObject *delcolor = NULL; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
423 PyObject *replcolor = NULL; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
424 Uint32 dcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
425 Uint32 rcolor; |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
426 Uint8 r1, g1, b1, r2, g2, b2, a2; |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
427 SDL_Surface *surface; |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
428 float distance = 0; |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
429 float wr, wg, wb; |
|
989
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 Uint32 x = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
432 Uint32 y = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
433 Uint32 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
434 Uint32 posy = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
435 Sint32 absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
436 Sint32 absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
437 Uint8 *pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
438 |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
439 static char *keys[] = { "color", "repcolor", "distance", "weights", NULL }; |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
440 |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
441 if (!PyArg_ParseTupleAndKeywords (args, kwds, "OO|fO", keys, &delcolor, |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
442 &replcolor, &distance, &weights)) |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
443 return NULL; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
444 |
| 993 | 445 if (distance < 0 || distance > 1) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
446 return RAISE (PyExc_ValueError, |
| 993 | 447 "distance must be in the range from 0.0 to 1.0"); |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
448 |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
449 surface = PySurface_AsSurface (array->surface); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
450 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
|
451 !_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
|
452 return NULL; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
453 |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
454 if (!_get_weights (weights, &wr, &wg, &wb)) |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
455 return NULL; |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
456 |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
457 surface = PySurface_AsSurface (array->surface); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
458 pixels = surface->pixels; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
459 absxstep = ABS (array->xstep); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
460 absystep = ABS (array->ystep); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
461 y = array->ystart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
462 |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
463 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
464 SDL_GetRGB (dcolor, surface->format, &r1, &g1, &b1); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
465 |
| 1001 | 466 Py_BEGIN_ALLOW_THREADS; |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
467 switch (surface->format->BytesPerPixel) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
468 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
469 case 1: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
470 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
471 Uint8 *pixel; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
472 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
473 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
474 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
475 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
476 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
477 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
478 pixel = ((Uint8 *) pixels + y * surface->pitch + x); |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
479 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
480 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
481 GET_PIXELVALS_1 (r2, g2, b2, a2, pixel, surface->format); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
482 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
483 distance) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
484 *pixel = (Uint8) rcolor; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
485 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
486 else if (*pixel == dcolor) |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
487 *pixel = (Uint8) rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
488 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
489 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
490 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
491 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
492 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
493 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
494 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
495 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
496 case 2: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
497 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
498 Uint16 *pixel; |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
499 int ppa = (surface->flags & SDL_SRCALPHA && |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
500 surface->format->Amask); |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
501 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
502 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
503 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
504 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
505 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
506 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
507 pixel = ((Uint16 *) (pixels + y * surface->pitch) + x); |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
508 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
509 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
510 GET_PIXELVALS (r2, g2, b2, a2, (Uint32) *pixel, |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
511 surface->format, ppa); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
512 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
513 distance) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
514 *pixel = (Uint16) rcolor; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
515 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
516 else if (*pixel == dcolor) |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
517 *pixel = (Uint16) rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
518 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
519 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
520 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
521 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
522 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
523 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
524 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
525 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
526 case 3: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
527 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
528 Uint8 *px; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
529 Uint32 pxcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
530 SDL_PixelFormat *format = surface->format; |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
531 int ppa = (surface->flags & SDL_SRCALPHA && format->Amask); |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
532 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
533 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
534 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
535 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
536 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
537 { |
|
1023
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
538 px = ((Uint8 *) (pixels + y * surface->pitch) + x * 3); |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
539 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
540 pxcolor = (px[0]) + (px[1] << 8) + (px[2] << 16); |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
541 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
542 { |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
543 GET_PIXELVALS (r2, g2, b2, a2, pxcolor, format, ppa); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
544 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
545 distance) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
546 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
547 *(px + (format->Rshift >> 3)) = (Uint8) (rcolor >> 16); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
548 *(px + (format->Gshift >> 3)) = (Uint8) (rcolor >> 8); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
549 *(px + (format->Bshift >> 3)) = (Uint8) rcolor; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
550 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
551 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
552 else if (pxcolor == dcolor) |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
553 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
554 *(px + (format->Rshift >> 3)) = (Uint8) (rcolor >> 16); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
555 *(px + (format->Gshift >> 3)) = (Uint8) (rcolor >> 8); |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
556 *(px + (format->Bshift >> 3)) = (Uint8) rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
557 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
558 #else |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
559 pxcolor = (px[2]) + (px[1] << 8) + (px[0] << 16); |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
560 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
561 { |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
562 GET_PIXELVALS (r2, g2, b2, a2, pxcolor, format, ppa); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
563 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
564 distance) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
565 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
566 *(px + 2 - (format->Rshift >> 3)) = |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
567 (Uint8) (rcolor >> 16); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
568 *(px + 2 - (format->Gshift >> 3)) = |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
569 (Uint8) (rcolor >> 8); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
570 *(px + 2 - (format->Bshift >> 3)) = (Uint8) rcolor; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
571 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
572 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
573 else if (pxcolor == dcolor) |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
574 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
575 *(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
|
576 *(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
|
577 *(px + 2 - (format->Bshift >> 3)) = (Uint8) rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
578 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
579 #endif |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
580 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
581 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
582 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
583 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
584 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
585 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
586 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
587 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
588 default: |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
589 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
590 Uint32 *pixel; |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
591 int ppa = (surface->flags & SDL_SRCALPHA && |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
592 surface->format->Amask); |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
593 while (posy < array->ylen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
594 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
595 x = array->xstart; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
596 posx = 0; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
597 while (posx < array->xlen) |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
598 { |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
599 pixel = ((Uint32 *) (pixels + y * surface->pitch) + x); |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
600 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
601 { |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
602 GET_PIXELVALS (r2, g2, b2, a2, *pixel, |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
603 surface->format, ppa); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
604 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
605 distance) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
606 *pixel = rcolor; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
607 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
608 else if (*pixel == dcolor) |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
609 *pixel = rcolor; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
610 x += array->xstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
611 posx += absxstep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
612 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
613 y += array->ystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
614 posy += absystep; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
615 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
616 break; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
617 } |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
618 } |
| 1001 | 619 Py_END_ALLOW_THREADS; |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
620 Py_RETURN_NONE; |
|
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
diff
changeset
|
621 } |
| 990 | 622 |
| 623 static PyObject* | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
624 _extract_color (PyPixelArray *array, PyObject *args, PyObject *kwds) |
| 990 | 625 { |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
626 PyObject *weights = NULL; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
627 PyObject *sf = NULL; |
| 990 | 628 PyObject *excolor = NULL; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
629 PyPixelArray *newarray = NULL; |
| 990 | 630 Uint32 color; |
| 631 Uint32 white; | |
| 632 Uint32 black; | |
| 633 SDL_Surface *surface; | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
634 float distance = 0; |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
635 float wr, wg, wb; |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
636 Uint8 r1, g1, b1, r2, g2, b2, a2; |
| 990 | 637 |
| 638 Uint32 x = 0; | |
| 639 Uint32 y = 0; | |
| 640 Uint32 posx = 0; | |
| 641 Uint32 posy = 0; | |
| 642 Sint32 absxstep; | |
| 643 Sint32 absystep; | |
| 644 Uint8 *pixels; | |
| 645 | |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
646 static char *keys[] = { "color", "distance", "weights", NULL }; |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
647 |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
648 if (!PyArg_ParseTupleAndKeywords (args, kwds, "O|fO", keys, &excolor, |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
649 &distance, &weights)) |
| 990 | 650 return NULL; |
| 651 | |
| 993 | 652 if (distance < 0 || distance > 1) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
653 return RAISE (PyExc_ValueError, |
| 993 | 654 "distance must be in the range from 0.0 to 1.0"); |
| 1007 | 655 if (!_get_weights (weights, &wr, &wg, &wb)) |
| 656 return NULL; | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
657 |
| 990 | 658 surface = PySurface_AsSurface (array->surface); |
| 659 if (!_get_color_from_object (excolor, surface->format, &color)) | |
| 660 return NULL; | |
| 661 | |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
662 /* Create the b/w mask surface. */ |
|
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
663 sf = _make_surface (array); |
|
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
664 if (!sf) |
|
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
665 return NULL; |
|
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
666 newarray = (PyPixelArray *) PyPixelArray_New (sf); |
|
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
667 if (!newarray) |
| 1007 | 668 { |
| 669 Py_DECREF (sf); | |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
670 return NULL; |
| 1007 | 671 } |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
672 surface = PySurface_AsSurface (newarray->surface); |
|
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
673 |
| 990 | 674 black = SDL_MapRGBA (surface->format, 0, 0, 0, 255); |
| 675 white = SDL_MapRGBA (surface->format, 255, 255, 255, 255); | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
676 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
677 SDL_GetRGB (color, surface->format, &r1, &g1, &b1); |
| 990 | 678 |
| 679 pixels = surface->pixels; | |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
680 absxstep = ABS (newarray->xstep); |
|
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
681 absystep = ABS (newarray->ystep); |
|
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
682 y = newarray->ystart; |
| 990 | 683 |
| 1001 | 684 Py_BEGIN_ALLOW_THREADS; |
| 990 | 685 switch (surface->format->BytesPerPixel) |
| 686 { | |
| 687 case 1: | |
| 688 { | |
| 689 Uint8 *pixel; | |
| 1007 | 690 while (posy < newarray->ylen) |
| 990 | 691 { |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
692 x = newarray->xstart; |
| 990 | 693 posx = 0; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
694 while (posx < newarray->xlen) |
| 990 | 695 { |
| 696 pixel = ((Uint8 *) pixels + y * surface->pitch + x); | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
697 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
698 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
699 GET_PIXELVALS_1 (r2, g2, b2, a2, pixel, surface->format); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
700 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
701 distance) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
702 *pixel = (Uint8) white; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
703 else |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
704 *pixel = (Uint8) black; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
705 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
706 else |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
707 *pixel = (*pixel == color) ? (Uint8) white : (Uint8) black; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
708 x += newarray->xstep; |
| 990 | 709 posx += absxstep; |
| 710 } | |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
711 y += newarray->ystep; |
| 990 | 712 posy += absystep; |
| 713 } | |
| 714 break; | |
| 715 } | |
| 716 case 2: | |
| 717 { | |
| 718 Uint16 *pixel; | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
719 int ppa = (surface->flags & SDL_SRCALPHA && |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
720 surface->format->Amask); |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
721 while (posy < newarray->ylen) |
| 990 | 722 { |
| 1007 | 723 x = newarray->xstart; |
| 990 | 724 posx = 0; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
725 while (posx < newarray->xlen) |
| 990 | 726 { |
| 727 pixel = ((Uint16 *) (pixels + y * surface->pitch) + x); | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
728 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
729 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
730 GET_PIXELVALS (r2, g2, b2, a2, (Uint32) *pixel, |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
731 surface->format, ppa); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
732 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
733 distance) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
734 *pixel = (Uint16) white; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
735 else |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
736 *pixel = (Uint16) black; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
737 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
738 else |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
739 *pixel = (*pixel == color) ? (Uint16) white : |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
740 (Uint16) black; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
741 x += newarray->xstep; |
| 990 | 742 posx += absxstep; |
| 743 } | |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
744 y += newarray->ystep; |
| 990 | 745 posy += absystep; |
| 746 } | |
| 747 break; | |
| 748 } | |
| 749 case 3: | |
| 750 { | |
| 751 Uint8 *px; | |
| 752 Uint32 pxcolor; | |
| 753 SDL_PixelFormat *format = surface->format; | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
754 int ppa = (surface->flags & SDL_SRCALPHA && format->Amask); |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
755 while (posy < newarray->ylen) |
| 990 | 756 { |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
757 x = newarray->xstart; |
| 990 | 758 posx = 0; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
759 while (posx < newarray->xlen) |
| 990 | 760 { |
|
1023
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
761 px = ((Uint8 *) (pixels + y * surface->pitch) + x * 3); |
| 990 | 762 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
| 763 pxcolor = (px[0]) + (px[1] << 8) + (px[2] << 16); | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
764 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
765 { |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
766 GET_PIXELVALS (r2, g2, b2, a2, pxcolor, format, ppa); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
767 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
768 distance) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
769 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
770 *(px + (format->Rshift >> 3)) = (Uint8) (white >> 16); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
771 *(px + (format->Gshift >> 3)) = (Uint8) (white >> 8); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
772 *(px + (format->Bshift >> 3)) = (Uint8) white; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
773 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
774 else |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
775 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
776 *(px + (format->Rshift >> 3)) = (Uint8) (black >> 16); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
777 *(px + (format->Gshift >> 3)) = (Uint8) (black >> 8); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
778 *(px + (format->Bshift >> 3)) = (Uint8) black; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
779 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
780 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
781 else if (pxcolor == color) |
| 990 | 782 { |
| 783 *(px + (format->Rshift >> 3)) = (Uint8) (white >> 16); | |
| 784 *(px + (format->Gshift >> 3)) = (Uint8) (white >> 8); | |
| 785 *(px + (format->Bshift >> 3)) = (Uint8) white; | |
| 786 } | |
| 787 else | |
| 788 { | |
| 789 *(px + (format->Rshift >> 3)) = (Uint8) (black >> 16); | |
| 790 *(px + (format->Gshift >> 3)) = (Uint8) (black >> 8); | |
| 791 *(px + (format->Bshift >> 3)) = (Uint8) black; | |
| 792 } | |
| 793 #else | |
| 794 pxcolor = (px[2]) + (px[1] << 8) + (px[0] << 16); | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
795 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
796 { |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
797 GET_PIXELVALS (r2, g2, b2, a2, pxcolor, format, ppa); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
798 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
799 distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
800 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
801 *(px + 2 - (format->Rshift >> 3)) = |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
802 (Uint8) (white >> 16); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
803 *(px + 2 - (format->Gshift >> 3)) = |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
804 (Uint8) (white >> 8); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
805 *(px + 2 - (format->Bshift >> 3)) = (Uint8) white; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
806 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
807 else |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
808 { |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
809 *(px + 2 - (format->Rshift >> 3)) = |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
810 (Uint8) (black >> 16); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
811 *(px + 2 - (format->Gshift >> 3)) = |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
812 (Uint8) (black >> 8); |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
813 *(px + 2 - (format->Bshift >> 3)) = (Uint8) black; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
814 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
815 } |
| 996 | 816 else if (pxcolor == color) |
| 990 | 817 { |
| 818 *(px + 2 - (format->Rshift >> 3)) = (Uint8) (white >> 16); | |
| 819 *(px + 2 - (format->Gshift >> 3)) = (Uint8) (white >> 8); | |
| 820 *(px + 2 - (format->Bshift >> 3)) = (Uint8) white; | |
| 821 } | |
| 822 else | |
| 823 { | |
| 824 *(px + 2 - (format->Rshift >> 3)) = (Uint8) (black >> 16); | |
| 825 *(px + 2 - (format->Gshift >> 3)) = (Uint8) (black >> 8); | |
| 826 *(px + 2 - (format->Bshift >> 3)) = (Uint8) black; | |
| 827 } | |
| 828 #endif | |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
829 x += newarray->xstep; |
| 990 | 830 posx += absxstep; |
| 831 } | |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
832 y += newarray->ystep; |
| 990 | 833 posy += absystep; |
| 834 } | |
| 835 break; | |
| 836 } | |
| 837 default: | |
| 838 { | |
| 839 Uint32 *pixel; | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
840 int ppa = (surface->flags & SDL_SRCALPHA && |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
841 surface->format->Amask); |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
842 while (posy < newarray->ylen) |
| 990 | 843 { |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
844 x = newarray->xstart; |
| 990 | 845 posx = 0; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
846 while (posx < newarray->xlen) |
| 990 | 847 { |
| 848 pixel = ((Uint32 *) (pixels + y * surface->pitch) + x); | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
849 if (distance) |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
850 { |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
851 GET_PIXELVALS (r2, g2, b2, a2, *pixel, |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
852 surface->format, ppa); |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
853 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) <= |
|
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
996
diff
changeset
|
854 distance) |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
855 *pixel = white; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
856 else |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
857 *pixel = black; |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
858 } |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
859 else |
|
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
860 *pixel = (*pixel == color) ? white : black; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
861 x += newarray->xstep; |
| 990 | 862 posx += absxstep; |
| 863 } | |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
864 y += newarray->ystep; |
| 990 | 865 posy += absystep; |
| 866 } | |
| 867 break; | |
| 868 } | |
| 869 } | |
| 1001 | 870 Py_END_ALLOW_THREADS; |
|
991
684d96c73d0d
Changed PixelArray.extract() to return a new PixelArray mask instead of performing an in place operation.
marcus
parents:
990
diff
changeset
|
871 return (PyObject *) newarray; |
| 990 | 872 } |
| 1007 | 873 |
| 874 static PyObject* | |
| 875 _compare (PyPixelArray *array, PyObject *args, PyObject *kwds) | |
| 876 { | |
| 877 PyPixelArray *array2 = NULL; | |
| 878 PyPixelArray *newarray = NULL; | |
| 879 PyObject *weights = NULL; | |
| 880 PyObject *sf = NULL; | |
| 881 SDL_Surface *surface1 = NULL; | |
| 882 SDL_Surface *surface2 = NULL; | |
| 883 Uint32 black; | |
| 884 Uint32 white; | |
| 885 float distance = 0; | |
| 886 Uint8 r1, g1, b1, a1, r2, g2, b2, a2; | |
| 887 float wr, wg, wb; | |
| 888 | |
| 889 Uint32 x = 0; | |
| 890 Uint32 y = 0; | |
| 891 Uint32 vx = 0; | |
| 892 Uint32 vy = 0; | |
| 893 Uint32 posx = 0; | |
| 894 Uint32 posy = 0; | |
| 895 Sint32 absxstep; | |
| 896 Sint32 absystep; | |
| 897 Uint8 *pixels1; | |
| 898 Uint8 *pixels2; | |
| 899 | |
| 900 static char *keys[] = { "array", "distance", "weights", NULL }; | |
| 901 | |
| 902 if (!PyArg_ParseTupleAndKeywords (args, kwds, "O|fO", keys, &newarray, | |
| 903 &distance, &weights)) | |
| 904 return NULL; | |
| 905 | |
| 906 if (!PyPixelArray_Check (newarray)) | |
| 907 return RAISE (PyExc_TypeError, "invalid array type"); | |
| 908 array2 = (PyPixelArray *) newarray; | |
| 909 newarray = NULL; | |
| 910 if (distance < 0 || distance > 1) | |
| 911 return RAISE (PyExc_ValueError, | |
| 912 "distance must be in the range from 0.0 to 1.0"); | |
| 913 if (!_get_weights (weights, &wr, &wg, &wb)) | |
| 914 return NULL; | |
| 915 | |
| 916 if (array->ylen / ABS (array->ystep) != array2->ylen / ABS (array2->ystep) | |
| 917 || array->xlen / ABS (array->xstep) != array2->xlen / ABS (array2->xstep)) | |
| 918 { | |
| 919 /* Bounds do not match. */ | |
| 920 PyErr_SetString (PyExc_ValueError, "array sizes do not match"); | |
| 921 return NULL; | |
| 922 } | |
| 923 | |
| 924 surface1 = PySurface_AsSurface (array->surface); | |
| 925 surface2 = PySurface_AsSurface (array2->surface); | |
| 926 if (surface2->format->BytesPerPixel != surface1->format->BytesPerPixel) | |
| 927 return RAISE (PyExc_ValueError, "bit depths do not match"); | |
| 928 | |
| 929 /* Create the b/w mask surface. */ | |
| 930 sf = _make_surface (array); | |
| 931 if (!sf) | |
| 932 return NULL; | |
| 933 newarray = (PyPixelArray *) PyPixelArray_New (sf); | |
| 934 if (!newarray) | |
| 935 { | |
| 936 Py_DECREF (sf); | |
| 937 return NULL; | |
| 938 } | |
| 939 surface1 = PySurface_AsSurface (newarray->surface); | |
| 940 | |
| 941 black = SDL_MapRGBA (surface1->format, 0, 0, 0, 255); | |
| 942 white = SDL_MapRGBA (surface1->format, 255, 255, 255, 255); | |
| 943 | |
| 944 pixels1 = surface1->pixels; | |
| 945 pixels2 = surface2->pixels; | |
| 946 absxstep = ABS (array2->xstep); | |
| 947 absystep = ABS (array2->ystep); | |
| 948 y = array2->ystart; | |
| 949 | |
| 950 Py_BEGIN_ALLOW_THREADS; | |
| 951 switch (surface1->format->BytesPerPixel) | |
| 952 { | |
| 953 case 1: | |
| 954 { | |
| 955 Uint8 *pixel1, *pixel2; | |
| 956 while (posy < newarray->ylen) | |
| 957 { | |
| 958 vx = array2->xstart; | |
| 959 x = newarray->xstart; | |
| 960 posx = 0; | |
| 961 while (posx < newarray->xlen) | |
| 962 { | |
| 963 pixel1 = ((Uint8 *) pixels1 + y * surface1->pitch + x); | |
| 964 pixel2 = ((Uint8 *) pixels2 + vy * surface2->pitch + vx); | |
| 965 if (distance) | |
| 966 { | |
| 967 GET_PIXELVALS_1 (r1, g1, b1, a1, pixel1, surface1->format); | |
| 968 GET_PIXELVALS_1 (r2, g2, b2, a2, pixel2, surface2->format); | |
| 969 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) > | |
| 970 distance) | |
| 971 *pixel1 = (Uint8) white; | |
| 972 else | |
| 973 *pixel1 = (Uint8) black; | |
| 974 } | |
| 975 else | |
| 976 *pixel1 = (*pixel1 == *pixel2) ? (Uint8) white : | |
| 977 (Uint8) black; | |
| 978 vx += array2->xstep; | |
| 979 x += newarray->xstep; | |
| 980 posx += absxstep; | |
| 981 } | |
| 982 vy += array2->ystep; | |
| 983 y += newarray->ystep; | |
| 984 posy += absystep; | |
| 985 } | |
| 986 break; | |
| 987 } | |
| 988 case 2: | |
| 989 { | |
| 990 Uint16 *pixel1, *pixel2; | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
991 int ppa = (surface1->flags & SDL_SRCALPHA && |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
992 surface1->format->Amask); |
| 1007 | 993 while (posy < newarray->ylen) |
| 994 { | |
| 995 vx = array2->xstart; | |
| 996 x = array->xstart; | |
| 997 posx = 0; | |
| 998 while (posx < newarray->xlen) | |
| 999 { | |
| 1000 pixel1 = ((Uint16 *) (pixels1 + y * surface1->pitch) + x); | |
| 1001 pixel2 = ((Uint16 *) (pixels2 + vy * surface2->pitch) + vx); | |
| 1002 if (distance) | |
| 1003 { | |
| 1004 GET_PIXELVALS (r1, g1, b1, a1, (Uint32) *pixel1, | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1005 surface1->format, ppa); |
| 1007 | 1006 GET_PIXELVALS (r2, g2, b2, a2, (Uint32) *pixel2, |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1007 surface1->format, ppa); |
| 1007 | 1008 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) > |
| 1009 distance) | |
| 1010 *pixel1 = (Uint16) white; | |
| 1011 else | |
| 1012 *pixel1 = (Uint16) black; | |
| 1013 } | |
| 1014 else | |
| 1015 *pixel1 = (*pixel1 == *pixel2) ? (Uint16) white : | |
| 1016 (Uint16) black; | |
| 1017 vx += array2->xstep; | |
| 1018 x += newarray->xstep; | |
| 1019 posx += absxstep; | |
| 1020 } | |
| 1021 vy += array2->ystep; | |
| 1022 y += newarray->ystep; | |
| 1023 posy += absystep; | |
| 1024 } | |
| 1025 break; | |
| 1026 } | |
| 1027 case 3: | |
| 1028 { | |
| 1029 Uint8 *px1, *px2; | |
| 1030 Uint32 pxcolor1, pxcolor2; | |
| 1031 SDL_PixelFormat *format = surface1->format; | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1032 int ppa1 = (surface1->flags & SDL_SRCALPHA && |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1033 surface1->format->Amask); |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1034 int ppa2 = (surface2->flags & SDL_SRCALPHA && |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1035 surface2->format->Amask); |
| 1007 | 1036 while (posy < newarray->ylen) |
| 1037 { | |
| 1038 vx = array2->xstart; | |
| 1039 x = newarray->xstart; | |
| 1040 posx = 0; | |
| 1041 while (posx < newarray->xlen) | |
| 1042 { | |
|
1023
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
1043 px1 = ((Uint8 *) (pixels1 + y * surface1->pitch) + x * 3); |
|
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
1044 px2 = ((Uint8 *) (pixels2 + vy * surface2->pitch) + vx * 3); |
| 1007 | 1045 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
| 1046 pxcolor1 = (px1[0]) + (px1[1] << 8) + (px1[2] << 16); | |
| 1047 pxcolor2 = (px2[0]) + (px2[1] << 8) + (px2[2] << 16); | |
| 1048 if (distance) | |
| 1049 { | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1050 GET_PIXELVALS (r1, g1, b1, a1, pxcolor1, |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1051 surface1->format, ppa1); |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1052 GET_PIXELVALS (r2, g2, b2, a2, pxcolor2, |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1053 surface2->format, ppa2); |
| 1007 | 1054 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) > |
| 1055 distance) | |
| 1056 { | |
| 1057 *(px1 + (format->Rshift >> 3)) = (Uint8) (white >> 16); | |
| 1058 *(px1 + (format->Gshift >> 3)) = (Uint8) (white >> 8); | |
| 1059 *(px1 + (format->Bshift >> 3)) = (Uint8) white; | |
| 1060 } | |
| 1061 else | |
| 1062 { | |
| 1063 *(px1 + (format->Rshift >> 3)) = (Uint8) (black >> 16); | |
| 1064 *(px1 + (format->Gshift >> 3)) = (Uint8) (black >> 8); | |
| 1065 *(px1 + (format->Bshift >> 3)) = (Uint8) black; | |
| 1066 } | |
| 1067 } | |
| 1068 else if (pxcolor1 != pxcolor2) | |
| 1069 { | |
| 1070 *(px1 + (format->Rshift >> 3)) = (Uint8) (white >> 16); | |
| 1071 *(px1 + (format->Gshift >> 3)) = (Uint8) (white >> 8); | |
| 1072 *(px1 + (format->Bshift >> 3)) = (Uint8) white; | |
| 1073 } | |
| 1074 else | |
| 1075 { | |
| 1076 *(px1 + (format->Rshift >> 3)) = (Uint8) (black >> 16); | |
| 1077 *(px1 + (format->Gshift >> 3)) = (Uint8) (black >> 8); | |
| 1078 *(px1 + (format->Bshift >> 3)) = (Uint8) black; | |
| 1079 } | |
| 1080 #else | |
| 1081 pxcolor1 = (px1[2]) + (px1[1] << 8) + (px1[0] << 16); | |
| 1082 pxcolor2 = (px2[2]) + (px2[1] << 8) + (px2[0] << 16); | |
| 1083 if (distance) | |
| 1084 { | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1085 GET_PIXELVALS (r1, g1, b1, a1, pxcolor1, |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1086 surface1->format, ppa1); |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1087 GET_PIXELVALS (r2, g2, b2, a2, pxcolor2, |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1088 surface2->format, ppa2); |
| 1007 | 1089 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) > |
| 1090 distance) | |
| 1091 { | |
| 1092 *(px1 + 2 - (format->Rshift >> 3)) = | |
| 1093 (Uint8) (white >> 16); | |
| 1094 *(px1 + 2 - (format->Gshift >> 3)) = | |
| 1095 (Uint8) (white >> 8); | |
| 1096 *(px1 + 2 - (format->Bshift >> 3)) = (Uint8) white; | |
| 1097 } | |
| 1098 else | |
| 1099 { | |
| 1100 *(px1 + 2 - (format->Rshift >> 3)) = | |
| 1101 (Uint8) (black >> 16); | |
| 1102 *(px1 + 2 - (format->Gshift >> 3)) = | |
| 1103 (Uint8) (black >> 8); | |
| 1104 *(px1 + 2 - (format->Bshift >> 3)) = (Uint8) black; | |
| 1105 } | |
| 1106 } | |
| 1107 else if (pxcolor1 != pxcolor2) | |
| 1108 { | |
| 1109 *(px1 + 2 - (format->Rshift >> 3)) = (Uint8) (white >> 16); | |
| 1110 *(px1 + 2 - (format->Gshift >> 3)) = (Uint8) (white >> 8); | |
| 1111 *(px1 + 2 - (format->Bshift >> 3)) = (Uint8) white; | |
| 1112 } | |
| 1113 else | |
| 1114 { | |
| 1115 *(px1 + 2 - (format->Rshift >> 3)) = (Uint8) (black >> 16); | |
| 1116 *(px1 + 2 - (format->Gshift >> 3)) = (Uint8) (black >> 8); | |
| 1117 *(px1 + 2 - (format->Bshift >> 3)) = (Uint8) black; | |
| 1118 } | |
| 1119 #endif | |
| 1120 vx += array2->xstep; | |
| 1121 x += newarray->xstep; | |
| 1122 posx += absxstep; | |
| 1123 } | |
| 1124 vy += array2->ystep; | |
| 1125 y += newarray->ystep; | |
| 1126 posy += absystep; | |
| 1127 } | |
| 1128 break; | |
| 1129 } | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1130 default: |
| 1007 | 1131 { |
| 1132 Uint32 *pixel1, *pixel2; | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1133 int ppa1 = (surface1->flags & SDL_SRCALPHA && |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1134 surface1->format->Amask); |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1135 int ppa2 = (surface2->flags & SDL_SRCALPHA && |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1136 surface2->format->Amask); |
| 1007 | 1137 while (posy < newarray->ylen) |
| 1138 { | |
| 1139 vx = array2->xstart; | |
| 1140 x = newarray->xstart; | |
| 1141 posx = 0; | |
| 1142 while (posx < newarray->xlen) | |
| 1143 { | |
| 1144 pixel1 = ((Uint32 *) (pixels1 + y * surface1->pitch) + x); | |
| 1145 pixel2 = ((Uint32 *) (pixels2 + vy * surface2->pitch) + vx); | |
| 1146 if (distance) | |
| 1147 { | |
|
1505
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1148 GET_PIXELVALS (r1, g1, b1, a1, *pixel1, |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1149 surface1->format, ppa1); |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1150 GET_PIXELVALS (r2, g2, b2, a2, *pixel2, |
|
902b98865c6c
fix per-pixel alpha bug involving pixel unpacking
Lenard Lindstrom <len-l@telus.net>
parents:
1037
diff
changeset
|
1151 surface2->format, ppa2); |
| 1007 | 1152 if (COLOR_DIFF_RGB (wr, wg, wb, r1, g1, b1, r2, g2, b2) > |
| 1153 distance) | |
| 1154 *pixel1 = white; | |
| 1155 else | |
| 1156 *pixel1 = black; | |
| 1157 } | |
| 1158 else | |
| 1159 *pixel1 = (*pixel1 == *pixel2) ? white : black; | |
| 1160 vx += array2->xstep; | |
| 1161 x += newarray->xstep; | |
| 1162 posx += absxstep; | |
| 1163 } | |
| 1164 vy += array2->ystep; | |
| 1165 y += newarray->ystep; | |
| 1166 posy += absystep; | |
| 1167 } | |
| 1168 break; | |
| 1169 } | |
| 1170 } | |
| 1171 Py_END_ALLOW_THREADS; | |
| 1172 return (PyObject *) newarray; | |
| 1173 } |
