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