annotate src/surface.c @ 3194:9fcb7abf3185 default tip

Remove some gcc 4.7.2 compiler warnings
author Lenard Lindstrom <len-l@telus.net>
date Tue, 23 Apr 2013 19:53:36 -0700
parents eb3dc1a0d9d1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
1 /*
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2 pygame - Python Game Library
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
3 Copyright (C) 2000-2001 Pete Shinners
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
4 Copyright (C) 2007 Marcus von Appen
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
5
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
6 This library is free software; you can redistribute it and/or
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
7 modify it under the terms of the GNU Library General Public
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
8 License as published by the Free Software Foundation; either
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
9 version 2 of the License, or (at your option) any later version.
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
10
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
11 This library is distributed in the hope that it will be useful,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
14 Library General Public License for more details.
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
15
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
16 You should have received a copy of the GNU Library General Public
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
17 License along with this library; if not, write to the Free
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
19
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
20 Pete Shinners
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
21 pete@shinners.org
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
22 */
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
23
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
24 #define PYGAMEAPI_SURFACE_INTERNAL
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
25
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
26 #include "surface.h"
1937
0d661c00c1aa Merged FreeType branch into trunk.
tanoku
parents: 1900
diff changeset
27 #include "doc/surface_doc.h"
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
28 #include "structmember.h"
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
29 #include "pgcompat.h"
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
30 #include "pgview.h"
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
31 #include "pgarrinter.h"
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
32
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
33 typedef enum {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
34 VIEWKIND_2D = 2,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
35 VIEWKIND_3D = 3,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
36 VIEWKIND_RED,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
37 VIEWKIND_GREEN,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
38 VIEWKIND_BLUE,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
39 VIEWKIND_ALPHA,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
40 } SurfViewKind;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
41
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
42 int
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
43 PySurface_Blit (PyObject * dstobj, PyObject * srcobj, SDL_Rect * dstrect,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
44 SDL_Rect * srcrect, int the_args);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
45
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
46 /* statics */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
47 static PyObject *PySurface_New (SDL_Surface * info);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
48 static PyObject *surface_new (PyTypeObject *type, PyObject *args,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
49 PyObject *kwds);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
50 static intptr_t surface_init (PySurfaceObject *self, PyObject *args,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
51 PyObject *kwds);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
52 static PyObject* surface_str (PyObject *self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
53 static void surface_dealloc (PyObject *self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
54 static void surface_cleanup (PySurfaceObject * self);
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
55 static void surface_move (Uint8 *src, Uint8 *dst, int h,
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
56 int span, int srcpitch, int dstpitch);
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
57
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
58 static PyObject *surf_get_at (PyObject *self, PyObject *args);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
59 static PyObject *surf_set_at (PyObject *self, PyObject *args);
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
60 static PyObject *surf_get_at_mapped (PyObject *self, PyObject *args);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
61 static PyObject *surf_map_rgb (PyObject *self, PyObject *args);
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
62 static PyObject *surf_unmap_rgb (PyObject *self, PyObject *arg);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
63 static PyObject *surf_lock (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
64 static PyObject *surf_unlock (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
65 static PyObject *surf_mustlock (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
66 static PyObject *surf_get_locked (PyObject *self);
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
67 static PyObject *surf_get_locks (PyObject *self);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
68 static PyObject *surf_get_palette (PyObject *self);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
69 static PyObject *surf_get_palette_at (PyObject *self, PyObject *args);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
70 static PyObject *surf_set_palette (PyObject *self, PyObject *args);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
71 static PyObject *surf_set_palette_at (PyObject *self, PyObject *args);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
72 static PyObject *surf_set_colorkey (PyObject *self, PyObject *args);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
73 static PyObject *surf_get_colorkey (PyObject *self);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
74 static PyObject *surf_set_alpha (PyObject *self, PyObject *args);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
75 static PyObject *surf_get_alpha (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
76 static PyObject *surf_copy (PyObject *self);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
77 static PyObject *surf_convert (PyObject *self, PyObject *args);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
78 static PyObject *surf_convert_alpha (PyObject *self, PyObject *args);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
79 static PyObject *surf_set_clip (PyObject *self, PyObject *args);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
80 static PyObject *surf_get_clip (PyObject *self);
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
81 static PyObject *surf_blit (PyObject *self, PyObject *args, PyObject *keywds);
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
82 static PyObject *surf_fill (PyObject *self, PyObject *args, PyObject *keywds);
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
83 static PyObject *surf_scroll (PyObject *self,
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
84 PyObject *args, PyObject *keywds);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
85 static PyObject *surf_get_abs_offset (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
86 static PyObject *surf_get_abs_parent (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
87 static PyObject *surf_get_bitsize (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
88 static PyObject *surf_get_bytesize (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
89 static PyObject *surf_get_flags (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
90 static PyObject *surf_get_height (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
91 static PyObject *surf_get_pitch (PyObject *self);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
92 static PyObject *surf_get_rect (PyObject *self, PyObject *args,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
93 PyObject *kwargs);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
94 static PyObject *surf_get_width (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
95 static PyObject *surf_get_shifts (PyObject *self);
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
96 static PyObject *surf_set_shifts (PyObject *self, PyObject *args);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
97 static PyObject *surf_get_size (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
98 static PyObject *surf_get_losses (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
99 static PyObject *surf_get_masks (PyObject *self);
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
100 static PyObject *surf_set_masks (PyObject *self, PyObject *args);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
101 static PyObject *surf_get_offset (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
102 static PyObject *surf_get_parent (PyObject *self);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
103 static PyObject *surf_subsurface (PyObject *self, PyObject *args);
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
104 static PyObject *surf_get_buffer (PyObject *self);
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
105 static PyObject *surf_get_view (PyObject *self, PyObject *args, PyObject *kwds);
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
106 static PyObject *surf_get_bounding_rect (PyObject *self, PyObject *args,
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
107 PyObject *kwargs);
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
108 static PyObject *surf_get_pixels_address (PyObject *self,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
109 PyObject *closure);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
110 static int surf_view_kind(PyObject *obj, void *view_kind_vptr);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
111 #if PY3
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
112 static void surf_arraystruct_capsule_destr(PyObject *capsule);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
113 #endif
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
114 static void surf_view_destr(PyObject *view);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
115 static PyObject *_raise_get_view_ndim_error(int bitsize, SurfViewKind kind);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
116
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
117
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
118 static PyGetSetDef surface_getsets[] = {
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
119 { "_pixels_address", (getter)surf_get_pixels_address,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
120 NULL, "pixel buffer address (readonly)", NULL },
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
121 { NULL, NULL, NULL, NULL, NULL }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
122 };
425
879ca7f86dc2 subrect work
pygame
parents: 401
diff changeset
123
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
124 static struct PyMethodDef surface_methods[] = {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
125 { "get_at", surf_get_at, METH_VARARGS, DOC_SURFACEGETAT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
126 { "set_at", surf_set_at, METH_VARARGS, DOC_SURFACESETAT },
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
127 { "get_at_mapped", surf_get_at_mapped, METH_VARARGS,
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
128 DOC_SURFACEGETATMAPPED },
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
129 { "map_rgb", surf_map_rgb, METH_VARARGS, DOC_SURFACEMAPRGB },
1472
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
130 { "unmap_rgb", surf_unmap_rgb, METH_O, DOC_SURFACEUNMAPRGB },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
131
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
132 { "get_palette", (PyCFunction) surf_get_palette, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
133 DOC_SURFACEGETPALETTE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
134 { "get_palette_at", surf_get_palette_at, METH_VARARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
135 DOC_SURFACEGETPALETTEAT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
136 { "set_palette", surf_set_palette, METH_VARARGS, DOC_SURFACESETPALETTE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
137 { "set_palette_at", surf_set_palette_at, METH_VARARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
138 DOC_SURFACESETPALETTEAT },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
139
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
140 { "lock", (PyCFunction) surf_lock, METH_NOARGS, DOC_SURFACELOCK },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
141 { "unlock", (PyCFunction) surf_unlock, METH_NOARGS, DOC_SURFACEUNLOCK },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
142 { "mustlock", (PyCFunction) surf_mustlock, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
143 DOC_SURFACEMUSTLOCK },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
144 { "get_locked", (PyCFunction) surf_get_locked, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
145 DOC_SURFACEGETLOCKED },
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
146 { "get_locks", (PyCFunction) surf_get_locks, METH_NOARGS,
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
147 DOC_SURFACEGETLOCKS },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
148
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
149 { "set_colorkey", surf_set_colorkey, METH_VARARGS, DOC_SURFACESETCOLORKEY },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
150 { "get_colorkey", (PyCFunction) surf_get_colorkey, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
151 DOC_SURFACEGETCOLORKEY },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
152 { "set_alpha", surf_set_alpha, METH_VARARGS, DOC_SURFACESETALPHA },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
153 { "get_alpha", (PyCFunction) surf_get_alpha, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
154 DOC_SURFACEGETALPHA },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
155
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
156 { "copy", (PyCFunction) surf_copy, METH_NOARGS, DOC_SURFACECOPY },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
157 { "__copy__", (PyCFunction) surf_copy, METH_NOARGS, DOC_SURFACECOPY },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
158 { "convert", surf_convert, METH_VARARGS, DOC_SURFACECONVERT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
159 { "convert_alpha", surf_convert_alpha, METH_VARARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
160 DOC_SURFACECONVERTALPHA },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
161
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
162 { "set_clip", surf_set_clip, METH_VARARGS, DOC_SURFACESETCLIP },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
163 { "get_clip", (PyCFunction) surf_get_clip, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
164 DOC_SURFACEGETCLIP },
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
165
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
166 { "fill", (PyCFunction) surf_fill, METH_VARARGS | METH_KEYWORDS,
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
167 DOC_SURFACEFILL },
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
168 { "blit", (PyCFunction) surf_blit, METH_VARARGS | METH_KEYWORDS,
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
169 DOC_SURFACEBLIT },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
170
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
171 { "scroll", (PyCFunction) surf_scroll, METH_VARARGS | METH_KEYWORDS,
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
172 DOC_SURFACESCROLL },
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
173
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
174 { "get_flags", (PyCFunction) surf_get_flags, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
175 DOC_SURFACEGETFLAGS },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
176 { "get_size", (PyCFunction) surf_get_size, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
177 DOC_SURFACEGETSIZE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
178 { "get_width", (PyCFunction) surf_get_width, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
179 DOC_SURFACEGETWIDTH },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
180 { "get_height", (PyCFunction) surf_get_height, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
181 DOC_SURFACEGETHEIGHT },
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
182 { "get_rect", (PyCFunction) surf_get_rect, METH_VARARGS | METH_KEYWORDS,
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
183 DOC_SURFACEGETRECT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
184 { "get_pitch", (PyCFunction) surf_get_pitch, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
185 DOC_SURFACEGETPITCH },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
186 { "get_bitsize", (PyCFunction) surf_get_bitsize, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
187 DOC_SURFACEGETBITSIZE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
188 { "get_bytesize", (PyCFunction) surf_get_bytesize, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
189 DOC_SURFACEGETBYTESIZE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
190 { "get_masks", (PyCFunction) surf_get_masks, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
191 DOC_SURFACEGETMASKS },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
192 { "get_shifts", (PyCFunction) surf_get_shifts, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
193 DOC_SURFACEGETSHIFTS },
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
194 { "set_masks", (PyCFunction) surf_set_masks, METH_VARARGS,
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
195 DOC_SURFACESETMASKS },
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
196 { "set_shifts", (PyCFunction) surf_set_shifts, METH_VARARGS,
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
197 DOC_SURFACESETSHIFTS },
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
198
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
199 { "get_losses", (PyCFunction) surf_get_losses, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
200 DOC_SURFACEGETLOSSES },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
201
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
202 { "subsurface", surf_subsurface, METH_VARARGS, DOC_SURFACESUBSURFACE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
203 { "get_offset", (PyCFunction) surf_get_offset, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
204 DOC_SURFACEGETOFFSET },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
205 { "get_abs_offset", (PyCFunction) surf_get_abs_offset, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
206 DOC_SURFACEGETABSOFFSET },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
207 { "get_parent", (PyCFunction) surf_get_parent, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
208 DOC_SURFACEGETPARENT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
209 { "get_abs_parent", (PyCFunction) surf_get_abs_parent, METH_NOARGS,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
210 DOC_SURFACEGETABSPARENT },
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
211 { "get_bounding_rect", (PyCFunction) surf_get_bounding_rect,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
212 METH_VARARGS | METH_KEYWORDS,
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
213 DOC_SURFACEGETBOUNDINGRECT},
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
214 { "get_buffer", (PyCFunction) surf_get_buffer, METH_NOARGS,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
215 DOC_SURFACEGETBUFFER},
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
216 { "get_view", (PyCFunction) surf_get_view, METH_VARARGS | METH_KEYWORDS,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
217 DOC_SURFACEGETVIEW},
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
218
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
219 { NULL, NULL, 0, NULL }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
220 };
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
221
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
222 static PyTypeObject PySurface_Type = {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
223 TYPE_HEAD (NULL, 0)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
224 "pygame.Surface", /* name */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
225 sizeof (PySurfaceObject), /* basic size */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
226 0, /* itemsize */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
227 surface_dealloc, /* dealloc */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
228 0, /* print */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
229 NULL, /* getattr */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
230 NULL, /* setattr */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
231 NULL, /* compare */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
232 surface_str, /* repr */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
233 NULL, /* as_number */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
234 NULL, /* as_sequence */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
235 NULL, /* as_mapping */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
236 (hashfunc) NULL, /* hash */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
237 (ternaryfunc) NULL, /* call */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
238 (reprfunc) NULL, /* str */
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
239 0,
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
240 0L, 0L,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
241 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
242 DOC_PYGAMESURFACE, /* Documentation string */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
243 0, /* tp_traverse */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
244 0, /* tp_clear */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
245 0, /* tp_richcompare */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
246 offsetof (PySurfaceObject, weakreflist), /* tp_weaklistoffset */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
247 0, /* tp_iter */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
248 0, /* tp_iternext */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
249 surface_methods, /* tp_methods */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
250 0, /* tp_members */
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
251 surface_getsets, /* tp_getset */
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
252 0, /* tp_base */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
253 0, /* tp_dict */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
254 0, /* tp_descr_get */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
255 0, /* tp_descr_set */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
256 0, /* tp_dictoffset */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
257 (initproc) surface_init, /* tp_init */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
258 0, /* tp_alloc */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
259 surface_new, /* tp_new */
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
260 };
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
261
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
262 #define PySurface_Check(x) ((x)->ob_type == &PySurface_Type)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
263
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
264 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
265 PySurface_New (SDL_Surface *s)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
266 {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
267 PySurfaceObject *self;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
268
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
269 if (!s)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
270 return RAISE (PyExc_SDLError, SDL_GetError ());
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
271
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
272 self = (PySurfaceObject *)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
273 PySurface_Type.tp_new (&PySurface_Type, NULL, NULL);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
274
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
275 if (self)
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
276 self->surf = s;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
277
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
278 return (PyObject *) self;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
279 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
280
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
281 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
282 surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
283 {
76675068d35a weakref surface
pygame
parents: 497
diff changeset
284 PySurfaceObject *self;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
285
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
286 self = (PySurfaceObject *) type->tp_alloc (type, 0);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
287 if (self) {
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
288 self->surf = NULL;
76675068d35a weakref surface
pygame
parents: 497
diff changeset
289 self->subsurface = NULL;
76675068d35a weakref surface
pygame
parents: 497
diff changeset
290 self->weakreflist = NULL;
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
291 self->dependency = NULL;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
292 self->locklist = NULL;
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
293 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
294 return (PyObject *) self;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
295 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
296
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
297 /* surface object internals */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
298 static void
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
299 surface_cleanup (PySurfaceObject *self)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
300 {
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
301 if (self->surf) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
302 if (!(self->surf->flags & SDL_HWSURFACE) ||
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
303 SDL_WasInit (SDL_INIT_VIDEO)) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
304 /* unsafe to free hardware surfaces without video init */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
305 /* i question SDL's ability to free a locked hardware surface */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
306 SDL_FreeSurface (self->surf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
307 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
308 self->surf = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
309 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
310 if (self->subsurface) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
311 Py_XDECREF (self->subsurface->owner);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
312 PyMem_Del (self->subsurface);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
313 self->subsurface = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
314 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
315 if (self->dependency) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
316 Py_DECREF (self->dependency);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
317 self->dependency = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
318 }
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
319
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
320 if (self->locklist) {
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
321 Py_DECREF (self->locklist);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
322 self->locklist = NULL;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
323 }
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
324 }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
325
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
326 static void
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
327 surface_dealloc (PyObject *self)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
328 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
329 if (((PySurfaceObject *) self)->weakreflist)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
330 PyObject_ClearWeakRefs (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
331 surface_cleanup ((PySurfaceObject *) self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
332 self->ob_type->tp_free (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
333 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
334
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
335 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
336 surface_str (PyObject *self)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
337 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
338 char str[1024];
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
339 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
340 const char *type;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
341
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
342 if (surf) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
343 type = (surf->flags & SDL_HWSURFACE) ? "HW" : "SW";
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
344 sprintf (str, "<Surface(%dx%dx%d %s)>", surf->w,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
345 surf->h, surf->format->BitsPerPixel, type);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
346 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
347 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
348 strcpy (str, "<Surface(Dead Display)>");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
349 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
350
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
351 return Text_FromUTF8 (str);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
352 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
353
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
354 static intptr_t
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
355 surface_init (PySurfaceObject *self, PyObject *args, PyObject *kwds)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
356 {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
357 Uint32 flags = 0;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
358 int width, height;
850
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
359 PyObject *depth = NULL, *masks = NULL, *size = NULL;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
360 int bpp;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
361 Uint32 Rmask, Gmask, Bmask, Amask;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
362 SDL_Surface *surface;
1515
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
363 SDL_PixelFormat default_format, *format;
850
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
364 int length;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
365
850
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
366 char *kwids[] = { "size", "flags", "depth", "masks", NULL };
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
367 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iOO", kwids, &size, &flags, &depth, &masks))
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
368 return -1;
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
369
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
370 if (PySequence_Check (size) && (length = PySequence_Length (size)) == 2) {
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
371 if ( (!IntFromObjIndex (size, 0, &width)) ||
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
372 (!IntFromObjIndex (size, 1, &height)) ) {
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
373 RAISE (PyExc_ValueError, "size needs to be (int width, int height)");
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
374 return -1;
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
375 }
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
376 } else {
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
377 RAISE (PyExc_ValueError, "size needs to be (int width, int height)");
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
378 return -1;
850
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
379 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
380
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
381 if (width < 0 || height < 0) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
382 RAISE (PyExc_SDLError, "Invalid resolution for Surface");
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
383 return -1;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
384 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
385
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
386 surface_cleanup (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
387
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
388 if (depth && masks) { /* all info supplied, most errorchecking
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
389 * needed */
848
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
390 if (PySurface_Check (depth)) {
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
391 RAISE (PyExc_ValueError, "cannot pass surface for depth and color masks");
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
392 return -1;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
393 }
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
394 if (!IntFromObj (depth, &bpp)) {
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
395 RAISE (PyExc_ValueError, "invalid bits per pixel depth argument");
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
396 return -1;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
397 }
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
398 if (!PySequence_Check (masks) || PySequence_Length (masks) != 4) {
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
399 RAISE (PyExc_ValueError, "masks argument must be sequence of four numbers");
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
400 return -1;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
401 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
402 if (!UintFromObjIndex (masks, 0, &Rmask) ||
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
403 !UintFromObjIndex (masks, 1, &Gmask) ||
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
404 !UintFromObjIndex (masks, 2, &Bmask) ||
848
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
405 !UintFromObjIndex (masks, 3, &Amask)) {
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
406 RAISE (PyExc_ValueError, "invalid mask values in masks sequence");
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
407 return -1;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
408 }
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
409 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
410 else if (depth && PyNumber_Check (depth)) { /* use default masks */
848
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
411 if (!IntFromObj (depth, &bpp)) {
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
412 RAISE (PyExc_ValueError, "invalid bits per pixel depth argument");
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
413 return -1;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
414 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
415 if (flags & SDL_SRCALPHA){
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
416 switch (bpp) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
417
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
418 case 16:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
419 Rmask = 0xF << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
420 Gmask = 0xF << 4;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
421 Bmask = 0xF;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
422 Amask = 0xF << 12;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
423 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
424 case 32:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
425 Rmask = 0xFF << 16;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
426 Gmask = 0xFF << 8;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
427 Bmask = 0xFF;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
428 Amask = 0xFF << 24;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
429 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
430 default:
848
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
431 RAISE (PyExc_ValueError, "no standard masks exist for given bitdepth with alpha");
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
432 return -1;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
433 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
434 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
435 else {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
436 Amask = 0;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
437 switch (bpp) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
438
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
439 case 8:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
440 Rmask = 0xFF >> 6 << 5;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
441 Gmask = 0xFF >> 5 << 2;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
442 Bmask = 0xFF >> 6;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
443 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
444 case 12:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
445 Rmask = 0xFF >> 4 << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
446 Gmask = 0xFF >> 4 << 4;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
447 Bmask = 0xFF >> 4;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
448 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
449 case 15:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
450 Rmask = 0xFF >> 3 << 10;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
451 Gmask = 0xFF >> 3 << 5;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
452 Bmask = 0xFF >> 3;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
453 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
454 case 16:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
455 Rmask = 0xFF >> 3 << 11;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
456 Gmask = 0xFF >> 2 << 5;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
457 Bmask = 0xFF >> 3;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
458 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
459 case 24:
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
460 case 32:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
461 Rmask = 0xFF << 16;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
462 Gmask = 0xFF << 8;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
463 Bmask = 0xFF;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
464 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
465 default:
848
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
466 RAISE (PyExc_ValueError, "nonstandard bit depth given");
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
467 return -1;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
468 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
469 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
470 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
471 else { /* no depth or surface */
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
472 SDL_PixelFormat* pix;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
473 if (depth && PySurface_Check (depth))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
474 pix = ((PySurfaceObject*) depth)->surf->format;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
475 else if (SDL_GetVideoSurface ())
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
476 pix = SDL_GetVideoSurface ()->format;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
477 else if (SDL_WasInit (SDL_INIT_VIDEO))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
478 pix = SDL_GetVideoInfo ()->vfmt;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
479 else {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
480 pix = &default_format;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
481 pix->BitsPerPixel = 32;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
482 pix->Amask = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
483 pix->Rmask = 0xFF0000;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
484 pix->Gmask = 0xFF00;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
485 pix->Bmask = 0xFF;
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
486 }
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
487 bpp = pix->BitsPerPixel;
848
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
488
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
489 if (flags & SDL_SRCALPHA) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
490 switch (bpp) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
491
848
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
492 case 16:
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
493 Rmask = 0xF << 8;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
494 Gmask = 0xF << 4;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
495 Bmask = 0xF;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
496 Amask = 0xF << 12;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
497 break;
915
9146c917f4e0 making it so asking for a SRCALPHA surface with an unspecified bit depth but a video depth of 24-bit results in a 32-bit surface
brian
parents: 878
diff changeset
498 case 24:
9146c917f4e0 making it so asking for a SRCALPHA surface with an unspecified bit depth but a video depth of 24-bit results in a 32-bit surface
brian
parents: 878
diff changeset
499 bpp = 32;
9146c917f4e0 making it so asking for a SRCALPHA surface with an unspecified bit depth but a video depth of 24-bit results in a 32-bit surface
brian
parents: 878
diff changeset
500 // we automatically step up to 32 if video is 24, fall through to case below
848
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
501 case 32:
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
502 Rmask = 0xFF << 16;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
503 Gmask = 0xFF << 8;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
504 Bmask = 0xFF;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
505 Amask = 0xFF << 24;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
506 break;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
507 default:
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
508 RAISE (PyExc_ValueError, "no standard masks exist for given bitdepth with alpha");
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
509 return -1;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
510 }
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
511 } else {
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
512 Rmask = pix->Rmask;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
513 Gmask = pix->Gmask;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
514 Bmask = pix->Bmask;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
515 Amask = pix->Amask;
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
516 }
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
517
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
518 }
848
aef082943758 fixed a bunch of problems with surface creation. Todo with error checking the arguments... the exceptions were not being raised correctly. Also SRCALPHA without specifying a bit depth was not working correctly.
Rene Dudfield <renesd@gmail.com>
parents: 847
diff changeset
519
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
520 surface = SDL_CreateRGBSurface (flags, width, height, bpp, Rmask, Gmask,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
521 Bmask, Amask);
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 860
diff changeset
522
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
523 if (!surface) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
524 RAISE (PyExc_SDLError, SDL_GetError ());
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
525 return -1;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
526 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
527
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
528 if (masks) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
529 /* Confirm the surface was created correctly (masks were valid).
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
530 Also ensure that 24 and 32 bit surfaces have 8 bit fields
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
531 (no losses).
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
532 */
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
533 format = surface->format;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
534 Rmask = (0xFF >> format->Rloss) << format->Rshift;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
535 Gmask = (0xFF >> format->Gloss) << format->Gshift;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
536 Bmask = (0xFF >> format->Bloss) << format->Bshift;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
537 Amask = (0xFF >> format->Aloss) << format->Ashift;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
538 if (format->Rmask != Rmask ||
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
539 format->Gmask != Gmask ||
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
540 format->Bmask != Bmask ||
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
541 format->Amask != Amask ||
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
542 (format->BytesPerPixel >= 3 &&
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
543 (format->Rloss || format->Gloss || format->Bloss ||
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
544 (surface->flags & SDL_SRCALPHA ?
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
545 format->Aloss : format->Aloss != 8)))) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
546 SDL_FreeSurface (surface);
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
547 RAISE (PyExc_ValueError, "Invalid mask values");
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
548 return -1;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
549 }
1515
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
550 }
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
551
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
552 if (surface) {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
553 self->surf = surface;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
554 self->subsurface = NULL;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
555 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
556
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
557 return 0;
345
935c139eb672 Surface and Rect subclassable
pygame
parents: 307
diff changeset
558 }
935c139eb672 Surface and Rect subclassable
pygame
parents: 307
diff changeset
559
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
560 /* surface object methods */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
561 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
562 surf_get_at (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
563 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
564 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
565 SDL_PixelFormat *format = surf->format;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
566 Uint8 *pixels = (Uint8 *) surf->pixels;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
567 int x, y;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
568 Uint32 color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
569 Uint8 *pix;
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
570 Uint8 rgba[4];
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
571
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
572 if (!PyArg_ParseTuple (args, "(ii)", &x, &y))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
573 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
574 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
575 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
576
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
577 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
578 return RAISE (PyExc_SDLError, "Cannot call on OPENGL Surfaces");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
579
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
580 if (x < 0 || x >= surf->w || y < 0 || y >= surf->h)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
581 return RAISE (PyExc_IndexError, "pixel index out of range");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
582
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
583 if (format->BytesPerPixel < 1 || format->BytesPerPixel > 4)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
584 return RAISE (PyExc_RuntimeError, "invalid color depth for surface");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
585
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
586 if (!PySurface_Lock (self))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
587 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
588
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
589 pixels = (Uint8 *) surf->pixels;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
590
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
591 switch (format->BytesPerPixel) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
592
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
593 case 1:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
594 color = (Uint32)*((Uint8 *) pixels + y * surf->pitch + x);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
595 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
596 case 2:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
597 color = (Uint32)*((Uint16 *) (pixels + y * surf->pitch) + x);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
598 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
599 case 3:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
600 pix = ((Uint8 *) (pixels + y * surf->pitch) + x * 3);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
601 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
602 color = (pix[0]) + (pix[1] << 8) + (pix[2] << 16);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
603 #else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
604 color = (pix[2]) + (pix[1] << 8) + (pix[0] << 16);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
605 #endif
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
606 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
607 default: /* case 4: */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
608 color = *((Uint32 *) (pixels + y * surf->pitch) + x);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
609 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
610 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
611 if (!PySurface_Unlock (self))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
612 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
613
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
614 SDL_GetRGBA (color, format, rgba, rgba+1, rgba+2, rgba+3);
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
615 return PyColor_New (rgba);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
616 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
617
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
618 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
619 surf_set_at (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
620 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
621 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
622 SDL_PixelFormat *format = surf->format;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
623 Uint8 *pixels;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
624 int x, y;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
625 Uint32 color;
859
0c1408a4a30d surface.set_at((0,0), 0x0000FF) was failing for 24 bit surfaces.
Rene Dudfield <renesd@gmail.com>
parents: 854
diff changeset
626 Uint8 rgba[4] = {0, 0, 0, 0 };
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
627 PyObject *rgba_obj;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
628 Uint8 *byte_buf;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
629
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
630 if (!PyArg_ParseTuple (args, "(ii)O", &x, &y, &rgba_obj))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
631 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
632 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
633 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
634
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
635 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
636 return RAISE (PyExc_SDLError, "Cannot call on OPENGL Surfaces");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
637
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
638 if (format->BytesPerPixel < 1 || format->BytesPerPixel > 4)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
639 return RAISE (PyExc_RuntimeError, "invalid color depth for surface");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
640
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
641 if (x < surf->clip_rect.x || x >= surf->clip_rect.x + surf->clip_rect.w ||
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
642 y < surf->clip_rect.y || y >= surf->clip_rect.y + surf->clip_rect.h) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
643 /* out of clip area */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
644 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
645 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
646
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
647 if (PyInt_Check (rgba_obj)) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
648 color = (Uint32) PyInt_AsLong (rgba_obj);
1111
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
649 if (PyErr_Occurred () && (Sint32) color == -1)
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
650 return RAISE (PyExc_TypeError, "invalid color argument");
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
651 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
652 else if (PyLong_Check (rgba_obj)) {
1111
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
653 color = (Uint32) PyLong_AsUnsignedLong (rgba_obj);
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
654 if (PyErr_Occurred () && (Sint32) color == -1)
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
655 return RAISE (PyExc_TypeError, "invalid color argument");
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
656 }
1037
c4c38b97db3b Added Color class.
marcus
parents: 930
diff changeset
657 else if (RGBAFromColorObj (rgba_obj, rgba))
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
658 color = SDL_MapRGBA (surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
659 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
660 return RAISE (PyExc_TypeError, "invalid color argument");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
661
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
662 if (!PySurface_Lock (self))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
663 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
664 pixels = (Uint8 *) surf->pixels;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
665
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
666 switch (format->BytesPerPixel) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
667
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
668 case 1:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
669 *((Uint8 *) pixels + y * surf->pitch + x) = (Uint8) color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
670 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
671 case 2:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
672 *((Uint16 *) (pixels + y * surf->pitch) + x) = (Uint16) color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
673 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
674 case 3:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
675 byte_buf = (Uint8 *) (pixels + y * surf->pitch) + x * 3;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
676 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
859
0c1408a4a30d surface.set_at((0,0), 0x0000FF) was failing for 24 bit surfaces.
Rene Dudfield <renesd@gmail.com>
parents: 854
diff changeset
677 *(byte_buf + (format->Rshift >> 3)) = (Uint8) (color >> 16);
0c1408a4a30d surface.set_at((0,0), 0x0000FF) was failing for 24 bit surfaces.
Rene Dudfield <renesd@gmail.com>
parents: 854
diff changeset
678 *(byte_buf + (format->Gshift >> 3)) = (Uint8) (color >> 8);
0c1408a4a30d surface.set_at((0,0), 0x0000FF) was failing for 24 bit surfaces.
Rene Dudfield <renesd@gmail.com>
parents: 854
diff changeset
679 *(byte_buf + (format->Bshift >> 3)) = (Uint8) color;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
680 #else
859
0c1408a4a30d surface.set_at((0,0), 0x0000FF) was failing for 24 bit surfaces.
Rene Dudfield <renesd@gmail.com>
parents: 854
diff changeset
681 *(byte_buf + 2 - (format->Rshift >> 3)) = (Uint8) (color >> 16);
0c1408a4a30d surface.set_at((0,0), 0x0000FF) was failing for 24 bit surfaces.
Rene Dudfield <renesd@gmail.com>
parents: 854
diff changeset
682 *(byte_buf + 2 - (format->Gshift >> 3)) = (Uint8) (color >> 8);
0c1408a4a30d surface.set_at((0,0), 0x0000FF) was failing for 24 bit surfaces.
Rene Dudfield <renesd@gmail.com>
parents: 854
diff changeset
683 *(byte_buf + 2 - (format->Bshift >> 3)) = (Uint8) color;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
684 #endif
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
685 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
686 default: /* case 4: */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
687 *((Uint32 *) (pixels + y * surf->pitch) + x) = color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
688 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
689 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
690
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
691 if (!PySurface_Unlock (self))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
692 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
693 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
694 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
695
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
696 static PyObject*
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
697 surf_get_at_mapped (PyObject *self, PyObject *args)
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
698 {
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
699 SDL_Surface *surf = PySurface_AsSurface (self);
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
700 SDL_PixelFormat *format = surf->format;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
701 Uint8 *pixels = (Uint8 *) surf->pixels;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
702 int x, y;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
703 Uint32 color;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
704 Uint8 *pix;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
705
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
706 if (!PyArg_ParseTuple (args, "(ii)", &x, &y))
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
707 return NULL;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
708 if (!surf)
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
709 return RAISE (PyExc_SDLError, "display Surface quit");
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
710
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
711 if (surf->flags & SDL_OPENGL)
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
712 return RAISE (PyExc_SDLError, "Cannot call on OPENGL Surfaces");
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
713
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
714 if (x < 0 || x >= surf->w || y < 0 || y >= surf->h)
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
715 return RAISE (PyExc_IndexError, "pixel index out of range");
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
716
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
717 if (format->BytesPerPixel < 1 || format->BytesPerPixel > 4)
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
718 return RAISE (PyExc_RuntimeError, "invalid color depth for surface");
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
719
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
720 if (!PySurface_Lock (self))
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
721 return NULL;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
722
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
723 pixels = (Uint8 *) surf->pixels;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
724
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
725 switch (format->BytesPerPixel) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
726
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
727 case 1:
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
728 color = (Uint32)*((Uint8 *) pixels + y * surf->pitch + x);
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
729 break;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
730 case 2:
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
731 color = (Uint32)*((Uint16 *) (pixels + y * surf->pitch) + x);
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
732 break;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
733 case 3:
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
734 pix = ((Uint8 *) (pixels + y * surf->pitch) + x * 3);
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
735 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
736 color = (pix[0]) + (pix[1] << 8) + (pix[2] << 16);
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
737 #else
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
738 color = (pix[2]) + (pix[1] << 8) + (pix[0] << 16);
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
739 #endif
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
740 break;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
741 default: /* case 4: */
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
742 color = *((Uint32 *) (pixels + y * surf->pitch) + x);
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
743 break;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
744 }
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
745 if (!PySurface_Unlock (self))
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
746 return NULL;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
747
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
748 return PyInt_FromLong ((long)color);
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
749 }
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
750
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
751 static PyObject*
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
752 surf_map_rgb (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
753 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
754 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
755 Uint8 rgba[4];
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
756 int color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
757
1037
c4c38b97db3b Added Color class.
marcus
parents: 930
diff changeset
758 if (!RGBAFromColorObj (args, rgba))
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
759 return RAISE (PyExc_TypeError, "Invalid RGBA argument");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
760 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
761 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
762
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
763 color = SDL_MapRGBA (surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
1479
55f90112edd9 revert unintended change to surface.rgb_map in rev 1875
Lenard Lindstrom <len-l@telus.net>
parents: 1472
diff changeset
764 return PyInt_FromLong (color);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
765 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
766
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
767 static PyObject*
1472
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
768 surf_unmap_rgb (PyObject *self, PyObject *arg)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
769 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
770 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
771 Uint32 col;
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
772 Uint8 rgba[4];
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
773
1472
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
774 col = (Uint32)PyInt_AsLong (arg);
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
775 if (col == (Uint32) -1 && PyErr_Occurred()) {
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
776 PyErr_Clear();
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
777 return RAISE (PyExc_TypeError, "unmap_rgb expects 1 number argument");
1472
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
778 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
779 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
780 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
781
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
782 SDL_GetRGBA (col, surf->format, rgba, rgba+1, rgba+2, rgba+3);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
783
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
784 return PyColor_New (rgba);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
785 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
786
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
787 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
788 surf_lock (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
789 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
790 if (!PySurface_Lock (self))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
791 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
792 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
793 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
794
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
795 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
796 surf_unlock (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
797 {
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
798 PySurface_Unlock (self);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
799 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
800 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
801
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
802 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
803 surf_mustlock (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
804 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
805 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
806 return PyInt_FromLong (SDL_MUSTLOCK (surf) ||
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
807 ((PySurfaceObject *) self)->subsurface);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
808 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
809
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
810 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
811 surf_get_locked (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
812 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
813 PySurfaceObject *surf = (PySurfaceObject *) self;
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
814
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
815 if (surf->locklist && PyList_Size (surf->locklist) > 0)
854
e5533b8458df a few more changes from Marcus that I missed committing from the
Rene Dudfield <renesd@gmail.com>
parents: 850
diff changeset
816 Py_RETURN_TRUE;
e5533b8458df a few more changes from Marcus that I missed committing from the
Rene Dudfield <renesd@gmail.com>
parents: 850
diff changeset
817 Py_RETURN_FALSE;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
818 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
820 static PyObject*
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
821 surf_get_locks (PyObject *self)
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
822 {
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
823 PySurfaceObject *surf = (PySurfaceObject *) self;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
824 Py_ssize_t len, i = 0;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
825 PyObject *tuple, *tmp;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
826 if (!surf->locklist)
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
827 return PyTuple_New (0);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
828
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
829 len = PyList_Size (surf->locklist);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
830 tuple = PyTuple_New (len);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
831 if (!tuple)
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
832 return NULL;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
833
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
834 for (i = 0; i < len; i++) {
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
835 tmp = PyWeakref_GetObject (PyList_GetItem (surf->locklist, i));
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
836 Py_INCREF (tmp);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
837 PyTuple_SetItem (tuple, i, tmp);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
838 }
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
839 return tuple;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
840 }
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
841
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
842 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
843 surf_get_palette (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
844 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
845 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
846 SDL_Palette *pal = surf->format->palette;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
847 PyObject *list;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
848 int i;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
849 PyObject *color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
850 SDL_Color *c;
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
851 Uint8 rgba[4] = {0, 0, 0, 255};
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
852
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
853 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
854 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
855
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
856 if (!pal)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
857 return RAISE (PyExc_SDLError, "Surface has no palette to get\n");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
858
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
859 list = PyTuple_New (pal->ncolors);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
860 if (!list)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
861 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
862
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
863 for (i = 0; i < pal->ncolors; i++) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
864 c = &pal->colors[i];
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
865 rgba[0] = c->r;
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
866 rgba[1] = c->g;
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
867 rgba[2] = c->b;
1882
b52bfc5316c3 Surface.get_palette(_at) return Color with length 3.
Rene Dudfield <renesd@gmail.com>
parents: 1855
diff changeset
868 color = PyColor_NewLength (rgba, 3);
b52bfc5316c3 Surface.get_palette(_at) return Color with length 3.
Rene Dudfield <renesd@gmail.com>
parents: 1855
diff changeset
869
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
870 if (!color) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
871 Py_DECREF (list);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
872 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
873 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
874 PyTuple_SET_ITEM (list, i, color);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
875 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
876
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
877 return list;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
878 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
879
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
880 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
881 surf_get_palette_at (PyObject * self, PyObject * args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
882 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
883 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
884 SDL_Palette *pal = surf->format->palette;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
885 SDL_Color *c;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
886 int _index;
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
887 Uint8 rgba[4];
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
888
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
889 if (!PyArg_ParseTuple (args, "i", &_index))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
890 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
891 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
892 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
893
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
894 if (!pal)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
895 return RAISE (PyExc_SDLError, "Surface has no palette to set\n");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
896 if (_index >= pal->ncolors || _index < 0)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
897 return RAISE (PyExc_IndexError, "index out of bounds");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
898
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
899 c = &pal->colors[_index];
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
900 rgba[0] = c->r;
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
901 rgba[1] = c->g;
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
902 rgba[2] = c->b;
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
903 rgba[3] = 255;
1882
b52bfc5316c3 Surface.get_palette(_at) return Color with length 3.
Rene Dudfield <renesd@gmail.com>
parents: 1855
diff changeset
904
b52bfc5316c3 Surface.get_palette(_at) return Color with length 3.
Rene Dudfield <renesd@gmail.com>
parents: 1855
diff changeset
905 return PyColor_NewLength (rgba, 3);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
906 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
907
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
908 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
909 surf_set_palette (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
910 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
911 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
912 SDL_Palette *pal = surf->format->palette;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
913 SDL_Color *colors;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
914 PyObject *list, *item;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
915 int i, len;
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
916 Uint8 rgba[4];
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
917 int ecode;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
918
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
919 if (!PyArg_ParseTuple (args, "O", &list))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
920 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
921 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
922 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
923 if (!PySequence_Check (list))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
924 return RAISE (PyExc_ValueError, "Argument must be a sequence type");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
925
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
926 if (!pal)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
927 return RAISE (PyExc_SDLError, "Surface has no palette\n");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
928
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
929 if (!SDL_WasInit (SDL_INIT_VIDEO))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
930 return RAISE (PyExc_SDLError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
931 "cannot set palette without pygame.display initialized");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
932
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
933 len = MIN (pal->ncolors, PySequence_Length (list));
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
934
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
935 colors = (SDL_Color *) malloc (len * sizeof (SDL_Color));
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
936 if (!colors)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
937 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
938
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
939 for (i = 0; i < len; i++) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
940 item = PySequence_GetItem (list, i);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
941
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
942 ecode = RGBAFromObj (item, rgba);
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
943 Py_DECREF (item);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
944 if (!ecode) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
945 free (colors);
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
946 return RAISE (PyExc_ValueError,
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
947 "takes a sequence of integers of RGB");
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
948 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
949 if (rgba[3] != 255) {
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
950 free (colors);
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
951 return RAISE (PyExc_ValueError,
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
952 "takes an alpha value of 255");
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
953 }
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
954 colors[i].r = (unsigned char) rgba[0];
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
955 colors[i].g = (unsigned char) rgba[1];
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
956 colors[i].b = (unsigned char) rgba[2];
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
957 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
958
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
959 SDL_SetColors (surf, colors, 0, len);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
960 free (colors);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
961 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
962 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
963
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
964 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
965 surf_set_palette_at (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
966 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
967 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
968 SDL_Palette *pal = surf->format->palette;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
969 SDL_Color color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
970 int _index;
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
971 PyObject *color_obj;
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
972 Uint8 rgba[4];
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
973
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
974 if (!PyArg_ParseTuple (args, "iO", &_index, &color_obj))
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
975 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
976 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
977 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
978
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
979 if (!RGBAFromObj (color_obj, rgba)) {
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
980 return RAISE (PyExc_ValueError,
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
981 "takes a sequence of integers of RGB for argument 2");
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
982 }
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
983
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
984 if (!pal) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
985 PyErr_SetString (PyExc_SDLError, "Surface is not palettized\n");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
986 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
987 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
988
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
989 if (_index >= pal->ncolors || _index < 0) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
990 PyErr_SetString (PyExc_IndexError, "index out of bounds");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
991 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
992 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
993
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
994 if (!SDL_WasInit (SDL_INIT_VIDEO))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
995 return RAISE (PyExc_SDLError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
996 "cannot set palette without pygame.display initialized");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
997
1855
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
998 color.r = rgba[0];
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
999 color.g = rgba[1];
817395a5cda7 let Surface methods accept and return Color instances
Lenard Lindstrom <len-l@telus.net>
parents: 1585
diff changeset
1000 color.b = rgba[2];
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1001
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1002 SDL_SetColors (surf, &color, _index, 1);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1003
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1004 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1005 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1006
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1007 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1008 surf_set_colorkey (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1009 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1010 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1011 Uint32 flags = 0, color = 0;
1111
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1012 PyObject *rgba_obj = NULL;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1013 Uint8 rgba[4];
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1014 int result, hascolor = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1015
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1016 if (!PyArg_ParseTuple (args, "|Oi", &rgba_obj, &flags))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1017 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1018 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1019 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1020
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1021 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1022 return RAISE (PyExc_SDLError, "Cannot call on OPENGL Surfaces");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1023
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1024 if (rgba_obj && rgba_obj != Py_None) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1025 if (PyInt_Check (rgba_obj)) {
1111
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1026 color = (Uint32) PyInt_AsLong (rgba_obj);
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1027 if (PyErr_Occurred () && (Sint32) color == -1)
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1028 return RAISE (PyExc_TypeError, "invalid color argument");
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1029 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1030 else if (PyLong_Check (rgba_obj)) {
1111
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1031 color = (Uint32) PyLong_AsUnsignedLong (rgba_obj);
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1032 if (PyErr_Occurred () && (Sint32) color == -1)
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1033 return RAISE (PyExc_TypeError, "invalid color argument");
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1034 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1035 else if (RGBAFromColorObj (rgba_obj, rgba)) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1036 color = SDL_MapRGBA (surf->format, rgba[0], rgba[1], rgba[2],
1111
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1037 rgba[3]);
a1866511e5bf Fixed some rounding issues for the color conversions. Fixed colorkey assignment issues. The Color stuff still has some problems though.
marcus
parents: 1085
diff changeset
1038 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1039 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1040 return RAISE (PyExc_TypeError, "invalid color argument");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1041 hascolor = 1;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1042 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1043 if (hascolor)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1044 flags |= SDL_SRCCOLORKEY;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1045
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1046 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1047 result = SDL_SetColorKey (surf, flags, color);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1048 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1049
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1050 if (result == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1051 return RAISE (PyExc_SDLError, SDL_GetError ());
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1052
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1053 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1054 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1055
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1056 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1057 surf_get_colorkey (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1058 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1059 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1060 Uint8 r, g, b, a;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1061
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1062 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1063 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1064
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1065 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1066 return RAISE (PyExc_SDLError, "Cannot call on OPENGL Surfaces");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1067
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1068 if (!(surf->flags & SDL_SRCCOLORKEY))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1069 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1070
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1071 SDL_GetRGBA (surf->format->colorkey, surf->format, &r, &g, &b, &a);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1072 return Py_BuildValue ("(bbbb)", r, g, b, a);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1073 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1074
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1075 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1076 surf_set_alpha (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1077 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1078 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1079 Uint32 flags = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1080 PyObject *alpha_obj = NULL, *intobj = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1081 Uint8 alpha;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1082 int result, alphaval = 255, hasalpha = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1083
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1084 if (!PyArg_ParseTuple (args, "|Oi", &alpha_obj, &flags))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1085 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1086 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1087 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1088
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1089 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1090 return RAISE (PyExc_SDLError, "Cannot call on OPENGL Surfaces");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1091
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1092 if (alpha_obj && alpha_obj != Py_None) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1093 if (PyNumber_Check (alpha_obj) &&
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1094 (intobj = PyNumber_Int (alpha_obj))) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1095 if (PyInt_Check (intobj)) {
1117
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1096 alphaval = (int) PyInt_AsLong (intobj);
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1097 Py_DECREF (intobj);
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1098 }
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1099 else
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1100 return RAISE (PyExc_TypeError, "invalid alpha argument");
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1101 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1102 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1103 return RAISE (PyExc_TypeError, "invalid alpha argument");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1104 hasalpha = 1;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1105 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1106 if (hasalpha)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1107 flags |= SDL_SRCALPHA;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1108
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1109 if (alphaval > 255)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1110 alpha = 255;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1111 else if (alphaval < 0)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1112 alpha = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1113 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1114 alpha = (Uint8) alphaval;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1115
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1116 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1117 result = SDL_SetAlpha (surf, flags, alpha);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1118 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1119
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1120 if (result == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1121 return RAISE (PyExc_SDLError, SDL_GetError ());
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1122
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1123 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1124 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1125
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1126 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1127 surf_get_alpha (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1128 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1129 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1130
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1131 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1132 return RAISE (PyExc_SDLError, "Cannot call on OPENGL Surfaces");
847
c371a13ae53b fixed a segfault for get_bitsize, get_bytesize, and get_alpha with 24 bit surfaces, and uninitialised pygame.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
1133 if (!surf)
c371a13ae53b fixed a segfault for get_bitsize, get_bytesize, and get_alpha with 24 bit surfaces, and uninitialised pygame.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
1134 return RAISE (PyExc_SDLError, "display Surface quit");
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1135
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1136 if (surf->flags & SDL_SRCALPHA)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1137 return PyInt_FromLong (surf->format->alpha);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1138
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1139 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1140 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1141
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1142 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1143 surf_copy (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1144 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1145 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1146 PyObject *final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1147 SDL_Surface *newsurf;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1148
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1149 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1150 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1151
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1152 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1153 return RAISE (PyExc_SDLError, "Cannot copy opengl display");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1154
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1155 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1156 newsurf = SDL_ConvertSurface (surf, surf->format, surf->flags);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1157 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1158
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1159 final = PySurface_New (newsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1160 if (!final)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1161 SDL_FreeSurface (newsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1162 return final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1163 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1164
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1165 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1166 surf_convert (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1167 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1168 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1169 PyObject *final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1170 PyObject *argobject = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1171 SDL_Surface *src;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1172 SDL_Surface *newsurf;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1173 Uint32 flags = -1;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1174
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1175 if (!SDL_WasInit (SDL_INIT_VIDEO))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1176 return RAISE (PyExc_SDLError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1177 "cannot convert without pygame.display initialized");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1178
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1179 if (!PyArg_ParseTuple (args, "|Oi", &argobject, &flags))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1180 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1181
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1182 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1183 return RAISE (PyExc_SDLError, "Cannot convert opengl display");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1184
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1185 PySurface_Prep (self);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1186 if (argobject) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1187 if (PySurface_Check (argobject)) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1188 src = PySurface_AsSurface (argobject);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1189 flags = src->flags |
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1190 (surf->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1191 newsurf = SDL_ConvertSurface (surf, src->format, flags);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1192 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1193 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1194 int bpp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1195 SDL_PixelFormat format;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1196
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1197 memcpy (&format, surf->format, sizeof (format));
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1198 if (IntFromObj (argobject, &bpp)) {
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1199 Uint32 Rmask, Gmask, Bmask, Amask;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1200
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1201 if (flags != -1 && flags & SDL_SRCALPHA) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1202 switch (bpp) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1203
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1204 case 16:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1205 Rmask = 0xF << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1206 Gmask = 0xF << 4;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1207 Bmask = 0xF;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1208 Amask = 0xF << 12;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1209 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1210 case 32:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1211 Rmask = 0xFF << 16;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1212 Gmask = 0xFF << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1213 Bmask = 0xFF;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1214 Amask = 0xFF << 24;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1215 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1216 default:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1217 return RAISE (PyExc_ValueError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1218 "no standard masks exist for given "
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1219 "bitdepth with alpha");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1220 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1221 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1222 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1223 Amask = 0;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1224 switch (bpp) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1225
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1226 case 8:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1227 Rmask = 0xFF >> 6 << 5;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1228 Gmask = 0xFF >> 5 << 2;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1229 Bmask = 0xFF >> 6;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1230 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1231 case 12:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1232 Rmask = 0xFF >> 4 << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1233 Gmask = 0xFF >> 4 << 4;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1234 Bmask = 0xFF >> 4;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1235 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1236 case 15:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1237 Rmask = 0xFF >> 3 << 10;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1238 Gmask = 0xFF >> 3 << 5;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1239 Bmask = 0xFF >> 3;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1240 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1241 case 16:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1242 Rmask = 0xFF >> 3 << 11;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1243 Gmask = 0xFF >> 2 << 5;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1244 Bmask = 0xFF >> 3;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1245 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1246 case 24:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1247 case 32:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1248 Rmask = 0xFF << 16;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1249 Gmask = 0xFF << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1250 Bmask = 0xFF;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1251 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1252 default:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1253 return RAISE (PyExc_ValueError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1254 "nonstandard bit depth given");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1255 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1256 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1257 format.Rmask = Rmask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1258 format.Gmask = Gmask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1259 format.Bmask = Bmask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1260 format.Amask = Amask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1261 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1262 else if (PySequence_Check (argobject) &&
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1263 PySequence_Size (argobject) == 4) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1264 Uint32 mask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1265
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1266 if (!UintFromObjIndex (argobject, 0, &format.Rmask) ||
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1267 !UintFromObjIndex (argobject, 1, &format.Gmask) ||
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1268 !UintFromObjIndex (argobject, 2, &format.Bmask) ||
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1269 !UintFromObjIndex (argobject, 3, &format.Amask)) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1270 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1271 return RAISE (PyExc_ValueError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1272 "invalid color masks given");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1273 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1274 mask = format.Rmask | format.Gmask | format.Bmask |
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1275 format.Amask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1276 for (bpp = 0; bpp < 32; ++bpp)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1277 if (!(mask >> bpp))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1278 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1279 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1280 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1281 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1282 return RAISE
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1283 (PyExc_ValueError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1284 "invalid argument specifying new format to convert to");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1285 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1286 format.BitsPerPixel = (Uint8) bpp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1287 format.BytesPerPixel = (bpp + 7) / 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1288 if (flags == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1289 flags = surf->flags;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1290 if (format.Amask)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1291 flags |= SDL_SRCALPHA;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1292 newsurf = SDL_ConvertSurface (surf, &format, flags);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1293 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1294 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1295 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1296 if (SDL_WasInit (SDL_INIT_VIDEO))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1297 newsurf = SDL_DisplayFormat (surf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1298 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1299 newsurf = SDL_ConvertSurface (surf, surf->format, surf->flags);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1300 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1301 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1302
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1303 final = PySurface_New (newsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1304 if (!final)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1305 SDL_FreeSurface (newsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1306 return final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1307 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1308
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1309 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1310 surf_convert_alpha (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1311 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1312 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1313 PyObject *final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1314 PySurfaceObject *srcsurf = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1315 SDL_Surface *newsurf, *src;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1316
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1317 if (!SDL_WasInit (SDL_INIT_VIDEO))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1318 return RAISE (PyExc_SDLError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1319 "cannot convert without pygame.display initialized");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1320
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1321 if (!PyArg_ParseTuple (args, "|O!", &PySurface_Type, &srcsurf))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1322 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1323
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1324 PySurface_Prep (self);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1325 if (srcsurf) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1326 /*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1327 * hmm, we have to figure this out, not all depths have good
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1328 * support for alpha
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1329 */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1330 src = PySurface_AsSurface (srcsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1331 newsurf = SDL_DisplayFormatAlpha (surf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1332 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1333 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1334 newsurf = SDL_DisplayFormatAlpha (surf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1335 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1336
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1337 final = PySurface_New (newsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1338 if (!final)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1339 SDL_FreeSurface (newsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1340 return final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1341 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1342
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1343 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1344 surf_set_clip (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1345 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1346 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1347 PyObject *item;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1348 GAME_Rect *rect = NULL, temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1349 SDL_Rect sdlrect;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1350 int result;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1351
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1352 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1353 return RAISE (PyExc_SDLError, "display Surface quit");
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1354 if (PyTuple_Size (args)) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1355 item = PyTuple_GET_ITEM (args, 0);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1356 if (item == Py_None && PyTuple_Size (args) == 1) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1357 result = SDL_SetClipRect (surf, NULL);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1358 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1359 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1360 rect = GameRect_FromObject (args, &temp);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1361 if (!rect)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1362 return RAISE (PyExc_ValueError, "invalid rectstyle object");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1363 sdlrect.x = rect->x;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1364 sdlrect.y = rect->y;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1365 sdlrect.h = rect->h;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1366 sdlrect.w = rect->w;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1367 result = SDL_SetClipRect (surf, &sdlrect);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1368 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1369 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1370 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1371 result = SDL_SetClipRect (surf, NULL);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1372 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1373
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1374 if (result == -1) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1375 return RAISE (PyExc_SDLError, SDL_GetError ());
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1376 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1377
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1378 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1379 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1380
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1381 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1382 surf_get_clip (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1383 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1384 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1385
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1386 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1387 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1388 return PyRect_New (&surf->clip_rect);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1389 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1390
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1391
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1392 static PyObject*
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1393 surf_fill (PyObject *self, PyObject *args, PyObject *keywds)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1394 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1395 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1396 GAME_Rect *rect, temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1397 PyObject *r = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1398 Uint32 color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1399 int result;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1400 PyObject *rgba_obj;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1401 Uint8 rgba[4];
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1402 SDL_Rect sdlrect;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1403 int blendargs = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1404
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1405 static char *kwids[] = {"color", "rect", "special_flags", NULL};
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1406 if (!PyArg_ParseTupleAndKeywords (args, keywds, "O|Oi", kwids,
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1407 &rgba_obj, &r, &blendargs))
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1408 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1409 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1410 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1411
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1412 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1413 return RAISE (PyExc_SDLError, "Cannot call on OPENGL Surfaces");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1414
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1415 if (PyInt_Check (rgba_obj))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1416 color = (Uint32) PyInt_AsLong (rgba_obj);
1117
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1417 else if (PyLong_Check (rgba_obj))
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1418 color = (Uint32) PyLong_AsUnsignedLong (rgba_obj);
1037
c4c38b97db3b Added Color class.
marcus
parents: 930
diff changeset
1419 else if (RGBAFromColorObj (rgba_obj, rgba))
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1420 color = SDL_MapRGBA (surf->format, rgba[0], rgba[1], rgba[2], rgba[3]);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1421 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1422 return RAISE (PyExc_TypeError, "invalid color argument");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1423
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1424 if (!r || r == Py_None) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1425 rect = &temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1426 temp.x = temp.y = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1427 temp.w = surf->w;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1428 temp.h = surf->h;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1429 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1430 else if (!(rect = GameRect_FromObject (r, &temp)))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1431 return RAISE (PyExc_ValueError, "invalid rectstyle object");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1432
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1433 /* we need a fresh copy so our Rect values don't get munged */
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1434 if (rect != &temp) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1435 memcpy (&temp, rect, sizeof (temp));
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1436 rect = &temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1437 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1438
3032
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1439 if (rect->w < 0 || rect->h < 0 || rect->x > surf->w || rect->y > surf->h) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1440 sdlrect.x = sdlrect.y = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1441 sdlrect.w = sdlrect.h = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1442 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1443 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1444 sdlrect.x = rect->x;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1445 sdlrect.y = rect->y;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1446 sdlrect.w = rect->w;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1447 sdlrect.h = rect->h;
3033
efe9c4a4e42f Another fix for #93 where x or y were less than 0.
Rene Dudfield <renesd@gmail.com>
parents: 3032 3030
diff changeset
1448
3032
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1449 // clip the rect to be within the surface.
3124
eb3dc1a0d9d1 Return empty rect if coordinates make rect off screen. Fixes #123.
Rene Dudfield <renesd@gmail.com>
parents: 3033
diff changeset
1450 if(sdlrect.x + sdlrect.w <= 0 || sdlrect.y + sdlrect.h <= 0) {
eb3dc1a0d9d1 Return empty rect if coordinates make rect off screen. Fixes #123.
Rene Dudfield <renesd@gmail.com>
parents: 3033
diff changeset
1451 sdlrect.w = 0;
eb3dc1a0d9d1 Return empty rect if coordinates make rect off screen. Fixes #123.
Rene Dudfield <renesd@gmail.com>
parents: 3033
diff changeset
1452 sdlrect.h = 0;
eb3dc1a0d9d1 Return empty rect if coordinates make rect off screen. Fixes #123.
Rene Dudfield <renesd@gmail.com>
parents: 3033
diff changeset
1453 }
eb3dc1a0d9d1 Return empty rect if coordinates make rect off screen. Fixes #123.
Rene Dudfield <renesd@gmail.com>
parents: 3033
diff changeset
1454
3033
efe9c4a4e42f Another fix for #93 where x or y were less than 0.
Rene Dudfield <renesd@gmail.com>
parents: 3032 3030
diff changeset
1455 if (sdlrect.x < 0) {
efe9c4a4e42f Another fix for #93 where x or y were less than 0.
Rene Dudfield <renesd@gmail.com>
parents: 3032 3030
diff changeset
1456 sdlrect.x = 0;
efe9c4a4e42f Another fix for #93 where x or y were less than 0.
Rene Dudfield <renesd@gmail.com>
parents: 3032 3030
diff changeset
1457 }
efe9c4a4e42f Another fix for #93 where x or y were less than 0.
Rene Dudfield <renesd@gmail.com>
parents: 3032 3030
diff changeset
1458 if (sdlrect.y < 0) {
efe9c4a4e42f Another fix for #93 where x or y were less than 0.
Rene Dudfield <renesd@gmail.com>
parents: 3032 3030
diff changeset
1459 sdlrect.y = 0;
efe9c4a4e42f Another fix for #93 where x or y were less than 0.
Rene Dudfield <renesd@gmail.com>
parents: 3032 3030
diff changeset
1460 }
efe9c4a4e42f Another fix for #93 where x or y were less than 0.
Rene Dudfield <renesd@gmail.com>
parents: 3032 3030
diff changeset
1461
3032
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1462 if(sdlrect.x + sdlrect.w > surf->w) {
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1463 sdlrect.w = sdlrect.w + (surf->w - (sdlrect.x + sdlrect.w));
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1464 }
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1465 if(sdlrect.y + sdlrect.h > surf->h) {
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1466 sdlrect.h = sdlrect.h + (surf->h - (sdlrect.y + sdlrect.h));
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1467 }
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1468
3124
eb3dc1a0d9d1 Return empty rect if coordinates make rect off screen. Fixes #123.
Rene Dudfield <renesd@gmail.com>
parents: 3033
diff changeset
1469 /* printf("%d, %d, %d, %d\n", sdlrect.x, sdlrect.y, sdlrect.w, sdlrect.h); */
3032
77c972eb11f0 [BUG] Fixes #93. Where oversized input rect would not work
Rene Dudfield <renesd@gmail.com>
parents: 3004
diff changeset
1470
3033
efe9c4a4e42f Another fix for #93 where x or y were less than 0.
Rene Dudfield <renesd@gmail.com>
parents: 3032 3030
diff changeset
1471
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1472 if (blendargs != 0) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1473
825
bae45548347d commented out some printf's.
Rene Dudfield <renesd@gmail.com>
parents: 819
diff changeset
1474 /*
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1475 printf ("Using blendargs: %d\n", blendargs);
825
bae45548347d commented out some printf's.
Rene Dudfield <renesd@gmail.com>
parents: 819
diff changeset
1476 */
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1477 result = surface_fill_blend (surf, &sdlrect, color, blendargs);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1478 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1479 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1480 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1481 result = SDL_FillRect (surf, &sdlrect, color);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1482 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1483 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1484 if (result == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1485 return RAISE (PyExc_SDLError, SDL_GetError ());
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1486 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1487 return PyRect_New (&sdlrect);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1488 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1489
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1490 static PyObject*
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1491 surf_blit (PyObject *self, PyObject *args, PyObject *keywds)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1492 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1493 SDL_Surface *src, *dest = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1494 GAME_Rect *src_rect, temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1495 PyObject *srcobject, *argpos, *argrect = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1496 int dx, dy, result;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1497 SDL_Rect dest_rect, sdlsrc_rect;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1498 int sx, sy;
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1499 int the_args = 0;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1500
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1501 static char *kwids[] = {"source", "dest", "area", "special_flags", NULL};
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1502 if (!PyArg_ParseTupleAndKeywords (args, keywds, "O!O|Oi", kwids,
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1503 &PySurface_Type, &srcobject, &argpos,
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1504 &argrect, &the_args))
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1505 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1506
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1507 src = PySurface_AsSurface (srcobject);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1508 if (!dest || !src)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1509 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1510
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1511 if (dest->flags & SDL_OPENGL &&
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1512 !(dest->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL)))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1513 return RAISE (PyExc_SDLError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1514 "Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1515
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1516 if ((src_rect = GameRect_FromObject (argpos, &temp))) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1517 dx = src_rect->x;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1518 dy = src_rect->y;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1519 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1520 else if (TwoIntsFromObj (argpos, &sx, &sy)) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1521 dx = sx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1522 dy = sy;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1523 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1524 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1525 return RAISE (PyExc_TypeError, "invalid destination position for blit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1526
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1527 if (argrect && argrect != Py_None) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1528 if (!(src_rect = GameRect_FromObject (argrect, &temp)))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1529 return RAISE (PyExc_TypeError, "Invalid rectstyle argument");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1530 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1531 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1532 temp.x = temp.y = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1533 temp.w = src->w;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1534 temp.h = src->h;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1535 src_rect = &temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1536 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1537
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1538 dest_rect.x = (short) dx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1539 dest_rect.y = (short) dy;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1540 dest_rect.w = (unsigned short) src_rect->w;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1541 dest_rect.h = (unsigned short) src_rect->h;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1542 sdlsrc_rect.x = (short) src_rect->x;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1543 sdlsrc_rect.y = (short) src_rect->y;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1544 sdlsrc_rect.w = (unsigned short) src_rect->w;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1545 sdlsrc_rect.h = (unsigned short) src_rect->h;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1546
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1547 if (!the_args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1548 the_args = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1549
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1550 result = PySurface_Blit (self, srcobject, &dest_rect, &sdlsrc_rect,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1551 the_args);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1552 if (result != 0)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1553 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1554
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1555 return PyRect_New (&dest_rect);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1556 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1557
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1558 static PyObject*
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1559 surf_scroll (PyObject *self, PyObject *args, PyObject *keywds)
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1560 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1561 int dx = 0, dy = 0;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1562 SDL_Surface *surf;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1563 int bpp;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1564 int pitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1565 SDL_Rect *clip_rect;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1566 int w, h;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1567 Uint8 *src, *dst;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1568
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1569 static char *kwids[] = {"dx", "dy", NULL};
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1570 if (!PyArg_ParseTupleAndKeywords (args, keywds, "|ii", kwids, &dx, &dy)) {
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1571 return NULL;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1572 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1573
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1574 surf = PySurface_AsSurface (self);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1575 if (!surf) {
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1576 return RAISE (PyExc_SDLError, "display Surface quit");
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1577 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1578
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1579 if (surf->flags & SDL_OPENGL &&
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1580 !(surf->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL))) {
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1581 return RAISE (PyExc_SDLError,
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1582 "Cannot scroll an OPENGL Surfaces (OPENGLBLIT is ok)");
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1583 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1584
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1585 if (dx == 0 && dy == 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1586 Py_RETURN_NONE;
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1587 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1588
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1589 clip_rect = &surf->clip_rect;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1590 w = clip_rect->w;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1591 h = clip_rect->h;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1592 if (dx >= w || dx <= -w || dy >= h || dy <= -h) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1593 Py_RETURN_NONE;
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1594 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1595
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1596 if (!PySurface_Lock (self)) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1597 return NULL;
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1598 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1599
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1600 bpp = surf->format->BytesPerPixel;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1601 pitch = surf->pitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1602 src = dst = (Uint8 *) surf->pixels +
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1603 clip_rect->y * pitch + clip_rect->x * bpp;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1604 if (dx >= 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1605 w -= dx;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1606 if (dy > 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1607 h -= dy;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1608 dst += dy * pitch + dx * bpp;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1609 }
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1610 else {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1611 h += dy;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1612 src -= dy * pitch;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1613 dst += dx * bpp;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1614 }
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1615 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1616 else {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1617 w += dx;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1618 if (dy > 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1619 h -= dy;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1620 src -= dx * bpp;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1621 dst += dy * pitch;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1622 }
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1623 else {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1624 h += dy;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1625 src -= dy * pitch + dx * bpp;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1626 }
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1627 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1628 surface_move (src, dst, h, w * bpp, pitch, pitch);
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1629
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1630 if (!PySurface_Unlock (self)) {
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1631 return NULL;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1632 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1633
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1634 Py_RETURN_NONE;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1635 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1636
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1637 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1638 surf_get_flags (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1639 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1640 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1641
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1642 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1643 return RAISE (PyExc_SDLError, "display Surface quit");
854
e5533b8458df a few more changes from Marcus that I missed committing from the
Rene Dudfield <renesd@gmail.com>
parents: 850
diff changeset
1644 return PyInt_FromLong ((long)surf->flags);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1645 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1646
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1647 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1648 surf_get_pitch (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1649 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1650 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1651
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1652 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1653 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1654 return PyInt_FromLong (surf->pitch);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1655 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1656
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1657 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1658 surf_get_size (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1659 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1660 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1661
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1662 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1663 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1664 return Py_BuildValue ("(ii)", surf->w, surf->h);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1665 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1666
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1667 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1668 surf_get_width (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1669 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1670 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1671
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1672 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1673 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1674 return PyInt_FromLong (surf->w);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1675 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1676
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1677 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1678 surf_get_height (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1679 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1680 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1681
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1682 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1683 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1684 return PyInt_FromLong (surf->h);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1685 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1686
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1687 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1688 surf_get_rect (PyObject *self, PyObject *args, PyObject *kwargs)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1689 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1690 PyObject *rect;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1691 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1692
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
1693 if (PyTuple_GET_SIZE (args) > 0) {
1578
c0d170c1e636 all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents: 1553
diff changeset
1694 return RAISE (PyExc_TypeError,
c0d170c1e636 all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents: 1553
diff changeset
1695 "get_rect only accepts keyword arguments");
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
1696 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
1697
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1698 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1699 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1700
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1701 rect = PyRect_New4 (0, 0, surf->w, surf->h);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1702 if (rect && kwargs) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1703 PyObject *key, *value;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1704 Py_ssize_t pos = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1705
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1706 while (PyDict_Next (kwargs, &pos, &key, &value)) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1707 if ((PyObject_SetAttr (rect, key, value) == -1)) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1708 Py_DECREF (rect);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1709 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1710 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1711 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1712 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1713 return rect;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1714 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1715
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1716 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1717 surf_get_bitsize (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1718 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1719 SDL_Surface *surf = PySurface_AsSurface (self);
847
c371a13ae53b fixed a segfault for get_bitsize, get_bytesize, and get_alpha with 24 bit surfaces, and uninitialised pygame.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
1720 if (!surf)
c371a13ae53b fixed a segfault for get_bitsize, get_bytesize, and get_alpha with 24 bit surfaces, and uninitialised pygame.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
1721 return RAISE (PyExc_SDLError, "display Surface quit");
c371a13ae53b fixed a segfault for get_bitsize, get_bytesize, and get_alpha with 24 bit surfaces, and uninitialised pygame.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
1722
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1723 return PyInt_FromLong (surf->format->BitsPerPixel);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1724 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1725
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1726 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1727 surf_get_bytesize (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1728 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1729 SDL_Surface *surf = PySurface_AsSurface (self);
847
c371a13ae53b fixed a segfault for get_bitsize, get_bytesize, and get_alpha with 24 bit surfaces, and uninitialised pygame.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
1730 if (!surf)
c371a13ae53b fixed a segfault for get_bitsize, get_bytesize, and get_alpha with 24 bit surfaces, and uninitialised pygame.
Rene Dudfield <renesd@gmail.com>
parents: 831
diff changeset
1731 return RAISE (PyExc_SDLError, "display Surface quit");
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1732 return PyInt_FromLong (surf->format->BytesPerPixel);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1733 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1734
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1735 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1736 surf_get_masks (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1737 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1738 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1739
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1740 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1741 return RAISE (PyExc_SDLError, "display Surface quit");
1900
46cf8eef39cc 64bit issues with Surface.get_masks and UintFromObj. thanks Lorenz Quack!
Rene Dudfield <renesd@gmail.com>
parents: 1882
diff changeset
1742 return Py_BuildValue ("(IIII)", surf->format->Rmask, surf->format->Gmask,
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1743 surf->format->Bmask, surf->format->Amask);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1744 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1745
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1746
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1747 static PyObject*
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1748 surf_set_masks (PyObject *self, PyObject *args)
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1749 {
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1750 SDL_Surface *surf = PySurface_AsSurface (self);
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1751 /* Need to use 64bit vars so this works on 64 bit pythons. */
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1752 Uint64 r, g, b, a;
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1753
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1754 if (!PyArg_ParseTuple (args, "(kkkk)", &r, &g, &b, &a))
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1755 return NULL;
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1756 if (!surf)
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1757 return RAISE (PyExc_SDLError, "display Surface quit");
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1758
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1759 /*
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1760 printf("passed in: %d, %d, %d, %d\n", r,g,b,a );
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1761 printf("what are: %d, %d, %d, %d\n", surf->format->Rmask, surf->format->Gmask, surf->format->Bmask, surf->format->Amask);
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1762 */
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1763
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1764 surf->format->Rmask = (Uint32)r;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1765 surf->format->Gmask = (Uint32)g;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1766 surf->format->Bmask = (Uint32)b;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1767 surf->format->Amask = (Uint32)a;
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1768
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1769 Py_RETURN_NONE;
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1770 }
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1771
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1772
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1773
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1774
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1775
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1776 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1777 surf_get_shifts (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1778 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1779 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1780
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1781 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1782 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1783 return Py_BuildValue ("(iiii)", surf->format->Rshift, surf->format->Gshift,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1784 surf->format->Bshift, surf->format->Ashift);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1785 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1786
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1787
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1788 static PyObject*
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1789 surf_set_shifts (PyObject *self, PyObject *args)
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1790 {
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1791 SDL_Surface *surf = PySurface_AsSurface (self);
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1792 Uint64 r, g, b, a;
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1793
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1794 if (!PyArg_ParseTuple (args, "(kkkk)", &r, &g, &b, &a))
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1795 return NULL;
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1796 if (!surf)
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1797 return RAISE (PyExc_SDLError, "display Surface quit");
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1798
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1799 surf->format->Rshift = (Uint8)r;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1800 surf->format->Gshift = (Uint8)g;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1801 surf->format->Bshift = (Uint8)b;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1802 surf->format->Ashift = (Uint8)a;
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1803
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1804 Py_RETURN_NONE;
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1805 }
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1806
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1807
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1808
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1809
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1810
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1811
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1812
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1813 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1814 surf_get_losses (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1815 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1816 SDL_Surface *surf = PySurface_AsSurface (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1817
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1818 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1819 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1820 return Py_BuildValue ("(iiii)", surf->format->Rloss, surf->format->Gloss,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1821 surf->format->Bloss, surf->format->Aloss);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1822 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1823
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1824 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1825 surf_subsurface (PyObject *self, PyObject *args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1826 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1827 SDL_Surface *surf = PySurface_AsSurface (self);
3004
38cdc3d7302a Bug fix: Issue 2 - Surface.subsurface segfault
Lenard Lindstrom <len-l@telus.net>
parents: 2305
diff changeset
1828 SDL_PixelFormat *format;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1829 GAME_Rect *rect, temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1830 SDL_Surface *sub;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1831 PyObject *subobj;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1832 int pixeloffset;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1833 char *startpixel;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1834 struct SubSurface_Data *data;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1835
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1836 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1837 return RAISE (PyExc_SDLError, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1838 if (surf->flags & SDL_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1839 return RAISE (PyExc_SDLError, "Cannot call on OPENGL Surfaces");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1840
3004
38cdc3d7302a Bug fix: Issue 2 - Surface.subsurface segfault
Lenard Lindstrom <len-l@telus.net>
parents: 2305
diff changeset
1841 format = surf->format;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1842 if (!(rect = GameRect_FromObject (args, &temp)))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1843 return RAISE (PyExc_ValueError, "invalid rectstyle argument");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1844 if (rect->x < 0 || rect->y < 0 || rect->x + rect->w > surf->w
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1845 || rect->y + rect->h > surf->h)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1846 return RAISE (PyExc_ValueError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1847 "subsurface rectangle outside surface area");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1848
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1849 PySurface_Lock (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1850
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1851 pixeloffset = rect->x * format->BytesPerPixel + rect->y * surf->pitch;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1852 startpixel = ((char *) surf->pixels) + pixeloffset;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1853
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1854 sub = SDL_CreateRGBSurfaceFrom (startpixel, rect->w, rect->h,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1855 format->BitsPerPixel, surf->pitch,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1856 format->Rmask, format->Gmask,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1857 format->Bmask, format->Amask);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1858
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1859 PySurface_Unlock (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1860
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1861 if (!sub)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1862 return RAISE (PyExc_SDLError, SDL_GetError ());
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1863
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1864 /* copy the colormap if we need it */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1865 if (surf->format->BytesPerPixel == 1 && surf->format->palette)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1866 SDL_SetPalette (sub, SDL_LOGPAL, surf->format->palette->colors, 0,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1867 surf->format->palette->ncolors);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1868 if (surf->flags & SDL_SRCALPHA)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1869 SDL_SetAlpha (sub, surf->flags & SDL_SRCALPHA, format->alpha);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1870 if (surf->flags & SDL_SRCCOLORKEY)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1871 SDL_SetColorKey (sub, surf->flags & (SDL_SRCCOLORKEY | SDL_RLEACCEL),
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1872 format->colorkey);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1873
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1874 data = PyMem_New (struct SubSurface_Data, 1);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1875 if (!data)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1876 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1877
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1878 subobj = PySurface_New (sub);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1879 if (!subobj) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1880 PyMem_Del (data);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1881 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1882 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1883 Py_INCREF (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1884 data->owner = self;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1885 data->pixeloffset = pixeloffset;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1886 data->offsetx = rect->x;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1887 data->offsety = rect->y;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1888 ((PySurfaceObject *) subobj)->subsurface = data;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1889
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1890 return subobj;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1891 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1892
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1893 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1894 surf_get_offset (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1895 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1896 struct SubSurface_Data *subdata;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1897
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1898 subdata = ((PySurfaceObject *) self)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1899 if (!subdata)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1900 return Py_BuildValue ("(ii)", 0, 0);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1901 return Py_BuildValue ("(ii)", subdata->offsetx, subdata->offsety);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1902 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1903
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1904 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1905 surf_get_abs_offset (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1906 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1907 struct SubSurface_Data *subdata;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1908 PyObject *owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1909 int offsetx, offsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1910
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1911 subdata = ((PySurfaceObject *) self)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1912 if (!subdata)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1913 return Py_BuildValue ("(ii)", 0, 0);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1914
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1915 subdata = ((PySurfaceObject *) self)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1916 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1917 offsetx = subdata->offsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1918 offsety = subdata->offsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1919
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1920 while (((PySurfaceObject *) owner)->subsurface) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1921 subdata = ((PySurfaceObject *) owner)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1922 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1923 offsetx += subdata->offsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1924 offsety += subdata->offsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1925 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1926 return Py_BuildValue ("(ii)", offsetx, offsety);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1927 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1928
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1929 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1930 surf_get_parent (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1931 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1932 struct SubSurface_Data *subdata;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1933
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1934 subdata = ((PySurfaceObject *) self)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1935 if (!subdata)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1936 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1937
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1938 Py_INCREF (subdata->owner);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1939 return subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1940 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1941
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1942 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1943 surf_get_abs_parent (PyObject *self)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1944 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1945 struct SubSurface_Data *subdata;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1946 PyObject *owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1947
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1948 subdata = ((PySurfaceObject *) self)->subsurface;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1949 if (!subdata) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1950 Py_INCREF (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1951 return self;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1952 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1953
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1954 subdata = ((PySurfaceObject *) self)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1955 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1956
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1957 while (((PySurfaceObject *) owner)->subsurface) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1958 subdata = ((PySurfaceObject *) owner)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1959 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1960 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1961
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1962 Py_INCREF (owner);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1963 return owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1964 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1965
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1966 static PyObject *
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1967 surf_get_bounding_rect (PyObject *self, PyObject *args, PyObject *kwargs)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1968 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1969 PyObject *rect;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1970 SDL_Surface *surf = PySurface_AsSurface (self);
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1971 SDL_PixelFormat *format = surf->format;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1972 Uint8 *pixels = (Uint8 *) surf->pixels;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1973 Uint8 *pixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1974 int x, y;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1975 int min_x, min_y, max_x, max_y;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1976 int min_alpha = 1;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1977 int found_alpha = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1978 Uint8 r, g, b, a;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1979 int has_colorkey = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1980 Uint8 keyr, keyg, keyb;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1981
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1982 char *kwids[] = { "min_alpha", NULL };
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1983 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwids, &min_alpha))
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1984 return RAISE (PyExc_ValueError,
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1985 "get_bounding_rect only accepts a single optional min_alpha argument");
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1986
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1987 if (!surf)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1988 return RAISE (PyExc_SDLError, "display Surface quit");
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1989
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1990 if (!PySurface_Lock (self))
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1991 return RAISE (PyExc_SDLError, "could not lock surface");
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1992
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
1993 if (surf->flags & SDL_SRCCOLORKEY) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1994 has_colorkey = 1;
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1995 SDL_GetRGBA (surf->format->colorkey,
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1996 surf->format,
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1997 &keyr, &keyg, &keyb, &a);
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1998 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1999
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2000 pixels = (Uint8 *) surf->pixels;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2001
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2002 min_y = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2003 min_x = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2004 max_x = surf->w;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2005 max_y = surf->h;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2006
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2007 found_alpha = 0;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2008 for (y = max_y - 1; y >= min_y; --y) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2009 for (x = min_x; x < max_x; ++x) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2010 pixel = (pixels + y * surf->pitch) + x*format->BytesPerPixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2011 SDL_GetRGBA (*((Uint32*)pixel), surf->format, &r, &g, &b, &a);
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
2012 if ((a >= min_alpha && has_colorkey == 0) ||
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2013 (has_colorkey != 0 && (r != keyr || g != keyg || b != keyb))) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2014 found_alpha = 1;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2015 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2016 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2017 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2018 if (found_alpha == 1) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2019 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2020 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2021 max_y = y;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2022 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2023 found_alpha = 0;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2024 for (x = max_x - 1; x >= min_x; --x) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2025 for (y = min_y; y < max_y; ++y) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2026 pixel = (pixels + y * surf->pitch) + x*format->BytesPerPixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2027 SDL_GetRGBA (*((Uint32*)pixel), surf->format, &r, &g, &b, &a);
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
2028 if ((a >= min_alpha && has_colorkey == 0) ||
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2029 (has_colorkey != 0 && (r != keyr || g != keyg || b != keyb))) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2030 found_alpha = 1;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2031 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2032 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2033 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2034 if (found_alpha == 1) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2035 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2036 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2037 max_x = x;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2038 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2039 found_alpha = 0;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2040 for (y = min_y; y < max_y; ++y) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2041 min_y = y;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2042 for (x = min_x; x < max_x; ++x) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2043 pixel = (pixels + y * surf->pitch) + x*format->BytesPerPixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2044 SDL_GetRGBA (*((Uint32*)pixel), surf->format, &r, &g, &b, &a);
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
2045 if ((a >= min_alpha && has_colorkey == 0) ||
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2046 (has_colorkey != 0 && (r != keyr || g != keyg || b != keyb))) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2047 found_alpha = 1;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2048 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2049 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2050 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2051 if (found_alpha == 1) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2052 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2053 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2054 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2055 found_alpha = 0;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2056 for (x = min_x; x < max_x; ++x) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2057 min_x = x;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2058 for (y = min_y; y < max_y; ++y) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2059 pixel = (pixels + y * surf->pitch) + x*format->BytesPerPixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2060 SDL_GetRGBA (*((Uint32*)pixel), surf->format, &r, &g, &b, &a);
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
2061 if ((a >= min_alpha && has_colorkey == 0) ||
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2062 (has_colorkey != 0 && (r != keyr || g != keyg || b != keyb))) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2063 found_alpha = 1;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2064 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2065 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2066 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2067 if (found_alpha == 1) {
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2068 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2069 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2070 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2071 if (!PySurface_Unlock (self))
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2072 return RAISE (PyExc_SDLError, "could not unlock surface");
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2073
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2074 rect = PyRect_New4 (min_x, min_y, max_x - min_x, max_y - min_y);
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2075 return rect;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2076 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2077
1085
31789d104e1f Fixed locking and ref count leaks in Numeric surfarray.
marcus
parents: 1037
diff changeset
2078 static PyObject
31789d104e1f Fixed locking and ref count leaks in Numeric surfarray.
marcus
parents: 1037
diff changeset
2079 *surf_get_buffer (PyObject *self)
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2080 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2081 PyObject *buffer;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2082 PyObject *lock;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2083 SDL_Surface *surface = PySurface_AsSurface (self);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2084 Py_ssize_t length;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2085
868
5c55c84986c1 Added pygame.get_sdl_byteorder() to get the SDL byte order. Added pixelarray and mask html docs. Fixed buffer length in surface.get_buffer().
marcus
parents: 862
diff changeset
2086 length = (Py_ssize_t) surface->pitch * surface->h;
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2087
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2088 buffer = PyBufferProxy_New (self, NULL, length, NULL);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2089 if (!buffer) {
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2090 return RAISE (PyExc_SDLError,
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2091 "could not acquire a buffer for the surface");
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2092 }
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2093
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2094 lock = PySurface_LockLifetime (self, buffer);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2095 if (!lock) {
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2096 Py_DECREF (buffer);
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2097 return RAISE (PyExc_SDLError, "could not lock surface");
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2098 }
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2099 ((PyBufferProxy *) buffer)->buffer = surface->pixels;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2100 ((PyBufferProxy *) buffer)->lock = lock;
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2101
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2102 return buffer;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2103 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2104
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2105 static PyObject *
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2106 _raise_get_view_ndim_error(int bitsize, SurfViewKind kind) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2107 const char *kind_names[] = {"2D", "3D", "red", "green", "blue", "alpha"};
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2108 const char *name;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2109
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2110 switch (kind) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2111
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2112 case VIEWKIND_2D:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2113 name = kind_names[0];
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2114 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2115 case VIEWKIND_3D:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2116 name = kind_names[1];
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2117 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2118 case VIEWKIND_RED:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2119 name = kind_names[2];
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2120 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2121 case VIEWKIND_GREEN:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2122 name = kind_names[3];
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2123 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2124 case VIEWKIND_BLUE:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2125 name = kind_names[4];
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2126 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2127 case VIEWKIND_ALPHA:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2128 name = kind_names[5];
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2129 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2130 default:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2131 PyErr_Format(PyExc_SystemError,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2132 "pygame bug in _raise_get_view_ndim_error:"
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2133 " unknown view kind %d", (int) kind);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2134 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2135 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2136 PyErr_Format(PyExc_ValueError,
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2137 "unsupported bit depth %d for %s reference array",
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2138 bitsize, name);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2139 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2140 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2141
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2142 static PyObject *
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2143 surf_get_view(PyObject *self, PyObject *args, PyObject *kwds)
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2144 {
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2145 # define SURF_GET_VIEW_MAXDIM 3
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2146 const int lilendian = (SDL_BYTEORDER == SDL_LIL_ENDIAN);
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2147 const int maxdim = SURF_GET_VIEW_MAXDIM;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2148 typedef struct {
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2149 PyArrayInterface inter;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2150 Py_intptr_t shape_mem[SURF_GET_VIEW_MAXDIM];
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2151 Py_intptr_t strides_mem[SURF_GET_VIEW_MAXDIM];
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2152 } Interface;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2153 # undef SURF_GET_VIEW_MAXDIM
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2154 SurfViewKind view_kind = VIEWKIND_2D;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2155 int ndim = maxdim;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2156 PyObject *capsule;
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2157 Interface *allocation;
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2158 PyArrayInterface *inter;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2159 SDL_Surface *surface = PySurface_AsSurface(self);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2160 int pixelsize;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2161 int itemsize = 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2162 Py_intptr_t *shape;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2163 Py_intptr_t *strides;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2164 Uint8 *startpixel;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2165 Uint32 mask = 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2166 int pixelstep;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2167
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2168 PyObject *view;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2169 char *keywords[] = {"kind", 0};
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2170
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2171 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", keywords,
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2172 surf_view_kind, &view_kind)) {
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2173 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2174 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2175
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2176 if (!surface) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2177 return RAISE(PyExc_SDLError, "display Surface quit");
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2178 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2179
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2180 allocation = PyMem_New(Interface, 1);
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2181 if (!allocation) {
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2182 return PyErr_NoMemory();
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2183 }
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2184 inter = (PyArrayInterface *)allocation;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2185 inter->shape = allocation->shape_mem;
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2186 inter->strides = allocation->strides_mem;
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2187 #if PY3
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2188 capsule = PyCapsule_New(inter, 0, surf_arraystruct_capsule_destr);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2189 #else
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2190 capsule = PyCObject_FromVoidPtr(inter, PyMem_Free);
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2191 #endif
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2192 if (!capsule) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2193 PyMem_Free(inter);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2194 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2195 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2196 view = PgView_New(capsule, self, surf_view_destr);
3029
7866ddf0ec0d Fix memory leak with with pygame.surfarray.pixels3d - thanks Christopher Night
Lenard@lind7608.Belkin
parents: 3004
diff changeset
2197 Py_DECREF(capsule);
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2198 if (!view) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2199 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2200 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2201 if (!PySurface_LockBy(self, view)) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2202 Py_DECREF(view);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2203 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2204 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2205
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2206 startpixel = surface->pixels;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2207 pixelsize = surface->format->BytesPerPixel;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2208 inter->two = 2;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2209 inter->typekind = 'u';
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2210 inter->flags = PAI_ALIGNED | PAI_NOTSWAPPED | PAI_WRITEABLE;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2211 inter->descr = 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2212 shape = inter->shape;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2213 strides = inter->strides;
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: 2171
diff changeset
2214 shape[0] = (Py_intptr_t)surface->w;
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: 2171
diff changeset
2215 shape[1] = (Py_intptr_t)surface->h;
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: 2171
diff changeset
2216 strides[0] = (Py_intptr_t)pixelsize;
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: 2171
diff changeset
2217 strides[1] = (Py_intptr_t)surface->pitch;
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2218 switch (view_kind) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2219
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2220 case VIEWKIND_2D:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2221 ndim = 2;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2222 itemsize = pixelsize;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2223 if (strides[1] == shape[0] * pixelsize) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2224 inter->flags |= PAI_CONTIGUOUS;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2225 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2226 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2227 case VIEWKIND_3D:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2228 if (pixelsize < 3) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2229 Py_DECREF(view);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2230 return _raise_get_view_ndim_error(pixelsize * 8, view_kind);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2231 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2232 ndim = 3;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2233 itemsize = 1;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2234 shape[2] = 3;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2235 if (surface->format->Rmask == 0xff0000 &&
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2236 surface->format->Gmask == 0x00ff00 &&
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2237 surface->format->Bmask == 0x0000ff)
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2238 {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2239 strides[2] = lilendian ? -1 : 1;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2240 startpixel += lilendian ? 2 : 1;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2241 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2242 else if (surface->format->Bmask == 0xff0000 &&
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2243 surface->format->Gmask == 0x00ff00 &&
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2244 surface->format->Rmask == 0x0000ff)
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2245 {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2246 strides[2] = lilendian ? 1 : -1;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2247 startpixel += lilendian ? 0 : (pixelsize - 1);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2248 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2249 else {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2250 Py_DECREF(view);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2251 return RAISE(PyExc_ValueError,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2252 "unsupport colormasks for 3D reference array");
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2253 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2254 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2255 case VIEWKIND_RED:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2256 mask = surface->format->Rmask;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2257 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2258 case VIEWKIND_GREEN:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2259 mask = surface->format->Gmask;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2260 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2261 case VIEWKIND_BLUE:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2262 mask = surface->format->Bmask;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2263 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2264 case VIEWKIND_ALPHA:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2265 mask = surface->format->Amask;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2266 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2267 default:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2268 Py_DECREF(view);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2269 PyErr_Format(PyExc_SystemError,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2270 "pygame bug in surf_get_view:"
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2271 " unrecognized view kind %d", (int)view_kind);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2272 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2273 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2274 if (!itemsize) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2275 /* Color plane */
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2276 ndim = 2;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2277 pixelstep = pixelsize;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2278 itemsize = 1;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2279 switch (mask) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2280
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2281 case 0x000000ffU:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2282 startpixel += lilendian ? 0 : 3;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2283 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2284 case 0x0000ff00U:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2285 startpixel += lilendian ? 1 : 2;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2286 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2287 case 0x00ff0000U:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2288 startpixel += lilendian ? 2 : 1;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2289 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2290 case 0xff000000U:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2291 startpixel += lilendian ? 3 : 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2292 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2293 default:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2294 Py_DECREF(view);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2295 return RAISE(PyExc_ValueError,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2296 "unsupported colormasks for alpha reference array");
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2297 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2298 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2299 if (ndim < 3) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2300 inter->flags |= PAI_FORTRAN;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2301 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2302 inter->nd = ndim;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2303 inter->itemsize = itemsize;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2304 inter->data = startpixel;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2305
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2306 return view;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2307 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2308
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2309 static int
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2310 surf_view_kind(PyObject *obj, void *view_kind_vptr)
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2311 {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2312 unsigned long ch;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2313 SurfViewKind *view_kind_ptr = (SurfViewKind *)view_kind_vptr;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2314
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2315 if (PyUnicode_Check(obj)) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2316 if (PyUnicode_GET_SIZE(obj) != 1) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2317 PyErr_SetString(PyExc_TypeError,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2318 "expected a length 1 string for argument 1");
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2319 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2320 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2321 ch = *PyUnicode_AS_UNICODE(obj);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2322 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2323 else if (Bytes_Check(obj)) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2324 if (Bytes_GET_SIZE(obj) != 1) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2325 PyErr_SetString(PyExc_TypeError,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2326 "expected a length 1 string for argument 1");
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2327 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2328 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2329 ch = *Bytes_AS_STRING(obj);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2330 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2331 else {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2332 PyErr_Format(PyExc_TypeError,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2333 "expected a length one string for argument 1: got '%s'",
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2334 Py_TYPE(obj)->tp_name);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2335 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2336 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2337 switch (ch) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2338
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2339 case '2':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2340 *view_kind_ptr = VIEWKIND_2D;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2341 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2342 case 'R':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2343 case 'r':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2344 *view_kind_ptr = VIEWKIND_RED;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2345 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2346 case 'G':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2347 case 'g':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2348 *view_kind_ptr = VIEWKIND_GREEN;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2349 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2350 case 'B':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2351 case 'b':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2352 *view_kind_ptr = VIEWKIND_BLUE;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2353 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2354 case 'A':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2355 case 'a':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2356 *view_kind_ptr = VIEWKIND_ALPHA;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2357 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2358 case '3':
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2359 *view_kind_ptr = VIEWKIND_3D;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2360 break;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2361 default:
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2362 PyErr_Format(PyExc_TypeError,
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2363 "unrecognized view kind '%c' for argument 1", (int)ch);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2364 return 0;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2365 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2366 return 1;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2367 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2368
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2369 #if PY3
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2370 static void
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2371 surf_arraystruct_capsule_destr(PyObject *capsule)
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2372 {
2137
e4a059ae7977 add updates to surface.c, etc that were skipped in the merge with the surface_buffer branch
Lenard Lindstrom <len-l@telus.net>
parents: 2131
diff changeset
2373 PyMem_Free(PyCapsule_GetPointer(capsule, 0));
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2374 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2375 #endif
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2376
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2377 static void
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2378 surf_view_destr(PyObject *view)
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2379 {
3030
3705fa59dd5b Fix Surface instance reference count bug when a Surface.get_view() is garbage collected.
Lenard Lindstrom <len-l@telus.net>
parents: 3029
diff changeset
2380 PyObject *surf = PgView_GetParent(view);
3705fa59dd5b Fix Surface instance reference count bug when a Surface.get_view() is garbage collected.
Lenard Lindstrom <len-l@telus.net>
parents: 3029
diff changeset
2381
3705fa59dd5b Fix Surface instance reference count bug when a Surface.get_view() is garbage collected.
Lenard Lindstrom <len-l@telus.net>
parents: 3029
diff changeset
2382 PySurface_UnlockBy(surf, view);
3705fa59dd5b Fix Surface instance reference count bug when a Surface.get_view() is garbage collected.
Lenard Lindstrom <len-l@telus.net>
parents: 3029
diff changeset
2383 Py_DECREF(surf);
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2384 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2385
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2386 static PyObject *
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2387 surf_get_pixels_address(PyObject *self, PyObject *closure)
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2388 {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2389 SDL_Surface *surface = PySurface_AsSurface(self);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2390 void *address;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2391
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2392 if (!surface) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2393 Py_RETURN_NONE;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2394 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2395 if (!surface->pixels) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2396 return PyLong_FromLong(0L);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2397 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2398 address = surface->pixels;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2399 #if SIZEOF_VOID_P > SIZEOF_LONG
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2400 return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)address);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2401 #else
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2402 return PyLong_FromUnsignedLong((unsigned long)address);
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2403 #endif
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2404 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2405
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2406 static void
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2407 surface_move (Uint8 *src, Uint8 *dst, int h, int span,
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2408 int srcpitch, int dstpitch)
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2409 {
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2410 if (src < dst) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2411 src += (h - 1) * srcpitch;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2412 dst += (h - 1) * dstpitch;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2413 srcpitch = -srcpitch;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2414 dstpitch = -dstpitch;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2415 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2416 while (h--) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2417 memmove(dst, src, span);
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2418 src += srcpitch;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2419 dst += dstpitch;
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2420 }
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2421 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2422
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2423 static int
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2424 surface_do_overlap (SDL_Surface *src, SDL_Rect *srcrect,
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2425 SDL_Surface *dst, SDL_Rect *dstrect)
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2426 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2427 Uint8 *srcpixels;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2428 Uint8 *dstpixels;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2429 int srcx = srcrect->x, srcy = srcrect->y;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2430 int dstx = dstrect->x, dsty = dstrect->y;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2431 int x, y;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2432 int w = srcrect-> w, h= srcrect->h;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2433 int maxw, maxh;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2434 SDL_Rect *clip = &dst->clip_rect;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2435 int span;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2436 int dstoffset;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2437
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2438 /* clip the source rectangle to the source surface */
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2439 if (srcx < 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2440 w += srcx;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2441 dstx -= srcx;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2442 srcx = 0;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2443 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2444 maxw = src->w - srcx;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2445 if (maxw < w) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2446 w = maxw;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2447 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2448 srcy = srcrect->y;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2449 if (srcy < 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2450 h += srcy;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2451 dsty -= srcy;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2452 srcy = 0;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2453 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2454 maxh = src->h - srcy;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2455 if (maxh < h) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2456 h = maxh;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2457 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2458
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2459 /* clip the destination rectangle against the clip rectangle */
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2460 x = clip->x - dstx;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2461 if (x > 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2462 w -= x;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2463 dstx += x;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2464 srcx += x;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2465 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2466 x = dstx + w - clip->x - clip->w;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2467 if (x > 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2468 w -= x;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2469 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2470 y = clip->y - dsty;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2471 if (y > 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2472 h -= y;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2473 dsty += y;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2474 srcy += y;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2475 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2476 y = dsty + h - clip->y - clip->h;
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2477 if (y > 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2478 h -= y;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2479 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2480
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2481 if (w <= 0 || h <= 0) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2482 return 0;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2483 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2484
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2485 srcpixels = ((Uint8 *) src->pixels + src->offset +
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2486 srcy * src->pitch +
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2487 srcx * src->format->BytesPerPixel);
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2488 dstpixels = ((Uint8 *) dst->pixels + src->offset +
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2489 dsty * dst->pitch +
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2490 dstx * dst->format->BytesPerPixel);
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2491
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2492 if (dstpixels <= srcpixels) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2493 return 0;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2494 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2495
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2496 span = w * src->format->BytesPerPixel;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2497
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2498 if (dstpixels >= srcpixels + (h - 1) * src->pitch + span) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2499 return 0;
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2500 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2501
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2502 dstoffset = (dstpixels - srcpixels) % src->pitch;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2503
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2504 return dstoffset < span || dstoffset > src->pitch - span;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2505 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2506
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2507 /*this internal blit function is accessable through the C api*/
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2508 int
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2509 PySurface_Blit (PyObject * dstobj, PyObject * srcobj, SDL_Rect * dstrect,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2510 SDL_Rect * srcrect, int the_args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2511 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2512 SDL_Surface *src = PySurface_AsSurface (srcobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2513 SDL_Surface *dst = PySurface_AsSurface (dstobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2514 SDL_Surface *subsurface = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2515 int result, suboffsetx = 0, suboffsety = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2516 SDL_Rect orig_clip, sub_clip;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2517
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2518 /* passthrough blits to the real surface */
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2519 if (((PySurfaceObject *) dstobj)->subsurface) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2520 PyObject *owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2521 struct SubSurface_Data *subdata;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2522
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2523 subdata = ((PySurfaceObject *) dstobj)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2524 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2525 subsurface = PySurface_AsSurface (owner);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2526 suboffsetx = subdata->offsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2527 suboffsety = subdata->offsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2528
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2529 while (((PySurfaceObject *) owner)->subsurface) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2530 subdata = ((PySurfaceObject *) owner)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2531 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2532 subsurface = PySurface_AsSurface (owner);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2533 suboffsetx += subdata->offsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2534 suboffsety += subdata->offsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2535 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2536
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2537 SDL_GetClipRect (subsurface, &orig_clip);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2538 SDL_GetClipRect (dst, &sub_clip);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2539 sub_clip.x += suboffsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2540 sub_clip.y += suboffsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2541 SDL_SetClipRect (subsurface, &sub_clip);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2542 dstrect->x += suboffsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2543 dstrect->y += suboffsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2544 dst = subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2545 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2546 else {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2547 PySurface_Prep (dstobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2548 subsurface = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2549 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2550
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2551 PySurface_Prep (srcobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2552
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2553 /* see if we should handle alpha ourselves */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2554 if (dst->format->Amask && (dst->flags & SDL_SRCALPHA) &&
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2555 !(src->format->Amask && !(src->flags & SDL_SRCALPHA)) &&
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2556 /* special case, SDL works */
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2557 (dst->format->BytesPerPixel == 2 || dst->format->BytesPerPixel == 4)) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2558 /* Py_BEGIN_ALLOW_THREADS */
1142
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1137
diff changeset
2559 result = pygame_AlphaBlit (src, srcrect, dst, dstrect, the_args);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2560 /* Py_END_ALLOW_THREADS */
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2561 }
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2562 else if (the_args != 0 ||
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2563 (src->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY) &&
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2564 /* This simplification is possible because a source subsurface
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2565 is converted to its owner with a clip rect and a dst
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2566 subsurface cannot be blitted to its owner because the
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2567 owner is locked.
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2568 */
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2569 dst->pixels == src->pixels &&
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2570 surface_do_overlap (src, srcrect, dst, dstrect))) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2571 /* Py_BEGIN_ALLOW_THREADS */
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2572 result = pygame_Blit (src, srcrect, dst, dstrect, the_args);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2573 /* Py_END_ALLOW_THREADS */
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2574 }
1526
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2575 /* can't blit alpha to 8bit, crashes SDL */
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2576 else if (dst->format->BytesPerPixel == 1 &&
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2577 (src->format->Amask || src->flags & SDL_SRCALPHA)) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2578 /* Py_BEGIN_ALLOW_THREADS */
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2579 if (src->format->BytesPerPixel == 1) {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2580 result = pygame_Blit (src, srcrect, dst, dstrect, 0);
1526
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2581 }
2305
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2582 else if (SDL_WasInit (SDL_INIT_VIDEO)) {
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2583 src = SDL_DisplayFormat (src);
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2584 if (src) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2585 result = SDL_BlitSurface (src, srcrect, dst, dstrect);
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2586 SDL_FreeSurface (src);
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2587 }
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2588 else {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2589 result = -1;
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2590 }
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2591 }
2305
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2592 else {
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2593 SDL_PixelFormat *fmt = src->format;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2594 SDL_PixelFormat newfmt;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2595
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2596 newfmt.palette = 0; /* Set NULL (or SDL gets confused) */
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2597 newfmt.BitsPerPixel = fmt->BitsPerPixel;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2598 newfmt.BytesPerPixel = fmt->BytesPerPixel;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2599 newfmt.Amask = 0;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2600 newfmt.Rmask = fmt->Rmask;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2601 newfmt.Gmask = fmt->Gmask;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2602 newfmt.Bmask = fmt->Bmask;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2603 newfmt.Ashift = 0;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2604 newfmt.Rshift = fmt->Rshift;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2605 newfmt.Gshift = fmt->Gshift;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2606 newfmt.Bshift = fmt->Bshift;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2607 newfmt.Aloss = 0;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2608 newfmt.Rloss = fmt->Rloss;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2609 newfmt.Gloss = fmt->Gloss;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2610 newfmt.Bloss = fmt->Bloss;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2611 newfmt.colorkey = 0;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2612 newfmt.alpha = 0;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2613 src = SDL_ConvertSurface (src, &newfmt, SDL_SWSURFACE);
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2614 if (src) {
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2615 result = SDL_BlitSurface (src, srcrect, dst, dstrect);
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2616 SDL_FreeSurface (src);
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2617 }
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2618 else {
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2619 result = -1;
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2620 }
a1c860de4b0b Bug fix: Surface.blit seqfaulted on Debian for 8 bit target and 32 source with per-pixel alpha when the display was not initialized; add special blit case.
Lenard Lindstrom <len-l@telus.net>
parents: 2300
diff changeset
2621 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2622 /* Py_END_ALLOW_THREADS */
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2623 }
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2624 else {
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2625 /* Py_BEGIN_ALLOW_THREADS */
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2626 result = SDL_BlitSurface (src, srcrect, dst, dstrect);
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2627 /* Py_END_ALLOW_THREADS */
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2628 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2629
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2630 if (subsurface) {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2631 SDL_SetClipRect (subsurface, &orig_clip);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2632 dstrect->x -= suboffsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2633 dstrect->y -= suboffsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2634 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2635 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2636 PySurface_Unprep (dstobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2637 PySurface_Unprep (srcobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2638
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2639 if (result == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2640 RAISE (PyExc_SDLError, SDL_GetError ());
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2641 if (result == -2)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2642 RAISE (PyExc_SDLError, "Surface was lost");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2643
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2644 return result != 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2645 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2646
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2647 static PyMethodDef _surface_methods[] =
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2648 {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2649 { NULL, NULL, 0, NULL }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2650 };
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2651
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2652 MODINIT_DEFINE (surface)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2653 {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2654 PyObject *module, *dict, *apiobj, *lockmodule;
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2655 int ecode;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2656 static void* c_api[PYGAMEAPI_SURFACE_NUMSLOTS];
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2657
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2658 #if PY3
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2659 static struct PyModuleDef _module = {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2660 PyModuleDef_HEAD_INIT,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2661 "surface",
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2662 DOC_PYGAMESURFACE,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2663 -1,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2664 _surface_methods,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2665 NULL, NULL, NULL, NULL
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2666 };
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2667 #endif
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2668
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2669 /* imported needed apis; Do this first so if there is an error
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2670 the module is not loaded.
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2671 */
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2672 import_pygame_base ();
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2673 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2674 MODINIT_ERROR;
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2675 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2676 import_pygame_color ();
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2677 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2678 MODINIT_ERROR;
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2679 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2680 import_pygame_rect ();
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2681 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2682 MODINIT_ERROR;
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2683 }
2131
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2684 import_pygame_bufferproxy ();
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2685 if (PyErr_Occurred ()) {
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2686 MODINIT_ERROR;
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2687 }
018779fb04f5 Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents: 2120
diff changeset
2688 import_pygame_view ();
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2689 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2690 MODINIT_ERROR;
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2691 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2692
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2693 /* import the surflock module manually */
1585
b9a1d6556447 symbian branch merging
Rene Dudfield <renesd@gmail.com>
parents: 1578
diff changeset
2694 lockmodule = PyImport_ImportModule (IMPPREFIX "surflock");
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2695 if (lockmodule != NULL) {
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2696 PyObject *_dict = PyModule_GetDict (lockmodule);
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2697 PyObject *_c_api = PyDict_GetItemString (_dict, PYGAMEAPI_LOCAL_ENTRY);
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2698
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2699 if (PyCapsule_CheckExact (_c_api)) {
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2700 int i;
2120
42e2bde1a12c Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents: 1937
diff changeset
2701 void **localptr =
42e2bde1a12c Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents: 1937
diff changeset
2702 (void *)PyCapsule_GetPointer (_c_api,
42e2bde1a12c Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents: 1937
diff changeset
2703 PG_CAPSULE_NAME("surflock"));
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2704
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2705 for (i = 0; i < PYGAMEAPI_SURFLOCK_NUMSLOTS; ++i)
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2706 PyGAME_C_API[i + PYGAMEAPI_SURFLOCK_FIRSTSLOT] = localptr[i];
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2707 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2708 Py_DECREF (lockmodule);
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2709 }
2171
93eb55c6f722 remove tags and make all block bracing consistent with PEP 7
Lenard Lindstrom <len-l@telus.net>
parents: 2139
diff changeset
2710 else {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2711 MODINIT_ERROR;
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2712 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2713
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2714 /* type preparation */
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2715 if (PyType_Ready(&PySurface_Type) < 0) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2716 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2717 }
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2718
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2719 /* create the module */
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2720 #if PY3
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2721 module = PyModule_Create (&_module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2722 #else
1585
b9a1d6556447 symbian branch merging
Rene Dudfield <renesd@gmail.com>
parents: 1578
diff changeset
2723 module = Py_InitModule3 (MODPREFIX "surface", _surface_methods, DOC_PYGAMESURFACE);
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2724 #endif
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2725 if (module == NULL) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2726 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2727 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2728 dict = PyModule_GetDict (module);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2729
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2730 if (PyDict_SetItemString (dict, "SurfaceType", (PyObject *) &PySurface_Type)) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2731 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2732 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2733 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2734 if (PyDict_SetItemString (dict, "Surface", (PyObject *) &PySurface_Type)) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2735 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2736 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2737 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2738
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2739 /* export the c api */
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2740 c_api[0] = &PySurface_Type;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2741 c_api[1] = PySurface_New;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2742 c_api[2] = PySurface_Blit;
2120
42e2bde1a12c Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents: 1937
diff changeset
2743 apiobj = encapsulate_api (c_api, "surface");
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2744 if (apiobj == NULL) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2745 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2746 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2747 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2748 ecode = PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj);
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2749 Py_DECREF (apiobj);
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2750 if (ecode) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2751 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2752 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2753 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
2754 /* Py_INCREF (PySurface_Type.tp_dict); INCREF's done in SetItemString */
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2755 if (PyDict_SetItemString (dict, "_dict", PySurface_Type.tp_dict)) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2756 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2757 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2758 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2759 MODINIT_RETURN (module);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2760 }