annotate src/surface.c @ 1849:301bc61643a9 math_module

merged changes from trunk
author lorenz
date Mon, 16 Nov 2009 18:31:40 +0000
parents 02c1e8e9c102
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"
1849
301bc61643a9 merged changes from trunk
lorenz
parents: 1839
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"
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
30
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
31 int
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
32 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
33 SDL_Rect * srcrect, int the_args);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
34
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
35 /* statics */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
36 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
37 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
38 PyObject *kwds);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
39 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
40 PyObject *kwds);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
41 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
42 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
43 static void surface_cleanup (PySurfaceObject * self);
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
44 static void surface_move (Uint8 *src, Uint8 *dst, int h,
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
45 int span, int srcpitch, int dstpitch);
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
46
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
47 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
48 static PyObject *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
49 static PyObject *surf_map_rgb (PyObject *self, PyObject *args);
1472
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
50 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
51 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
52 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
53 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
54 static PyObject *surf_get_locked (PyObject *self);
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69 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
70 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
71 static PyObject *surf_scroll (PyObject *self,
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
72 PyObject *args, PyObject *keywds);
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_abs_offset (PyObject *self);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 PyObject *kwargs);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91 static PyObject *surf_subsurface (PyObject *self, PyObject *args);
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
92 static PyObject *surf_get_buffer (PyObject *self);
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
93 static PyObject *surf_get_bounding_rect (PyObject *self, PyObject *args,
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
94 PyObject *kwargs);
425
879ca7f86dc2 subrect work
pygame
parents: 401
diff changeset
95
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
96 static struct PyMethodDef surface_methods[] =
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
97 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
98 { "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
99 { "set_at", surf_set_at, METH_VARARGS, DOC_SURFACESETAT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
100 { "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
101 { "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
102
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
103 { "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
104 DOC_SURFACEGETPALETTE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
105 { "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
106 DOC_SURFACEGETPALETTEAT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
107 { "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
108 { "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
109 DOC_SURFACESETPALETTEAT },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
110
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
111 { "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
112 { "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
113 { "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
114 DOC_SURFACEMUSTLOCK },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
115 { "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
116 DOC_SURFACEGETLOCKED },
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
117 { "get_locks", (PyCFunction) surf_get_locks, METH_NOARGS,
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
118 DOC_SURFACEGETLOCKS },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
119
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
120 { "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
121 { "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
122 DOC_SURFACEGETCOLORKEY },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
123 { "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
124 { "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
125 DOC_SURFACEGETALPHA },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
126
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
127 { "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
128 { "__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
129 { "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
130 { "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
131 DOC_SURFACECONVERTALPHA },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
132
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
133 { "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
134 { "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
135 DOC_SURFACEGETCLIP },
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
136
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
137 { "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
138 DOC_SURFACEFILL },
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
139 { "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
140 DOC_SURFACEBLIT },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
141
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
142 { "scroll", (PyCFunction) surf_scroll, METH_VARARGS | METH_KEYWORDS,
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
143 DOC_SURFACESCROLL },
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
144
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
145 { "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
146 DOC_SURFACEGETFLAGS },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
147 { "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
148 DOC_SURFACEGETSIZE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
149 { "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
150 DOC_SURFACEGETWIDTH },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
151 { "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
152 DOC_SURFACEGETHEIGHT },
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
153 { "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
154 DOC_SURFACEGETRECT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
155 { "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
156 DOC_SURFACEGETPITCH },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
157 { "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
158 DOC_SURFACEGETBITSIZE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
159 { "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
160 DOC_SURFACEGETBYTESIZE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
161 { "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
162 DOC_SURFACEGETMASKS },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
163 { "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
164 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
165 { "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
166 DOC_SURFACESETMASKS },
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
167 { "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
168 DOC_SURFACESETSHIFTS },
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
169
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
170 { "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
171 DOC_SURFACEGETLOSSES },
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
172
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
173 { "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
174 { "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
175 DOC_SURFACEGETOFFSET },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
176 { "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
177 DOC_SURFACEGETABSOFFSET },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
178 { "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
179 DOC_SURFACEGETPARENT },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
180 { "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
181 DOC_SURFACEGETABSPARENT },
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
182 { "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
183 METH_VARARGS | METH_KEYWORDS,
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
184 DOC_SURFACEGETBOUNDINGRECT},
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
185 { "get_buffer", (PyCFunction) surf_get_buffer, METH_NOARGS,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
186 DOC_SURFACEGETBUFFER},
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
187
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
188 { NULL, NULL, 0, NULL }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
189 };
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
190
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
191 static PyTypeObject PySurface_Type =
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
192 {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
193 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
194 "pygame.Surface", /* name */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
195 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
196 0, /* itemsize */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
197 surface_dealloc, /* dealloc */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
198 0, /* print */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
199 NULL, /* getattr */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
200 NULL, /* setattr */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
201 NULL, /* compare */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
202 surface_str, /* repr */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
203 NULL, /* as_number */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
204 NULL, /* as_sequence */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
205 NULL, /* as_mapping */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
206 (hashfunc) NULL, /* hash */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
207 (ternaryfunc) NULL, /* call */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
208 (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
209 0,
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
210 0L, 0L,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
211 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
212 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
213 0, /* tp_traverse */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
214 0, /* tp_clear */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
215 0, /* tp_richcompare */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
216 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
217 0, /* tp_iter */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
218 0, /* tp_iternext */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
219 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
220 0, /* tp_members */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
221 0, /* tp_getset */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
222 0, /* tp_base */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
223 0, /* tp_dict */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
224 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
225 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
226 0, /* tp_dictoffset */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
227 (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
228 0, /* tp_alloc */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
229 surface_new, /* tp_new */
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
230 };
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
231
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
232 #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
233
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
234 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
235 PySurface_New (SDL_Surface *s)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
236 {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
237 PySurfaceObject *self;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
238
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
239 if (!s)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
240 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
241
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
242 self = (PySurfaceObject *)
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
243 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
244
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
245 if (self)
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
246 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
247
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
248 return (PyObject *) self;
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
249 }
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
250
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
251 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
252 surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
253 {
76675068d35a weakref surface
pygame
parents: 497
diff changeset
254 PySurfaceObject *self;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
255
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
256 self = (PySurfaceObject *) type->tp_alloc (type, 0);
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
257 if (self)
76675068d35a weakref surface
pygame
parents: 497
diff changeset
258 {
76675068d35a weakref surface
pygame
parents: 497
diff changeset
259 self->surf = NULL;
76675068d35a weakref surface
pygame
parents: 497
diff changeset
260 self->subsurface = NULL;
76675068d35a weakref surface
pygame
parents: 497
diff changeset
261 self->weakreflist = NULL;
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
262 self->dependency = NULL;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
263 self->locklist = NULL;
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
264 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
265 return (PyObject *) self;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
266 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
267
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
268 /* surface object internals */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
269 static void
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
270 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
271 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
272 if (self->surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
273 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
274 if (!(self->surf->flags & SDL_HWSURFACE) ||
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
275 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
276 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
277 /* 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
278 /* 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
279 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
280 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
281 self->surf = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
282 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
283 if (self->subsurface)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
284 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
285 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
286 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
287 self->subsurface = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
288 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
289 if (self->dependency)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
290 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
291 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
292 self->dependency = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
293 }
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
294
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
295 if (self->locklist)
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
296 {
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
297 Py_DECREF (self->locklist);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
298 self->locklist = NULL;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
299 }
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
300 }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
301
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
302 static void
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
303 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
304 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
305 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
306 PyObject_ClearWeakRefs (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
307 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
308 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
309 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
310
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
311 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
312 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
313 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
314 char str[1024];
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
315 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
316 const char *type;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
317
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
318 if (surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
319 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
320 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
321 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
322 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
323 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
324 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
325 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
326 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
327 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
328
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
329 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
330 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
331
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
332 static intptr_t
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
333 surface_init (PySurfaceObject *self, PyObject *args, PyObject *kwds)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
334 {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
335 Uint32 flags = 0;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
336 int width, height;
850
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
337 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
338 int bpp;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
339 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
340 SDL_Surface *surface;
1515
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
341 SDL_PixelFormat default_format, *format;
850
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
342 int length;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
343
850
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
344 char *kwids[] = { "size", "flags", "depth", "masks", NULL };
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
345 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
346 return -1;
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
347
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
348 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
349
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
350 if ( (!IntFromObjIndex (size, 0, &width)) ||
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
351 (!IntFromObjIndex (size, 1, &height)) ) {
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
352 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
353 return -1;
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
354 }
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
355 } else {
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
356 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
357 return -1;
850
0ecaae1530b0 added keyword argument processing for Surface.
Rene Dudfield <renesd@gmail.com>
parents: 848
diff changeset
358 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
359
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
360 if (width < 0 || height < 0)
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
361 {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
362 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
363 return -1;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
364 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
365
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
366 surface_cleanup (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
367
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
368 if (depth && masks) /* all info supplied, most errorchecking
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
369 * needed */
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
370 {
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
371 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
372 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
373 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
374 }
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
375 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
376 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
377 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
378 }
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
379 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
380 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
381 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
382 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
383 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
384 !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
385 !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
386 !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
387 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
388 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
389 }
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
390 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
391 else if (depth && PyNumber_Check (depth)) /* use default masks */
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
392 {
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
393 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
394 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
395 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
396 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
397 if (flags & SDL_SRCALPHA)
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
398 {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
399 switch (bpp)
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
400 {
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
401 case 16:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
402 Rmask = 0xF << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
403 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
404 Bmask = 0xF;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
405 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
406 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
407 case 32:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
408 Rmask = 0xFF << 16;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
409 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
410 Bmask = 0xFF;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
411 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
412 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
413 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
414 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
415 return -1;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
416 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
417 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
418 else
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
419 {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
420 Amask = 0;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
421 switch (bpp)
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
422 {
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
423 case 8:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
424 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
425 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
426 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
427 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
428 case 12:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
429 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
430 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
431 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
432 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
433 case 15:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
434 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
435 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
436 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
437 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
438 case 16:
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
439 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
440 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
441 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
442 break;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
443 case 24:
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
444 case 32:
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 << 16;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
446 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
447 Bmask = 0xFF;
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 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
450 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
451 return -1;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
452 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
453 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
454 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
455 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
456 {
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
457 SDL_PixelFormat* pix;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
458 if (depth && PySurface_Check (depth))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
459 pix = ((PySurfaceObject*) depth)->surf->format;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
460 else if (SDL_GetVideoSurface ())
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
461 pix = SDL_GetVideoSurface ()->format;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
462 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
463 pix = SDL_GetVideoInfo ()->vfmt;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
464 else
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
465 {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
466 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
467 pix->BitsPerPixel = 32;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
468 pix->Amask = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
469 pix->Rmask = 0xFF0000;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
470 pix->Gmask = 0xFF00;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
471 pix->Bmask = 0xFF;
520
76675068d35a weakref surface
pygame
parents: 497
diff changeset
472 }
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
473 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
474
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
475 if (flags & SDL_SRCALPHA)
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
476 {
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
477 switch (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
478 {
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
479 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
480 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
481 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
482 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
483 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
484 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
485 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
486 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
487 // 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
488 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
489 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
490 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
491 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
492 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
493 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
494 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
495 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
496 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
497 }
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
498 } 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
499 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
500 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
501 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
502 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
503 }
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
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
505 }
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
506
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
507 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
508 Bmask, Amask);
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 860
diff changeset
509
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
510 if (!surface)
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
511 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
512 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
513 return -1;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
514 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
515
1515
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
516 if (masks)
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
517 {
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
518 /* Confirm the surface was created correctly (masks were valid).
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
519 Also ensure that 24 and 32 bit surfaces have 8 bit fields
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
520 (no losses).
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
521 */
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
522 format = surface->format;
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
523 Rmask = (0xFF >> format->Rloss) << format->Rshift;
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
524 Gmask = (0xFF >> format->Gloss) << format->Gshift;
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
525 Bmask = (0xFF >> format->Bloss) << format->Bshift;
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
526 Amask = (0xFF >> format->Aloss) << format->Ashift;
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
527 if (format->Rmask != Rmask ||
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
528 format->Gmask != Gmask ||
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
529 format->Bmask != Bmask ||
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
530 format->Amask != Amask ||
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
531 (format->BytesPerPixel >= 3 &&
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
532 (format->Rloss || format->Gloss || format->Bloss ||
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
533 (surface->flags & SDL_SRCALPHA ?
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
534 format->Aloss : format->Aloss != 8))))
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
535 {
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
536 SDL_FreeSurface (surface);
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
537 RAISE (PyExc_ValueError, "Invalid mask values");
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
538 return -1;
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
539 }
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
540 }
425c8b3fc5ac Make pygame.Surface raise a ValueError for questionable masks
Lenard Lindstrom <len-l@telus.net>
parents: 1499
diff changeset
541
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
542 if (surface)
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
543 {
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
544 self->surf = surface;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
545 self->subsurface = NULL;
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
546 }
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
547
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
548 return 0;
345
935c139eb672 Surface and Rect subclassable
pygame
parents: 307
diff changeset
549 }
935c139eb672 Surface and Rect subclassable
pygame
parents: 307
diff changeset
550
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
551 /* surface object methods */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
552 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
553 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
554 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
555 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
556 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
557 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
558 int x, y;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
559 Uint32 color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
560 Uint8 *pix;
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
561 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
562
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
563 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
564 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
565 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
566 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
567
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
568 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
569 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
570
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
571 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
572 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
573
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
574 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
575 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
576
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
577 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
578 return NULL;
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 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
581
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
582 switch (format->BytesPerPixel)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
583 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
584 case 1:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
585 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
586 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
587 case 2:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
588 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
589 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
590 case 3:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
591 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
592 #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
593 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
594 #else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
595 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
596 #endif
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
597 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
598 default: /* case 4: */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
599 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
600 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
601 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
602 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
603 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
604
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
605 SDL_GetRGBA (color, format, rgba, rgba+1, rgba+2, rgba+3);
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
606 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
607 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
608
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
609 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
610 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
611 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
612 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
613 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
614 Uint8 *pixels;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
615 int x, y;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
616 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
617 Uint8 rgba[4] = {0, 0, 0, 0 };
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
618 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
619 Uint8 *byte_buf;
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 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
622 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
623 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
624 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
625
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
626 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
627 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
628
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
629 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
630 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
631
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
632 if (x < surf->clip_rect.x || x >= surf->clip_rect.x + surf->clip_rect.w ||
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
633 y < surf->clip_rect.y || y >= surf->clip_rect.y + surf->clip_rect.h)
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 /* 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
636 Py_RETURN_NONE;
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
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
639 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
640 {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
641 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
642 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
643 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
644 }
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
645 else if (PyLong_Check (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
646 {
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
647 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
648 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
649 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
650 }
1037
c4c38b97db3b Added Color class.
marcus
parents: 930
diff changeset
651 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
652 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
653 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
654 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
655
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
656 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
657 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
658 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
659
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
660 switch (format->BytesPerPixel)
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 case 1:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
663 *((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
664 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
665 case 2:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
666 *((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
667 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
668 case 3:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
669 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
670 #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
671 *(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
672 *(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
673 *(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
674 #else
859
0c1408a4a30d surface.set_at((0,0), 0x0000FF) was failing for 24 bit surfaces.
Rene Dudfield <renesd@gmail.com>
parents: 854
diff changeset
675 *(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
676 *(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
677 *(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
678 #endif
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
679 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
680 default: /* case 4: */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
681 *((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
682 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
683 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
684
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
685 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
686 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
687 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
688 }
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 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
691 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
692 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
693 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
694 Uint8 rgba[4];
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
695 int color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
696
1037
c4c38b97db3b Added Color class.
marcus
parents: 930
diff changeset
697 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
698 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
699 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
700 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
701
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
702 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
703 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
704 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
705
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
706 static PyObject*
1472
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
707 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
708 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
709 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
710 Uint32 col;
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
711 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
712
1472
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
713 col = (Uint32)PyInt_AsLong (arg);
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
714 if (col == (Uint32) -1 && PyErr_Occurred()) {
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
715 PyErr_Clear();
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
716 return RAISE (PyExc_TypeError, "unmap_rgb expects 1 number argument");
9b7d1498d7f6 surface.unmap_rgb now METH_O
Lenard Lindstrom <len-l@telus.net>
parents: 1413
diff changeset
717 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
718 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
719 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
720
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
721 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
722
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
723 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
724 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
725
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
726 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
727 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
728 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
729 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
730 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
731 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
732 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
733
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
734 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
735 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
736 {
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
737 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
738 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
739 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
740
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
741 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
742 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
743 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
744 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
745 return PyInt_FromLong (SDL_MUSTLOCK (surf) ||
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
746 ((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
747 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
748
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
749 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
750 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
751 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
752 PySurfaceObject *surf = (PySurfaceObject *) self;
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
753
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
754 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
755 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
756 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
757 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
758
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
759 static PyObject*
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
760 surf_get_locks (PyObject *self)
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
761 {
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
762 PySurfaceObject *surf = (PySurfaceObject *) self;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
763 Py_ssize_t len, i = 0;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
764 PyObject *tuple, *tmp;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
765 if (!surf->locklist)
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
766 return PyTuple_New (0);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
767
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
768 len = PyList_Size (surf->locklist);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
769 tuple = PyTuple_New (len);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
770 if (!tuple)
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
771 return NULL;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
772
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
773 for (i = 0; i < len; i++)
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
774 {
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
775 tmp = PyWeakref_GetObject (PyList_GetItem (surf->locklist, i));
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
776 Py_INCREF (tmp);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
777 PyTuple_SetItem (tuple, i, tmp);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
778 }
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
779 return tuple;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
780 }
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
781
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
782 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
783 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
784 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
785 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
786 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
787 PyObject *list;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
788 int i;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
789 PyObject *color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
790 SDL_Color *c;
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
791 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
792
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
793 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
794 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
795
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
796 if (!pal)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
797 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
798
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
799 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
800 if (!list)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
801 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
802
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
803 for (i = 0; i < pal->ncolors; i++)
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 c = &pal->colors[i];
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
806 rgba[0] = c->r;
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
807 rgba[1] = c->g;
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
808 rgba[2] = c->b;
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
809 color = PyColor_NewLength (rgba, 3);
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
810
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
811 if (!color)
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 Py_DECREF (list);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
814 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
815 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
816 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
817 }
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 return list;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
820 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
821
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
822 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
823 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
824 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
825 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
826 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
827 SDL_Color *c;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
828 int _index;
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
829 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
830
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
831 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
832 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
833 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
834 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
835
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
836 if (!pal)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
837 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
838 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
839 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
840
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
841 c = &pal->colors[_index];
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
842 rgba[0] = c->r;
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
843 rgba[1] = c->g;
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
844 rgba[2] = c->b;
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
845 rgba[3] = 255;
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
846
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
847 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
848 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
849
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
850 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
851 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
852 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
853 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
854 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
855 SDL_Color *colors;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
856 PyObject *list, *item;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
857 int i, len;
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
858 Uint8 rgba[4];
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
859 int ecode;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
860
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
861 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
862 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
863 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
864 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
865 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
866 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
867
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
868 if (!pal)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
869 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
870
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
871 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
872 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
873 "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
874
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
875 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
876
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
877 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
878 if (!colors)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
879 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
880
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
881 for (i = 0; i < len; i++)
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 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
884
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
885 ecode = RGBAFromObj (item, rgba);
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
886 Py_DECREF (item);
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
887 if (!ecode)
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
888 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
889 free (colors);
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
890 return RAISE (PyExc_ValueError,
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
891 "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
892 }
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
893 if (rgba[3] != 255)
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
894 {
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
895 free (colors);
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
896 return RAISE (PyExc_ValueError,
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
897 "takes an alpha value of 255");
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
898 }
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
899 colors[i].r = (unsigned char) rgba[0];
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
900 colors[i].g = (unsigned char) rgba[1];
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
901 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
902 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
903
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
904 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
905 free (colors);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
906 Py_RETURN_NONE;
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
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
909 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
910 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
911 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
912 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
913 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
914 SDL_Color color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
915 int _index;
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
916 PyObject *color_obj;
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
917 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
918
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
919 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
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
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
924 if (!RGBAFromObj (color_obj, rgba))
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
925 {
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
926 return RAISE (PyExc_ValueError,
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
927 "takes a sequence of integers of RGB for argument 2");
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
928 }
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
929
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
930 if (!pal)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
931 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
932 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
933 return NULL;
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
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
936 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
937 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
938 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
939 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
940 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
941
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
942 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
943 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
944 "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
945
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
946 color.r = rgba[0];
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
947 color.g = rgba[1];
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
948 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
949
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
950 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
951
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
952 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
953 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
954
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
955 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
956 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
957 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
958 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
959 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
960 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
961 Uint8 rgba[4];
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
962 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
963
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
964 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
965 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
966 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
967 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
968
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
969 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
970 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
971
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
972 if (rgba_obj && rgba_obj != Py_None)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
973 {
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
974 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
975 {
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
976 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
977 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
978 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
979 }
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
980 else if (PyLong_Check (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
981 {
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
982 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
983 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
984 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
985 }
1037
c4c38b97db3b Added Color class.
marcus
parents: 930
diff changeset
986 else if (RGBAFromColorObj (rgba_obj, rgba))
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
987 {
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
988 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
989 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
990 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
991 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
992 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
993 hascolor = 1;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
994 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
995 if (hascolor)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
996 flags |= SDL_SRCCOLORKEY;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
997
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
998 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
999 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
1000 PySurface_Unprep (self);
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 if (result == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1003 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
1004
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1005 Py_RETURN_NONE;
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
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1008 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1009 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
1010 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1011 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
1012 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
1013
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1014 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1015 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
1016
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1017 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
1018 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
1019
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1020 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
1021 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1022
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1023 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
1024 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
1025 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1026
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1027 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1028 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
1029 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1030 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
1031 Uint32 flags = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1032 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
1033 Uint8 alpha;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1034 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
1035
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1036 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
1037 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1038 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1039 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
1040
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1041 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
1042 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
1043
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1044 if (alpha_obj && alpha_obj != Py_None)
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 if (PyNumber_Check (alpha_obj) && (intobj = PyNumber_Int (alpha_obj)))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1047 {
1117
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1048 if (PyInt_Check (intobj))
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1049 {
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1050 alphaval = (int) PyInt_AsLong (intobj);
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1051 Py_DECREF (intobj);
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1052 }
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1053 else
fa8a25ebb16a Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents: 1111
diff changeset
1054 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
1055 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1056 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1057 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
1058 hasalpha = 1;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1059 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1060 if (hasalpha)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1061 flags |= SDL_SRCALPHA;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1062
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1063 if (alphaval > 255)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1064 alpha = 255;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1065 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
1066 alpha = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1067 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1068 alpha = (Uint8) alphaval;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1069
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1070 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1071 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
1072 PySurface_Unprep (self);
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 if (result == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1075 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
1076
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1077 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1078 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1079
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1080 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1081 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
1082 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1083 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
1084
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1085 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
1086 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
1087 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
1088 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
1089
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1090 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
1091 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
1092
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1093 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1094 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1095
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1096 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1097 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
1098 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1099 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
1100 PyObject *final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1101 SDL_Surface *newsurf;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1102
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1103 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1104 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
1105
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1106 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
1107 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
1108
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1109 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1110 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
1111 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1112
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1113 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
1114 if (!final)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1115 SDL_FreeSurface (newsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1116 return final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1117 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1118
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1119 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1120 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
1121 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1122 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
1123 PyObject *final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1124 PyObject *argobject = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1125 SDL_Surface *src;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1126 SDL_Surface *newsurf;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1127 Uint32 flags = -1;
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 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
1130 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
1131 "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
1132
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1133 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
1134 return NULL;
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_OPENGL)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1137 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
1138
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1139 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1140 if (argobject)
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 if (PySurface_Check (argobject))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1143 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1144 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
1145 flags = src->flags |
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1146 (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
1147 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
1148 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1149 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1150 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1151 int bpp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1152 SDL_PixelFormat format;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1153
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1154 memcpy (&format, surf->format, sizeof (format));
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1155 if (IntFromObj (argobject, &bpp))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1156 {
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1157 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
1158
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1159 if (flags != -1 && flags & SDL_SRCALPHA)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1160 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1161 switch (bpp)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1162 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1163 case 16:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1164 Rmask = 0xF << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1165 Gmask = 0xF << 4;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1166 Bmask = 0xF;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1167 Amask = 0xF << 12;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1168 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1169 case 32:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1170 Rmask = 0xFF << 16;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1171 Gmask = 0xFF << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1172 Bmask = 0xFF;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1173 Amask = 0xFF << 24;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1174 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1175 default:
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_ValueError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1177 "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
1178 "bitdepth with alpha");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1179 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1180 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1181 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1182 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1183 Amask = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1184 switch (bpp)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1185 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1186 case 8:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1187 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
1188 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
1189 Bmask = 0xFF >> 6;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1190 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1191 case 12:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1192 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
1193 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
1194 Bmask = 0xFF >> 4;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1195 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1196 case 15:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1197 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
1198 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
1199 Bmask = 0xFF >> 3;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1200 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1201 case 16:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1202 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
1203 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
1204 Bmask = 0xFF >> 3;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1205 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1206 case 24:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1207 case 32:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1208 Rmask = 0xFF << 16;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1209 Gmask = 0xFF << 8;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1210 Bmask = 0xFF;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1211 break;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1212 default:
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1213 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
1214 "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
1215 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1216 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1217 format.Rmask = Rmask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1218 format.Gmask = Gmask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1219 format.Bmask = Bmask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1220 format.Amask = Amask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1221 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1222 else if (PySequence_Check (argobject) &&
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1223 PySequence_Size (argobject) == 4)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1224 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1225 Uint32 mask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1226
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1227 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
1228 !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
1229 !UintFromObjIndex (argobject, 2, &format.Bmask) ||
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1230 !UintFromObjIndex (argobject, 3, &format.Amask))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1231 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1232 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1233 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
1234 "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
1235 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1236 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
1237 format.Amask;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1238 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
1239 if (!(mask >> bpp))
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 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1242 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1243 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1244 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1245 return RAISE
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1246 (PyExc_ValueError,
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1247 "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
1248 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1249 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
1250 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
1251 if (flags == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1252 flags = surf->flags;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1253 if (format.Amask)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1254 flags |= SDL_SRCALPHA;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1255 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
1256 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1257 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1258 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1259 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1260 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
1261 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
1262 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1263 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
1264 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1265 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1266
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1267 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
1268 if (!final)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1269 SDL_FreeSurface (newsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1270 return final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1271 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1272
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1273 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1274 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
1275 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1276 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
1277 PyObject *final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1278 PySurfaceObject *srcsurf = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1279 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
1280
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1281 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
1282 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
1283 "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
1284
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1285 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
1286 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1287
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1288 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1289 if (srcsurf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1290 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1291 /*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1292 * 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
1293 * support for alpha
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1294 */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1295 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
1296 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
1297 }
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_DisplayFormatAlpha (surf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1300 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1301
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1302 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
1303 if (!final)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1304 SDL_FreeSurface (newsurf);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1305 return final;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1306 }
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 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1309 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
1310 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1311 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
1312 PyObject *item;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1313 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
1314 SDL_Rect sdlrect;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1315 int result;
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 (!surf)
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, "display Surface quit");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1319 if (PyTuple_Size (args))
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 item = PyTuple_GET_ITEM (args, 0);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1322 if (item == Py_None && PyTuple_Size (args) == 1)
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 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
1325 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1326 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1327 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1328 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
1329 if (!rect)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1330 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
1331 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
1332 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
1333 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
1334 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
1335 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
1336 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1337 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1338 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1339 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1340 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
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 if (result == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1344 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1345 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
1346 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1347
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1348 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1349 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1350
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1351 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1352 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
1353 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1354 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
1355
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1356 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1357 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
1358 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
1359 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1360
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1361
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1362 static PyObject*
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1363 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
1364 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1365 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
1366 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
1367 PyObject *r = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1368 Uint32 color;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1369 int result;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1370 PyObject *rgba_obj;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1371 Uint8 rgba[4];
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1372 SDL_Rect sdlrect;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1373 int blendargs = 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1374
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1375 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
1376 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
1377 &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
1378 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1379 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1380 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
1381
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1382 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
1383 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
1384
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1385 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
1386 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
1387 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
1388 color = (Uint32) PyLong_AsUnsignedLong (rgba_obj);
1037
c4c38b97db3b Added Color class.
marcus
parents: 930
diff changeset
1389 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
1390 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
1391 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1392 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
1393
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1394 if (!r || r == Py_None)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1395 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1396 rect = &temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1397 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
1398 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
1399 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
1400 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1401 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
1402 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
1403
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1404 /* we need a fresh copy so our Rect values don't get munged */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1405 if (rect != &temp)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1406 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1407 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
1408 rect = &temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1409 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1410
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1411 if (rect->w < 0 || rect->h < 0)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1412 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1413 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
1414 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
1415 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1416 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1417 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1418 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
1419 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
1420 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
1421 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
1422
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1423 if (blendargs != 0)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1424 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1425
825
bae45548347d commented out some printf's.
Rene Dudfield <renesd@gmail.com>
parents: 819
diff changeset
1426 /*
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1427 printf ("Using blendargs: %d\n", blendargs);
825
bae45548347d commented out some printf's.
Rene Dudfield <renesd@gmail.com>
parents: 819
diff changeset
1428 */
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1429 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
1430 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1431 else
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 PySurface_Prep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1434 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
1435 PySurface_Unprep (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1436 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1437 if (result == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1438 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
1439 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1440 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
1441 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1442
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1443 static PyObject*
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1444 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
1445 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1446 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
1447 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
1448 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
1449 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
1450 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
1451 int sx, sy;
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1452 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
1453
1413
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1454 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
1455 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
1456 &PySurface_Type, &srcobject, &argpos,
11b95e1ab94c Add keyword arguments to Surface blit and fill
Lenard Lindstrom <len-l@telus.net>
parents: 1372
diff changeset
1457 &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
1458 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1459
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1460 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
1461 if (!dest || !src)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1462 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
1463
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1464 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
1465 !(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
1466 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
1467 "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
1468
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1469 if ((src_rect = GameRect_FromObject (argpos, &temp)))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1470 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1471 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
1472 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
1473 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1474 else if (TwoIntsFromObj (argpos, &sx, &sy))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1475 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1476 dx = sx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1477 dy = sy;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1478 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1479 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1480 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
1481
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1482 if (argrect && argrect != Py_None)
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 (!(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
1485 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
1486 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1487 else
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 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
1490 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
1491 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
1492 src_rect = &temp;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1493 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1494
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1495 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
1496 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
1497 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
1498 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
1499 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
1500 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
1501 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
1502 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
1503
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1504 if (!the_args)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1505 the_args = 0;
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 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
1508 the_args);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1509 if (result != 0)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1510 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1511
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1512 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
1513 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1514
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1515 static PyObject*
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1516 surf_scroll (PyObject *self, PyObject *args, PyObject *keywds)
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1517 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1518 int dx = 0, dy = 0;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1519 SDL_Surface *surf;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1520 int bpp;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1521 int pitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1522 SDL_Rect *clip_rect;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1523 int w, h;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1524 Uint8 *src, *dst;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1526 static char *kwids[] = {"dx", "dy", NULL};
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1527 if (!PyArg_ParseTupleAndKeywords (args, keywds, "|ii", kwids, &dx, &dy))
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1528 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1529 return NULL;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1530 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1531
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1532 surf = PySurface_AsSurface (self);
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1533 if (!surf)
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1534 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1535 return RAISE (PyExc_SDLError, "display Surface quit");
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1536 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1537
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1538 if (surf->flags & SDL_OPENGL &&
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1539 !(surf->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL)))
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1540 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1541 return RAISE (PyExc_SDLError,
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1542 "Cannot scroll an OPENGL Surfaces (OPENGLBLIT is ok)");
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1543 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1544
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1545 if (dx == 0 && dy == 0)
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1546 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1547 Py_RETURN_NONE;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1548 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1549
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1550 clip_rect = &surf->clip_rect;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1551 w = clip_rect->w;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1552 h = clip_rect->h;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1553 if (dx >= w || dx <= -w || dy >= h || dy <= -h)
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1554 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1555 Py_RETURN_NONE;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1556 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1557
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1558 if (!PySurface_Lock (self))
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1559 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1560 return NULL;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1561 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1562
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1563 bpp = surf->format->BytesPerPixel;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1564 pitch = surf->pitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1565 src = dst = (Uint8 *) surf->pixels +
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1566 clip_rect->y * pitch + clip_rect->x * bpp;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1567 if (dx >= 0)
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 w -= dx;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1570 if (dy > 0)
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1571 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1572 h -= dy;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1573 dst += dy * pitch + dx * bpp;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1574 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1575 else
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1576 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1577 h += dy;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1578 src -= dy * pitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1579 dst += dx * bpp;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1580 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1581 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1582 else
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 w += dx;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1585 if (dy > 0)
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1586 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1587 h -= dy;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1588 src -= dx * bpp;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1589 dst += dy * pitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1590 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1591 else
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1592 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1593 h += dy;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1594 src -= dy * pitch + dx * bpp;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1595 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1596 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1597 surface_move (src, dst, h, w * bpp, pitch, pitch);
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 if (!PySurface_Unlock (self))
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1600 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1601 return NULL;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1602 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1603
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1604 Py_RETURN_NONE;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1605 }
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1606
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
1607 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1608 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
1609 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1610 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
1611
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1612 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1613 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
1614 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
1615 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1616
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1617 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1618 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
1619 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1620 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
1621
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1622 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1623 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
1624 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
1625 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1626
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1627 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1628 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
1629 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1630 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
1631
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1632 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1633 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
1634 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
1635 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1636
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
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_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
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");
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1644 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
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_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
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->h);
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*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1658 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
1659 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1660 PyObject *rect;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1661 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
1662
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
1663 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
1664 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
1665 "get_rect only accepts keyword arguments");
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
1666 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
1667
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1668 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1669 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
1670
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1671 rect = PyRect_New4 (0, 0, 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
1672 if (rect && kwargs)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1673 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1674 PyObject *key, *value;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1675 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
1676
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1677 while (PyDict_Next (kwargs, &pos, &key, &value))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1678 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1679 if ((PyObject_SetAttr (rect, key, value) == -1))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1680 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1681 Py_DECREF (rect);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1682 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1683 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1684 }
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 return rect;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1687 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1688
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1689 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1690 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
1691 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1692 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
1693 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
1694 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
1695
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1696 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
1697 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1698
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1699 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1700 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
1701 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1702 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
1703 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
1704 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
1705 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
1706 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1707
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1708 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1709 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
1710 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1711 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
1712
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1713 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1714 return RAISE (PyExc_SDLError, "display Surface quit");
1839
02c1e8e9c102 merged changes from trunk to math_module branch
lorenz
parents: 1585
diff changeset
1715 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
1716 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
1717 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1718
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1719
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1720 static PyObject*
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1721 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
1722 {
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1723 SDL_Surface *surf = PySurface_AsSurface (self);
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1724 /* 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
1725 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
1726
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1727 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
1728 return NULL;
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1729 if (!surf)
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1730 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
1731
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1732 /*
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1733 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
1734 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
1735 */
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1736
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1737 surf->format->Rmask = (Uint32)r;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1738 surf->format->Gmask = (Uint32)g;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1739 surf->format->Bmask = (Uint32)b;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1740 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
1741
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1742 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
1743 }
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1744
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1745
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
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1748
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1749 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1750 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
1751 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1752 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
1753
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1754 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1755 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
1756 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
1757 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
1758 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1759
1234
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1760
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1761 static PyObject*
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1762 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
1763 {
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1764 SDL_Surface *surf = PySurface_AsSurface (self);
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1765 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
1766
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1767 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
1768 return NULL;
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1769 if (!surf)
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1770 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
1771
1493
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1772 surf->format->Rshift = (Uint8)r;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1773 surf->format->Gshift = (Uint8)g;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1774 surf->format->Bshift = (Uint8)b;
4d9e03f4380b fixed some 64 bit issues... failing tests.
Rene Dudfield <renesd@gmail.com>
parents: 1479
diff changeset
1775 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
1776
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1777 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
1778 }
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1779
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1780
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1781
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1782
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1783
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1784
2ad2aa11e514 Added Surface.set_masks and .set_shifts useful for using data in
Rene Dudfield <renesd@gmail.com>
parents: 1142
diff changeset
1785
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1786 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1787 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
1788 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1789 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
1790
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1791 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1792 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
1793 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
1794 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
1795 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1796
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1797 static PyObject*
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1798 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
1799 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1800 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
1801 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
1802 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
1803 SDL_Surface *sub;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1804 PyObject *subobj;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1805 int pixeloffset;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1806 char *startpixel;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1807 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
1808
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1809 if (!surf)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1810 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
1811 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
1812 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
1813
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1814 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
1815 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
1816 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
1817 || 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
1818 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
1819 "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
1820
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1821 PySurface_Lock (self);
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 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
1824 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
1825
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1826 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
1827 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
1828 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
1829 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
1830
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1831 PySurface_Unlock (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1832
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1833 if (!sub)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1834 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
1835
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1836 /* 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
1837 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
1838 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
1839 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
1840 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
1841 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
1842 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
1843 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
1844 format->colorkey);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1845
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1846 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
1847 if (!data)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1848 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1849
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1850 subobj = PySurface_New (sub);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1851 if (!subobj)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1852 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1853 PyMem_Del (data);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1854 return NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1855 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1856 Py_INCREF (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1857 data->owner = self;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1858 data->pixeloffset = pixeloffset;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1859 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
1860 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
1861 ((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
1862
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1863 return subobj;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1864 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1865
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1866 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1867 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
1868 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1869 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
1870
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1871 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
1872 if (!subdata)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1873 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
1874 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
1875 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1876
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1877 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1878 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
1879 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1880 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
1881 PyObject *owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1882 int offsetx, offsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1883
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1884 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
1885 if (!subdata)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1886 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
1887
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1888 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
1889 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1890 offsetx = subdata->offsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1891 offsety = subdata->offsety;
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 while (((PySurfaceObject *) owner)->subsurface)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1894 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1895 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
1896 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1897 offsetx += subdata->offsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1898 offsety += subdata->offsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1899 }
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)", offsetx, offsety);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1901 }
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 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1904 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
1905 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1906 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
1907
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1908 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
1909 if (!subdata)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1910 Py_RETURN_NONE;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1911
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1912 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
1913 return subdata->owner;
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
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1916 static PyObject*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
1917 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
1918 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1919 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
1920 PyObject *owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1921
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1922 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
1923 if (!subdata)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1924 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1925 Py_INCREF (self);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1926 return self;
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 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
1930 owner = subdata->owner;
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 while (((PySurfaceObject *) owner)->subsurface)
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 *) owner)->subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1935 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1936 }
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 (owner);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
1939 return 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
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1942 static PyObject *
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1943 surf_get_bounding_rect (PyObject *self, PyObject *args, PyObject *kwargs)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1944 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1945 PyObject *rect;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1946 SDL_Surface *surf = PySurface_AsSurface (self);
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1947 SDL_PixelFormat *format = surf->format;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1948 Uint8 *pixels = (Uint8 *) surf->pixels;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1949 Uint8 *pixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1950 int x, y;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1951 int min_x, min_y, max_x, max_y;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1952 int min_alpha = 1;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1953 int found_alpha = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1954 Uint8 r, g, b, a;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1955 int has_colorkey = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1956 Uint8 keyr, keyg, keyb;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1957
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1958 char *kwids[] = { "min_alpha", NULL };
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1959 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
1960 return RAISE (PyExc_ValueError,
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1961 "get_bounding_rect only accepts a single optional min_alpha argument");
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1962
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1963 if (!surf)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1964 return RAISE (PyExc_SDLError, "display Surface quit");
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1965
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1966 if (!PySurface_Lock (self))
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1967 return RAISE (PyExc_SDLError, "could not lock surface");
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1968
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1969 if (surf->flags & SDL_SRCCOLORKEY)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1970 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1971 has_colorkey = 1;
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1972 SDL_GetRGBA (surf->format->colorkey,
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1973 surf->format,
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1974 &keyr, &keyg, &keyb, &a);
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1975 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1976
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1977 pixels = (Uint8 *) surf->pixels;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1978
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1979 min_y = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1980 min_x = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1981 max_x = surf->w;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1982 max_y = surf->h;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1983
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1984 found_alpha = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1985 for (y = max_y - 1; y >= min_y; --y)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1986 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1987 for (x = min_x; x < max_x; ++x)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1988 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1989 pixel = (pixels + y * surf->pitch) + x*format->BytesPerPixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1990 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
1991 if ((a >= min_alpha && has_colorkey == 0) ||
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
1992 (has_colorkey != 0 && (r != keyr || g != keyg || b != keyb)))
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1993 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1994 found_alpha = 1;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1995 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1996 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1997 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1998 if (found_alpha == 1)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
1999 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2000 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2001 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2002 max_y = y;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2003 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2004 found_alpha = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2005 for (x = max_x - 1; x >= min_x; --x)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2006 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2007 for (y = min_y; y < max_y; ++y)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2008 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2009 pixel = (pixels + y * surf->pitch) + x*format->BytesPerPixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2010 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
2011 if ((a >= min_alpha && has_colorkey == 0) ||
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
2012 (has_colorkey != 0 && (r != keyr || g != keyg || b != keyb)))
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2013 {
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 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2018 if (found_alpha == 1)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2019 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2020 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2021 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2022 max_x = x;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2023 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2024 found_alpha = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2025 for (y = min_y; y < max_y; ++y)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2026 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2027 min_y = y;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2028 for (x = min_x; x < max_x; ++x)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2029 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2030 pixel = (pixels + y * surf->pitch) + x*format->BytesPerPixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2031 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
2032 if ((a >= min_alpha && has_colorkey == 0) ||
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
2033 (has_colorkey != 0 && (r != keyr || g != keyg || b != keyb)))
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2034 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2035 found_alpha = 1;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2036 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2037 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2038 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2039 if (found_alpha == 1)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2040 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2041 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2042 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2043 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2044 found_alpha = 0;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2045 for (x = min_x; x < max_x; ++x)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2046 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2047 min_x = x;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2048 for (y = min_y; y < max_y; ++y)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2049 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2050 pixel = (pixels + y * surf->pitch) + x*format->BytesPerPixel;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2051 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
2052 if ((a >= min_alpha && has_colorkey == 0) ||
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1234
diff changeset
2053 (has_colorkey != 0 && (r != keyr || g != keyg || b != keyb)))
930
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2054 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2055 found_alpha = 1;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2056 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2057 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2058 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2059 if (found_alpha == 1)
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2060 {
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2061 break;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2062 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2063 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2064 if (!PySurface_Unlock (self))
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2065 return RAISE (PyExc_SDLError, "could not unlock surface");
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2066
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2067 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
2068 return rect;
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2069 }
6c7f1d4107f4 surface.get_bounding_rect
brian
parents: 915
diff changeset
2070
1085
31789d104e1f Fixed locking and ref count leaks in Numeric surfarray.
marcus
parents: 1037
diff changeset
2071 static PyObject
31789d104e1f Fixed locking and ref count leaks in Numeric surfarray.
marcus
parents: 1037
diff changeset
2072 *surf_get_buffer (PyObject *self)
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2073 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2074 PyObject *buffer;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2075 PyObject *lock;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2076 SDL_Surface *surface = PySurface_AsSurface (self);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2077 Py_ssize_t length;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2078
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
2079 length = (Py_ssize_t) surface->pitch * surface->h;
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2080
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2081 buffer = PyBufferProxy_New (self, NULL, length, NULL);
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2082 if (!buffer)
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2083 {
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2084 return RAISE (PyExc_SDLError,
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2085 "could not acquire a buffer for the surface");
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2086 }
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 lock = PySurface_LockLifetime (self, buffer);
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2089 if (!lock)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2090 {
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2091 Py_DECREF (buffer);
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2092 return RAISE (PyExc_SDLError, "could not lock surface");
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2093 }
1137
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2094 ((PyBufferProxy *) buffer)->buffer = surface->pixels;
ec3ced33488f Reworked locking code to be more strict about locking.
marcus
parents: 1117
diff changeset
2095 ((PyBufferProxy *) buffer)->lock = lock;
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2096
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2097 return buffer;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2098 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents: 859
diff changeset
2099
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2100 static void
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2101 surface_move (Uint8 *src, Uint8 *dst, int h, int span,
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2102 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
2103 {
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2104 if (src < dst)
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2105 {
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2106 src += (h - 1) * srcpitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2107 dst += (h - 1) * dstpitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2108 srcpitch = -srcpitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2109 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
2110 }
1525
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2111 while (h--)
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2112 {
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2113 memmove(dst, src, span);
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2114 src += srcpitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2115 dst += dstpitch;
48ab3db38416 add Surface.scroll method
Lenard Lindstrom <len-l@telus.net>
parents: 1524
diff changeset
2116 }
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2117 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2118
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2119 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
2120 surface_do_overlap (SDL_Surface *src, SDL_Rect *srcrect,
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2121 SDL_Surface *dst, SDL_Rect *dstrect)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2122 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2123 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
2124 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
2125 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
2126 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
2127 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
2128 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
2129 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
2130 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
2131 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
2132 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
2133
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2134 /* clip the source rectangle to the source surface */
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2135 if (srcx < 0)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2136 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2137 w += srcx;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2138 dstx -= srcx;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2139 srcx = 0;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2140 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2141 maxw = src->w - srcx;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2142 if (maxw < w)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2143 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2144 w = maxw;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2145 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2146 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
2147 if (srcy < 0)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2148 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2149 h += srcy;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2150 dsty -= srcy;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2151 srcy = 0;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2152 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2153 maxh = src->h - srcy;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2154 if (maxh < h)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2155 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2156 h = maxh;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2157 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2158
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2159 /* 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
2160 x = clip->x - dstx;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2161 if (x > 0)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2162 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2163 w -= x;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2164 dstx += x;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2165 srcx += x;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2166 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2167 x = dstx + w - clip->x - clip->w;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2168 if (x > 0)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2169 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2170 w -= x;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2171 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2172 y = clip->y - dsty;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2173 if (y > 0)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2174 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2175 h -= y;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2176 dsty += y;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2177 srcy += y;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2178 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2179 y = dsty + h - clip->y - clip->h;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2180 if (y > 0)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2181 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2182 h -= y;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2183 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2184
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2185 if (w <= 0 || h <= 0)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2186 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2187 return 0;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2188 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2189
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2190 srcpixels = ((Uint8 *) src->pixels + src->offset +
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2191 srcy * 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
2192 srcx * 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
2193 dstpixels = ((Uint8 *) dst->pixels + src->offset +
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2194 dsty * dst->pitch +
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2195 dstx * dst->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
2196
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2197 if (dstpixels <= srcpixels)
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2198 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2199 return 0;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2200 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2201
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2202 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
2203
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2204 if (dstpixels >= srcpixels + (h - 1) * 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
2205 {
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2206 return 0;
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2207 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2208
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2209 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
2210
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2211 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
2212 }
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2213
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2214 /*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
2215 int
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2216 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
2217 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
2218 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2219 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
2220 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
2221 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
2222 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
2223 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
2224
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2225 /* passthrough blits to the real surface */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2226 if (((PySurfaceObject *) dstobj)->subsurface)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2227 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2228 PyObject *owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2229 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
2230
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2231 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
2232 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2233 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
2234 suboffsetx = subdata->offsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2235 suboffsety = subdata->offsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2236
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2237 while (((PySurfaceObject *) owner)->subsurface)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2238 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2239 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
2240 owner = subdata->owner;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2241 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
2242 suboffsetx += subdata->offsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2243 suboffsety += subdata->offsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2244 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2245
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2246 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
2247 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
2248 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
2249 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
2250 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
2251 dstrect->x += suboffsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2252 dstrect->y += suboffsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2253 dst = subsurface;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2254 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2255 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2256 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2257 PySurface_Prep (dstobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2258 subsurface = NULL;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2259 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2260
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2261 PySurface_Prep (srcobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2262
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2263 /* 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
2264 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
2265 !(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
2266 /* special case, SDL works */
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2267 (dst->format->BytesPerPixel == 2 || dst->format->BytesPerPixel == 4))
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2268 {
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2269 /* Py_BEGIN_ALLOW_THREADS */
1142
befac1186c08 some fixes for BLEND_RGBA_*
Rene Dudfield <renesd@gmail.com>
parents: 1137
diff changeset
2270 result = pygame_AlphaBlit (src, srcrect, dst, dstrect, the_args);
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2271 /* 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
2272 }
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2273 else if (the_args != 0 ||
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2274 (src->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY) &&
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2275 /* This simplification is possible because a source subsurface
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2276 is converted to its owner with a clip rect and a dst
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2277 subsurface cannot be blitted to its owner because the
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2278 owner is locked.
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2279 */
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2280 dst->pixels == src->pixels &&
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2281 surface_do_overlap (src, srcrect, dst, dstrect)))
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2282 {
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2283 /* 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
2284 result = pygame_Blit (src, srcrect, dst, dstrect, the_args);
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2285 /* 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
2286 }
1526
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2287 /* 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
2288 else if (dst->format->BytesPerPixel == 1 &&
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2289 (src->format->Amask || src->flags & SDL_SRCALPHA))
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2290 {
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2291 /* Py_BEGIN_ALLOW_THREADS */
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2292 if (src->format->BytesPerPixel == 1)
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2293 {
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2294 result = pygame_Blit (src, srcrect, dst, dstrect, 0);
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2295 }
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2296 else
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2297 {
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2298 src = SDL_DisplayFormat (src);
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2299 if (src)
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2300 {
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2301 result = SDL_BlitSurface (src, srcrect, dst, dstrect);
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2302 SDL_FreeSurface (src);
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2303 }
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2304 else
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2305 {
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2306 result = -1;
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2307 }
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2308 }
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2309 /* Py_END_ALLOW_THREADS */
9f20bb17cf3d Complete Pygame blitter support of 8bit surfaces
Lenard Lindstrom <len-l@telus.net>
parents: 1525
diff changeset
2310 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2311 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2312 {
1524
28a601e11e62 fix surface self-blits for colorkey and blanket alpha: Bugzilla Bug 19
Lenard Lindstrom <len-l@telus.net>
parents: 1515
diff changeset
2313 /* 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
2314 result = SDL_BlitSurface (src, srcrect, dst, 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
2315 /* 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
2316 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2317
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2318 if (subsurface)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2319 {
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2320 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
2321 dstrect->x -= suboffsetx;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2322 dstrect->y -= suboffsety;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2323 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2324 else
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2325 PySurface_Unprep (dstobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2326 PySurface_Unprep (srcobj);
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2327
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2328 if (result == -1)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2329 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
2330 if (result == -2)
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2331 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
2332
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2333 return result != 0;
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2334 }
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2335
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2336 static PyMethodDef _surface_methods[] =
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2337 {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2338 { NULL, NULL, 0, NULL }
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2339 };
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2340
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2341 MODINIT_DEFINE (surface)
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2342 {
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2343 PyObject *module, *dict, *apiobj, *lockmodule;
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2344 int ecode;
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2345 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
2346
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2347 #if PY3
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2348 static struct PyModuleDef _module = {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2349 PyModuleDef_HEAD_INIT,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2350 "surface",
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2351 DOC_PYGAMESURFACE,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2352 -1,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2353 _surface_methods,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2354 NULL, NULL, NULL, NULL
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2355 };
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2356 #endif
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2357
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2358 /* 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
2359 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
2360 */
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2361 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
2362 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2363 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
2364 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2365 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
2366 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2367 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
2368 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2369 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
2370 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2371 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
2372 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2373 import_pygame_bufferproxy();
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2374 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2375 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
2376 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2377
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2378 /* import the surflock module manually */
1585
b9a1d6556447 symbian branch merging
Rene Dudfield <renesd@gmail.com>
parents: 1578
diff changeset
2379 lockmodule = PyImport_ImportModule (IMPPREFIX "surflock");
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2380 if (lockmodule != NULL)
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2381 {
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2382 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
2383 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
2384
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2385 if (PyCObject_Check (_c_api))
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2386 {
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2387 int i;
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2388 void **localptr = (void *)PyCObject_AsVoidPtr (_c_api);
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2389
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2390 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
2391 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
2392 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2393 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
2394 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2395 else
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2396 {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2397 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
2398 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2399
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1493
diff changeset
2400 /* type preparation */
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2401 if (PyType_Ready(&PySurface_Type) < 0) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2402 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2403 }
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2404
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2405 /* create the module */
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2406 #if PY3
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2407 module = PyModule_Create (&_module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2408 #else
1585
b9a1d6556447 symbian branch merging
Rene Dudfield <renesd@gmail.com>
parents: 1578
diff changeset
2409 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
2410 #endif
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2411 if (module == NULL) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2412 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2413 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2414 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
2415
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2416 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
2417 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2418 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2419 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2420 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
2421 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2422 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2423 }
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2424
794
1633c4302f48 Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents: 735
diff changeset
2425 /* 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
2426 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
2427 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
2428 c_api[2] = PySurface_Blit;
819
f10c63453e4e Marcus has added in blend modes for the surface.fill function.
Rene Dudfield <renesd@gmail.com>
parents: 816
diff changeset
2429 apiobj = PyCObject_FromVoidPtr (c_api, NULL);
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2430 if (apiobj == NULL) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2431 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2432 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2433 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2434 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
2435 Py_DECREF (apiobj);
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2436 if (ecode) {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2437 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2438 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2439 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 830
diff changeset
2440 /* 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
2441 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
2442 DECREF_MOD (module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2443 MODINIT_ERROR;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2444 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1526
diff changeset
2445 MODINIT_RETURN (module);
7
99d32cc487b7 Initial revision
ahvezda
parents:
diff changeset
2446 }