Mercurial > pygame
annotate src/pixelarray.c @ 3194:9fcb7abf3185 default tip
Remove some gcc 4.7.2 compiler warnings
| author | Lenard Lindstrom <len-l@telus.net> |
|---|---|
| date | Tue, 23 Apr 2013 19:53:36 -0700 |
| parents | a76f2f499bbe |
| children |
| 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" |
| 1937 | 25 #include "doc/pixelarray_doc.h" |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
26 #include "pgarrinter.h" |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
27 #include "surface.h" |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
28 |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
29 #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
|
30 #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
|
31 #endif |
|
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
32 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
33 struct _pixelarray_t; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
34 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
35 /* The array, like its surface, is in column-major (FORTRAN) order. |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
36 This is the reverse of C's row-major order. All array descriptor |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
37 fields are relative to the original surface data. The pixels |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
38 field is adjusted for any offsets of the array view into the |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
39 surface. If dim1 is 0 the array is one dimensional. |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
40 */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
41 typedef struct _pixelarray_t { |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
42 PyObject_HEAD |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
43 PyObject *dict; /* dict for subclassing */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
44 PyObject *weakrefs; /* Weakrefs for subclassing */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
45 PyObject *surface; /* Surface associated with the array */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
46 PyObject *lock; /* Lock object for the surface */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
47 Py_ssize_t dim0; /* Shape 0 of array, in pixels */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
48 Py_ssize_t dim1; /* Shape 1 of array, in pixels */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
49 Py_ssize_t stride0; /* Offset, in bytes, between pixels within a row */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
50 Py_ssize_t stride1; /* Offset, in bytes, between rows */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
51 Uint8 *pixels; /* Start of array data */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
52 struct _pixelarray_t *parent; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
53 /* Parent pixel array: NULL if no parent */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
54 } PyPixelArray; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
55 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
56 static PyPixelArray *_pxarray_new_internal( |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
57 PyTypeObject *type, PyObject *surface, PyPixelArray *parent, Uint8 *pixels, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
58 Py_ssize_t dim0, Py_ssize_t dim1, Py_ssize_t stride0, Py_ssize_t stride1); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
59 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
60 static PyObject *_pxarray_new( |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
61 PyTypeObject *type, PyObject *args, PyObject *kwds); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
62 static void _pxarray_dealloc(PyPixelArray *self); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
63 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
64 static PyObject *_pxarray_get_dict(PyPixelArray *self, void *closure); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
65 static PyObject *_pxarray_get_surface(PyPixelArray *self, void *closure); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
66 static PyObject *_pxarray_get_itemsize(PyPixelArray *self, void *closure); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
67 static PyObject *_pxarray_get_shape(PyPixelArray *self, void *closure); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
68 static PyObject *_pxarray_get_strides(PyPixelArray *self, void *closure); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
69 static PyObject *_pxarray_get_ndim(PyPixelArray *self, void *closure); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
70 static PyObject *_pxarray_get_arraystruct(PyPixelArray *self, void *closure); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
71 static PyObject *_pxarray_get_pixelsaddress(PyPixelArray *self, void *closure); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
72 static PyObject *_pxarray_repr(PyPixelArray *array); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
73 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
74 static PyObject *_array_slice_internal( |
|
2234
78fe5b5d3a7d
fix type incompatibility in pixelarray.c for Mac i386 with gcc-4.0
Lenard Lindstrom <len-l@telus.net>
parents:
2220
diff
changeset
|
75 PyPixelArray *array, Py_ssize_t start, Py_ssize_t end, Py_ssize_t step); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
76 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
77 #if PY3 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
78 static void _pxarray_capsule_destr(PyObject *capsule); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
79 #endif |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
80 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
81 /* Sequence methods */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
82 static Py_ssize_t _pxarray_length(PyPixelArray *array); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
83 static PyObject *_pxarray_item(PyPixelArray *array, Py_ssize_t index); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
84 static int _array_assign_array( |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
85 PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, PyPixelArray *val); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
86 static int _array_assign_sequence( |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
87 PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, PyObject *val); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
88 static int _array_assign_slice( |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
89 PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, Uint32 color); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
90 static int _pxarray_ass_item( |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
91 PyPixelArray *array, Py_ssize_t index, PyObject *value); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
92 static int _pxarray_ass_slice( |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
93 PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, PyObject *value); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
94 static int _pxarray_contains(PyPixelArray *array, PyObject *value); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
95 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
96 /* Mapping methods */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
97 static int _get_subslice(PyObject *op, Py_ssize_t length, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
98 Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
99 static PyObject *_pxarray_subscript(PyPixelArray *array, PyObject *op); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
100 static int _pxarray_ass_subscript( |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
101 PyPixelArray *array, PyObject* op, PyObject* value); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
102 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
103 static PyObject *_pxarray_subscript_internal( |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
104 PyPixelArray *array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
105 Py_ssize_t xstart, Py_ssize_t xstop, Py_ssize_t xstep, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
106 Py_ssize_t ystart, Py_ssize_t ystop, Py_ssize_t ystep); |
| 860 | 107 |
| 108 /* C API interfaces */ | |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
109 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
|
110 |
| 1007 | 111 /* Incomplete forward declaration so we can use it in the methods included |
| 112 * below. | |
| 113 */ | |
|
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
|
114 static PyTypeObject PyPixelArray_Type; |
| 1007 | 115 #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
|
116 (Py_TYPE (o) == (PyTypeObject *) &PyPixelArray_Type) |
| 1037 | 117 |
| 1007 | 118 #define SURFACE_EQUALS(x,y) \ |
| 119 (((PyPixelArray *)x)->surface == ((PyPixelArray *)y)->surface) | |
| 120 | |
|
989
1bbdc02af359
Added PixelArray.replace() method. Moved pixelarray methods into an own source file.
marcus
parents:
988
diff
changeset
|
121 #include "pixelarray_methods.c" |
| 1037 | 122 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
123 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
124 * 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
|
125 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
126 static PyMethodDef _pxarray_methods[] = |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
127 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
128 { "compare", (PyCFunction)_compare, METH_VARARGS | METH_KEYWORDS, |
| 1007 | 129 DOC_PIXELARRAYCOMPARE }, |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
130 { "extract", (PyCFunction)_extract_color, METH_VARARGS | METH_KEYWORDS, |
| 990 | 131 DOC_PIXELARRAYEXTRACT }, |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
132 { "make_surface", (PyCFunction)_make_surface, METH_NOARGS, |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
133 DOC_PIXELARRAYMAKESURFACE }, |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
134 { "replace", (PyCFunction)_replace_color, METH_VARARGS | METH_KEYWORDS, |
| 1007 | 135 DOC_PIXELARRAYREPLACE }, |
|
2240
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
136 { "transpose", (PyCFunction)_transpose, METH_NOARGS, |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
137 DOC_PIXELARRAYTRANSPOSE }, |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
138 { NULL, NULL, 0, NULL } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
139 }; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
140 |
|
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
|
141 #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
|
142 static void |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
143 Text_ConcatAndDel(PyObject **string, PyObject *newpart) |
|
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
|
144 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
145 PyObject *result = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
146 if (*string && newpart) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
147 PyUnicode_Concat(*string, newpart); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
148 Py_DECREF(*string); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
149 Py_DECREF(newpart); |
|
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
|
150 } |
|
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
|
151 else { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
152 Py_XDECREF(*string); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
153 Py_XDECREF(newpart); |
|
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
|
154 } |
|
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
|
155 *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
|
156 } |
|
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
|
157 #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
|
158 #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
|
159 #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
|
160 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
161 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
162 * Getters and setters for the PyPixelArray. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
163 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
164 static PyGetSetDef _pxarray_getsets[] = |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
165 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
166 { "__dict__", (getter)_pxarray_get_dict, 0, 0, 0 }, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
167 { "surface", (getter)_pxarray_get_surface, 0, DOC_PIXELARRAYSURFACE, 0 }, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
168 { "itemsize", (getter)_pxarray_get_itemsize, 0, DOC_PIXELARRAYITEMSIZE, 0 }, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
169 { "shape", (getter)_pxarray_get_shape, 0, DOC_PIXELARRAYSHAPE, 0 }, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
170 { "strides", (getter)_pxarray_get_strides, 0, DOC_PIXELARRAYSTRIDES, 0 }, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
171 { "ndim", (getter)_pxarray_get_ndim, 0, DOC_PIXELARRAYNDIM, 0 }, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
172 { "__array_struct__", (getter)_pxarray_get_arraystruct, 0, "Version 3", 0 }, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
173 { "_pixels_address", (getter)_pxarray_get_pixelsaddress, 0, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
174 "pixel buffer address (readonly)", 0 }, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
175 { 0, 0, 0, 0, 0 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
176 }; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
177 |
|
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 * Sequence interface support for the PyPixelArray. |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
180 * 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
|
181 * 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
|
182 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
183 static PySequenceMethods _pxarray_sequence = |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
184 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
185 (lenfunc)_pxarray_length, /*sq_length*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
186 0, /*sq_concat*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
187 0, /*sq_repeat*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
188 (ssizeargfunc)_pxarray_item, /*sq_item*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
189 0, /*reserved*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
190 (ssizeobjargproc)_pxarray_ass_item, /*sq_ass_item*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
191 0, /*reserved*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
192 (objobjproc)_pxarray_contains, /*sq_contains*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
193 0, /*sq_inplace_concat*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
194 0 /*sq_inplace_repeat*/ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
195 }; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
196 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
197 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
198 * Mapping interface support for the PyPixelArray. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
199 */ |
| 960 | 200 static PyMappingMethods _pxarray_mapping = |
| 201 { | |
|
2234
78fe5b5d3a7d
fix type incompatibility in pixelarray.c for Mac i386 with gcc-4.0
Lenard Lindstrom <len-l@telus.net>
parents:
2220
diff
changeset
|
202 (lenfunc)_pxarray_length, /*mp_length*/ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
203 (binaryfunc)_pxarray_subscript, /*mp_subscript*/ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
204 (objobjargproc)_pxarray_ass_subscript, /*mp_ass_subscript*/ |
| 960 | 205 }; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
206 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
207 static PyTypeObject PyPixelArray_Type = |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
208 { |
|
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
|
209 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
|
210 "pygame.PixelArray", /* tp_name */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
211 sizeof (PyPixelArray), /* tp_basicsize */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
212 0, /* tp_itemsize */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
213 (destructor)_pxarray_dealloc, /* tp_dealloc */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
214 0, /* tp_print */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
215 0, /* tp_getattr */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
216 0, /* tp_setattr */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
217 0, /* tp_compare */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
218 (reprfunc)_pxarray_repr, /* tp_repr */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
219 0, /* tp_as_number */ |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
220 &_pxarray_sequence, /* tp_as_sequence */ |
|
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
221 &_pxarray_mapping, /* tp_as_mapping */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
222 0, /* tp_hash */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
223 0, /* tp_call */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
224 0, /* tp_str */ |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
225 0, /* tp_getattro */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
226 0, /* tp_setattro */ |
| 860 | 227 0, /* tp_as_buffer */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
228 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
|
229 DOC_PYGAMEPIXELARRAY, /* tp_doc */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
230 0, /* tp_traverse */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
231 0, /* tp_clear */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
232 0, /* tp_richcompare */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
233 offsetof(PyPixelArray, weakrefs), /* tp_weaklistoffset */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
234 PySeqIter_New, /* tp_iter */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
235 0, /* tp_iternext */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
236 _pxarray_methods, /* tp_methods */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
237 0, /* tp_members */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
238 _pxarray_getsets, /* tp_getset */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
239 0, /* tp_base */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
240 0, /* tp_dict */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
241 0, /* tp_descr_get */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
242 0, /* tp_descr_set */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
243 offsetof(PyPixelArray, dict), /* tp_dictoffset */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
244 0, /* tp_init */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
245 0, /* tp_alloc */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
246 _pxarray_new, /* tp_new */ |
| 1594 | 247 #ifndef __SYMBIAN32__ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
248 0, /* tp_free */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
249 0, /* tp_is_gc */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
250 0, /* tp_bases */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
251 0, /* tp_mro */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
252 0, /* tp_cache */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
253 0, /* tp_subclasses */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
254 0, /* tp_weaklist */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
255 0 /* tp_del */ |
| 1594 | 256 #endif |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
257 }; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
258 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
259 static PyPixelArray * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
260 _pxarray_new_internal(PyTypeObject *type, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
261 PyObject *surface, PyPixelArray *parent, Uint8 *pixels, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
262 Py_ssize_t dim0, Py_ssize_t dim1, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
263 Py_ssize_t stride0, Py_ssize_t stride1) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
264 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
265 PyPixelArray *self; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
266 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
267 self = (PyPixelArray *)type->tp_alloc(type, 0); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
268 if (!self) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
269 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
270 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
271 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
272 if (!parent) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
273 if (!surface) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
274 Py_TYPE(self)->tp_free((PyObject *)self); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
275 PyErr_SetString(PyExc_SystemError, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
276 "Pygame internal error in _pxarray_new_internal: " |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
277 "no parent or surface."); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
278 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
279 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
280 self->parent = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
281 self->surface = surface; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
282 Py_INCREF(surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
283 self->lock = PySurface_LockLifetime(surface, (PyObject *)self); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
284 if (!self->lock) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
285 Py_DECREF(surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
286 Py_TYPE(self)->tp_free((PyObject *)self); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
287 return 0; |
|
852
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 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
290 else { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
291 self->parent = parent; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
292 Py_INCREF(parent); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
293 surface = parent->surface; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
294 self->surface = surface; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
295 Py_INCREF(surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
296 self->lock = parent->lock; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
297 Py_INCREF(self->lock); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
298 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
299 self->dim0 = dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
300 self->dim1 = dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
301 self->stride0 = stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
302 self->stride1 = stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
303 self->pixels = pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
304 self->weakrefs = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
305 self->dict = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
306 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
307 return self; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
308 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
309 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
310 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
311 * Creates a new PyPixelArray. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
312 */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
313 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
314 _pxarray_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
852
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 PyObject *surfobj; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
317 SDL_Surface *surf; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
318 Py_ssize_t dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
319 Py_ssize_t dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
320 Py_ssize_t stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
321 Py_ssize_t stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
322 Uint8 *pixels; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
323 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
324 if (!PyArg_ParseTuple(args, "O!", &PySurface_Type, &surfobj)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
325 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
326 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
327 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
328 surf = PySurface_AsSurface(surfobj); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
329 dim0 = (Py_ssize_t)surf->w; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
330 dim1 = (Py_ssize_t)surf->h; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
331 stride0 = (Py_ssize_t)surf->format->BytesPerPixel; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
332 stride1 = (Py_ssize_t)surf->pitch; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
333 pixels = surf->pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
334 if (stride0 < 1 || stride0 > 4) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
335 return RAISE(PyExc_ValueError, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
336 "unsupport bit depth for reference array"); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
337 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
338 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
339 return (PyObject *)_pxarray_new_internal(type, surfobj, 0, pixels, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
340 dim0, dim1, stride0, stride1); |
|
852
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 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
344 * Deallocates the PyPixelArray and its members. |
|
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 static void |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
347 _pxarray_dealloc(PyPixelArray *self) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
348 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
349 if (self->weakrefs) { |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
350 PyObject_ClearWeakRefs ((PyObject *) self); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
351 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
352 Py_XDECREF(self->lock); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
353 Py_XDECREF(self->parent); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
354 Py_XDECREF(self->dict); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
355 Py_DECREF(self->surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
356 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
|
357 } |
|
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 /**** Getter and setter access ****/ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
360 |
|
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 * Getter for PixelArray.__dict__. |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
363 */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
364 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
365 _pxarray_get_dict(PyPixelArray *self, void *closure) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
366 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
367 if (!self->dict) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
368 self->dict = PyDict_New(); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
369 if (!self->dict) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
370 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
371 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
372 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
373 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
374 Py_INCREF(self->dict); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
375 return self->dict; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
376 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
377 |
|
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 * Getter for PixelArray.surface |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
380 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
381 static PyObject* |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
382 _pxarray_get_surface(PyPixelArray *self, void *closure) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
383 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
384 Py_INCREF(self->surface); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
385 return self->surface; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
386 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
387 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
388 /** |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
389 * Getter for PixelArray.itemsize |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
390 * (pixel size in bytes) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
391 */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
392 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
393 _pxarray_get_itemsize(PyPixelArray *self, void *closure) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
394 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
395 SDL_Surface *surf = PySurface_AsSurface(self->surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
396 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
397 return PyInt_FromLong((long)surf->format->BytesPerPixel); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
398 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
399 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
400 /** |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
401 * Getter for PixelArray.shape |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
402 */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
403 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
404 _pxarray_get_shape(PyPixelArray *self, void *closure) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
405 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
406 if (self->dim1) { |
|
2300
a76f2f499bbe
Fixes some array interface related crashes and test failures on the amd64 platform(win and osx). Thanks Christoph Gohlke.
Rene Dudfield <renesd@gmail.com>
parents:
2248
diff
changeset
|
407 return Py_BuildValue("(nn)", self->dim0, self->dim1); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
408 } |
|
2300
a76f2f499bbe
Fixes some array interface related crashes and test failures on the amd64 platform(win and osx). Thanks Christoph Gohlke.
Rene Dudfield <renesd@gmail.com>
parents:
2248
diff
changeset
|
409 return Py_BuildValue("(n)", self->dim0); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
410 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
411 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
412 /** |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
413 * Getter for PixelArray.strides |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
414 */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
415 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
416 _pxarray_get_strides(PyPixelArray *self, void *closure) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
417 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
418 if (self->dim1) { |
|
2300
a76f2f499bbe
Fixes some array interface related crashes and test failures on the amd64 platform(win and osx). Thanks Christoph Gohlke.
Rene Dudfield <renesd@gmail.com>
parents:
2248
diff
changeset
|
419 return Py_BuildValue("(nn)", self->stride0, self->stride1); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
420 } |
|
2300
a76f2f499bbe
Fixes some array interface related crashes and test failures on the amd64 platform(win and osx). Thanks Christoph Gohlke.
Rene Dudfield <renesd@gmail.com>
parents:
2248
diff
changeset
|
421 return Py_BuildValue("(n)", self->stride0); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
422 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
423 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
424 /** |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
425 * Getter for PixelArray.ndim |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
426 */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
427 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
428 _pxarray_get_ndim(PyPixelArray *self, void *closure) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
429 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
430 return PyInt_FromLong(self->dim1 ? 2L : 1L); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
431 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
432 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
433 /** |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
434 * Getter for PixelArray.__array_struct__ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
435 * (array struct interface) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
436 */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
437 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
438 _pxarray_get_arraystruct(PyPixelArray *self, void *closure) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
439 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
440 typedef struct { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
441 PyArrayInterface inter; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
442 Py_intptr_t shape_mem[2]; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
443 Py_intptr_t strides_mem[2]; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
444 } Interface; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
445 int itemsize = |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
446 (int)PySurface_AsSurface(self->surface)->format->BytesPerPixel; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
447 Interface *allocation; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
448 PyArrayInterface *inter; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
449 PyObject *capsule; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
450 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
451 allocation = PyMem_New(Interface, 1); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
452 if (!allocation) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
453 return PyErr_NoMemory(); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
454 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
455 inter = (PyArrayInterface *)allocation; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
456 inter->shape = allocation->shape_mem; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
457 inter->strides = allocation->strides_mem; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
458 #if PY3 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
459 capsule = PyCapsule_New(inter, 0, _pxarray_capsule_destr); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
460 #else |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
461 capsule = PyCObject_FromVoidPtr(inter, PyMem_Free); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
462 #endif |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
463 if (!capsule) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
464 PyMem_Free(inter); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
465 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
466 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
467 inter->two = 2; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
468 inter->typekind = 'u'; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
469 inter->itemsize = itemsize; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
470 inter->flags = PAI_ALIGNED | PAI_NOTSWAPPED | PAI_WRITEABLE | PAI_FORTRAN; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
471 inter->descr = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
472 inter->nd = self->dim1 ? 2 : 1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
473 inter->shape[0] = (Py_intptr_t)self->dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
474 inter->shape[1] = (Py_intptr_t)self->dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
475 inter->strides[0] = (Py_intptr_t)self->stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
476 inter->strides[1] = (Py_intptr_t)self->stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
477 if (self->stride0 == itemsize && |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
478 (!self->dim1 || self->stride1 == self->dim0 * itemsize)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
479 inter->flags |= PAI_CONTIGUOUS; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
480 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
481 inter->data = self->pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
482 return capsule; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
483 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
484 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
485 #if PY3 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
486 static void |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
487 _pxarray_capsule_destr (PyObject *capsule) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
488 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
489 PyMem_Free (PyCapsule_GetPointer (capsule, 0)); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
490 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
491 #endif |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
492 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
493 /** |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
494 * Getter for PixelArray._pixels_address |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
495 * (address of the array's pointer into its surface's pixel data) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
496 */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
497 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
498 _pxarray_get_pixelsaddress(PyPixelArray *self, void *closure) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
499 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
500 void *address = self->pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
501 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
502 #if SIZEOF_VOID_P > SIZEOF_LONG |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
503 return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)address); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
504 #else |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
505 return PyLong_FromUnsignedLong((unsigned long)address); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
506 #endif |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
507 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
508 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
509 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
510 /**** Methods ****/ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
511 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
512 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
513 * repr(PixelArray) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
514 */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
515 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
516 _pxarray_repr(PyPixelArray *array) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
517 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
518 SDL_Surface *surf = PySurface_AsSurface(array->surface); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
519 PyObject *string; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
520 int bpp; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
521 Uint8 *pixels = array->pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
522 int ndim = array->dim1 ? 2 : 1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
523 Py_ssize_t dim0 = array->dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
524 Py_ssize_t dim1 = array->dim1 ? array->dim1 : 1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
525 Py_ssize_t stride0 = array->stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
526 Py_ssize_t stride1 = array->stride1; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
527 Uint32 pixel; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
528 Py_ssize_t x; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
529 Py_ssize_t y; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
530 Uint8 *pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
531 Uint8 *pixel_p; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
532 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
533 bpp = surf->format->BytesPerPixel; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
534 |
|
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
|
535 string = Text_FromUTF8 ("PixelArray("); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
536 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
537 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
538 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
539 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
540 pixelrow = pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
541 if (ndim == 2) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
542 Text_ConcatAndDel(&string, Text_FromUTF8("[")); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
543 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
544 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
545 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
546 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
547 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
548 switch (bpp) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
549 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
550 case 1: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
551 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
552 Text_ConcatAndDel(&string, Text_FromUTF8("\n [")); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
553 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
554 return 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
|
555 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
556 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
557 for (x = 0; x < dim0 - 1; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
558 Text_ConcatAndDel(&string, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
559 Text_FromFormat("%ld, ", (long)*pixel_p)); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
560 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
561 return 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
|
562 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
563 pixel_p += stride0; |
| 860 | 564 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
565 Text_ConcatAndDel(&string, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
566 Text_FromFormat("%ld]", (long)*pixel_p)); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
567 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
568 return 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
|
569 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
570 pixelrow += stride1; |
| 860 | 571 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
572 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
573 case 2: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
574 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
575 Text_ConcatAndDel(&string, Text_FromUTF8("\n [")); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
576 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
577 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
578 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
579 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
580 for (x = 0; x < dim0 - 1; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
581 Text_ConcatAndDel(&string, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
582 Text_FromFormat("%ld, ", |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
583 (long)*(Uint16 *)pixel_p)); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
584 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
585 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
586 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
587 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
588 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
589 Text_ConcatAndDel(&string, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
590 Text_FromFormat("%ld]", |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
591 (long)*(Uint16 *)pixel_p)); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
592 if (string == 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
|
593 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
|
594 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
595 pixelrow += stride1; |
| 860 | 596 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
597 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
598 case 3: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
599 for (y = 0; y < dim1; ++y) { |
|
2220
43fa96b3924d
fix PixelArray.__repr__ formatting bug for 24 bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents:
2219
diff
changeset
|
600 Text_ConcatAndDel(&string, Text_FromUTF8("\n [")); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
601 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
602 for (x = 0; x < dim0 - 1; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
603 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
604 pixel = (pixel_p[0]) + (pixel_p[1] << 8) + (pixel_p[2] << 16); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
605 #else |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
606 pixel = (pixel_p[2]) + (pixel_p[1] << 8) + (pixel_p[0] << 16); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
607 #endif |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
608 Text_ConcatAndDel(&string, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
609 Text_FromFormat("%ld, ", (long)pixel)); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
610 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
611 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
612 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
613 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
614 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
615 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
616 pixel = (pixel_p[0]) + (pixel_p[1] << 8) + (pixel_p[2] << 16); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
617 #else |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
618 pixel = (pixel_p[2]) + (pixel_p[1] << 8) + (pixel_p[0] << 16); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
619 #endif |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
620 Text_ConcatAndDel(&string, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
621 Text_FromFormat("%ld]", (long)pixel)); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
622 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
623 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
624 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
625 pixelrow += stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
626 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
627 break; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
628 default: /* case 4: */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
629 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
630 Text_ConcatAndDel(&string, Text_FromUTF8("\n [")); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
631 if (!string) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
632 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
633 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
634 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
635 for (x = 0; x < dim0 - 1; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
636 Text_ConcatAndDel(&string, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
637 Text_FromFormat("%ld, ", |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
638 (long)*(Uint32 *)pixel_p)); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
639 if (!string) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
640 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
641 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
642 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
643 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
644 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
645 Text_ConcatAndDel(&string, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
646 Text_FromFormat("%ld]", |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
647 (long)*(Uint32 *)pixel_p)); |
|
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
|
648 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
|
649 { |
|
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
|
650 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
|
651 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
652 pixelrow += stride1; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
653 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
654 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
655 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
656 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
657 if (ndim == 2) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
658 Text_ConcatAndDel(&string, Text_FromUTF8 ("]\n)")); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
659 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
660 else { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
661 Text_ConcatAndDel (&string, Text_FromUTF8 ("\n)")); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
662 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
663 return string; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
664 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
665 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
666 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
667 _pxarray_subscript_internal(PyPixelArray *array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
668 Py_ssize_t xstart, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
669 Py_ssize_t xstop, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
670 Py_ssize_t xstep, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
671 Py_ssize_t ystart, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
672 Py_ssize_t ystop, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
673 Py_ssize_t ystep) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
674 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
675 /* Special case: if xstep or ystep are zero, then the corresponding |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
676 * dimension is removed. If both are zero, then a single integer |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
677 * pixel value is returned. |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
678 */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
679 Py_ssize_t dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
680 Py_ssize_t dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
681 Py_ssize_t stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
682 Py_ssize_t stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
683 Uint8 *pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
684 Py_ssize_t absxstep = ABS(xstep); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
685 Py_ssize_t absystep = ABS(ystep); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
686 Py_ssize_t dx = xstop - xstart; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
687 Py_ssize_t dy = ystop - ystart; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
688 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
689 if (!array->dim1) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
690 ystart = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
691 ystop = 1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
692 ystep = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
693 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
694 if (!(xstep || ystep)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
695 return _get_single_pixel(array, xstart, ystart); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
696 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
697 if (xstep) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
698 dim0 = (ABS(dx) + absxstep - 1) / absxstep; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
699 stride0 = array->stride0 * xstep; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
700 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
701 else { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
702 /* Move dimension 2 into 1 */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
703 dim0 = (ABS(dy) + absystep - 1) / absystep; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
704 stride0 = array->stride1 * ystep; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
705 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
706 if (xstep && ystep) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
707 dim1 = (ABS(dy) + absystep - 1) / absystep; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
708 stride1 = array->stride1 * ystep; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
709 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
710 else { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
711 /* Only a one dimensional array */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
712 dim1 = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
713 stride1 = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
714 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
715 pixels = array->pixels + xstart * array->stride0 + ystart * array->stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
716 return (PyObject *)_pxarray_new_internal(&PyPixelArray_Type, 0, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
717 array, pixels, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
718 dim0, dim1, stride0, stride1); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
719 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
720 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
721 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
722 * 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
|
723 */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
724 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
725 _array_slice_internal(PyPixelArray *array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
726 Py_ssize_t start, Py_ssize_t end, Py_ssize_t step) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
727 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
728 if (end == start) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
729 return RAISE(PyExc_IndexError, "array size must not be 0"); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
730 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
731 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
732 if (start >= array->dim0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
733 return RAISE(PyExc_IndexError, "array index out of range"); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
734 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
735 return _pxarray_subscript_internal(array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
736 start, end, step, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
737 0, array->dim1, 1); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
738 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
739 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
740 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
741 /**** Sequence interfaces ****/ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
742 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
743 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
744 * len (array) |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
745 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
746 static Py_ssize_t |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
747 _pxarray_length(PyPixelArray *array) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
748 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
749 return array->dim0; |
|
852
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 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
753 * array[x] |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
754 */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
755 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
756 _pxarray_item(PyPixelArray *array, Py_ssize_t index) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
757 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
758 if (index < 0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
759 index = array->dim0 - index; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
760 if (index < 0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
761 return RAISE(PyExc_IndexError, "array index out of range"); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
762 } |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
763 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
764 if (index >= array->dim0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
765 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
|
766 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
767 return _pxarray_subscript_internal(array, index, 0, 0, 0, array->dim1, 1); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
768 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
769 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
770 static int |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
771 _array_assign_array(PyPixelArray *array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
772 Py_ssize_t low, Py_ssize_t high, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
773 PyPixelArray *val) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
774 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
775 SDL_Surface *surf = PySurface_AsSurface(array->surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
776 Py_ssize_t dim0 = ABS(high - low); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
777 Py_ssize_t dim1 = array->dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
778 Py_ssize_t stride0 = high >= low ? array->stride0 : -array->stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
779 Py_ssize_t stride1 = array->stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
780 Uint8 *pixels = array->pixels + low * array->stride0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
781 int bpp; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
782 Py_ssize_t val_dim0 = val->dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
783 Py_ssize_t val_dim1 = val->dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
784 Py_ssize_t val_stride0 = val->stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
785 Py_ssize_t val_stride1 = val->stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
786 Uint8 *val_pixels = val->pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
787 SDL_Surface *val_surf = PySurface_AsSurface(val->surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
788 int val_bpp; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
789 Uint8 *pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
790 Uint8 *pixel_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
791 Uint8 *val_pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
792 Uint8 *val_pixel_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
793 Uint8 *copied_pixels = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
794 Py_ssize_t x; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
795 Py_ssize_t y; |
|
2240
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
796 int sizes_match = 0; |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
797 |
|
2240
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
798 /* Broadcast length 1 val dimensions.*/ |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
799 if (val_dim0 == 1) { |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
800 val_dim0 = dim0; |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
801 val_stride0 = 0; |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
802 } |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
803 if (val_dim1 == 1) { |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
804 val_dim1 = dim1; |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
805 val_stride1 = 0; |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
806 } |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
807 |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
808 if (val_dim1) { |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
809 sizes_match = (dim0 == val_dim0 && dim1 == val_dim1); |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
810 } |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
811 else if (dim1) { |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
812 sizes_match = (dim1 == val_dim0); |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
813 } |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
814 else { |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
815 sizes_match = (dim0 == val_dim0); |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
816 } |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
817 if (!sizes_match) { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
818 /* Bounds do not match. */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
819 PyErr_SetString(PyExc_ValueError, "array sizes do not match"); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
820 return -1; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
821 } |
|
2240
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
822 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
823 bpp = surf->format->BytesPerPixel; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
824 val_bpp = val_surf->format->BytesPerPixel; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
825 if (val_bpp != bpp) { |
|
2240
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
826 /* bpp do not match. We cannot guarantee that the padding and columns |
| 959 | 827 * would be set correctly. */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
828 PyErr_SetString(PyExc_ValueError, "bit depths do not match"); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
829 return -1; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
830 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
831 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
832 /* 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
|
833 * first. */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
834 if (SURFACE_EQUALS(array, val)) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
835 /* We assign a different view or so. Copy the source buffer. */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
836 size_t size = val_surf->h * val_surf->pitch; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
837 int val_offset = val_pixels - (Uint8 *)val_surf->pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
838 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
839 copied_pixels = (Uint8 *)malloc(size); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
840 if (!copied_pixels) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
841 PyErr_NoMemory(); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
842 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
843 } |
|
2248
5985bf3a6235
Fix VC compiler errors and warings for pixelarray and pixelcopy (and remove some spaces on empty lines as well)
Lenard Lindstrom <len-l@telus.net>
parents:
2240
diff
changeset
|
844 val_pixels = (Uint8 *)memcpy(copied_pixels, val_surf->pixels, size) + val_offset; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
845 } |
|
2248
5985bf3a6235
Fix VC compiler errors and warings for pixelarray and pixelcopy (and remove some spaces on empty lines as well)
Lenard Lindstrom <len-l@telus.net>
parents:
2240
diff
changeset
|
846 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
847 if (!dim1) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
848 dim1 = 1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
849 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
850 pixelrow = pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
851 val_pixelrow = val_pixels; |
| 959 | 852 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
853 switch (bpp) { |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
854 |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
855 case 1: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
856 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
857 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
858 val_pixel_p = val_pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
859 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
860 *pixel_p = *val_pixel_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
861 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
862 val_pixel_p += val_stride0; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
863 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
864 pixelrow += stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
865 val_pixelrow += val_stride1; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
866 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
867 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
868 case 2: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
869 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
870 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
871 val_pixel_p = val_pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
872 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
873 *((Uint16 *)pixel_p) = *((Uint16 *)val_pixel_p); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
874 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
875 val_pixel_p += val_stride0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
876 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
877 pixelrow += stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
878 val_pixelrow += val_stride1; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
879 } |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
880 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
881 case 3: |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
882 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
883 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
884 Uint32 Roffset = surf->format->Rshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
885 Uint32 Goffset = surf->format->Gshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
886 Uint32 Boffset = surf->format->Bshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
887 Uint32 vRoffset = val_surf->format->Rshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
888 Uint32 vGoffset = val_surf->format->Gshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
889 Uint32 vBoffset = val_surf->format->Bshift >> 3; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
890 #else |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
891 Uint32 Roffset = 2 - surf->format->Rshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
892 Uint32 Goffset = 2 - surf->format->Gshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
893 Uint32 Boffset = 2 - surf->format->Bshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
894 Uint32 vRoffset = 2 - val_surf->format->Rshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
895 Uint32 vGoffset = 2 - val_surf->format->Gshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
896 Uint32 vBoffset = 2 - val_surf->format->Bshift >> 3; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
897 #endif |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
898 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
899 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
900 val_pixel_p = val_pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
901 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
902 pixel_p[Roffset] = val_pixel_p[vRoffset]; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
903 pixel_p[Goffset] = val_pixel_p[vGoffset]; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
904 pixel_p[Boffset] = val_pixel_p[vBoffset]; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
905 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
906 val_pixel_p += val_stride0; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
907 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
908 pixelrow += stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
909 val_pixelrow += val_stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
910 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
911 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
912 break; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
913 default: /* case 4: */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
914 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
915 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
916 val_pixel_p = val_pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
917 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
918 *((Uint32 *)pixel_p) = *((Uint32 *)val_pixel_p); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
919 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
920 val_pixel_p += val_stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
921 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
922 pixelrow += stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
923 val_pixelrow += val_stride1; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
924 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
925 break; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
926 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
927 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
928 if (copied_pixels) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
929 free(copied_pixels); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
930 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
931 return 0; |
|
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 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
934 static int |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
935 _array_assign_sequence(PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
936 PyObject *val) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
937 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
938 SDL_Surface *surf = PySurface_AsSurface(array->surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
939 SDL_PixelFormat *format; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
940 Py_ssize_t dim0 = ABS (high - low); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
941 Py_ssize_t dim1 = array->dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
942 Py_ssize_t stride0 = high >= low ? array->stride0 : -array->stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
943 Py_ssize_t stride1 = array->stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
944 Uint8 *pixels = array->pixels + low * array->stride0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
945 int bpp; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
946 Py_ssize_t val_dim0 = PySequence_Size(val); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
947 Uint32 *val_colors; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
948 Uint8 *pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
949 Uint8 *pixel_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
950 Uint32 *val_color_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
951 Py_ssize_t x; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
952 Py_ssize_t y; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
953 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
954 if (val_dim0 != dim0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
955 PyErr_SetString(PyExc_ValueError, "sequence size mismatch"); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
956 return -1; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
957 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
958 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
959 format = surf->format; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
960 bpp = format->BytesPerPixel; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
961 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
962 if (!dim1) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
963 dim1 = 1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
964 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
965 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
966 /* Copy the values. */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
967 val_colors = malloc(sizeof(Uint32) * val_dim0); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
968 if (!val_colors) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
969 PyErr_NoMemory(); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
970 return -1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
971 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
972 for (x = 0; x < val_dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
973 if (!_get_color_from_object(PySequence_Fast_GET_ITEM(val, x), |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
974 format, (val_colors + x))) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
975 free (val_colors); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
976 return -1; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
977 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
978 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
979 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
980 pixelrow = pixels; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
981 |
| 1001 | 982 Py_BEGIN_ALLOW_THREADS; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
983 switch (bpp) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
984 |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
985 case 1: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
986 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
987 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
988 val_color_p = val_colors; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
989 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
990 *pixel_p = (Uint8)*val_color_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
991 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
992 ++val_color_p; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
993 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
994 pixelrow += stride1; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
995 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
996 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
997 case 2: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
998 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
999 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1000 val_color_p = val_colors; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1001 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1002 *((Uint16 *)pixel_p) = (Uint16)*val_color_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1003 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1004 ++val_color_p; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1005 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1006 pixelrow += stride1; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1007 } |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1008 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1009 case 3: |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1010 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1011 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1012 Uint32 Roffset = surf->format->Rshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1013 Uint32 Goffset = surf->format->Gshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1014 Uint32 Boffset = surf->format->Bshift >> 3; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1015 #else |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1016 Uint32 Roffset = 2 - surf->format->Rshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1017 Uint32 Goffset = 2 - surf->format->Gshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1018 Uint32 Boffset = 2 - surf->format->Bshift >> 3; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1019 #endif |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1020 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1021 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1022 val_color_p = val_colors; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1023 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1024 pixel_p[Roffset] = (Uint8)(*val_color_p >> 16); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1025 pixel_p[Goffset] = (Uint8)(*val_color_p >> 8); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1026 pixel_p[Boffset] = (Uint8)*val_color_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1027 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1028 ++val_color_p; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1029 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1030 pixelrow += stride1; |
| 1166 | 1031 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1032 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1033 break; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1034 default: /* case 4: */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1035 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1036 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1037 val_color_p = val_colors; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1038 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1039 *((Uint32 *)pixel_p) = *val_color_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1040 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1041 ++val_color_p; |
| 1166 | 1042 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1043 pixelrow += stride1; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1044 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1045 break; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1046 } |
| 1001 | 1047 Py_END_ALLOW_THREADS; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1048 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1049 free(val_colors); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1050 return 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1051 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1052 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1053 static int |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1054 _array_assign_slice(PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1055 Uint32 color) |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1056 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1057 SDL_Surface *surf = PySurface_AsSurface(array->surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1058 Py_ssize_t dim0 = ABS (high - low); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1059 Py_ssize_t dim1 = array->dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1060 Py_ssize_t stride0 = high >= low ? array->stride0 : -array->stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1061 Py_ssize_t stride1 = array->stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1062 Uint8 *pixels = array->pixels + low * array->stride0; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1063 int bpp; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1064 Uint8 *pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1065 Uint8 *pixel_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1066 Py_ssize_t x; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1067 Py_ssize_t y; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1068 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1069 bpp = surf->format->BytesPerPixel; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1070 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1071 if (!dim1) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1072 dim1 = 1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1073 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1074 pixelrow = pixels; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1075 |
| 1001 | 1076 Py_BEGIN_ALLOW_THREADS; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1077 switch (bpp) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1078 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1079 case 1: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1080 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1081 Uint8 c = (Uint8)color; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1082 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1083 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1084 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1085 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1086 *pixel_p = c; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1087 pixel_p += stride0; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1088 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1089 pixelrow += stride1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1090 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1091 } |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1092 break; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1093 case 2: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1094 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1095 Uint16 c = (Uint16)color; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1096 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1097 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1098 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1099 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1100 *((Uint16 *)pixel_p) = c; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1101 pixel_p += stride0; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1102 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1103 pixelrow += stride1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1104 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1105 } |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1106 break; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1107 case 3: |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1108 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1109 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1110 Uint32 Roffset = surf->format->Rshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1111 Uint32 Goffset = surf->format->Gshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1112 Uint32 Boffset = surf->format->Bshift >> 3; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1113 #else |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1114 Uint32 Roffset = 2 - surf->format->Rshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1115 Uint32 Goffset = 2 - surf->format->Gshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1116 Uint32 Boffset = 2 - surf->format->Bshift >> 3; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1117 #endif |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1118 Uint8 r = (Uint8)(color >> 16); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1119 Uint8 g = (Uint8)(color >> 8); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1120 Uint8 b = (Uint8)(color); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1121 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1122 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1123 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1124 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1125 pixel_p[Roffset] = r; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1126 pixel_p[Goffset] = g; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1127 pixel_p[Boffset] = b; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1128 pixel_p += stride0; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1129 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1130 pixelrow += stride1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1131 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1132 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1133 break; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1134 default: /* case 4: */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1135 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1136 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1137 for (x = 0; x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1138 *((Uint32 *)pixel_p) = color; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1139 pixel_p += stride0; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1140 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1141 pixelrow += stride1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1142 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1143 break; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1144 } |
| 1001 | 1145 Py_END_ALLOW_THREADS; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1146 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1147 return 0; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1148 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1149 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1150 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1151 * array[x] = ... |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1152 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1153 static int |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1154 _pxarray_ass_item(PyPixelArray *array, Py_ssize_t index, PyObject *value) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1155 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1156 SDL_Surface *surf = PySurface_AsSurface(array->surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1157 Py_ssize_t y = 0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1158 int bpp; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1159 Uint8 *pixels = array->pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1160 Uint8 *pixel_p; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1161 Uint32 color = 0; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1162 Py_ssize_t dim0 = array->dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1163 Py_ssize_t dim1 = array->dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1164 Py_ssize_t stride0 = array->stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1165 Py_ssize_t stride1 = array->stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1166 PyPixelArray *tmparray = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1167 int retval; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1168 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1169 bpp = surf->format->BytesPerPixel; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1170 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1171 if (!_get_color_from_object(value, surf->format, &color)) { |
|
2240
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
1172 if (PyTuple_Check (value)) { |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
1173 return -1; |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
1174 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1175 if (PyPixelArray_Check(value)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1176 PyErr_Clear(); /* _get_color_from_object */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1177 return _array_assign_array(array, index, index + 1, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1178 (PyPixelArray *)value); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1179 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1180 else if (PySequence_Check(value)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1181 PyErr_Clear(); /* _get_color_from_object */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1182 tmparray = (PyPixelArray *) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1183 _pxarray_subscript_internal(array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1184 index, 0, 0, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1185 0, array->dim1, 1); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1186 if (!tmparray) { |
|
2240
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
1187 return -1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1188 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1189 retval = _array_assign_sequence(tmparray, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1190 0, tmparray->dim0, value); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1191 Py_DECREF(tmparray); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1192 return retval; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1193 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1194 else { /* Error already set by _get_color_from_object(). */ |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1195 return -1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1196 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1197 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1198 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1199 if (index < 0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1200 index += dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1201 if (index < 0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1202 PyErr_SetString(PyExc_IndexError, "array index out of range"); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1203 return -1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1204 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1205 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1206 if (index >= dim0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1207 PyErr_SetString(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
|
1208 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1209 pixels += index * stride0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1210 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1211 pixel_p = pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1212 if (!dim1) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1213 dim1 = 1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1214 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1215 |
| 1001 | 1216 Py_BEGIN_ALLOW_THREADS; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1217 /* Single value assignment. */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1218 switch (bpp) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1219 |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1220 case 1: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1221 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1222 *((Uint8 *)pixel_p) = (Uint8)color; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1223 pixel_p += stride1; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1224 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1225 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1226 case 2: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1227 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1228 *((Uint16 *)pixel_p) = (Uint16)color; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1229 pixel_p += stride1; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1230 } |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1231 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1232 case 3: |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1233 { |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1234 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1235 Uint32 Roffset = surf->format->Rshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1236 Uint32 Goffset = surf->format->Gshift >> 3; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1237 Uint32 Boffset = surf->format->Bshift >> 3; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1238 #else |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1239 Uint32 Roffset = 2 - (surf->format->Rshift >> 3); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1240 Uint32 Goffset = 2 - (surf->format->Gshift >> 3); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1241 Uint32 Boffset = 2 - (surf->format->Bshift >> 3); |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1242 #endif |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1243 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1244 pixel_p[Roffset] = (Uint8)(color >> 16); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1245 pixel_p[Goffset] = (Uint8)(color >> 8); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1246 pixel_p[Boffset] = (Uint8)color; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1247 pixel_p += stride1; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1248 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1249 break; |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1250 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1251 default: /* case 4: */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1252 for (y = 0; y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1253 *((Uint32 *)pixel_p) = color; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1254 pixel_p += stride1; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1255 } |
|
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1256 break; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1257 } |
| 1001 | 1258 Py_END_ALLOW_THREADS; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1259 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1260 return 0; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1261 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1262 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1263 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1264 * array[x:y] = .... |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1265 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1266 static int |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1267 _pxarray_ass_slice(PyPixelArray *array, Py_ssize_t low, Py_ssize_t high, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1268 PyObject *value) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1269 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1270 SDL_Surface *surf = PySurface_AsSurface(array->surface); |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1271 Uint32 color; |
| 860 | 1272 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1273 if (low < 0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1274 low = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1275 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1276 else if (low > (Sint32)array->dim0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1277 low = array->dim0; |
| 874 | 1278 } |
|
2248
5985bf3a6235
Fix VC compiler errors and warings for pixelarray and pixelcopy (and remove some spaces on empty lines as well)
Lenard Lindstrom <len-l@telus.net>
parents:
2240
diff
changeset
|
1279 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1280 if (high < low) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1281 high = low; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1282 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1283 else if (high > (Sint32)array->dim0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1284 high = array->dim0; |
| 874 | 1285 } |
| 860 | 1286 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1287 if (PyPixelArray_Check(value)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1288 return _array_assign_array(array, low, high, (PyPixelArray *)value); |
| 959 | 1289 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1290 if (_get_color_from_object(value, surf->format, &color)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1291 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
|
1292 } |
|
2240
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
1293 if (PyTuple_Check (value)) { |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
1294 return -1; |
|
be3228f63883
Make PixelArray more internally consistent
Lenard Lindstrom <len-l@telus.net>
parents:
2234
diff
changeset
|
1295 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1296 PyErr_Clear(); /* In case _get_color_from_object set it */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1297 if (PySequence_Check(value)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1298 return _array_assign_sequence(array, low, high, value); |
| 874 | 1299 } |
| 1300 return 0; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1301 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1302 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1303 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1304 * x in array |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1305 */ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1306 static int |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1307 _pxarray_contains(PyPixelArray *array, PyObject *value) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1308 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1309 SDL_Surface *surf = PySurface_AsSurface(array->surface); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1310 Py_ssize_t dim0 = array->dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1311 Py_ssize_t dim1 = array->dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1312 Py_ssize_t stride0 = array->stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1313 Py_ssize_t stride1 = array->stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1314 Uint8 *pixels = array->pixels; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1315 int bpp; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1316 Uint32 color; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1317 Uint8 *pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1318 Uint8 *pixel_p; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1319 Py_ssize_t x; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1320 Py_ssize_t y; |
| 1001 | 1321 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
|
1322 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1323 bpp = surf->format->BytesPerPixel; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1324 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1325 if (!_get_color_from_object(value, surf->format, &color)) { |
|
867
a249a10980f0
Fixed bufferproxy stringifcation method. Fixed PixelArray's contains() method.
marcus
parents:
866
diff
changeset
|
1326 return -1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1327 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1328 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1329 if (!dim1) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1330 dim1 = 1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1331 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1332 pixelrow = pixels; |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1333 |
| 1001 | 1334 Py_BEGIN_ALLOW_THREADS; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1335 switch (bpp) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1336 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1337 case 1: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1338 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1339 Uint8 c = (Uint8)color; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1340 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1341 for (y = 0; !found && y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1342 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1343 for (x = 0; !found && x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1344 found = *pixel_p == c ? 1 : 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1345 pixel_p += stride0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1346 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1347 pixelrow += stride1; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1348 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1349 } |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1350 break; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1351 case 2: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1352 { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1353 Uint16 c = (Uint16)color; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1354 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1355 for (y = 0; !found && y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1356 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1357 for (x = 0; !found && x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1358 found = *((Uint16 *)pixel_p) == c ? 1 : 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1359 pixel_p += stride0; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1360 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1361 pixelrow += stride1; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1362 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1363 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1364 break; |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1365 case 3: |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1366 for (y = 0; !found && y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1367 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1368 for (x = 0; !found && x < dim0; ++x) { |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1369 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1370 found = (((Uint32)pixel_p[0]) + |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1371 ((Uint32)pixel_p[1] << 8) + |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1372 ((Uint32)pixel_p[2] << 16) ) == color; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1373 #else |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1374 found = (((Uint32)pixel_p[2]) + |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1375 ((Uint32)pixel_p[1] << 8) + |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1376 ((Uint32)pixel_p[0] << 16) ) == color; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1377 #endif |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1378 pixel_p += stride0; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1379 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1380 pixelrow += stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1381 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1382 break; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1383 default: /* case 4: */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1384 for (y = 0; !found && y < dim1; ++y) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1385 pixel_p = pixelrow; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1386 for (x = 0; !found && x < dim0; ++x) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1387 found = *((Uint32 *)pixel_p) == color ? 1 : 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1388 pixel_p += stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1389 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1390 pixelrow += stride1; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1391 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1392 break; |
|
865
965348e5286c
Added 24-bit support to PixelArray class. Fixed 8 and 16-bit support.
marcus
parents:
860
diff
changeset
|
1393 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1394 Py_END_ALLOW_THREADS; |
| 1001 | 1395 |
| 1396 return found; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1397 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1398 |
| 988 | 1399 |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1400 /**** Mapping interfaces ****/ |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1401 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1402 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1403 * 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
|
1404 * array[x,y], array[:,:], ... |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1405 */ |
| 960 | 1406 static int |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1407 _get_subslice(PyObject *op, Py_ssize_t length, Py_ssize_t *start, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1408 Py_ssize_t *stop, Py_ssize_t *step) |
| 960 | 1409 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1410 /* Special case: return step as 0 for an integer op. |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1411 */ |
| 960 | 1412 *start = -1; |
| 1413 *stop = -1; | |
| 1414 *step = -1; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1415 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1416 if (PySlice_Check(op)) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1417 Py_ssize_t slicelen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1418 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1419 /* Operator is a slice: array[x::, */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1420 if (Slice_GET_INDICES_EX(op, length, start, stop, step, &slicelen)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1421 return -1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1422 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1423 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1424 else if (PyInt_Check(op)) { |
| 960 | 1425 /* Plain index: array[x, */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1426 *start = PyInt_AsLong(op); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1427 if (*start < 0) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1428 *start += length; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1429 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1430 if (*start >= length || *start < 0) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1431 PyErr_SetString(PyExc_IndexError, "invalid index"); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1432 return -1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1433 } |
| 960 | 1434 *stop = (*start) + 1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1435 *step = 0; |
| 960 | 1436 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1437 else if (PyLong_Check(op)) { |
| 960 | 1438 long long val = -1; |
| 1439 /* Plain index: array[x, */ | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1440 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1441 val = PyLong_AsLong(op); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1442 if ((val < INT_MIN) || (val > INT_MAX)) { |
| 960 | 1443 PyErr_SetString(PyExc_ValueError, |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1444 "index too big for array access"); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1445 return -1; |
| 960 | 1446 } |
| 1447 *start = (int) val; | |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1448 if (*start < 0) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1449 *start += length; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1450 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1451 if (*start >= length || *start < 0) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1452 PyErr_SetString(PyExc_IndexError, "invalid index"); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1453 return -1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1454 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1455 *stop = (*start) + 1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1456 *step = 0; |
| 960 | 1457 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1458 /* No errors. */ |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1459 return 0; |
| 960 | 1460 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1461 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1462 /** |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1463 * 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
|
1464 * 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
|
1465 */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1466 static PyObject * |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1467 _pxarray_subscript(PyPixelArray *array, PyObject *op) |
| 960 | 1468 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1469 Py_ssize_t dim0 = array->dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1470 Py_ssize_t dim1 = array->dim1; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1471 |
| 960 | 1472 /* Note: order matters here. |
| 1473 * First check array[x,y], then array[x:y:z], then array[x] | |
| 1474 * Otherwise it'll fail. | |
| 1475 */ | |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1476 if (PySequence_Check(op)) { |
| 960 | 1477 PyObject *obj; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1478 Py_ssize_t size = PySequence_Size(op); |
| 960 | 1479 Py_ssize_t xstart, xstop, xstep; |
| 1480 Py_ssize_t ystart, ystop, ystep; | |
|
2248
5985bf3a6235
Fix VC compiler errors and warings for pixelarray and pixelcopy (and remove some spaces on empty lines as well)
Lenard Lindstrom <len-l@telus.net>
parents:
2240
diff
changeset
|
1481 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1482 if (size == 0) { |
| 960 | 1483 /* array[,], array[()] ... */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1484 Py_INCREF(array); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1485 return (PyObject *)array; |
| 960 | 1486 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1487 if (size > 2 || (size == 2 && !dim1)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1488 return RAISE(PyExc_IndexError, "too many indices for the array"); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1489 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1490 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1491 obj = PySequence_Fast_GET_ITEM(op, 0); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1492 if (obj == Py_Ellipsis || obj == Py_None) { |
| 960 | 1493 /* Operator is the ellipsis or None |
| 1494 * array[...,XXX], array[None,XXX] | |
| 1495 */ | |
|
976
a9b65f86052c
Fixed reference counting issues in PixelArray. Improved loops, indices and positioning in PixelArray.
marcus
parents:
971
diff
changeset
|
1496 xstart = 0; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1497 xstop = dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1498 xstep = 1; |
| 960 | 1499 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1500 else if (_get_subslice(obj, dim0, &xstart, &xstop, &xstep)) { |
| 960 | 1501 /* Error on retrieving the subslice. */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1502 return 0; |
| 960 | 1503 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1504 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1505 if (size == 2) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1506 obj = PySequence_Fast_GET_ITEM(op, 1); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1507 if (obj == Py_Ellipsis || obj == Py_None) { |
| 960 | 1508 /* Operator is the ellipsis or None |
| 1509 * array[XXX,...], array[XXX,None] | |
| 1510 */ | |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1511 ystart = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1512 ystop = dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1513 ystep = 1; |
| 960 | 1514 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1515 else if (_get_subslice(obj, dim1, &ystart, &ystop, &ystep)) { |
| 960 | 1516 /* Error on retrieving the subslice. */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1517 return 0; |
| 960 | 1518 } |
| 1519 } | |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1520 else { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1521 ystart = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1522 ystop = dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1523 ystep = 1; |
| 960 | 1524 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1525 |
| 960 | 1526 /* Null value? */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1527 if (xstart == xstop || ystart == ystop) { |
| 960 | 1528 Py_RETURN_NONE; |
| 1529 } | |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1530 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1531 return _pxarray_subscript_internal(array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1532 xstart, xstop, xstep, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1533 ystart, ystop, ystep); |
| 960 | 1534 } |
|
2219
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1535 else if (op == Py_Ellipsis) { |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1536 Py_INCREF(array); |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1537 return (PyObject *)array; |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1538 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1539 else if (PySlice_Check(op)) { |
| 960 | 1540 /* A slice */ |
| 1541 Py_ssize_t slicelen; | |
| 1542 Py_ssize_t step; | |
| 1543 Py_ssize_t start; | |
| 1544 Py_ssize_t stop; | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1545 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1546 if (Slice_GET_INDICES_EX(op, dim0, &start, &stop, &step, &slicelen)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1547 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1548 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1549 if (slicelen < 0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1550 return RAISE(PyExc_IndexError, "Unable to handle negative slice"); |
| 960 | 1551 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1552 if (slicelen == 0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1553 Py_RETURN_NONE; |
| 960 | 1554 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1555 return _pxarray_subscript_internal(array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1556 start, stop, step, 0, dim1, 1); |
| 960 | 1557 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1558 else if (PyIndex_Check(op) || PyInt_Check(op) || PyLong_Check(op)) { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1559 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
|
1560 #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
|
1561 PyObject *val = PyNumber_Index (op); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1562 if (!val) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1563 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1564 } |
| 960 | 1565 /* A simple index. */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1566 i = PyNumber_AsSsize_t(val, PyExc_IndexError); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1567 #else |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1568 i = PyInt_Check(op) ? PyInt_AsLong(op) : PyLong_AsLong(op); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1569 #endif |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1570 if (i == -1 && PyErr_Occurred()) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1571 return 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1572 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1573 if (i < 0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1574 i += dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1575 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1576 if (i < 0 || i >= dim0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1577 return RAISE(PyExc_IndexError, "array index out of range"); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1578 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1579 return _pxarray_subscript_internal(array, i, i + 1, 0, 0, dim1, 1); |
| 960 | 1580 } |
| 1581 | |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1582 return RAISE(PyExc_TypeError, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1583 "index must be an integer, sequence or slice"); |
| 960 | 1584 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1585 |
| 960 | 1586 static int |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1587 _pxarray_ass_subscript(PyPixelArray *array, PyObject* op, PyObject* value) |
| 960 | 1588 { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1589 /* 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
|
1590 * temporary subarrays. |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1591 */ |
|
2300
a76f2f499bbe
Fixes some array interface related crashes and test failures on the amd64 platform(win and osx). Thanks Christoph Gohlke.
Rene Dudfield <renesd@gmail.com>
parents:
2248
diff
changeset
|
1592 Py_ssize_t dim0 = array->dim0; |
|
a76f2f499bbe
Fixes some array interface related crashes and test failures on the amd64 platform(win and osx). Thanks Christoph Gohlke.
Rene Dudfield <renesd@gmail.com>
parents:
2248
diff
changeset
|
1593 Py_ssize_t dim1 = array->dim1; |
| 960 | 1594 |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1595 /* Note: order matters here. |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1596 * 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
|
1597 * Otherwise it'll fail. |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1598 */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1599 if (PySequence_Check(op)) |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1600 { |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1601 PyPixelArray *tmparray; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1602 PyObject *obj; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1603 Py_ssize_t size = PySequence_Size(op); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1604 Py_ssize_t xstart, xstop, xstep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1605 Py_ssize_t ystart, ystop, ystep; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1606 int retval; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1607 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1608 if (size > 2 || (size == 2 && !dim1)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1609 PyErr_SetString(PyExc_IndexError, "too many indices for the array"); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1610 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1611 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1612 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1613 obj = PySequence_Fast_GET_ITEM(op, 0); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1614 if (obj == Py_Ellipsis || obj == Py_None) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1615 /* Operator is the ellipsis or None |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1616 * array[...,XXX], array[None,XXX] |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1617 */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1618 xstart = 0; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1619 xstop = dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1620 xstep = 1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1621 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1622 else if (_get_subslice(obj, dim0, &xstart, &xstop, &xstep)) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1623 /* Error on retrieving the subslice. */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1624 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1625 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1626 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1627 if (size == 2) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1628 obj = PySequence_Fast_GET_ITEM(op, 1); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1629 if (obj == Py_Ellipsis || obj == Py_None) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1630 /* Operator is the ellipsis or None |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1631 * array[XXX,...], array[XXX,None] |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1632 */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1633 ystart = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1634 ystop = dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1635 ystep = 1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1636 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1637 else if (_get_subslice(obj, dim1, &ystart, &ystop, &ystep)) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1638 /* Error on retrieving the subslice. */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1639 return -1; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1640 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1641 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1642 else { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1643 ystart = 0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1644 ystop = dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1645 ystep = 1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1646 } |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1647 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1648 /* Null value? Do nothing then. */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1649 if (xstart == xstop || ystart == ystop) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1650 return 0; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1651 } |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1652 |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1653 /* Single value? */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1654 if (ABS(xstop - xstart) == 1 && ABS(ystop - ystart) == 1) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1655 tmparray = (PyPixelArray *) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1656 _pxarray_subscript_internal(array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1657 xstart, xstart + 1, 1, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1658 ystart, ystart + 1, 1); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1659 if (!tmparray) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1660 return -1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1661 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1662 retval = _pxarray_ass_item(tmparray, 0, value); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1663 Py_DECREF(tmparray); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1664 return retval; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1665 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1666 tmparray = (PyPixelArray *) |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1667 _pxarray_subscript_internal(array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1668 xstart, xstop, xstep, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1669 ystart, ystop, ystep); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1670 if (!tmparray) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1671 return -1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1672 } |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1673 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1674 retval = _pxarray_ass_slice(tmparray, 0, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1675 (Py_ssize_t)tmparray->dim0, value); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1676 Py_DECREF(tmparray); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1677 return retval; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1678 } |
|
2219
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1679 else if (op == Py_Ellipsis) { |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1680 /* A slice */ |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1681 PyPixelArray *tmparray = |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1682 (PyPixelArray *) _pxarray_subscript_internal(array, |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1683 0, array->dim0, 1, |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1684 0, array->dim1, 1); |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1685 int retval; |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1686 |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1687 if (!tmparray) { |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1688 return -1; |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1689 } |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1690 |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1691 retval = _pxarray_ass_slice(tmparray, 0, |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1692 (Py_ssize_t)tmparray->dim0, value); |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1693 Py_DECREF(tmparray); |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1694 return retval; |
|
12d56393ec02
Allow [...] as a valid PixelArray subscript, consistent with NumPy
Lenard Lindstrom <len-l@telus.net>
parents:
2218
diff
changeset
|
1695 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1696 else if (PySlice_Check(op)) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1697 /* A slice */ |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1698 PyPixelArray *tmparray; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1699 Py_ssize_t slicelen; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1700 Py_ssize_t step; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1701 Py_ssize_t start; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1702 Py_ssize_t stop; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1703 int retval; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1704 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1705 if (Slice_GET_INDICES_EX(op, array->dim0, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1706 &start, &stop, &step, &slicelen)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1707 return -1; |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1708 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1709 if (slicelen < 0) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1710 PyErr_SetString(PyExc_IndexError, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1711 "Unable to handle negative slice"); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1712 return -1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1713 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1714 if (slicelen == 0) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1715 return 0; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1716 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1717 tmparray = (PyPixelArray *)_array_slice_internal(array, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1718 start, stop, step); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1719 if (!tmparray) { |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1720 return -1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1721 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1722 retval = _pxarray_ass_slice(tmparray, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1723 0, (Py_ssize_t)tmparray->dim0, value); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1724 Py_DECREF(tmparray); |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1725 return retval; |
|
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1726 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1727 else if (PyIndex_Check(op) || PyInt_Check(op) || PyLong_Check(op)) { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1728 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
|
1729 #if PY_VERSION_HEX >= 0x02050000 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1730 PyObject *val = PyNumber_Index(op); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1731 if (!val) { |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1732 return -1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1733 } |
| 960 | 1734 /* A simple index. */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1735 i = PyNumber_AsSsize_t(val, PyExc_IndexError); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1736 #else |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1737 i = PyInt_Check(op) ? PyInt_AsLong (op) : PyLong_AsLong (op); |
|
971
68793bdcb85f
Changed various PixelArray loops for mappings. Fixed 2.4 compatibility issues introduced with rev. 1153.
marcus
parents:
960
diff
changeset
|
1738 #endif |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1739 if (i == -1 && PyErr_Occurred()) { |
| 960 | 1740 return -1; |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1741 } |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1742 return _pxarray_ass_item(array, i, value); |
| 960 | 1743 } |
|
982
2c37905a2091
Added subscript support and make_surface() method to PixelArray.
marcus
parents:
976
diff
changeset
|
1744 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1745 PyErr_SetString(PyExc_TypeError, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1746 "index must be an integer, sequence or slice"); |
| 960 | 1747 return -1; |
| 1748 } | |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1749 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1750 |
| 860 | 1751 /**** C API interfaces ****/ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1752 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
|
1753 { |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1754 SDL_Surface *surf; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1755 Py_ssize_t dim0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1756 Py_ssize_t dim1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1757 Py_ssize_t stride0; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1758 Py_ssize_t stride1; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1759 Uint8 *pixels; |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1760 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1761 if (!PySurface_Check(surfobj)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1762 return RAISE(PyExc_TypeError, "argument is no a Surface"); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1763 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1764 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1765 surf = PySurface_AsSurface(surfobj); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1766 dim0 = (Py_ssize_t)surf->w; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1767 dim1 = (Py_ssize_t)surf->h; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1768 stride0 = (Py_ssize_t)surf->format->BytesPerPixel; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1769 stride1 = (Py_ssize_t)surf->pitch; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1770 pixels = surf->pixels; |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1771 if (stride0 < 1 || stride0 > 4) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1772 return RAISE(PyExc_ValueError, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1773 "unsupported bit depth for reference array"); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1774 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1775 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1776 return (PyObject *)_pxarray_new_internal(&PyPixelArray_Type, surfobj, 0, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1777 pixels, |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1778 dim0, dim1, stride0, stride1); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1779 } |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1780 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1781 |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1782 MODINIT_DEFINE(pixelarray) |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1783 { |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1784 PyObject *module; |
| 860 | 1785 PyObject *apiobj; |
| 1786 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
|
1787 |
|
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
|
1788 #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
|
1789 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
|
1790 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
|
1791 "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
|
1792 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
|
1793 -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
|
1794 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
|
1795 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
|
1796 }; |
|
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
|
1797 #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
|
1798 |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1168
diff
changeset
|
1799 /* 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
|
1800 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
|
1801 */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1802 import_pygame_base(); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1803 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
|
1804 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
|
1805 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1168
diff
changeset
|
1806 import_pygame_color(); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1807 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
|
1808 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
|
1809 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1810 import_pygame_surface(); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1811 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
|
1812 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
|
1813 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1168
diff
changeset
|
1814 |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1168
diff
changeset
|
1815 /* type preparation */ |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1816 if (PyType_Ready(&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
|
1817 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
|
1818 } |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1819 |
|
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1820 /* 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
|
1821 #if PY3 |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1822 module = PyModule_Create(&_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
|
1823 #else |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1824 module = Py_InitModule3(MODPREFIX "pixelarray", 0, 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
|
1825 #endif |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1826 if (!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
|
1827 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
|
1828 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1829 Py_INCREF(&PyPixelArray_Type); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1830 if (PyModule_AddObject(module, "PixelArray", |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1831 (PyObject *)&PyPixelArray_Type)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1832 Py_DECREF((PyObject *)&PyPixelArray_Type); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1833 DECREF_MOD(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
|
1834 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
|
1835 } |
|
1011
61a09a2965b0
_Really_ fixed 24bpp access for pygame.surfarray.pixels3d().
marcus
parents:
1009
diff
changeset
|
1836 PyPixelArray_Type.tp_getattro = PyObject_GenericGetAttr; |
| 860 | 1837 |
| 1838 c_api[0] = &PyPixelArray_Type; | |
| 1839 c_api[1] = PyPixelArray_New; | |
|
2120
42e2bde1a12c
Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1840 apiobj = encapsulate_api (c_api, "pixelarray"); |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1841 if (apiobj == NULL) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1842 DECREF_MOD(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
|
1843 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
|
1844 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1845 if (PyModule_AddObject(module, PYGAMEAPI_LOCAL_ENTRY, apiobj)) { |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1846 Py_DECREF(apiobj); |
|
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1847 DECREF_MOD(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
|
1848 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
|
1849 } |
|
2218
7b81f1162a96
Add an array struct interface and the ndim, itemsize, shape, strides, and _pixels_address properties.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
1850 MODINIT_RETURN(module); |
|
852
4db78800a93a
A PixelArray class, which is meant to replace surfarray.
Rene Dudfield <renesd@gmail.com>
parents:
diff
changeset
|
1851 } |
