annotate src/pixelcopy.c @ 3172:d1b367fc08bc tests-returncode

Use a return code of 1 when the tests fail.
author Thomas Kluyver <takowl@gmail.com>
date Wed, 09 Jan 2013 10:13:57 +0000
parents 841b902f3d15
children 9fcb7abf3185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1 /*
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
2 pygame - Python Game Library
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
3 Copyright (C) 2000-2001 Pete Shinners
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
4
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
9
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
13 Library General Public License for more details.
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
14
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
16 License along with this library; if not, write to the Free
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
18
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
19 Pete Shinners
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
20 pete@shinners.org
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
21 */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
22
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
23 #include <stddef.h>
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
24 #include "pygame.h"
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
25 #include "pgcompat.h"
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
26 #include "doc/pixelcopy_doc.h"
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
27 #include "pgarrinter.h"
3014
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
28 #include "pgview.h"
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
29 #include <SDL_byteorder.h>
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
30
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
31 #if !defined(DOC_PYGAMEBLITARRAY)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
32 #define DOC_PYGAMEBLITARRAY DOC_PYGAMESURFARRAYBLITARRAY
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
33 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
34 #if !defined(DOC_PYGAMECOPYSURFACE)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
35 #define DOC_PYGAMECOPYSURFACE "Copy surface pixels to an array object"
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
36 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
37
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
38 typedef enum {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
39 VIEWKIND_RED,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
40 VIEWKIND_GREEN,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
41 VIEWKIND_BLUE,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
42 VIEWKIND_ALPHA,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
43 VIEWKIND_COLORKEY,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
44 VIEWKIND_RGB
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
45 } _pc_view_kind_t;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
46
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
47 typedef union {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
48 Uint32 value;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
49 Uint8 bytes[sizeof(Uint32)];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
50 } _pc_pixel_t;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
51
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
52 static int
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
53 _view_kind(PyObject *obj, void *view_kind_vptr)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
54 {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
55 unsigned long ch;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
56 _pc_view_kind_t *view_kind_ptr = (_pc_view_kind_t *)view_kind_vptr;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
57
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
58 if (PyUnicode_Check(obj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
59 if (PyUnicode_GET_SIZE(obj) != 1) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
60 PyErr_SetString(PyExc_TypeError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
61 "expected a length 1 string for argument 3");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
62 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
63 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
64 ch = *PyUnicode_AS_UNICODE(obj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
65 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
66 else if (Bytes_Check(obj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
67 if (Bytes_GET_SIZE(obj) != 1) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
68 PyErr_SetString(PyExc_TypeError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
69 "expected a length 1 string for argument 3");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
70 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
71 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
72 ch = *Bytes_AS_STRING(obj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
73 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
74 else {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
75 PyErr_Format(PyExc_TypeError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
76 "expected a length one string for argument 3: got '%s'",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
77 Py_TYPE(obj)->tp_name);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
78 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
79 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
80 switch (ch) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
81
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
82 case 'R':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
83 case 'r':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
84 *view_kind_ptr = VIEWKIND_RED;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
85 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
86 case 'G':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
87 case 'g':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
88 *view_kind_ptr = VIEWKIND_GREEN;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
89 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
90 case 'B':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
91 case 'b':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
92 *view_kind_ptr = VIEWKIND_BLUE;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
93 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
94 case 'A':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
95 case 'a':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
96 *view_kind_ptr = VIEWKIND_ALPHA;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
97 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
98 case 'C':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
99 case 'c':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
100 *view_kind_ptr = VIEWKIND_COLORKEY;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
101 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
102 case 'P':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
103 case 'p':
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
104 *view_kind_ptr = VIEWKIND_RGB;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
105 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
106 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
107 PyErr_Format(PyExc_TypeError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
108 "unrecognized view kind '%c' for argument 3", (int)ch);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
109 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
110 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
111 return 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
112 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
113
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
114 static int
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
115 _copy_mapped(PyArrayInterface *inter, SDL_Surface *surf)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
116 {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
117 int pixelsize = surf->format->BytesPerPixel;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
118 int intsize = inter->itemsize;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
119 char *src = (char *)surf->pixels;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
120 char *dst = (char *)inter->data;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
121 int w = surf->w;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
122 int h = surf->h;
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
123 Py_intptr_t dx_src = surf->format->BytesPerPixel;
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
124 Py_intptr_t dy_src = surf->pitch;
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
125 Py_intptr_t dz_src = 1;
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
126 Py_intptr_t dx_dst = inter->strides[0];
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
127 Py_intptr_t dy_dst = inter->strides[1];
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
128 Py_intptr_t dz_dst = 1;
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
129 Py_intptr_t x, y, z;
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
130
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
131 if (inter->shape[0] != w || inter->shape[1] != h) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
132 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
133 "Expected a (%d, %d) target: got (%d, %d)",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
134 w, h, (int)inter->shape[0], (int)inter->shape[1]);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
135 return -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
136 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
137 if (intsize < pixelsize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
138 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
139 "Expected at least a target byte size of %d: got %d",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
140 pixelsize, intsize);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
141 return -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
142 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
143 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
144 if (!(inter->flags & PAI_NOTSWAPPED)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
145 dst += intsize - 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
146 dz_dst = -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
147 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
148 #else
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
149 if (inter->flags & PAI_NOTSWAPPED) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
150 dst += intsize - 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
151 dz_dst = -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
152 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
153 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
154 for (x = 0; x < w; ++x) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
155 for (y = 0; y < h; ++y) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
156 for (z = 0; z < pixelsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
157 dst[dx_dst * x + dy_dst * y + dz_dst * z] =
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
158 src[dx_src * x + dy_src * y + dz_src * z];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
159 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
160 while (z < intsize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
161 dst[dx_dst * x + dy_dst * y + dz_dst * z] = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
162 ++z;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
163 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
164 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
165 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
166
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
167 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
168 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
169
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
170 static int
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
171 _copy_colorplane(PyArrayInterface *inter,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
172 SDL_Surface *surf,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
173 _pc_view_kind_t view_kind,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
174 Uint8 opaque,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
175 Uint8 clear)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
176 {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
177 SDL_PixelFormat *format = surf->format;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
178 int pixelsize = surf->format->BytesPerPixel;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
179 Uint32 flags = surf->flags;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
180 int intsize = inter->itemsize;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
181 char *src = (char *)surf->pixels;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
182 char *dst = (char *)inter->data;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
183 int w = surf->w;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
184 int h = surf->h;
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
185 Py_intptr_t dx_src = surf->format->BytesPerPixel;
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
186 Py_intptr_t dy_src = surf->pitch;
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
187 Py_intptr_t dx_dst = inter->strides[0];
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
188 Py_intptr_t dy_dst = inter->strides[1];
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
189 Py_intptr_t dz_dst = 1;
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
190 Py_intptr_t dz_pix;
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
191 Py_intptr_t x, y, z;
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
192 Uint8 r, g, b, a;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
193 Uint8 *element;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
194 _pc_pixel_t pixel = { 0 };
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
195 Uint32 colorkey;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
196
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
197 if (inter->shape[0] != w || inter->shape[1] != h) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
198 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
199 "Expected a (%d, %d) target: got (%d, %d)",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
200 w, h, (int)inter->shape[0], (int)inter->shape[1]);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
201 return -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
202 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
203 if (intsize < 1) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
204 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
205 "Expected at least a target byte size of 1: got %d",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
206 intsize);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
207 return -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
208 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
209 switch (view_kind) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
210 case VIEWKIND_RED:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
211 element = &r;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
212 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
213 case VIEWKIND_GREEN:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
214 element = &g;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
215 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
216 case VIEWKIND_BLUE:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
217 element = &b;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
218 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
219 case VIEWKIND_ALPHA:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
220 element = &a;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
221 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
222 case VIEWKIND_COLORKEY:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
223 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
224 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
225 PyErr_Format(PyExc_SystemError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
226 "pygame bug in _copy_colorplane: unknown view kind %d",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
227 (int)view_kind);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
228 return -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
229 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
230 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
231 dz_pix = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
232 if (!(inter->flags & PAI_NOTSWAPPED)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
233 dst += intsize - 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
234 dz_dst = -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
235 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
236 #else
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
237 dz_pix = (unsigned)(sizeof(Uint32) - pixelsize - 1);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
238 if (inter->flags & PAI_NOTSWAPPED) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
239 dst += intsize - 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
240 dz_dst = -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
241 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
242 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
243 if (view_kind == VIEWKIND_COLORKEY && flags & SDL_SRCCOLORKEY) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
244 colorkey = format->colorkey;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
245 for (x = 0; x < w; ++x) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
246 for (y = 0; y < h; ++y) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
247 for (z = 0; z < pixelsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
248 pixel.bytes[dz_pix + z] = src[dx_src * x + dy_src * y + z];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
249 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
250 dst[dx_dst * x + dy_dst * y] =
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
251 pixel.value == colorkey ? clear : opaque;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
252 for (z = 1; z < intsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
253 dst[dx_dst * x + dy_dst * y + dz_dst * z] = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
254 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
255 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
256 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
257 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
258 else if ((view_kind != VIEWKIND_COLORKEY) &&
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
259 (view_kind != VIEWKIND_ALPHA || flags & SDL_SRCALPHA)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
260 for (x = 0; x < w; ++x) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
261 for (y = 0; y < h; ++y) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
262 for (z = 0; z < pixelsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
263 pixel.bytes[dz_pix + z] = src[dx_src * x + dy_src * y + z];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
264 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
265 SDL_GetRGBA(pixel.value, format, &r, &g, &b, &a);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
266 dst[dx_dst * x + dy_dst * y] = *element;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
267 for (z = 1; z < intsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
268 dst[dx_dst * x + dy_dst * y + dz_dst * z] = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
269 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
270 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
271 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
272 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
273 else {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
274 for (x = 0; x < w; ++x) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
275 for (y = 0; y < h; ++y) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
276 dst[dx_dst * x + dy_dst * y] = opaque;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
277 for (z = 1; z < intsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
278 dst[dx_dst * x + dy_dst * y + dz_dst * z] = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
279 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
280 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
281 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
282 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
283
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
284 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
285 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
286
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
287 static int
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
288 _copy_unmapped(PyArrayInterface *inter, SDL_Surface *surf)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
289 {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
290 SDL_PixelFormat *format = surf->format;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
291 int pixelsize = surf->format->BytesPerPixel;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
292 int intsize = inter->itemsize;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
293 char *src = (char *)surf->pixels;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
294 char *dst = (char *)inter->data;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
295 int w = surf->w;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
296 int h = surf->h;
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
297 Py_intptr_t dx_src = surf->format->BytesPerPixel;
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
298 Py_intptr_t dy_src = surf->pitch;
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
299 Py_intptr_t dx_dst = inter->strides[0];
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
300 Py_intptr_t dy_dst = inter->strides[1];
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
301 Py_intptr_t dp_dst = inter->strides[2];
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
302 Py_intptr_t dz_dst = 1;
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
303 Py_intptr_t dz_pix;
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
304 Py_intptr_t x, y, z;
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
305 _pc_pixel_t pixel = { 0 };
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
306 Uint8 r, g, b;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
307
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
308 if (inter->shape[0] != w ||
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
309 inter->shape[1] != h ||
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
310 inter->shape[2] != 3 ) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
311 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
312 "Expected a (%d, %d, 3) target: got (%d, %d, %d)",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
313 w, h,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
314 (int)inter->shape[0],
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
315 (int)inter->shape[1],
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
316 (int)inter->shape[2]);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
317 return -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
318 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
319 if (intsize < 1) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
320 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
321 "Expected at least a target byte size of 1: got %d",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
322 intsize);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
323 return -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
324 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
325 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
326 dz_pix = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
327 if (!(inter->flags & PAI_NOTSWAPPED)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
328 dst += intsize - 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
329 dz_dst = -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
330 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
331 #else
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
332 dz_pix = (unsigned)(sizeof(Uint32) - pixelsize - 1);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
333 if (inter->flags & PAI_NOTSWAPPED) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
334 dst += intsize - 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
335 dz_dst = -1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
336 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
337 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
338 for (x = 0; x < w; ++x) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
339 for (y = 0; y < h; ++y) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
340 for (z = 0; z < pixelsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
341 pixel.bytes[dz_pix + z] = src[dx_src * x + dy_src * y + z];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
342 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
343 SDL_GetRGB(pixel.value, format, &r, &g, &b);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
344 dst[dx_dst * x + dy_dst * y] = r;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
345 for (z = 1; z < intsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
346 dst[dx_dst * x + dy_dst * y + dz_dst * z] = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
347 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
348 dst[dx_dst * x + dy_dst * y + dp_dst] = g;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
349 for (z = 1; z < intsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
350 dst[dx_dst * x + dy_dst * y + dz_dst * z] = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
351 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
352 dst[dx_dst * x + dy_dst * y + 2 * dp_dst] = b;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
353 for (z = 1; z < intsize; ++z) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
354 dst[dx_dst * x + dy_dst * y + dz_dst * z] = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
355 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
356 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
357 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
358
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
359 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
360 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
361
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
362 /*macros used to blit arrays*/
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
363 #define COPYMACRO_2D(DST, SRC) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
364 for (loopy = 0; loopy < sizey; ++loopy) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
365 { \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
366 DST* imgrow = (DST*)(((char*)surf->pixels)+loopy*surf->pitch); \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
367 Uint8* datarow = (Uint8*)array_data + stridey * loopy; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
368 for (loopx = 0; loopx < sizex; ++loopx) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
369 *(imgrow + loopx) = (DST)*(SRC*)(datarow + stridex * loopx); \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
370 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
371
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
372 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
373 #define COPYMACRO_2D_24_PIXEL(pix, data, SRC) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
374 *pix++ = *data; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
375 *pix++ = *(data + 1); \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
376 *pix++ = *(data + 2);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
377 #else
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
378 #define COPYMACRO_2D_24_PIXEL(pix, data, SRC) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
379 *pix++ = *(data + sizeof (SRC) - 1); \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
380 *pix++ = *(data + sizeof (SRC) - 2); \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
381 *pix++ = *(data + sizeof (SRC) - 3);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
382 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
383
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
384 #define COPYMACRO_2D_24(SRC) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
385 for (loopy = 0; loopy < sizey; ++loopy) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
386 { \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
387 Uint8 *pix = ((Uint8 *)surf->pixels) + loopy * surf->pitch; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
388 Uint8 *data = (Uint8 *)array_data + stridey * loopy; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
389 Uint8 *end = pix + 3 * sizex; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
390 while (pix != end) { \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
391 COPYMACRO_2D_24_PIXEL(pix, data, SRC) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
392 data += stridex; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
393 } \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
394 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
395
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
396 #define COPYMACRO_3D(DST, SRC) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
397 for (loopy = 0; loopy < sizey; ++loopy) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
398 { \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
399 DST *pix = (DST *)(((char *)surf->pixels) + surf->pitch * loopy); \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
400 char *data = array_data + stridey * loopy; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
401 for (loopx = 0; loopx < sizex; ++loopx) { \
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: 2203
diff changeset
402 *pix++ = (DST)((*(SRC *)(data) >> Rloss << Rshift) | \
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
403 (*(SRC *)(data+stridez) >> Gloss << Gshift) | \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
404 (*(SRC *)(data+stridez2) >> Bloss << Bshift) | \
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: 2203
diff changeset
405 alpha); \
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
406 data += stridex; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
407 } \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
408 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
409
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
410 #define COPYMACRO_3D_24(SRC) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
411 for (loopy = 0; loopy < sizey; ++loopy) \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
412 { \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
413 Uint8 *pix = ((Uint8*)surf->pixels) + surf->pitch * loopy; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
414 Uint8 *data = (Uint8*)array_data + stridey * loopy; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
415 Uint8 *end = pix + 3 * sizex; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
416 while (pix != end) { \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
417 *pix++ = (Uint8)*(SRC*)(data + stridez_0); \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
418 *pix++ = (Uint8)*(SRC*)(data + stridez_1); \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
419 *pix++ = (Uint8)*(SRC*)(data + stridez_2); \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
420 data += stridex; \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
421 } \
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
422 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
423
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
424 static PyObject*
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
425 array_to_surface(PyObject *self, PyObject *arg)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
426 {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
427 PyObject *surfobj, *arrayobj;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
428 PyObject *cobj;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
429 PyArrayInterface *inter;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
430 char *array_data;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
431 SDL_Surface* surf;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
432 SDL_PixelFormat* format;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
433 int loopx, loopy;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
434 int stridex, stridey, stridez=0, stridez2=0, sizex, sizey;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
435 int Rloss, Gloss, Bloss, Rshift, Gshift, Bshift;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
436
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
437 if (!PyArg_ParseTuple(arg, "O!O", &PySurface_Type, &surfobj, &arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
438 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
439 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
440 surf = PySurface_AsSurface(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
441 format = surf->format;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
442
3014
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
443 if (Pg_GetArrayInterface(arrayobj, &cobj, &inter)) {
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
444 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
445 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
446
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
447 switch (inter->typekind) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
448 case 'i': /* integer */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
449 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
450 case 'u': /* unsigned integer */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
451 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
452 case 'S': /* fixed length character field */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
453 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
454 case 'V': /* structured element: record */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
455 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
456 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
457 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
458 PyErr_Format(PyExc_ValueError, "unsupported array type '%c'",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
459 inter->typekind);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
460 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
461 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
462
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
463 if (!(inter->nd == 2 || (inter->nd == 3 && inter->shape[2] == 3)))
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
464 return RAISE(PyExc_ValueError, "must be a valid 2d or 3d array\n");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
465
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
466 if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
467 return RAISE(PyExc_ValueError, "unsupport bit depth for surface");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
468
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
469 stridex = inter->strides[0];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
470 stridey = inter->strides[1];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
471 if (inter->nd == 3) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
472 stridez = inter->strides[2];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
473 stridez2 = stridez*2;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
474 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
475 sizex = inter->shape[0];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
476 sizey = inter->shape[1];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
477 Rloss = format->Rloss; Gloss = format->Gloss; Bloss = format->Bloss;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
478 Rshift = format->Rshift; Gshift = format->Gshift; Bshift = format->Bshift;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
479
2145
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
480 /* Do any required broadcasting. */
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
481 if (sizex == 1) {
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
482 sizex = surf->w;
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
483 stridex = 0;
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
484 }
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
485 if (sizey == 1) {
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
486 sizey = surf->h;
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
487 stridey = 0;
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
488 }
a8b391f2a5fa add array broadcasting to surfarray.blit_surface (pixelcopy.array_to_surface). Also do small ALSA related fix to array examples
Lenard Lindstrom <len-l@telus.net>
parents: 2141
diff changeset
489
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
490 if (sizex != surf->w || sizey != surf->h) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
491 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
492 return RAISE(PyExc_ValueError, "array must match surface dimensions");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
493 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
494 if (!PySurface_LockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
495 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
496 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
497 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
498
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
499 array_data = (char *)inter->data;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
500
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
501 switch (surf->format->BytesPerPixel) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
502 case 1:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
503 if (inter->nd == 2) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
504 switch (inter->itemsize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
505 case sizeof (Uint8):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
506 COPYMACRO_2D(Uint8, Uint8);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
507 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
508 case sizeof (Uint16):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
509 COPYMACRO_2D(Uint8, Uint16);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
510 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
511 case sizeof (Uint32):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
512 COPYMACRO_2D(Uint8, Uint32);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
513 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
514 case sizeof (Uint64):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
515 COPYMACRO_2D(Uint8, Uint64);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
516 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
517 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
518 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
519 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
520 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
521 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
522 return RAISE(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
523 "unsupported datatype for array\n");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
524 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
525 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
526 else {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
527 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
528 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
529 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
530 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
531 return RAISE(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
532 "unsupported datatype for array\n");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
533 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
534 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
535 case 2:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
536 if (inter->nd == 2) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
537 switch (inter->itemsize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
538 case sizeof (Uint16):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
539 COPYMACRO_2D(Uint16, Uint16);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
540 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
541 case sizeof (Uint32):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
542 COPYMACRO_2D(Uint16, Uint32);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
543 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
544 case sizeof (Uint64):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
545 COPYMACRO_2D(Uint16, Uint64);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
546 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
547 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
548 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
549 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
550 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
551 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
552 return RAISE(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
553 "unsupported datatype for array\n");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
554 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
555 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
556 else {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
557 Uint16 alpha = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
558 if (format->Amask) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
559 alpha = 255 >> format->Aloss << format->Ashift;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
560 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
561 switch (inter->itemsize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
562 case sizeof (Uint8):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
563 COPYMACRO_3D(Uint16, Uint8);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
564 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
565 case sizeof (Uint16):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
566 COPYMACRO_3D(Uint16, Uint16);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
567 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
568 case sizeof (Uint32):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
569 COPYMACRO_3D(Uint16, Uint32);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
570 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
571 case sizeof (Uint64):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
572 COPYMACRO_3D(Uint16, Uint64);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
573 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
574 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
575 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
576 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
577 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
578 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
579 return RAISE(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
580 "unsupported datatype for array\n");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
581 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
582 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
583 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
584 case 3:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
585 /* Assumption: The rgb components of a 24 bit pixel are in
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
586 separate bytes.
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
587 */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
588 if (inter->nd == 2) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
589 switch (inter->itemsize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
590 case sizeof (Uint32):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
591 COPYMACRO_2D_24(Uint32);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
592 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
593 case sizeof (Uint64):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
594 COPYMACRO_2D_24(Uint64);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
595 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
596 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
597 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
598 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
599 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
600 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
601 return RAISE(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
602 "unsupported datatype for array\n");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
603 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
604 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
605 else {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
606 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
607 size_t stridez_0 = (Rshift == 0 ? 0 :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
608 Gshift == 0 ? stridez :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
609 stridez2 );
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
610 size_t stridez_1 = (Rshift == 8 ? 0 :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
611 Gshift == 8 ? stridez :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
612 stridez2 );
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
613 size_t stridez_2 = (Rshift == 16 ? 0 :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
614 Gshift == 16 ? stridez :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
615 stridez2 );
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
616 #else
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
617 size_t stridez_2 = (Rshift == 0 ? 0 :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
618 Gshift == 0 ? stridez :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
619 stridez2 );
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
620 size_t stridez_1 = (Rshift == 8 ? 0 :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
621 Gshift == 8 ? stridez :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
622 stridez2 );
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
623 size_t stridez_0 = (Rshift == 16 ? 0 :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
624 Gshift == 16 ? stridez :
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
625 stridez2 );
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
626 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
627 switch (inter->itemsize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
628 case sizeof (Uint8):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
629 COPYMACRO_3D_24(Uint8);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
630 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
631 case sizeof (Uint16):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
632 COPYMACRO_3D_24(Uint16);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
633 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
634 case sizeof (Uint32):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
635 COPYMACRO_3D_24(Uint32);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
636 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
637 case sizeof (Uint64):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
638 COPYMACRO_3D_24(Uint64);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
639 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
640 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
641 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
642 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
643 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
644 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
645 return RAISE(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
646 "unsupported datatype for array\n");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
647 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
648 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
649 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
650 case 4:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
651 if (inter->nd == 2) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
652 switch (inter->itemsize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
653 case sizeof (Uint32):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
654 COPYMACRO_2D(Uint32, Uint32);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
655 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
656 case sizeof (Uint64):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
657 COPYMACRO_2D(Uint32, Uint64);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
658 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
659 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
660 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
661 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
662 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
663 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
664 return RAISE(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
665 "unsupported datatype for array\n");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
666 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
667 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
668 else {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
669 Uint32 alpha = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
670 if (format->Amask) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
671 alpha = 255 >> format->Aloss << format->Ashift;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
672 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
673 switch (inter->itemsize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
674 case sizeof (Uint8):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
675 COPYMACRO_3D(Uint32, Uint8);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
676 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
677 case sizeof (Uint16):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
678 COPYMACRO_3D(Uint32, Uint16);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
679 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
680 case sizeof (Uint32):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
681 COPYMACRO_3D(Uint32, Uint32);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
682 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
683 case sizeof (Uint64):
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
684 COPYMACRO_3D(Uint32, Uint64);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
685 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
686 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
687 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
688 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
689 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
690 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
691 return RAISE(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
692 "unsupported datatype for array\n");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
693 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
694 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
695 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
696 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
697 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
698 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
699 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
700 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
701 return RAISE(PyExc_RuntimeError, "unsupported bit depth for image");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
702 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
703
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
704 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
705 if (!PySurface_UnlockBy(surfobj, arrayobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
706 return NULL;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
707 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
708 Py_RETURN_NONE;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
709 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
710
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
711 static PyObject *
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
712 surface_to_array(PyObject *self, PyObject *args, PyObject *kwds)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
713 {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
714 PyObject *arrayobj;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
715 PyObject *surfobj;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
716 PyObject *cobj;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
717 _pc_view_kind_t view_kind = VIEWKIND_RGB;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
718 Uint8 opaque = 255;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
719 Uint8 clear = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
720 SDL_Surface *surf;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
721 PyArrayInterface *inter;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
722 char *keywords[] = {"array", "surface", "kind", "opaque", "clear", 0};
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
723
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
724 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO!|O&BB", keywords,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
725 &arrayobj,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
726 &PySurface_Type, &surfobj,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
727 _view_kind, &view_kind,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
728 &opaque, &clear)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
729 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
730 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
731 if (!PySurface_Lock(surfobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
732 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
733 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
734 surf = PySurface_AsSurface(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
735
3014
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
736 if (Pg_GetArrayInterface(arrayobj, &cobj, &inter)) {
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
737 PySurface_Unlock(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
738 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
739 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
740 if (!(inter->flags & PAI_WRITEABLE)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
741 PyErr_SetString(PyExc_ValueError, "target not writeable");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
742 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
743 PySurface_Unlock(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
744 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
745 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
746 if (!(inter->typekind == 'u' || inter->typekind == 'i')) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
747 PyErr_SetString(PyExc_ValueError, "unsupported array item type");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
748 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
749 PySurface_Unlock(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
750 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
751 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
752
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
753 if (inter->nd == 2) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
754 if (view_kind == VIEWKIND_RGB) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
755 if (_copy_mapped(inter, surf)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
756 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
757 PySurface_Unlock(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
758 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
759 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
760 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
761 else {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
762 if (_copy_colorplane(inter, surf, view_kind, opaque, clear)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
763 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
764 PySurface_Unlock(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
765 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
766 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
767 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
768 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
769 else if (inter->nd == 3) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
770 if (view_kind != VIEWKIND_RGB) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
771 PyErr_SetString(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
772 "color planes only supported for 2d targets");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
773 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
774 PySurface_Unlock(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
775 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
776 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
777 if (_copy_unmapped(inter, surf)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
778 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
779 PySurface_Unlock(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
780 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
781 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
782 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
783 else {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
784 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
785 PySurface_Unlock(surfobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
786 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
787 "Unsupported array depth %d", (int)inter->nd);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
788 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
789 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
790
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
791 Py_DECREF(cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
792 if (!PySurface_Unlock(surfobj)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
793 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
794 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
795 Py_RETURN_NONE;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
796 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
797
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
798 static PyObject *
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
799 map_array(PyObject *self, PyObject *args)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
800 {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
801 # define PIXELCOPY_MAX_DIM 10
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
802 PyObject *src_array;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
803 PyObject *tar_array;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
804 PyObject *format_surf;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
805 SDL_PixelFormat *format;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
806 PyObject *src_cobj = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
807 PyObject *tar_cobj = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
808 PyArrayInterface *src_inter;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
809 Uint8 *src;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
810 int src_ndim;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
811 Py_intptr_t src_strides[PIXELCOPY_MAX_DIM];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
812 const int src_red = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
813 int src_green;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
814 int src_blue;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
815 PyArrayInterface *tar_inter;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
816 Uint8 *tar;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
817 int ndim;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
818 Py_intptr_t *shape;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
819 Py_intptr_t *tar_strides;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
820 int tar_itemsize;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
821 int tar_byte0 = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
822 int tar_byte1 = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
823 int tar_byte2 = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
824 int tar_byte3 = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
825 int tar_byte4 = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
826 int tar_bytes_end;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
827 int tar_bytes_incr = 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
828 Py_intptr_t counters[PIXELCOPY_MAX_DIM];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
829 int src_advances[PIXELCOPY_MAX_DIM];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
830 int tar_advances[PIXELCOPY_MAX_DIM];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
831 int dim_diff;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
832 int dim;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
833 int topdim;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
834 _pc_pixel_t pixel = { 0 };
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
835 int pix_bytesize;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
836 int pix_byte0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
837 int pix_byte1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
838 int pix_byte2;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
839 int pix_byte3;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
840 int i;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
841
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
842 if (!PyArg_ParseTuple(args, "OOO!",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
843 &tar_array, &src_array,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
844 &PySurface_Type, &format_surf)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
845 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
846 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
847
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
848 if (!PySurface_Lock(format_surf)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
849 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
850 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
851
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
852 /* Determine array shapes and check validity
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
853 */
3014
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
854 if (Pg_GetArrayInterface(tar_array, &tar_cobj, &tar_inter)) {
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
855 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
856 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
857 if (!(tar_inter->flags & PAI_WRITEABLE)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
858 PyErr_SetString(PyExc_ValueError, "target not writeable");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
859 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
860 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
861 tar = (Uint8 *)tar_inter->data;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
862 if (tar_inter->typekind != 'u' && tar_inter->typekind != 'i') {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
863 PyErr_SetString(PyExc_ValueError, "expected an integer target array");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
864 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
865 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
866 ndim = tar_inter->nd;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
867 tar_itemsize = tar_inter->itemsize;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
868 shape = tar_inter->shape;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
869 tar_strides = tar_inter->strides;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
870 if (ndim < 1) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
871 PyErr_SetString(PyExc_ValueError, "target array must be at least 1D");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
872 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
873 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
874 if (ndim > PIXELCOPY_MAX_DIM) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
875 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
876 "target array exceeds %d dimensions",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
877 (int)PIXELCOPY_MAX_DIM);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
878 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
879 }
3014
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
880 if (Pg_GetArrayInterface(src_array, &src_cobj, &src_inter)) {
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
881 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
882 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
883 if (src_inter->typekind != 'u' && src_inter->typekind != 'i') {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
884 PyErr_SetString(PyExc_ValueError, "expected an integer source array");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
885 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
886 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
887 src = (Uint8 *)src_inter->data;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
888 src_ndim = src_inter->nd;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
889 if (src_ndim < 1) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
890 PyErr_SetString(PyExc_ValueError, "source array must be at least 1D");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
891 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
892 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
893 if (src_inter->shape[src_ndim - 1] != 3) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
894 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
895 "Expected a (..., 3) source array: got (..., %d)",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
896 src_inter->shape[src_ndim - 1]);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
897 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
898 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
899 if (ndim < src_ndim - 1) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
900 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
901 "%d dimensional target has too few dimensions for"
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
902 " %d dimensional source",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
903 ndim, src_ndim);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
904 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
905 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
906 for (dim = 0; dim != ndim; ++dim) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
907 src_strides[dim] = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
908 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
909 dim_diff = ndim - src_ndim + 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
910 for (dim = dim_diff; dim != ndim; ++dim) {
2139
f804bebb7287 Surface.get_view('2') now returns a view for 24 bit surfaces.
Lenard Lindstrom <len-l@telus.net>
parents: 2136
diff changeset
911 if (src_inter->shape[dim - dim_diff] == 1) {
f804bebb7287 Surface.get_view('2') now returns a view for 24 bit surfaces.
Lenard Lindstrom <len-l@telus.net>
parents: 2136
diff changeset
912 src_strides[dim] = 0;
f804bebb7287 Surface.get_view('2') now returns a view for 24 bit surfaces.
Lenard Lindstrom <len-l@telus.net>
parents: 2136
diff changeset
913 }
f804bebb7287 Surface.get_view('2') now returns a view for 24 bit surfaces.
Lenard Lindstrom <len-l@telus.net>
parents: 2136
diff changeset
914 else if (src_inter->shape[dim - dim_diff] == shape[dim]) {
f804bebb7287 Surface.get_view('2') now returns a view for 24 bit surfaces.
Lenard Lindstrom <len-l@telus.net>
parents: 2136
diff changeset
915 src_strides[dim] = src_inter->strides[dim - dim_diff];
f804bebb7287 Surface.get_view('2') now returns a view for 24 bit surfaces.
Lenard Lindstrom <len-l@telus.net>
parents: 2136
diff changeset
916 }
f804bebb7287 Surface.get_view('2') now returns a view for 24 bit surfaces.
Lenard Lindstrom <len-l@telus.net>
parents: 2136
diff changeset
917 else {
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
918 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
919 "size mismatch between dimension %d of source and"
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
920 " dimension %d of target",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
921 dim - dim_diff, dim);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
922 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
923 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
924 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
925 for (dim = 0; dim != ndim - 1; ++dim) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
926 tar_advances[dim] =
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
927 tar_strides[dim] - shape[dim + 1] * tar_strides[dim + 1];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
928 src_advances[dim] =
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
929 src_strides[dim] - shape[dim + 1] * src_strides[dim + 1];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
930 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
931
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
932 /* Determine souce and destination pixel formats
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
933 */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
934 format = PySurface_AsSurface(format_surf)->format;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
935 pix_bytesize = format->BytesPerPixel;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
936 if (tar_itemsize < pix_bytesize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
937 PyErr_SetString(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
938 "target array itemsize is too small for pixel format");
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
939 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
940 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
941 src_green = src_inter->strides[src_ndim - 1];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
942 src_blue = 2 * src_green;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
943 tar_byte4 = pix_bytesize;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
944 tar_bytes_end = tar_itemsize;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
945 switch (pix_bytesize) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
946
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
947 case 1:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
948 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
949 case 2:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
950 tar_byte3 = 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
951 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
952 case 3:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
953 tar_byte2 = 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
954 tar_byte3 = 2;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
955 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
956 case 4:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
957 tar_byte1 = 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
958 tar_byte2 = 2;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
959 tar_byte3 = 3;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
960 break;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
961 default:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
962 PyErr_Format(PyExc_ValueError,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
963 "%d bytes per pixel target format not supported",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
964 pix_bytesize);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
965 goto fail;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
966 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
967 #if SDL_endian == SDL_lilendian
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
968 pix_byte0 = tar_byte0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
969 pix_byte1 = tar_byte1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
970 pix_byte2 = tar_byte2;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
971 pix_byte3 = tar_byte3;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
972
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
973 #define NEED_BYTESWAP(inter) (!((inter)->flags & PAI_NOTSWAPPED))
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
974 #else
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
975 pix_byte0 = 3 - tar_byte0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
976 pix_byte1 = 3 - tar_byte1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
977 pix_byte2 = 3 - tar_byte2;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
978 pix_byte3 = 3 - tar_byte3;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
979
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
980 #define NEED_BYTESWAP(inter) ((inter)->flags & PAI_NOTSWAPPED)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
981 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
982 if (NEED_BYTESWAP(src_inter)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
983 src += src_inter->strides[src_ndim - 1] - 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
984 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
985 if (NEED_BYTESWAP(tar_inter)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
986 tar += tar_strides[ndim - 1] - 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
987 tar_byte1 = -tar_byte1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
988 tar_byte2 = -tar_byte2;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
989 tar_byte3 = -tar_byte3;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
990 tar_byte4 = -tar_byte4;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
991 tar_bytes_end = -tar_bytes_end;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
992 tar_bytes_incr = -tar_bytes_incr;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
993 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
994
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
995 /* Iterate over arrays, left index varying slowest, copying pixels
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
996 */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
997 dim = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
998 topdim = ndim - 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
999 counters[0] = shape[0];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1000 while (counters[0]) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1001 if (!counters[dim]) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1002 /* Leave loop, moving left one index
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1003 */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1004 --dim;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1005 tar += tar_advances[dim];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1006 src += src_advances[dim];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1007 --counters[dim];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1008 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1009 else if (dim == topdim) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1010 /* Next iteration of inner most loop: copy pixel
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1011 */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1012 pixel.value =
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1013 SDL_MapRGB(format, src[src_red], src[src_green], src[src_blue]);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1014 tar[tar_byte0] = pixel.bytes[pix_byte0];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1015 tar[tar_byte1] = pixel.bytes[pix_byte1];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1016 tar[tar_byte2] = pixel.bytes[pix_byte2];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1017 tar[tar_byte3] = pixel.bytes[pix_byte3];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1018 for (i = tar_byte4;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1019 i != tar_bytes_end;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1020 i += tar_bytes_incr) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1021 tar[i] = 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1022 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1023 tar += tar_strides[dim];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1024 src += src_strides[dim];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1025 --counters[dim];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1026 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1027 else {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1028 /* Enter loop for next index to the right
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1029 */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1030 dim += 1;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1031 counters[dim] = shape[dim];
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1032 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1033 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1034
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1035 /* Cleanup
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1036 */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1037 Py_DECREF(src_cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1038 Py_DECREF(tar_cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1039 if (!PySurface_Unlock(format_surf)) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1040 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1041 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1042 Py_RETURN_NONE;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1043
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1044 fail:
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1045 Py_XDECREF(src_cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1046 Py_XDECREF(tar_cobj);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1047 PySurface_Unlock(format_surf);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1048 return 0;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1049 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1050
2203
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1051 static PyObject*
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1052 make_surface (PyObject* self, PyObject* arg)
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1053 {
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1054 PyArrayInterface *inter;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1055 PyObject *capsule;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1056 PyObject *surfobj;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1057 PyObject *args;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1058 PyObject *result;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1059 SDL_Surface* surf;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1060 int sizex, sizey, bitsperpixel;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1061 Uint32 rmask, gmask, bmask;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1062
3014
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
1063 if (Pg_GetArrayInterface(arg, &capsule, &inter)) {
2203
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1064 return 0;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1065 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1066
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1067 if (!(inter->nd == 2 || (inter->nd == 3 && inter->shape[2] == 3))) {
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1068 return RAISE (PyExc_ValueError, "must be a valid 2d or 3d array\n");
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1069 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1070 switch (inter->typekind) {
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1071 case 'i': /* integer */
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1072 break;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1073 case 'u': /* unsigned integer */
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1074 break;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1075 case 'S': /* fixed length character field */
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1076 break;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1077 case 'V': /* structured element: record */
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1078 break;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1079 default:
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1080 Py_DECREF(capsule);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1081 PyErr_Format(PyExc_ValueError, "unsupported array type '%c'",
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1082 inter->typekind);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1083 return NULL;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1084 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1085
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1086 if (inter->nd == 2) {
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1087 bitsperpixel = 8;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1088 rmask = 0xFF >> 6 << 5;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1089 gmask = 0xFF >> 5 << 2;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1090 bmask = 0xFF >> 6;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1091 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1092 else {
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1093 bitsperpixel = 32;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1094 rmask = 0xFF << 16;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1095 gmask = 0xFF << 8;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1096 bmask = 0xFF;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1097 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1098 sizex = inter->shape[0];
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1099 sizey = inter->shape[1];
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1100
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1101 surf = SDL_CreateRGBSurface (0, sizex, sizey, bitsperpixel, rmask, gmask,
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1102 bmask, 0);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1103 if (!surf) {
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1104 Py_DECREF(capsule);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1105 return RAISE(PyExc_SDLError, SDL_GetError());
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1106 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1107 surfobj = PySurface_New(surf);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1108 if (!surfobj) {
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1109 Py_DECREF(capsule);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1110 SDL_FreeSurface(surf);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1111 return 0;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1112 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1113
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1114 args = Py_BuildValue("(OO)", surfobj, arg);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1115 if (!args) {
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1116 Py_DECREF(capsule);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1117 Py_DECREF(surfobj);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1118 return 0;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1119 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1120
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1121 result = array_to_surface(self, args);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1122 Py_DECREF(capsule);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1123 Py_DECREF(args);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1124
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1125 if (!result)
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1126 {
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1127 Py_DECREF(surfobj);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1128 return 0;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1129 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1130 Py_DECREF(result);
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1131 return surfobj;
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1132 }
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1133
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1134 static PyMethodDef _pixelcopy_methods[] =
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1135 {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1136 { "array_to_surface", array_to_surface,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1137 METH_VARARGS, DOC_PYGAMEPIXELCOPYARRAYTOSURFACE },
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1138 { "surface_to_array", (PyCFunction)surface_to_array,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1139 METH_VARARGS | METH_KEYWORDS, DOC_PYGAMEPIXELCOPYSURFACETOARRAY },
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1140 { "map_array", map_array,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1141 METH_VARARGS, DOC_PYGAMEPIXELCOPYMAPARRAY },
2203
e21aecb03a4a Move surfarray.make_surface into pixelcopy so can create the new surface from array interface information. This allows surface creation from non-array arrays (PixelArray will be sprouting an array interface shortly.)
Lenard Lindstrom <len-l@telus.net>
parents: 2145
diff changeset
1142 { "make_surface", make_surface, METH_O, DOC_PYGAMEPIXELCOPYMAKESURFACE },
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1143 { 0, 0, 0, 0}
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1144 };
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1145
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1146 MODINIT_DEFINE(pixelcopy)
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1147 {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1148 PyObject *module;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1149
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1150 #if PY3
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1151 static struct PyModuleDef _module = {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1152 PyModuleDef_HEAD_INIT,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1153 "pixelcopy",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1154 DOC_PYGAMEPIXELCOPY,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1155 -1,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1156 _pixelcopy_methods,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1157 NULL, NULL, NULL, NULL
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1158 };
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1159 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1160
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1161 /* imported needed apis; Do this first so if there is an error
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1162 the module is not loaded.
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1163 */
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1164 import_pygame_base();
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1165 if (PyErr_Occurred()) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1166 MODINIT_ERROR;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1167 }
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1168 import_pygame_surface();
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1169 if (PyErr_Occurred()) {
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1170 MODINIT_ERROR;
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1171 }
3014
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
1172 import_pygame_view();
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
1173 if (PyErr_Occurred()) {
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
1174 MODINIT_ERROR;
841b902f3d15 Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
1175 }
2136
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1176
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1177 #if PY3
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1178 module = PyModule_Create(&_module);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1179 #else
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1180 module = Py_InitModule3("pixelcopy",
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1181 _pixelcopy_methods,
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1182 DOC_PYGAMEPIXELCOPY);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1183 #endif
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1184 MODINIT_RETURN(module);
9de026eb9cab Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff changeset
1185 }