Mercurial > pygame
annotate src/pixelarray.c @ 1137:ec3ced33488f
Reworked locking code to be more strict about locking.
Added Surface.get_locks() method.
| author | marcus |
|---|---|
| date | Mon, 16 Jun 2008 18:46:56 +0000 |
| parents | c4c38b97db3b |
| children | 0e9e1bae4150 |
| rev | line source |
|---|---|
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1 /* |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
2 pygame - Python Game Library |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
988
diff
changeset
|
3 Copyright (C) 2007-2008 Marcus von Appen |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
4 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
9 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
13 Library General Public License for more details. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
14 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
18 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
19 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
20 |
| 860 | 21 #define PYGAMEAPI_PIXELARRAY_INTERNAL |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
988
diff
changeset
|
22 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
23 #include "pygame.h" |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
24 #include "pygamedocs.h" |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
25 #include "surface.h" |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
26 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
27 #if PY_VERSION_HEX < 0x02050000 |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
28 #define PyIndex_Check(op) 0 |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
29 #endif |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
30 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
31 typedef struct |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
32 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
33 PyObject_HEAD |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
34 PyObject *dict; /* dict for subclassing */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
35 PyObject *weakrefs; /* Weakrefs for subclassing */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
36 PyObject *surface; /* Surface associated with the array. */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
37 PyObject *lock; /* Lock object for the surface. */ |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
38 Uint32 xstart; /* X offset for subarrays */ |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
39 Uint32 ystart; /* Y offset for subarrays */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
40 Uint32 xlen; /* X segment length. */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
41 Uint32 ylen; /* Y segment length. */ |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
42 Sint32 xstep; /* X offset step width. */ |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
43 Sint32 ystep; /* Y offset step width. */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
44 Uint32 padding; /* Padding to get to the next x offset. */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
45 PyObject *parent; /* Parent pixel array */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
46 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
47 } PyPixelArray; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
48 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
49 static PyPixelArray* _pxarray_new_internal (PyTypeObject *type, |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
50 PyObject *surface, Uint32 xstart, Uint32 ystart, Uint32 xlen, Uint32 ylen, |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
51 Sint32 xstep, Sint32 ystep, Uint32 padding, PyObject *parent); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
52 static PyObject* _pxarray_new (PyTypeObject *type, PyObject *args, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
53 PyObject *kwds); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
54 static void _pxarray_dealloc (PyPixelArray *self); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
55 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
56 static PyObject* _pxarray_get_dict (PyPixelArray *self, void *closure); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
57 static PyObject* _pxarray_get_surface (PyPixelArray *self, void *closure); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
58 static PyObject* _pxarray_repr (PyPixelArray *array); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
59 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
60 static PyObject* _array_slice_internal (PyPixelArray *array, Sint32 _start, |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
61 Sint32 _end, Sint32 _step); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
62 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
63 /* Sequence methods */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
64 static Py_ssize_t _pxarray_length (PyPixelArray *array); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
65 static PyObject* _pxarray_item (PyPixelArray *array, Py_ssize_t _index); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
66 static PyObject* _pxarray_slice (PyPixelArray *array, Py_ssize_t low, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
67 Py_ssize_t high); |
| 860 | 68 static int _array_assign_array (PyPixelArray *array, Py_ssize_t low, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
69 Py_ssize_t high, PyPixelArray *val); |
| 860 | 70 static int _array_assign_sequence (PyPixelArray *array, Py_ssize_t low, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
71 Py_ssize_t high, PyObject *val); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
72 static int _array_assign_slice (PyPixelArray *array, Py_ssize_t low, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
73 Py_ssize_t high, Uint32 color); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
74 static int _pxarray_ass_item (PyPixelArray *array, Py_ssize_t _index, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
75 PyObject *value); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
76 static int _pxarray_ass_slice (PyPixelArray *array, Py_ssize_t low, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
77 Py_ssize_t high, PyObject *value); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
78 static int _pxarray_contains (PyPixelArray *array, PyObject *value); |
| 988 | 79 static PyObject* _pxarray_iter (PyPixelArray *array); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
80 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
81 /* Mapping methods */ |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
82 static int _get_subslice (PyObject *op, Py_ssize_t length, Py_ssize_t *start, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
83 Py_ssize_t *stop, Py_ssize_t *step); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
84 static PyObject* _pxarray_subscript (PyPixelArray *array, PyObject *op); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
85 static int _pxarray_ass_subscript (PyPixelArray *array, PyObject* op, |
| 960 | 86 PyObject* value); |
| 860 | 87 |
| 88 /* C API interfaces */ | |
| 89 static PyObject* PyPixelArray_New (PyObject *surfobj); | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
90 |
| 1007 | 91 /* Incomplete forward declaration so we can use it in the methods included |
| 92 * below. | |
| 93 */ | |
| 1037 | 94 staticforward PyTypeObject PyPixelArray_Type; |
| 1007 | 95 #define PyPixelArray_Check(o) \ |
| 96 ((o)->ob_type == (PyTypeObject *) &PyPixelArray_Type) | |
| 1037 | 97 |
| 1007 | 98 #define SURFACE_EQUALS(x,y) \ |
| 99 (((PyPixelArray *)x)->surface == ((PyPixelArray *)y)->surface) | |
| 100 | |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
988
diff
changeset
|
101 #include "pixelarray_methods.c" |
| 1037 | 102 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
103 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
104 * Methods, which are bound to the PyPixelArray type. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
105 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
106 static PyMethodDef _pxarray_methods[] = |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
107 { |
| 1007 | 108 { "compare", (PyCFunction) _compare, METH_KEYWORDS, |
| 109 DOC_PIXELARRAYCOMPARE }, | |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
110 { "extract", (PyCFunction) _extract_color, METH_KEYWORDS, |
| 990 | 111 DOC_PIXELARRAYEXTRACT }, |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
112 { "make_surface", (PyCFunction) _make_surface, METH_NOARGS, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
113 DOC_PIXELARRAYMAKESURFACE }, |
| 1007 | 114 { "replace", (PyCFunction) _replace_color, METH_KEYWORDS, |
| 115 DOC_PIXELARRAYREPLACE }, | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
116 { NULL, NULL, 0, NULL } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
117 }; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
118 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
119 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
120 * Getters and setters for the PyPixelArray. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
121 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
122 static PyGetSetDef _pxarray_getsets[] = |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
123 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
124 { "__dict__", (getter) _pxarray_get_dict, NULL, NULL, NULL }, |
|
873
5f702ba03cc1
Minor PixelArray doc improvements. Updated WHATSNEW list.
marcus
parents:
867
diff
changeset
|
125 { "surface", (getter) _pxarray_get_surface, NULL, DOC_PIXELARRAYSURFACE, |
|
1137
ec3ced33488f
Reworked locking code to be more strict about locking.
marcus
parents:
1037
diff
changeset
|
126 NULL }, |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
127 { NULL, NULL, NULL, NULL, NULL } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
128 }; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
129 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
130 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
131 * Sequence interface support for the PyPixelArray. |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
132 * concat and repeat are not implemented due to the possible confusion |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
133 * of their behaviour (see lists numpy array). |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
134 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
135 static PySequenceMethods _pxarray_sequence = |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
136 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
137 (lenfunc) _pxarray_length, /*sq_length*/ |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
138 NULL, /*sq_concat*/ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
139 NULL, /*sq_repeat*/ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
140 (ssizeargfunc) _pxarray_item, /*sq_item*/ |
| 860 | 141 (ssizessizeargfunc) _pxarray_slice, /*sq_slice*/ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
142 (ssizeobjargproc) _pxarray_ass_item, /*sq_ass_item*/ |
| 860 | 143 (ssizessizeobjargproc) _pxarray_ass_slice, /*sq_ass_slice*/ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
144 (objobjproc) _pxarray_contains, /*sq_contains*/ |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
145 NULL, /*sq_inplace_concat*/ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
146 NULL, /*sq_inplace_repeat*/ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
147 }; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
148 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
149 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
150 * Mapping interface support for the PyPixelArray. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
151 */ |
| 960 | 152 static PyMappingMethods _pxarray_mapping = |
| 153 { | |
| 154 (inquiry) _pxarray_length, /*mp_length*/ | |
| 155 (binaryfunc) _pxarray_subscript, /*mp_subscript*/ | |
| 156 (objobjargproc) _pxarray_ass_subscript, /*mp_ass_subscript*/ | |
| 157 }; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
158 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
159 static PyTypeObject PyPixelArray_Type = |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
160 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
161 PyObject_HEAD_INIT(NULL) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
162 0, |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
163 "pygame.PixelArray", /* tp_name */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
164 sizeof (PyPixelArray), /* tp_basicsize */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
165 0, /* tp_itemsize */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
166 (destructor) _pxarray_dealloc, /* tp_dealloc */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
167 0, /* tp_print */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
168 0, /* tp_getattr */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
169 0, /* tp_setattr */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
170 0, /* tp_compare */ |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
171 (reprfunc) _pxarray_repr, /* tp_repr */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
172 0, /* tp_as_number */ |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
173 &_pxarray_sequence, /* tp_as_sequence */ |
|
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
174 &_pxarray_mapping, /* tp_as_mapping */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
175 0, /* tp_hash */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
176 0, /* tp_call */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
177 0, /* tp_str */ |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
178 0, /* tp_getattro */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
179 0, /* tp_setattro */ |
| 860 | 180 0, /* tp_as_buffer */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
181 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
182 DOC_PYGAMEPIXELARRAY, /* tp_doc */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
183 0, /* tp_traverse */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
184 0, /* tp_clear */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
185 0, /* tp_richcompare */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
186 offsetof (PyPixelArray, weakrefs), /* tp_weaklistoffset */ |
| 988 | 187 (getiterfunc) _pxarray_iter, /* tp_iter */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
188 0, /* tp_iternext */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
189 _pxarray_methods, /* tp_methods */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
190 0, /* tp_members */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
191 _pxarray_getsets, /* tp_getset */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
192 0, /* tp_base */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
193 0, /* tp_dict */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
194 0, /* tp_descr_get */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
195 0, /* tp_descr_set */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
196 offsetof (PyPixelArray, dict), /* tp_dictoffset */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
197 0, /* tp_init */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
198 0, /* tp_alloc */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
199 _pxarray_new, /* tp_new */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
200 0, /* tp_free */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
201 0, /* tp_is_gc */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
202 0, /* tp_bases */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
203 0, /* tp_mro */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
204 0, /* tp_cache */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
205 0, /* tp_subclasses */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
206 0, /* tp_weaklist */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
207 0 /* tp_del */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
208 }; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
209 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
210 static PyPixelArray* |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
211 _pxarray_new_internal (PyTypeObject *type, PyObject *surface, |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
212 Uint32 xstart, Uint32 ystart, Uint32 xlen, Uint32 ylen, |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
213 Sint32 xstep, Sint32 ystep, Uint32 padding, PyObject *parent) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
214 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
215 PyPixelArray *self = (PyPixelArray *) type->tp_alloc (type, 0); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
216 if (!self) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
217 return NULL; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
218 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
219 self->surface = (PyObject *) surface; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
220 self->lock = NULL; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
221 self->parent = NULL; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
222 Py_INCREF (surface); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
223 |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
224 if (!parent) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
225 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
226 /* Initial PixelArray */ |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
227 if (surface) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
228 { |
|
1137
ec3ced33488f
Reworked locking code to be more strict about locking.
marcus
parents:
1037
diff
changeset
|
229 self->lock = PySurface_LockLifetime (surface, (PyObject *) self); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
230 if (!self->lock) |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
231 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
232 Py_DECREF (surface); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
233 self->ob_type->tp_free ((PyObject *) self); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
234 return NULL; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
235 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
236 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
237 } |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
238 else |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
239 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
240 self->parent = parent; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
241 Py_INCREF (parent); |
|
1137
ec3ced33488f
Reworked locking code to be more strict about locking.
marcus
parents:
1037
diff
changeset
|
242 self->lock = ((PyPixelArray *)parent)->lock; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
243 Py_INCREF (self->lock); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
244 } |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
245 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
246 self->weakrefs = NULL; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
247 self->dict = NULL; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
248 self->xstart = xstart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
249 self->ystart = ystart; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
250 self->xlen = xlen; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
251 self->ylen = ylen; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
252 self->xstep = xstep; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
253 self->ystep = ystep; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
254 self->padding = padding; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
255 return self; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
256 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
257 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
258 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
259 * Creates a new PyPixelArray. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
260 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
261 static PyObject* |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
262 _pxarray_new (PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
263 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
264 PyObject *surfobj; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
265 SDL_Surface* surface; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
266 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
267 if (!PyArg_ParseTuple (args, "O!", &PySurface_Type, &surfobj)) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
268 return NULL; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
269 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
270 surface = PySurface_AsSurface (surfobj); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
271 if (surface->format->BytesPerPixel < 1 || |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
272 surface->format->BytesPerPixel > 4) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
273 return RAISE (PyExc_ValueError, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
274 "unsupport bit depth for reference array"); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
275 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
276 return (PyObject *) _pxarray_new_internal |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
277 (type, surfobj, 0, 0, (Uint32) surface->w, (Uint32) surface->h, 1, 1, |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
278 surface->pitch, NULL); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
279 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
280 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
281 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
282 * Deallocates the PyPixelArray and its members. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
283 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
284 static void |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
285 _pxarray_dealloc (PyPixelArray *self) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
286 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
287 if (self->weakrefs) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
288 PyObject_ClearWeakRefs ((PyObject *) self); |
| 988 | 289 Py_XDECREF (self->lock); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
290 Py_XDECREF (self->parent); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
291 Py_XDECREF (self->dict); |
| 988 | 292 Py_DECREF (self->surface); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
293 self->ob_type->tp_free ((PyObject *) self); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
294 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
295 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
296 /**** Getter and setter access ****/ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
297 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
298 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
299 * Getter for PixelArray.__dict__. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
300 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
301 static PyObject* |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
302 _pxarray_get_dict (PyPixelArray *self, void *closure) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
303 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
304 if (!self->dict) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
305 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
306 self->dict = PyDict_New (); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
307 if (!self->dict) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
308 return NULL; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
309 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
310 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
311 Py_INCREF (self->dict); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
312 return self->dict; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
313 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
314 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
315 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
316 * Getter for PixelArray.surface |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
317 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
318 static PyObject* |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
319 _pxarray_get_surface (PyPixelArray *self, void *closure) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
320 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
321 Py_XINCREF (self->surface); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
322 return self->surface; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
323 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
324 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
325 /**** Methods ****/ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
326 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
327 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
328 * repr(PixelArray) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
329 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
330 static PyObject* |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
331 _pxarray_repr (PyPixelArray *array) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
332 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
333 PyObject *string; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
334 SDL_Surface *surface; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
335 int bpp; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
336 Uint8 *pixels; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
337 Uint8 *px24; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
338 Uint32 pixel; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
339 Uint32 x = 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
340 Uint32 y = 0; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
341 Sint32 xlen = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
342 Sint32 absxstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
343 Sint32 absystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
344 Uint32 posx = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
345 Uint32 posy = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
346 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
347 surface = PySurface_AsSurface (array->surface); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
348 bpp = surface->format->BytesPerPixel; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
349 pixels = (Uint8 *) surface->pixels; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
350 |
| 960 | 351 /* |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
352 printf ("::ARRAY: %d:%d:%d, %d:%d:%d %d\n", |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
353 array->xstart, array->xlen, array->xstep, array->ystart, |
| 960 | 354 array->ylen, array->ystep, array->padding); |
| 355 */ | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
356 string = PyString_FromString ("PixelArray("); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
357 |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
358 absxstep = ABS (array->xstep); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
359 absystep = ABS (array->ystep); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
360 xlen = (Sint32) array->xlen - absxstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
361 |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
362 y = array->ystart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
363 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
364 switch (bpp) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
365 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
366 case 1: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
367 while (posy < array->ylen) |
| 860 | 368 { |
| 369 /* Construct the rows */ | |
| 370 PyString_ConcatAndDel (&string, PyString_FromString ("\n [")); | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
371 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
372 x = array->xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
373 while (posx < (Uint32)xlen) |
| 860 | 374 { |
| 375 /* Construct the columns */ | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
376 pixel = (Uint32) *((Uint8 *) pixels + x + y * array->padding); |
| 860 | 377 PyString_ConcatAndDel (&string, PyString_FromFormat |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
994
diff
changeset
|
378 ("%ld, ", (long)pixel)); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
379 x += array->xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
380 posx += absxstep; |
| 860 | 381 } |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
382 pixel = (Uint32) *((Uint8 *) pixels + x + y * array->padding); |
| 960 | 383 PyString_ConcatAndDel (&string, |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
994
diff
changeset
|
384 PyString_FromFormat ("%ld]", (long)pixel)); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
385 y += array->ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
386 posy += absystep; |
| 860 | 387 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
388 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
389 case 2: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
390 while (posy < array->ylen) |
| 860 | 391 { |
| 392 /* Construct the rows */ | |
| 393 PyString_ConcatAndDel (&string, PyString_FromString ("\n [")); | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
394 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
395 x = array->xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
396 while (posx < (Uint32)xlen) |
| 860 | 397 { |
| 398 /* Construct the columns */ | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
399 pixel = (Uint32) |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
400 *((Uint16 *) (pixels + y * array->padding) + x); |
| 860 | 401 PyString_ConcatAndDel (&string, PyString_FromFormat |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
994
diff
changeset
|
402 ("%ld, ", (long)pixel)); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
403 x += array->xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
404 posx += absxstep; |
| 860 | 405 } |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
406 pixel = (Uint32) *((Uint16 *) (pixels + y * array->padding) + x); |
| 960 | 407 PyString_ConcatAndDel (&string, |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
994
diff
changeset
|
408 PyString_FromFormat ("%ld]", (long)pixel)); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
409 y += array->ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
410 posy += absystep; |
| 860 | 411 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
412 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
413 case 3: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
414 while (posy < array->ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
415 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
416 /* Construct the rows */ |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
417 PyString_ConcatAndDel (&string, PyString_FromString ("\n [")); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
418 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
419 x = array->xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
420 while (posx < (Uint32)xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
421 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
422 /* Construct the columns */ |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
423 px24 = ((Uint8 *) (pixels + y * array->padding) + x * 3); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
424 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
425 pixel = (px24[0]) + (px24[1] << 8) + (px24[2] << 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
426 #else |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
427 pixel = (px24[2]) + (px24[1] << 8) + (px24[0] << 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
428 #endif |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
429 PyString_ConcatAndDel (&string, PyString_FromFormat |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
994
diff
changeset
|
430 ("%ld, ", (long)pixel)); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
431 x += array->xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
432 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
433 } |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
434 px24 = ((Uint8 *) (pixels + y * array->padding) + x * 3); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
435 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
436 pixel = (px24[0]) + (px24[1] << 8) + (px24[2] << 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
437 #else |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
438 pixel = (px24[2]) + (px24[1] << 8) + (px24[0] << 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
439 #endif |
| 960 | 440 PyString_ConcatAndDel (&string, |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
994
diff
changeset
|
441 PyString_FromFormat ("%ld]", (long)pixel)); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
442 y += array->ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
443 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
444 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
445 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
446 default: /* 4bpp */ |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
447 while (posy < array->ylen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
448 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
449 /* Construct the rows */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
450 PyString_ConcatAndDel (&string, PyString_FromString ("\n [")); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
451 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
452 x = array->xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
453 while (posx < (Uint32)xlen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
454 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
455 /* Construct the columns */ |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
456 pixel = *((Uint32 *) (pixels + y * array->padding) + x); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
457 PyString_ConcatAndDel (&string, PyString_FromFormat |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
994
diff
changeset
|
458 ("%ld, ", (long)pixel)); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
459 x += array->xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
460 posx += absxstep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
461 } |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
462 pixel = *((Uint32 *) (pixels + y * array->padding) + x); |
| 960 | 463 PyString_ConcatAndDel (&string, |
|
997
46a786465642
Added weight support to PixelArray.extract() and PixelArray.replace().
marcus
parents:
994
diff
changeset
|
464 PyString_FromFormat ("%ld]", (long)pixel)); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
465 y += array->ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
466 posy += absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
467 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
468 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
469 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
470 PyString_ConcatAndDel (&string, PyString_FromString ("\n)")); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
471 return string; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
472 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
473 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
474 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
475 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
476 * Creates a 2D slice of the array. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
477 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
478 static PyObject* |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
479 _array_slice_internal (PyPixelArray *array, Sint32 _start, Sint32 _end, |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
480 Sint32 _step) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
481 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
482 Uint32 xstart = 0; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
483 Uint32 ystart = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
484 Uint32 xlen; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
485 Uint32 ylen; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
486 Sint32 xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
487 Sint32 ystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
488 Uint32 padding; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
489 |
| 860 | 490 if (_end == _start) |
| 491 return RAISE (PyExc_IndexError, "array size must not be 0"); | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
492 |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
493 if (array->xlen == 1) |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
494 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
495 ystart = array->ystart + _start * array->ystep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
496 xstart = array->xstart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
497 xlen = array->xlen; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
498 ylen = ABS (_end - _start); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
499 ystep = _step; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
500 xstep = array->xstep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
501 padding = array->padding; |
| 988 | 502 |
| 503 /* Out of bounds? */ | |
| 504 if (_start >= (Sint32) array->ylen && ystep > 0) | |
| 505 return RAISE (PyExc_IndexError, "array index out of range"); | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
506 } |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
507 else |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
508 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
509 xstart = array->xstart + _start * array->xstep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
510 ystart = array->ystart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
511 xlen = ABS (_end - _start); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
512 ylen = array->ylen; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
513 xstep = _step; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
514 ystep = array->ystep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
515 padding = array->padding; |
| 988 | 516 |
| 517 /* Out of bounds? */ | |
| 518 if (_start >= (Sint32) array->xlen && xstep > 0) | |
| 519 return RAISE (PyExc_IndexError, "array index out of range"); | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
520 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
521 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
522 /* |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
523 printf ("VALS: %d:%d, %d:%d %d:%d %d\n", |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
524 xstart, ystart, xlen, xstep, ylen, ystep, padding); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
525 */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
526 return (PyObject *) _pxarray_new_internal |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
527 (&PyPixelArray_Type, array->surface, xstart, ystart, xlen, ylen, |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
528 xstep, ystep, padding, (PyObject *) array); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
529 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
530 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
531 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
532 /**** Sequence interfaces ****/ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
533 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
534 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
535 * len (array) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
536 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
537 static Py_ssize_t |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
538 _pxarray_length (PyPixelArray *array) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
539 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
540 if (array->xlen > 1) |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
541 return array->xlen / ABS (array->xstep); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
542 return array->ylen / ABS (array->ystep); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
543 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
544 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
545 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
546 * array[x] |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
547 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
548 static PyObject* |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
549 _pxarray_item (PyPixelArray *array, Py_ssize_t _index) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
550 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
551 SDL_Surface *surface; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
552 int bpp; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
553 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
554 if (_index < 0) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
555 return RAISE (PyExc_IndexError, "array index out of range"); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
556 |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
557 surface = PySurface_AsSurface (array->surface); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
558 bpp = surface->format->BytesPerPixel; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
559 |
| 960 | 560 /* Access of a single column. */ |
| 561 if (array->xlen == 1) | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
562 { |
| 988 | 563 if ((Uint32) _index >= array->ystart + array->ylen) |
| 564 return RAISE (PyExc_IndexError, "array index out of range"); | |
| 565 | |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
566 return _get_single_pixel ((Uint8 *) surface->pixels, bpp, |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
567 array->xstart, _index * array->padding * array->ystep); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
568 } |
| 960 | 569 if (array->ylen == 1) |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
570 { |
| 988 | 571 if ((Uint32) _index >= array->xstart + array->xlen) |
| 572 return RAISE (PyExc_IndexError, "array index out of range"); | |
| 573 | |
| 960 | 574 return _get_single_pixel ((Uint8 *) surface->pixels, bpp, |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
575 array->xstart + _index * array->xstep, |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
576 array->ystart * array->padding * array->ystep); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
577 } |
| 988 | 578 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
579 return _array_slice_internal (array, _index, _index + 1, 1); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
580 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
581 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
582 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
583 * array[x:y] |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
584 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
585 static PyObject* |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
586 _pxarray_slice (PyPixelArray *array, Py_ssize_t low, Py_ssize_t high) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
587 { |
| 860 | 588 if (low < 0) |
| 589 low = 0; | |
| 590 else if (low > (Sint32) array->xlen) | |
| 591 low = array->xlen; | |
| 592 | |
| 593 if (high < low) | |
| 594 high = low; | |
| 595 else if (high > (Sint32) array->xlen) | |
| 596 high = array->xlen; | |
| 597 | |
| 960 | 598 if (low == high) |
| 599 Py_RETURN_NONE; | |
| 600 | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
601 return _array_slice_internal (array, low, high, 1); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
602 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
603 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
604 static int |
| 860 | 605 _array_assign_array (PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
606 PyPixelArray *val) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
607 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
608 SDL_Surface *surface; |
| 959 | 609 SDL_Surface *valsf = NULL; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
610 Uint32 x = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
611 Uint32 y = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
612 Uint32 vx = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
613 Uint32 vy = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
614 int bpp; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
615 int valbpp; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
616 Uint8 *pixels; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
617 Uint8 *valpixels; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
618 int copied = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
619 |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
620 Uint32 xstart = 0; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
621 Uint32 ystart = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
622 Uint32 xlen; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
623 Uint32 ylen; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
624 Sint32 xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
625 Sint32 ystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
626 Uint32 padding; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
627 Uint32 posx = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
628 Uint32 posy = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
629 Sint32 absxstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
630 Sint32 absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
631 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
632 /* Set the correct slice indices */ |
| 860 | 633 surface = PySurface_AsSurface (array->surface); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
634 |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
635 if (array->xlen == 1) |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
636 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
637 xstart = array->xstart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
638 ystart = array->ystart + low * array->ystep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
639 xlen = array->xlen; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
640 ylen = ABS (high - low); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
641 ystep = 1; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
642 xstep = array->xstep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
643 padding = array->padding; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
644 } |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
645 else |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
646 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
647 xstart = array->xstart + low * array->xstep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
648 ystart = array->ystart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
649 xlen = ABS (high - low); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
650 ylen = array->ylen; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
651 xstep = 1; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
652 ystep = array->ystep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
653 padding = array->padding; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
654 } |
| 959 | 655 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
656 /* |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
657 printf ("ARRAY: %d:%d:%d, %d:%d:%d -- VAL: %d:%d:%d, %d:%d:%d\n", |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
658 xstart, xlen, xstep, ystart, ylen, ystep, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
659 val->xstart, val->xlen, val->xstep, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
660 val->ystart, val->ylen, val->ystep); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
661 */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
662 if (val->ylen / ABS (val->ystep) != ylen / ABS (ystep) || |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
663 val->xlen / ABS (val->xstep) != xlen / ABS (xstep)) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
664 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
665 /* Bounds do not match. */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
666 PyErr_SetString (PyExc_ValueError, "array sizes do not match"); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
667 return -1; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
668 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
669 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
670 valsf = PySurface_AsSurface (val->surface); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
671 bpp = surface->format->BytesPerPixel; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
672 valbpp = valsf->format->BytesPerPixel; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
673 pixels = (Uint8 *) surface->pixels; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
674 valpixels = valsf->pixels; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
675 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
676 if (bpp != valbpp) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
677 { |
| 959 | 678 /* bpp do not match. We cannot guarantee that the padding and co |
| 679 * would be set correctly. */ | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
680 PyErr_SetString (PyExc_ValueError, "bit depths do not match"); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
681 return -1; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
682 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
683 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
684 /* If we reassign the same array, we need to copy the pixels |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
685 * first. */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
686 if (SURFACE_EQUALS (array, val)) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
687 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
688 /* We assign a different view or so. Copy the source buffer. */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
689 valpixels = malloc ((size_t) (surface->pitch * surface->h)); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
690 if (!valpixels) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
691 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
692 PyErr_SetString (PyExc_ValueError, "could not copy pixels"); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
693 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
694 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
695 valpixels = memcpy (valpixels, pixels, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
696 (size_t) (surface->pitch * surface->h)); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
697 copied = 1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
698 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
699 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
700 absxstep = ABS (xstep); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
701 absystep = ABS (ystep); |
| 959 | 702 |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
703 y = ystart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
704 vy = val->ystart; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
705 |
| 1001 | 706 Py_BEGIN_ALLOW_THREADS; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
707 /* Single value assignment. */ |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
708 switch (bpp) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
709 { |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
710 case 1: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
711 while (posy < ylen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
712 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
713 vx = val->xstart; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
714 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
715 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
716 while (posx < xlen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
717 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
718 *((Uint8 *) pixels + y * padding + x) = |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
719 (Uint8)*((Uint8 *) valpixels + vy * val->padding + vx); |
| 959 | 720 vx += val->xstep; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
721 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
722 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
723 } |
| 959 | 724 vy += val->ystep; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
725 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
726 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
727 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
728 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
729 case 2: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
730 while (posy < ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
731 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
732 vx = val->xstart; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
733 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
734 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
735 while (posx < xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
736 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
737 *((Uint16 *) (pixels + y * padding) + x) = |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
738 (Uint16)*((Uint16 *) (valpixels + vy * val->padding) + vx); |
| 959 | 739 vx += val->xstep; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
740 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
741 posx += absxstep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
742 } |
| 959 | 743 vy += val->ystep; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
744 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
745 posy += absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
746 } |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
747 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
748 case 3: |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
749 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
750 Uint8 *px; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
751 Uint8 *vpx; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
752 SDL_PixelFormat *format = surface->format; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
753 SDL_PixelFormat *vformat = valsf->format; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
754 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
755 while (posy < ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
756 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
757 vx = val->xstart; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
758 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
759 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
760 while (posx < xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
761 { |
|
1023
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
762 px = ((Uint8 *) (pixels + y * padding) + x * 3); |
|
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
763 vpx = ((Uint8 *) (valpixels + vy * val->padding) + vx * 3); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
764 |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
765 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
| 960 | 766 *(px + (format->Rshift >> 3)) = |
| 767 *(vpx + (vformat->Rshift >> 3)); | |
| 768 *(px + (format->Gshift >> 3)) = | |
| 769 *(vpx + (vformat->Gshift >> 3)); | |
| 770 *(px + (format->Bshift >> 3)) = | |
| 771 *(vpx + (vformat->Bshift >> 3)); | |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
772 #else |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
773 *(px + 2 - (format->Rshift >> 3)) = |
|
887
5125fa1720a9
Fixed stupid compiler error for big endian platforms.
marcus
parents:
874
diff
changeset
|
774 *(vpx + 2 - (vformat->Rshift >> 3)); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
775 *(px + 2 - (format->Gshift >> 3)) = |
|
887
5125fa1720a9
Fixed stupid compiler error for big endian platforms.
marcus
parents:
874
diff
changeset
|
776 *(vpx + 2 - (vformat->Gshift >> 3)); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
777 *(px + 2 - (format->Bshift >> 3)) = |
|
887
5125fa1720a9
Fixed stupid compiler error for big endian platforms.
marcus
parents:
874
diff
changeset
|
778 *(vpx + 2 - (vformat->Bshift >> 3)); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
779 #endif |
| 959 | 780 vx += val->xstep; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
781 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
782 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
783 } |
| 959 | 784 vy += val->ystep; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
785 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
786 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
787 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
788 break; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
789 } |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
790 default: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
791 while (posy < ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
792 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
793 vx = val->xstart; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
794 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
795 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
796 while (posx < xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
797 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
798 *((Uint32 *) (pixels + y * padding) + x) = |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
799 (Uint32)*((Uint32 *) (valpixels + vy * val->padding) + vx); |
| 959 | 800 vx += val->xstep; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
801 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
802 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
803 } |
| 959 | 804 vy += val->ystep; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
805 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
806 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
807 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
808 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
809 } |
| 1001 | 810 Py_END_ALLOW_THREADS; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
811 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
812 if (copied) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
813 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
814 free (valpixels); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
815 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
816 return 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
817 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
818 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
819 static int |
| 860 | 820 _array_assign_sequence (PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
821 PyObject *val) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
822 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
823 SDL_Surface *surface; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
824 Uint32 x = 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
825 Uint32 y = 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
826 int bpp; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
827 Uint8 *pixels; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
828 Uint32 color = 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
829 Uint32 *colorvals = NULL; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
830 Py_ssize_t offset = 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
831 Py_ssize_t seqsize = PySequence_Size (val); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
832 |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
833 Uint32 xstart = 0; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
834 Uint32 ystart = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
835 Uint32 xlen; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
836 Uint32 ylen; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
837 Sint32 xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
838 Sint32 ystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
839 Uint32 padding; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
840 Uint32 posx = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
841 Uint32 posy = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
842 Sint32 absxstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
843 Sint32 absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
844 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
845 surface = PySurface_AsSurface (array->surface); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
846 bpp = surface->format->BytesPerPixel; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
847 pixels = (Uint8 *) surface->pixels; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
848 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
849 /* Set the correct slice indices */ |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
850 if (array->xlen == 1) |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
851 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
852 xstart = array->xstart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
853 ystart = array->ystart + low * array->ystep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
854 xlen = array->xlen; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
855 ylen = ABS (high - low); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
856 ystep = 1; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
857 xstep = array->xstep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
858 padding = array->padding; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
859 } |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
860 else |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
861 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
862 xstart = array->xstart + low * array->xstep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
863 ystart = array->ystart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
864 xlen = ABS (high - low); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
865 ylen = array->ylen; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
866 xstep = 1; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
867 ystep = array->ystep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
868 padding = array->padding; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
869 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
870 |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
871 /* |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
872 printf ("LEN: %d:%d - %d\n", xlen / xstep, ylen / ystep, seqsize); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
873 */ |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
874 if ((Uint32)seqsize != ylen / ABS (ystep)) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
875 { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
876 if ((Uint32)seqsize != xlen / ABS (xstep)) |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
877 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
878 PyErr_SetString(PyExc_ValueError, "sequence size mismatch"); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
879 return -1; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
880 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
881 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
882 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
883 if (seqsize == 1) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
884 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
885 /* Single value assignment. */ |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
886 _set_single_pixel (pixels, bpp, xstart, ystart + padding * ystep, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
887 surface->format, color); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
888 return 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
889 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
890 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
891 /* Copy the values. */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
892 colorvals = malloc (sizeof (Uint32) * seqsize); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
893 if (!colorvals) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
894 { |
|
866
ba268d059b00
Fixed exception messages in PixelArray. Added unit tests for PixelArray. Fixed doc strings for PixelArray.
marcus
parents:
865
diff
changeset
|
895 PyErr_SetString(PyExc_ValueError, "could not copy colors"); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
896 return -1; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
897 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
898 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
899 for (offset = 0; offset < seqsize; offset++) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
900 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
901 if (!_get_color_from_object (PySequence_Fast_GET_ITEM (val, offset), |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
902 surface->format, &color)) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
903 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
904 free (colorvals); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
905 return -1; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
906 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
907 colorvals[offset] = color; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
908 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
909 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
910 absxstep = ABS (xstep); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
911 absystep = ABS (ystep); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
912 y = ystart; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
913 |
| 1001 | 914 Py_BEGIN_ALLOW_THREADS; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
915 switch (bpp) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
916 { |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
917 case 1: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
918 while (posy < ylen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
919 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
920 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
921 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
922 while (posx < xlen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
923 { |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
924 color = *colorvals++; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
925 *((Uint8 *) pixels + y * padding + x) = (Uint8) color; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
926 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
927 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
928 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
929 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
930 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
931 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
932 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
933 case 2: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
934 while (posy < ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
935 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
936 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
937 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
938 while (posx < xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
939 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
940 color = *colorvals++; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
941 *((Uint16 *) (pixels + y * padding) + x) = (Uint16) color; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
942 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
943 posx += absxstep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
944 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
945 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
946 posy += absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
947 } |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
948 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
949 case 3: |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
950 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
951 Uint8 *px; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
952 SDL_PixelFormat *format = surface->format; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
953 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
954 while (posy < ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
955 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
956 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
957 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
958 while (posx < xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
959 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
960 color = *colorvals++; |
|
1023
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
961 px = ((Uint8 *) (pixels + y * padding) + x * 3); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
962 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
963 *(px + (format->Rshift >> 3)) = (Uint8) (color >> 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
964 *(px + (format->Gshift >> 3)) = (Uint8) (color >> 8); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
965 *(px + (format->Bshift >> 3)) = (Uint8) color; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
966 #else |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
967 *(px + 2 - (format->Rshift >> 3)) = (Uint8) (color >> 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
968 *(px + 2 - (format->Gshift >> 3)) = (Uint8) (color >> 8); |
| 1000 | 969 *(px + 2 - (format->Bshift >> 3)) = (Uint8) color; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
970 #endif |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
971 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
972 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
973 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
974 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
975 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
976 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
977 break; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
978 } |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
979 default: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
980 while (posy < ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
981 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
982 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
983 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
984 while (posx < xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
985 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
986 color = *colorvals++; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
987 *((Uint32 *) (pixels + y * padding) + x) = color; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
988 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
989 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
990 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
991 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
992 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
993 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
994 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
995 } |
| 1001 | 996 Py_END_ALLOW_THREADS; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
997 return 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
998 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
999 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1000 static int |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1001 _array_assign_slice (PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1002 Uint32 color) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1003 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1004 SDL_Surface *surface; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1005 Uint32 x = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1006 Uint32 y = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1007 int bpp; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1008 Uint8 *pixels; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1009 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1010 Uint32 xstart = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1011 Uint32 ystart = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1012 Uint32 xlen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1013 Uint32 ylen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1014 Sint32 xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1015 Sint32 ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1016 Uint32 padding; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1017 Uint32 posx = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1018 Uint32 posy = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1019 Sint32 absxstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1020 Sint32 absystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1021 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1022 surface = PySurface_AsSurface (array->surface); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1023 bpp = surface->format->BytesPerPixel; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1024 pixels = (Uint8 *) surface->pixels; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1025 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1026 /* Set the correct slice indices */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1027 if (array->xlen == 1) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1028 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1029 xstart = array->xstart; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1030 ystart = array->ystart + low * array->ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1031 xlen = array->xlen; |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
1032 ylen = ABS (high - low); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1033 ystep = array->ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1034 xstep = array->xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1035 padding = array->padding; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1036 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1037 else |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1038 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1039 xstart = array->xstart + low * array->xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1040 ystart = array->ystart; |
|
992
1577bcf02ed5
Added threshold recognition using weighted euclideance distances to PixelArray.replace() and PixelArray.extract(). Fixed slice assignment issue.
marcus
parents:
991
diff
changeset
|
1041 xlen = ABS (high - low); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1042 ylen = array->ylen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1043 xstep = array->xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1044 ystep = array->ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1045 padding = array->padding; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1046 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1047 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1048 absxstep = ABS (xstep); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1049 absystep = ABS (ystep); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1050 y = ystart; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1051 |
| 1001 | 1052 Py_BEGIN_ALLOW_THREADS; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1053 /* Single value assignment. */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1054 switch (bpp) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1055 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1056 case 1: |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1057 while (posy < ylen) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1058 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1059 posx = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1060 x = xstart; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1061 while (posx < xlen) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1062 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1063 *((Uint8 *) pixels + y * padding + x) = (Uint8) color; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1064 x += xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1065 posx += absxstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1066 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1067 y += ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1068 posy += absystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1069 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1070 break; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1071 case 2: |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1072 while (posy < ylen) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1073 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1074 posx = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1075 x = xstart; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1076 while (posx < xlen) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1077 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1078 *((Uint16 *) (pixels + y * padding) + x) = (Uint16) color; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1079 x += xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1080 posx += absxstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1081 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1082 y += ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1083 posy += absystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1084 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1085 break; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1086 case 3: |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1087 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1088 Uint8 *px; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1089 SDL_PixelFormat *format = surface->format; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1090 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1091 while (posy < ylen) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1092 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1093 posx = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1094 x = xstart; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1095 while (posx < xlen) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1096 { |
|
1023
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
1097 px = ((Uint8 *) (pixels + y * padding) + x * 3); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1098 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1099 *(px + (format->Rshift >> 3)) = (Uint8) (color >> 16); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1100 *(px + (format->Gshift >> 3)) = (Uint8) (color >> 8); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1101 *(px + (format->Bshift >> 3)) = (Uint8) color; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1102 #else |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1103 *(px + 2 - (format->Rshift >> 3)) = (Uint8) (color >> 16); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1104 *(px + 2 - (format->Gshift >> 3)) = (Uint8) (color >> 8); |
| 1000 | 1105 *(px + 2 - (format->Bshift >> 3)) = (Uint8) color; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1106 #endif |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1107 x += xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1108 posx += absxstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1109 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1110 y += ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1111 posy += absystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1112 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1113 break; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1114 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1115 default: /* 4 bpp */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1116 while (posy < ylen) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1117 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1118 posx = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1119 x = xstart; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1120 while (posx < xlen) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1121 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1122 *((Uint32 *) (pixels + y * padding) + x) = color; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1123 x += xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1124 posx += absxstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1125 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1126 y += ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1127 posy += absystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1128 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1129 break; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1130 } |
| 1001 | 1131 Py_END_ALLOW_THREADS; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1132 return 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1133 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1134 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1135 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1136 * array[x] = ... |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1137 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1138 static int |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1139 _pxarray_ass_item (PyPixelArray *array, Py_ssize_t _index, PyObject *value) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1140 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1141 SDL_Surface *surface; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1142 Uint32 x = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1143 Uint32 y = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1144 int bpp; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1145 Uint8 *pixels; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1146 Uint32 color = 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1147 |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1148 Uint32 xstart = 0; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1149 Uint32 ystart = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1150 Uint32 xlen; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1151 Uint32 ylen; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1152 Sint32 xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1153 Sint32 ystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1154 Uint32 padding; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1155 Uint32 posx = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1156 Uint32 posy = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1157 Sint32 absxstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1158 Sint32 absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1159 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1160 surface = PySurface_AsSurface (array->surface); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1161 bpp = surface->format->BytesPerPixel; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1162 pixels = (Uint8 *) surface->pixels; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1163 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1164 if (!_get_color_from_object (value, surface->format, &color)) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1165 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1166 if (PyPixelArray_Check (value)) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1167 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1168 PyErr_Clear (); /* _get_color_from_object */ |
| 860 | 1169 return _array_assign_array (array, _index, _index + 1, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1170 (PyPixelArray *) value); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1171 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1172 else if (PySequence_Check (value)) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1173 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1174 PyErr_Clear (); /* _get_color_from_object */ |
| 860 | 1175 return _array_assign_sequence (array, _index, _index + 1, value); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1176 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1177 else /* Error already set by _get_color_from_object(). */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1178 return -1; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1179 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1180 |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1181 /* Set the correct slice indices */ |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1182 if (array->xlen == 1) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1183 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1184 xstart = array->xstart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1185 ystart = array->ystart + _index * array->ystep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1186 xlen = array->xlen; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1187 ylen = 1; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1188 ystep = array->ystep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1189 xstep = array->xstep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1190 padding = array->padding; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1191 } |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1192 else |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1193 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1194 xstart = array->xstart + _index * array->xstep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1195 ystart = array->ystart; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1196 xlen = 1; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1197 ylen = array->ylen; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1198 xstep = array->xstep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1199 ystep = array->ystep; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1200 padding = array->padding; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1201 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1202 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1203 /* |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1204 printf ("ITEM: %d:%d, %d:%d %d:%d %d\n", |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1205 xstart, ystart, xlen, xstep, ylen, ystep, padding); |
| 1025 | 1206 */ |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1207 absxstep = ABS (xstep); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1208 absystep = ABS (ystep); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1209 y = ystart; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1210 |
| 1001 | 1211 Py_BEGIN_ALLOW_THREADS; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1212 /* Single value assignment. */ |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1213 switch (bpp) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1214 { |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1215 case 1: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1216 while (posy < ylen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1217 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1218 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1219 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1220 while (posx < xlen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1221 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1222 *((Uint8 *) pixels + y * padding + x) = (Uint8) color; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1223 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1224 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1225 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1226 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1227 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1228 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1229 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1230 case 2: |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1231 while (posy < ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1232 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1233 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1234 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1235 while (posx < xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1236 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1237 *((Uint16 *) (pixels + y * padding) + x) = (Uint16) color; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1238 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1239 posx += absxstep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1240 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1241 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1242 posy += absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1243 } |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1244 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1245 case 3: |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1246 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1247 Uint8 *px; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1248 SDL_PixelFormat *format = surface->format; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1249 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1250 while (posy < ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1251 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1252 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1253 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1254 while (posx < xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1255 { |
|
1023
1a7e9d62146c
Minor 24bpp changes for the PixelArray class. The should not change anything.
marcus
parents:
1011
diff
changeset
|
1256 px = ((Uint8 *) (pixels + y * padding) + x * 3); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1257 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1258 *(px + (format->Rshift >> 3)) = (Uint8) (color >> 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1259 *(px + (format->Gshift >> 3)) = (Uint8) (color >> 8); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1260 *(px + (format->Bshift >> 3)) = (Uint8) color; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1261 #else |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1262 *(px + 2 - (format->Rshift >> 3)) = (Uint8) (color >> 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1263 *(px + 2 - (format->Gshift >> 3)) = (Uint8) (color >> 8); |
| 1000 | 1264 *(px + 2 - (format->Bshift >> 3)) = (Uint8) color; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1265 #endif |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1266 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1267 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1268 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1269 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1270 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1271 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1272 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1273 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1274 default: /* 4 bpp */ |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1275 while (posy < ylen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1276 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1277 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1278 x = xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1279 while (posx < xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1280 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1281 *((Uint32 *) (pixels + y * padding) + x) = color; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1282 x += xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1283 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1284 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1285 y += ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1286 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1287 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1288 break; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1289 } |
| 1001 | 1290 Py_END_ALLOW_THREADS; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1291 return 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1292 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1293 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1294 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1295 * array[x:y] = .... |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1296 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1297 static int |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1298 _pxarray_ass_slice (PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1299 PyObject *value) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1300 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1301 SDL_Surface *surface; |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1302 Uint32 color; |
| 860 | 1303 |
| 874 | 1304 if (array->xlen != 1) |
| 1305 { | |
| 1306 if (low < 0) | |
| 1307 low = 0; | |
| 1308 else if (low > (Sint32) array->xlen) | |
| 1309 low = array->xlen; | |
| 1310 | |
| 1311 if (high < low) | |
| 1312 high = low; | |
| 1313 else if (high > (Sint32) array->xlen) | |
| 1314 high = array->xlen; | |
| 1315 } | |
| 1316 else | |
| 1317 { | |
| 1318 if (low < 0) | |
| 1319 low = 0; | |
| 1320 else if (low > (Sint32) array->ylen) | |
| 1321 low = array->ylen; | |
| 1322 | |
| 1323 if (high < low) | |
| 1324 high = low; | |
| 1325 else if (high > (Sint32) array->ylen) | |
| 1326 high = array->ylen; | |
| 1327 } | |
| 860 | 1328 |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1329 surface = PySurface_AsSurface (array->surface); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1330 /* |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1331 printf ("SLICE IS: %d:%d\n", low, high); |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1332 */ |
| 959 | 1333 if (PyPixelArray_Check (value)) |
| 1334 { | |
| 1335 return _array_assign_array (array, low, high, (PyPixelArray *) value); | |
| 1336 } | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1337 else if (_get_color_from_object (value, surface->format, &color)) |
| 874 | 1338 { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1339 return _array_assign_slice (array, low, high, color); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1340 } |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1341 else if (PySequence_Check (value)) |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1342 { |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1343 PyErr_Clear (); /* In case _get_color_from_object set it */ |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1344 return _array_assign_sequence (array, low, high, value); |
| 874 | 1345 } |
| 1346 return 0; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1347 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1348 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1349 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1350 * x in array |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1351 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1352 static int |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1353 _pxarray_contains (PyPixelArray *array, PyObject *value) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1354 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1355 SDL_Surface *surface; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1356 Uint32 x = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1357 Uint32 y = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1358 Uint8 *pixels; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1359 int bpp; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1360 Uint32 color; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1361 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1362 Uint32 posx = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1363 Uint32 posy = 0; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1364 Sint32 absxstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1365 Sint32 absystep; |
| 1001 | 1366 int found = 0; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1367 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1368 surface = PySurface_AsSurface (array->surface); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1369 bpp = surface->format->BytesPerPixel; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1370 pixels = (Uint8 *) surface->pixels; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1371 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1372 if (!_get_color_from_object (value, surface->format, &color)) |
|
867
a249a10980f0
Fixed bufferproxy stringifcation method. Fixed PixelArray's contains() method.
marcus
parents:
866
diff
changeset
|
1373 return -1; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1374 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1375 absxstep = ABS (array->xstep); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1376 absystep = ABS (array->ystep); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1377 y = array->ystart; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1378 |
| 1001 | 1379 Py_BEGIN_ALLOW_THREADS; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1380 switch (bpp) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1381 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1382 case 1: |
| 1001 | 1383 while (posy < array->ylen && !found) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1384 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1385 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1386 x = array->xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1387 while (posx < array->xlen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1388 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1389 if (*((Uint8 *) pixels + y * array->padding + x) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1390 == (Uint8) color) |
| 1001 | 1391 { |
| 1392 found = 1; | |
| 1393 break; | |
| 1394 } | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1395 x += array->xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1396 posx += absxstep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1397 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1398 y += array->ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1399 posy += absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1400 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1401 break; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1402 case 2: |
| 1001 | 1403 while (posy < array->ylen && !found) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1404 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1405 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1406 x = array->xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1407 while (posx < array->xlen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1408 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1409 if (*((Uint16 *) (pixels + y * array->padding) + x) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1410 == (Uint16) color) |
| 1001 | 1411 { |
| 1412 found = 1; | |
| 1413 break; | |
| 1414 } | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1415 x += array->xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1416 posx += absxstep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1417 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1418 y += array->ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1419 posy += absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1420 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1421 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1422 case 3: |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1423 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1424 Uint32 pxcolor; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1425 Uint8 *pix; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1426 |
| 1001 | 1427 while (posy < array->ylen && !found) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1428 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1429 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1430 x = array->xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1431 while (posx < array->xlen) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1432 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1433 pix = ((Uint8 *) (pixels + y * array->padding) + x * 3); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1434 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1435 pxcolor = (pix[0]) + (pix[1] << 8) + (pix[2] << 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1436 #else |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1437 pxcolor = (pix[2]) + (pix[1] << 8) + (pix[0] << 16); |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1438 #endif |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1439 if (pxcolor == color) |
| 1001 | 1440 { |
| 1441 found = 1; | |
| 1442 break; | |
| 1443 } | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1444 x += array->xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1445 posx += absxstep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1446 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1447 y += array->ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1448 posy += absystep; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1449 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1450 break; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1451 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1452 default: /* 4 bpp */ |
| 1001 | 1453 while (posy < array->ylen && !found) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1454 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1455 posx = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1456 x = array->xstart; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1457 while (posx < array->xlen) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1458 { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1459 if (*((Uint32 *) (pixels + y * array->padding) + x) |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1460 == color) |
| 1001 | 1461 { |
| 1462 found = 1; | |
| 1463 break; | |
| 1464 } | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1465 x += array->xstep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1466 posx += absxstep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1467 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1468 y += array->ystep; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1469 posy += absystep; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1470 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1471 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1472 } |
| 1001 | 1473 |
| 1474 Py_END_ALLOW_THREADS; | |
| 1475 return found; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1476 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1477 |
| 988 | 1478 /** |
| 1479 * iter (arrray), for x in array | |
| 1480 */ | |
| 1481 static PyObject* | |
| 1482 _pxarray_iter (PyPixelArray *array) | |
| 1483 { | |
| 1484 /* | |
| 1485 printf ("Iter ARRAY: %d:%d:%d %d:%d:%d\n", | |
| 1486 array->xstart, array->xlen, array->xstep, | |
| 1487 array->ystart, array->ylen, array->ystep); | |
| 1488 */ | |
| 1489 return PySeqIter_New ((PyObject *) array); | |
| 1490 } | |
| 1491 | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1492 /**** Mapping interfaces ****/ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1493 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1494 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1495 * Internally used parser function for the 2D slices: |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1496 * array[x,y], array[:,:], ... |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1497 */ |
| 960 | 1498 static int |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1499 _get_subslice (PyObject *op, Py_ssize_t length, Py_ssize_t *start, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1500 Py_ssize_t *stop, Py_ssize_t *step) |
| 960 | 1501 { |
| 1502 *start = -1; | |
| 1503 *stop = -1; | |
| 1504 *step = -1; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1505 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1506 if (PySlice_Check (op)) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1507 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1508 Py_ssize_t slicelen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1509 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1510 /* Operator is a slice: array[x::, */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1511 if (PySlice_GetIndicesEx ((PySliceObject *) op, length, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1512 start, stop, step, &slicelen) < 0) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1513 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1514 return 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1515 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1516 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1517 else if (PyInt_Check (op)) |
| 960 | 1518 { |
| 1519 /* Plain index: array[x, */ | |
| 1520 *start = PyInt_AsLong (op); | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1521 if (*start < 0) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1522 *start += length; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1523 if (*start >= length || *start < 0) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1524 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1525 PyErr_SetString(PyExc_IndexError, "invalid index"); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1526 return 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1527 } |
| 960 | 1528 *stop = (*start) + 1; |
| 1529 *step = 1; | |
| 1530 } | |
| 1531 else if (PyLong_Check (op)) | |
| 1532 { | |
| 1533 long long val = -1; | |
| 1534 /* Plain index: array[x, */ | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1535 |
| 960 | 1536 val = PyLong_AsLong (op); |
| 1537 if ((val < INT_MIN) || (val > INT_MAX)) | |
| 1538 { | |
| 1539 PyErr_SetString(PyExc_ValueError, | |
| 1540 "index too big for array access"); | |
| 1541 return 0; | |
| 1542 } | |
| 1543 *start = (int) val; | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1544 if (*start < 0) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1545 *start += length; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1546 if (*start >= length || *start < 0) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1547 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1548 PyErr_SetString(PyExc_IndexError, "invalid index"); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1549 return 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1550 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1551 *stop = (*start) + 1; |
| 960 | 1552 *step = 1; |
| 1553 } | |
| 1554 return 1; | |
| 1555 } | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1556 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1557 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1558 * Slicing support for 1D and 2D access. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1559 * array[x,y] is only supported for 2D arrays. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1560 */ |
| 960 | 1561 static PyObject* |
| 1562 _pxarray_subscript (PyPixelArray *array, PyObject *op) | |
| 1563 { | |
| 1564 SDL_Surface *surface = PySurface_AsSurface (array->surface); | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1565 |
| 960 | 1566 /* Note: order matters here. |
| 1567 * First check array[x,y], then array[x:y:z], then array[x] | |
| 1568 * Otherwise it'll fail. | |
| 1569 */ | |
| 1570 if (PySequence_Check (op)) | |
| 1571 { | |
| 1572 PyObject *obj; | |
| 1573 Py_ssize_t size = PySequence_Size (op); | |
| 1574 Py_ssize_t xstart, xstop, xstep; | |
| 1575 Py_ssize_t ystart, ystop, ystep; | |
| 1576 Py_ssize_t lenx, leny; | |
| 1577 | |
| 1578 if (size == 0) | |
| 1579 { | |
| 1580 /* array[,], array[()] ... */ | |
| 1581 Py_INCREF (array); | |
| 1582 return (PyObject *) array; | |
| 1583 } | |
| 1584 if (size > 2 || (size == 2 && array->xlen == 1)) | |
| 1585 return RAISE (PyExc_IndexError, "too many indices for the array"); | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1586 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1587 lenx = (array->xlen > 1) ? array->xlen / ABS (array->xstep) : 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1588 leny = array->ylen / ABS (array->ystep); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1589 |
| 960 | 1590 obj = PySequence_Fast_GET_ITEM (op, 0); |
| 1591 if (obj == Py_Ellipsis || obj == Py_None) | |
| 1592 { | |
| 1593 /* Operator is the ellipsis or None | |
| 1594 * array[...,XXX], array[None,XXX] | |
| 1595 */ | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1596 xstart = 0; |
| 960 | 1597 xstop = array->xlen; |
| 1598 xstep = array->xstep; | |
| 1599 } | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1600 else if (!_get_subslice (obj, lenx, &xstart, &xstop, &xstep)) |
| 960 | 1601 { |
| 1602 /* Error on retrieving the subslice. */ | |
| 1603 return NULL; | |
| 1604 } | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1605 |
| 960 | 1606 if (size == 2) |
| 1607 { | |
| 1608 obj = PySequence_Fast_GET_ITEM (op, 1); | |
| 1609 if (obj == Py_Ellipsis || obj == Py_None) | |
| 1610 { | |
| 1611 /* Operator is the ellipsis or None | |
| 1612 * array[XXX,...], array[XXX,None] | |
| 1613 */ | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1614 ystart = array->ystart; |
| 960 | 1615 ystop = array->ylen; |
| 1616 ystep = array->ystep; | |
| 1617 } | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1618 else if (!_get_subslice (obj, leny, &ystart, &ystop, &ystep)) |
| 960 | 1619 { |
| 1620 /* Error on retrieving the subslice. */ | |
| 1621 return NULL; | |
| 1622 } | |
| 1623 } | |
| 1624 else | |
| 1625 { | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1626 ystart = array->ystart; |
| 960 | 1627 ystop = array->ylen; |
| 1628 ystep = array->ystep; | |
| 1629 } | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1630 |
| 960 | 1631 /* Null value? */ |
| 1632 if (xstart == xstop || ystart == ystop) | |
| 1633 Py_RETURN_NONE; | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1634 /* |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1635 printf ("X: %d:%d:%d Y: %d:%d:%d\n", xstart, xstop, xstep, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1636 ystart, ystop, ystep); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1637 */ |
| 960 | 1638 /* Single value? */ |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1639 if (ABS (xstop - xstart) == 1 && ABS (ystop - ystart) == 1) |
| 960 | 1640 { |
| 1641 return _get_single_pixel ((Uint8 *) surface->pixels, | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1642 surface->format->BytesPerPixel, array->xstart + xstart, |
| 960 | 1643 ystart * array->padding * array->ystep); |
| 1644 } | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1645 |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1646 /* |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1647 printf ("NEW ARRAY: %d:%d:%d %d:%d:%d\n", |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1648 array->xstart + xstart, ABS (xstop - xstart), xstep, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1649 array->ystart + ystart, ABS (ystop - ystart), ystep); |
| 960 | 1650 */ |
| 1651 return (PyObject *) _pxarray_new_internal (&PyPixelArray_Type, | |
| 1652 array->surface, | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1653 (Uint32) array->xstart + xstart, |
|
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1654 (Uint32) array->ystart + ystart, |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1655 (Uint32) ABS (xstop - xstart), |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1656 (Uint32) ABS (ystop - ystart), |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1657 (Sint32) xstep, |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1658 (Sint32) ystep, |
| 960 | 1659 (Uint32) array->padding, (PyObject *) array); |
| 1660 } | |
| 1661 else if (PySlice_Check (op)) | |
| 1662 { | |
| 1663 /* A slice */ | |
| 1664 Py_ssize_t slicelen; | |
| 1665 Py_ssize_t step; | |
| 1666 Py_ssize_t start; | |
| 1667 Py_ssize_t stop; | |
| 1668 int retval; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1669 |
| 960 | 1670 if (array->xlen > 1) |
| 1671 { | |
| 1672 /* 2D array - slice along the x axis */ | |
| 1673 retval = PySlice_GetIndicesEx ((PySliceObject *) op, | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1674 (Py_ssize_t) (array->xlen / ABS (array->xstep)), &start, &stop, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1675 &step, &slicelen); |
| 960 | 1676 } |
| 1677 else | |
| 1678 { | |
| 1679 /* 1D array - use the y axis. */ | |
| 1680 retval = PySlice_GetIndicesEx ((PySliceObject *) op, | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1681 (Py_ssize_t) (array->ylen / ABS (array->ystep)), &start, &stop, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1682 &step, &slicelen); |
| 960 | 1683 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1684 if (retval < 0 || slicelen < 0) |
| 960 | 1685 return NULL; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1686 if (slicelen == 0) |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1687 Py_RETURN_NONE; |
| 960 | 1688 /* |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1689 printf ("start: %d, stop: %d, step: %d, len: %d\n", start, stop, |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1690 step, slicelen); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1691 */ |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1692 return (PyObject *) _array_slice_internal (array, start, stop, step); |
| 960 | 1693 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1694 else if (PyIndex_Check (op) || PyInt_Check (op) || PyLong_Check (op)) |
| 960 | 1695 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1696 Py_ssize_t i; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1697 #if PY_VERSION_HEX >= 0x02050000 |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1698 PyObject *val = PyNumber_Index (op); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1699 if (!val) |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1700 return NULL; |
| 960 | 1701 /* A simple index. */ |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1702 i = PyNumber_AsSsize_t (val, PyExc_IndexError); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1703 #else |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1704 if (PyInt_Check (op)) |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1705 i = PyInt_AsLong (op); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1706 else |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1707 i = PyLong_AsLong (op); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1708 #endif |
| 960 | 1709 if (i == -1 && PyErr_Occurred ()) |
| 1710 return NULL; | |
| 1711 if (i < 0) | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1712 i += (array->xlen > 1) ? array->xlen / ABS (array->xstep) : |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1713 array->ylen / ABS (array->ystep); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1714 |
| 960 | 1715 return _pxarray_item (array, i); |
| 1716 } | |
| 1717 | |
| 1718 return RAISE (PyExc_TypeError, | |
| 1719 "index must be an integer, sequence or slice"); | |
| 1720 } | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1721 |
| 960 | 1722 static int |
| 1723 _pxarray_ass_subscript (PyPixelArray *array, PyObject* op, PyObject* value) | |
| 1724 { | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1725 /* TODO: by time we can make this faster by avoiding the creation of |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1726 * temporary subarrays. |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1727 */ |
| 960 | 1728 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1729 /* Note: order matters here. |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1730 * First check array[x,y], then array[x:y:z], then array[x] |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1731 * Otherwise it'll fail. |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1732 */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1733 if (PySequence_Check (op)) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1734 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1735 PyPixelArray *tmparray; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1736 PyObject *obj; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1737 Py_ssize_t size = PySequence_Size (op); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1738 Py_ssize_t xstart, xstop, xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1739 Py_ssize_t ystart, ystop, ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1740 Py_ssize_t lenx, leny; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1741 int retval; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1742 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1743 if (size == 0) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1744 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1745 /* array[,], array[()] ... */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1746 if (array->xlen == 1) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1747 return _pxarray_ass_slice (array, 0, (Py_ssize_t) array->ylen, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1748 value); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1749 else |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1750 return _pxarray_ass_slice (array, 0, (Py_ssize_t) array->xlen, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1751 value); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1752 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1753 if (size > 2 || (size == 2 && array->xlen == 1)) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1754 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1755 PyErr_SetString (PyExc_IndexError, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1756 "too many indices for the array"); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1757 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1758 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1759 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1760 lenx = (array->xlen > 1) ? array->xlen / ABS (array->xstep) : 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1761 leny = array->ylen / ABS (array->ystep); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1762 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1763 obj = PySequence_Fast_GET_ITEM (op, 0); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1764 if (obj == Py_Ellipsis || obj == Py_None) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1765 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1766 /* Operator is the ellipsis or None |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1767 * array[...,XXX], array[None,XXX] |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1768 */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1769 xstart = 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1770 xstop = array->xlen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1771 xstep = array->xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1772 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1773 else if (!_get_subslice (obj, lenx, &xstart, &xstop, &xstep)) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1774 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1775 /* Error on retrieving the subslice. */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1776 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1777 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1778 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1779 if (size == 2) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1780 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1781 obj = PySequence_Fast_GET_ITEM (op, 1); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1782 if (obj == Py_Ellipsis || obj == Py_None) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1783 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1784 /* Operator is the ellipsis or None |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1785 * array[XXX,...], array[XXX,None] |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1786 */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1787 ystart = array->ystart; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1788 ystop = array->ylen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1789 ystep = array->ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1790 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1791 else if (!_get_subslice (obj, leny, &ystart, &ystop, &ystep)) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1792 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1793 /* Error on retrieving the subslice. */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1794 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1795 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1796 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1797 else |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1798 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1799 ystart = array->ystart; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1800 ystop = array->ylen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1801 ystep = array->ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1802 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1803 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1804 /* Null value? Do nothing then. */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1805 if (xstart == xstop || ystart == ystop) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1806 return 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1807 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1808 /* Single value? */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1809 if (ABS (xstop - xstart) == 1 && ABS (ystop - ystart) == 1) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1810 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1811 tmparray = _pxarray_new_internal (&PyPixelArray_Type, |
| 1025 | 1812 array->surface, |
| 1813 (Uint32) array->xstart + xstart, | |
| 1814 (Uint32) array->ystart + ystart, | |
| 1815 1, 1, 1, 1, (Uint32) array->padding, (PyObject *) array); | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1816 if (!tmparray) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1817 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1818 retval = _pxarray_ass_item (tmparray, 0, value); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1819 Py_DECREF (tmparray); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1820 return retval; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1821 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1822 tmparray =_pxarray_new_internal (&PyPixelArray_Type, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1823 array->surface, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1824 (Uint32) array->xstart + xstart, (Uint32) array->ystart + ystart, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1825 (Uint32) ABS (xstop - xstart), (Uint32) ABS (ystop - ystart), |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1826 (Sint32) xstep, (Sint32) ystep, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1827 (Uint32) array->padding, (PyObject *) array); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1828 if (!tmparray) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1829 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1830 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1831 if (tmparray->xlen == 1) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1832 retval = _pxarray_ass_slice (tmparray, 0, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1833 (Py_ssize_t) tmparray->ylen, value); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1834 else |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1835 retval = _pxarray_ass_slice (tmparray, 0, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1836 (Py_ssize_t) tmparray->xlen, value); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1837 Py_DECREF (tmparray); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1838 return retval; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1839 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1840 else if (PySlice_Check (op)) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1841 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1842 /* A slice */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1843 PyPixelArray *tmparray; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1844 Py_ssize_t slicelen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1845 Py_ssize_t step; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1846 Py_ssize_t start; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1847 Py_ssize_t stop; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1848 int retval; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1849 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1850 if (array->xlen > 1) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1851 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1852 /* 2D array - slice along the x axis */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1853 retval = PySlice_GetIndicesEx ((PySliceObject *) op, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1854 (Py_ssize_t) (array->xlen / ABS (array->xstep)), &start, &stop, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1855 &step, &slicelen); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1856 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1857 else |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1858 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1859 /* 1D array - use the y axis. */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1860 retval = PySlice_GetIndicesEx ((PySliceObject *) op, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1861 (Py_ssize_t) (array->ylen / ABS (array->ystep)), &start, &stop, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1862 &step, &slicelen); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1863 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1864 if (retval < 0 || slicelen < 0) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1865 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1866 if (slicelen == 0) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1867 return 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1868 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1869 /* |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1870 printf ("start: %d, stop: %d, step: %d, len: %d\n", start, stop, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1871 step, slicelen); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1872 */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1873 tmparray = (PyPixelArray *) _array_slice_internal (array, start, stop, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1874 step); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1875 if (!tmparray) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1876 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1877 if (tmparray->xlen == 1) |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1878 retval = _pxarray_ass_slice (tmparray, 0, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1879 (Py_ssize_t) tmparray->ylen, value); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1880 else |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1881 retval = _pxarray_ass_slice (tmparray, 0, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1882 (Py_ssize_t) tmparray->xlen, value); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1883 Py_DECREF (tmparray); |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1884 return retval; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1885 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1886 else if (PyIndex_Check (op) || PyInt_Check (op) || PyLong_Check (op)) |
| 960 | 1887 { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1888 Py_ssize_t i; |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1889 #if PY_VERSION_HEX >= 0x02050000 |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1890 PyObject *val = PyNumber_Index (op); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1891 if (!val) |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1892 return -1; |
| 960 | 1893 /* A simple index. */ |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1894 i = PyNumber_AsSsize_t (val, PyExc_IndexError); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1895 #else |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1896 if (PyInt_Check (op)) |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1897 i = PyInt_AsLong (op); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1898 else |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1899 i = PyLong_AsLong (op); |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1900 #endif |
| 960 | 1901 if (i == -1 && PyErr_Occurred ()) |
| 1902 return -1; | |
| 1903 if (i < 0) | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1904 i += (array->xlen > 1) ? array->xlen / ABS (array->xstep) : |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1905 array->ylen / ABS (array->ystep); |
| 960 | 1906 |
| 1907 return _pxarray_ass_item (array, i, value); | |
| 1908 } | |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1909 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1910 PyErr_SetString (PyExc_TypeError, |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1911 "index must be an integer, sequence or slice"); |
| 960 | 1912 return -1; |
| 1913 } | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1914 |
| 860 | 1915 /**** C API interfaces ****/ |
| 1916 static PyObject* PyPixelArray_New (PyObject *surfobj) | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1917 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1918 SDL_Surface *surface; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1919 |
| 860 | 1920 if (!PySurface_Check (surfobj)) |
| 1921 return RAISE (PyExc_TypeError, "argument is no a Surface"); | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1922 |
| 860 | 1923 surface = PySurface_AsSurface (surfobj); |
| 1924 if (surface->format->BytesPerPixel < 1 || | |
| 1925 surface->format->BytesPerPixel > 4) | |
| 1926 return RAISE (PyExc_ValueError, | |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
1927 "unsupported bit depth for reference array"); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1928 |
| 860 | 1929 return (PyObject *) _pxarray_new_internal |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1930 (&PyPixelArray_Type, surfobj, 0, 0, |
| 960 | 1931 (Uint32) surface->w, (Uint32) surface->h, 1, 1, |
| 1932 (Uint32) surface->pitch, NULL); | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1933 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1934 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1935 PYGAME_EXPORT |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1936 void initpixelarray (void) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1937 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1938 PyObject *module; |
| 860 | 1939 PyObject *dict; |
| 1940 PyObject *apiobj; | |
| 1941 static void* c_api[PYGAMEAPI_PIXELARRAY_NUMSLOTS]; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1942 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1943 if (PyType_Ready (&PyPixelArray_Type) < 0) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1944 return; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1945 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1946 /* create the module */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1947 module = Py_InitModule3 ("pixelarray", NULL, NULL); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1948 Py_INCREF (&PyPixelArray_Type); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1949 PyModule_AddObject (module, "PixelArray", (PyObject *) &PyPixelArray_Type); |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
1950 PyPixelArray_Type.tp_getattro = PyObject_GenericGetAttr; |
| 860 | 1951 dict = PyModule_GetDict (module); |
| 1952 | |
| 1953 c_api[0] = &PyPixelArray_Type; | |
| 1954 c_api[1] = PyPixelArray_New; | |
| 1955 apiobj = PyCObject_FromVoidPtr (c_api, NULL); | |
| 1956 PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj); | |
| 1957 Py_DECREF (apiobj); | |
| 1958 | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1959 /*imported needed apis*/ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1960 import_pygame_base (); |
| 1037 | 1961 import_pygame_color(); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1962 import_pygame_surface (); |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1963 } |
