Mercurial > pygame
annotate src/overlay.c @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 0d661c00c1aa |
| children |
| rev | line source |
|---|---|
| 539 | 1 /* |
|
607
52671d3e6a1d
fixes to compile on windows. See faq, http://python.project.cwi.nl/doc/FAQ.html#initializer-not-a-constant-while-building-dll-on-ms-windows
Rene Dudfield <renesd@gmail.com>
parents:
539
diff
changeset
|
2 * A part of the pydfb module. Provides interface for basic overlay |
| 539 | 3 * manipulation functions. |
| 4 * In this implementation overlay can use only one layer out of maximum | |
| 5 * possible. After getting overlay, no overlay can be created. | |
| 6 * | |
| 7 * Copyright (C) 2002-2003 Dmitry Borisov | |
| 8 * | |
| 9 * This library is free software; you can redistribute it and/or | |
| 10 * modify it under the terms of the GNU Library General Public | |
| 11 * License as published by the Free Software Foundation; either | |
| 12 * version 2 of the License, or (at your option) any later version. | |
| 13 * | |
| 14 * This library is distributed in the hope that it will be useful, | |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 17 * Library General Public License for more details. | |
| 18 * | |
| 19 * You should have received a copy of the GNU Library General Public | |
| 20 * License along with this library; if not, write to the Free | |
| 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 22 * | |
| 23 * Dmitry Borisov | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
24 */ |
| 539 | 25 |
| 26 #include <Python.h> | |
| 27 #include "pygame.h" | |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
28 #include "pgcompat.h" |
| 1937 | 29 #include "doc/overlay_doc.h" |
| 539 | 30 |
| 31 typedef struct | |
| 32 { | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
33 PyObject_HEAD |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
34 SDL_Overlay *cOverlay; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
35 GAME_Rect cRect; |
| 539 | 36 } PyGameOverlay; |
| 37 | |
| 38 static void | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
39 overlay_dealloc (PyGameOverlay *self) |
| 539 | 40 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
41 if (SDL_WasInit (SDL_INIT_VIDEO) && self->cOverlay) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
42 SDL_FreeYUVOverlay (self->cOverlay); |
| 539 | 43 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
44 PyObject_Free ((PyObject*)self); |
| 539 | 45 } |
| 46 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
47 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
48 Overlay_SetLocation (PyGameOverlay *self, PyObject *args) |
| 539 | 49 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
50 GAME_Rect *rect, temp; |
| 539 | 51 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
52 rect = GameRect_FromObject (args, &temp); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
53 if (!rect) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
54 return RAISE (PyExc_TypeError, "Invalid rectstyle argument"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
55 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
56 self->cRect.x = rect->x; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
57 self->cRect.y = rect->y; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
58 self->cRect.w = rect->w; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
59 self->cRect.h = rect->h; |
| 539 | 60 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
61 Py_RETURN_NONE; |
| 539 | 62 } |
| 63 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
64 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
65 Overlay_Display (PyGameOverlay *self, PyObject *args) |
| 539 | 66 { |
| 651 | 67 SDL_Rect cRect; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
68 // Parse data params for frame |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
69 int ls_y, ls_u, ls_v, y; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
70 unsigned char *src_y=0, *src_u=0, *src_v=0; |
| 651 | 71 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
72 if (PyTuple_Size (args)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
73 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
74 if (!PyArg_ParseTuple (args, "(s#s#s#)", &src_y, &ls_y, &src_u, &ls_u, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
75 &src_v, &ls_v)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
76 return NULL; |
| 651 | 77 } |
| 539 | 78 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
79 if (src_y) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
80 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
81 Uint8 *dst_y=0, *dst_u=0, *dst_v=0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
82 SDL_LockYUVOverlay (self->cOverlay); |
| 539 | 83 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
84 // No clipping at this time( only support for YUV420 ) |
|
777
e5f57903301d
Some fixes from John Popplewell. Thanks!
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
85 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
86 dst_y = self->cOverlay->pixels[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
87 dst_v = self->cOverlay->pixels[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
88 dst_u = self->cOverlay->pixels[2]; |
|
777
e5f57903301d
Some fixes from John Popplewell. Thanks!
Rene Dudfield <renesd@gmail.com>
parents:
735
diff
changeset
|
89 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
90 for (y = 0; y < self->cOverlay->h; y++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
91 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
92 memcpy (dst_y, src_y, self->cOverlay->w); |
| 539 | 93 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
94 src_y += ls_y / self->cOverlay->h; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
95 dst_y += self->cOverlay->pitches[0]; |
| 539 | 96 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
97 if (!(y & 1)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
98 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
99 src_u += (ls_u * 2)/self->cOverlay->h; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
100 src_v += (ls_v * 2)/self->cOverlay->h; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
101 dst_u += self->cOverlay->pitches[ 1 ]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
102 dst_v += self->cOverlay->pitches[ 2 ]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
103 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
104 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
105 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
106 memcpy (dst_u, src_u, (ls_u * 2) / self->cOverlay->h); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
107 memcpy (dst_v, src_v, (ls_v * 2) / self->cOverlay->h); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
108 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
109 } |
| 539 | 110 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
111 SDL_UnlockYUVOverlay (self->cOverlay); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
112 } |
| 651 | 113 |
| 114 cRect.x = self->cRect.x; | |
| 115 cRect.y = self->cRect.y; | |
| 116 cRect.w = self->cRect.w; | |
| 117 cRect.h = self->cRect.h; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
118 SDL_DisplayYUVOverlay (self->cOverlay, &cRect); |
| 651 | 119 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
120 Py_RETURN_NONE; |
| 539 | 121 } |
| 122 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
123 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
124 Overlay_GetHardware (PyGameOverlay *self) |
| 651 | 125 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
126 return PyInt_FromLong (self->cOverlay->hw_overlay); |
| 651 | 127 } |
| 128 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
129 PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
130 Overlay_New (PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 539 | 131 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
132 int pixelformat; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
133 PyGameOverlay *self; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
134 int w, h; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
135 SDL_Surface *screen; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
136 if (!PyArg_ParseTuple (args, "i(ii)", &pixelformat, &w, &h)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
137 return NULL; |
| 539 | 138 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
139 if (!SDL_WasInit (SDL_INIT_VIDEO)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
140 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
141 (PyExc_SDLError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
142 "cannot create overlay without pygame.display initialized"); |
| 539 | 143 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
144 screen = SDL_GetVideoSurface (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
145 if (!screen) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
146 return RAISE (PyExc_SDLError, "Display mode not set"); |
| 539 | 147 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
148 // Create new Overlay object |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
149 self= (PyGameOverlay *)type->tp_alloc (type, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
150 if (!self) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
151 return NULL; |
| 539 | 152 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
153 // Create layer with desired format |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
154 self->cOverlay = SDL_CreateYUVOverlay (w, h, pixelformat, screen); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
155 if (!self->cOverlay) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
156 return RAISE (PyExc_SDLError, "Cannot create overlay"); |
| 539 | 157 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
158 self->cRect.x= 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
159 self->cRect.y= 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
160 self->cRect.w= w; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
161 self->cRect.h= h; |
| 539 | 162 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
163 return (PyObject*)self; |
| 539 | 164 } |
| 165 | |
| 166 static PyMethodDef Overlay_methods[] = { | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
167 { "set_location", (PyCFunction) Overlay_SetLocation, METH_VARARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
168 DOC_OVERLAYSETLOCATION }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
169 { "display", (PyCFunction) Overlay_Display, METH_VARARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
170 DOC_OVERLAYDISPLAY }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
171 { "get_hardware", (PyCFunction) Overlay_GetHardware, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
172 DOC_OVERLAYGETHARDWARE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
173 {NULL, NULL, 0, NULL} /* Sentinel */ |
| 539 | 174 }; |
| 175 | |
| 176 PyTypeObject PyOverlay_Type = | |
| 177 { | |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
178 TYPE_HEAD (NULL, 0) |
| 539 | 179 "pygame.overlay", /*tp_name*/ |
| 180 sizeof(PyGameOverlay), /*tp_basicsize*/ | |
| 181 0, /*tp_itemsize*/ | |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
182 (destructor) overlay_dealloc, /*tp_dealloc*/ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
183 0, /*tp_print*/ |
| 539 | 184 0, /*tp_getattr*/ |
| 185 0, /*tp_setattr*/ | |
| 186 0, /*tp_compare*/ | |
| 187 0, /*tp_repr*/ | |
| 188 0, /*tp_as_number*/ | |
| 189 0, /*tp_as_sequence*/ | |
| 190 0, /*tp_as_mapping*/ | |
| 191 0, /*tp_hash */ | |
| 192 0, /*tp_call*/ | |
| 193 0, /*tp_str*/ | |
|
607
52671d3e6a1d
fixes to compile on windows. See faq, http://python.project.cwi.nl/doc/FAQ.html#initializer-not-a-constant-while-building-dll-on-ms-windows
Rene Dudfield <renesd@gmail.com>
parents:
539
diff
changeset
|
194 0, /*tp_getattro*/ |
| 539 | 195 0, /*tp_setattro*/ |
| 196 0, /*tp_as_buffer*/ | |
| 197 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ | |
| 627 | 198 DOC_PYGAMEOVERLAY, /* tp_doc */ |
| 539 | 199 0, /* tp_traverse */ |
| 200 0, /* tp_clear */ | |
| 201 0, /* tp_richcompare */ | |
| 202 0, /* tp_weaklistoffset */ | |
| 203 0, /* tp_iter */ | |
| 204 0, /* tp_iternext */ | |
| 205 Overlay_methods, /* tp_methods */ | |
| 206 0, /* tp_members */ | |
| 207 0, /* tp_getset */ | |
| 208 0, /* tp_base */ | |
| 209 0, /* tp_dict */ | |
| 210 0, /* tp_descr_get */ | |
| 211 0, /* tp_descr_set */ | |
| 212 0, /* tp_dictoffset */ | |
| 213 0, /* tp_init */ | |
|
607
52671d3e6a1d
fixes to compile on windows. See faq, http://python.project.cwi.nl/doc/FAQ.html#initializer-not-a-constant-while-building-dll-on-ms-windows
Rene Dudfield <renesd@gmail.com>
parents:
539
diff
changeset
|
214 0, /* tp_alloc */ |
| 539 | 215 Overlay_New, /* tp_new */ |
| 216 }; | |
| 217 | |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
218 static PyMethodDef _overlay_methods[] = |
| 539 | 219 { |
|
798
05346fb84a05
Some cleanups from Marcus to stop compiler warnings.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
220 { NULL, NULL, 0, NULL } |
| 539 | 221 }; |
| 222 | |
| 223 | |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
224 MODINIT_DEFINE (overlay) |
| 539 | 225 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
226 PyObject *module; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
227 |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
228 #if PY3 |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
229 static struct PyModuleDef _module = { |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
230 PyModuleDef_HEAD_INIT, |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
231 "overlay", |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
232 NULL, |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
233 -1, |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
234 _overlay_methods, |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
235 NULL, NULL, NULL, NULL |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
236 }; |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
237 #endif |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
238 |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
239 /* 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:
831
diff
changeset
|
240 the module is not loaded. |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
241 */ |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
242 import_pygame_base (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
243 if (PyErr_Occurred ()) { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1597
diff
changeset
|
244 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
245 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
246 import_pygame_rect (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
247 if (PyErr_Occurred ()) { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1597
diff
changeset
|
248 MODINIT_ERROR; |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
249 } |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
250 |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
251 if (PyType_Ready (&PyOverlay_Type) == -1) { |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
252 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
253 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
254 |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
831
diff
changeset
|
255 /* create the module */ |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
256 #if PY3 |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
257 module = PyModule_Create (&_module); |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
258 #else |
| 1597 | 259 module = Py_InitModule (MODPREFIX "overlay", _overlay_methods ); |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
260 #endif |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
261 if (module == NULL) { |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
262 MODINIT_ERROR; |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
263 } |
| 539 | 264 |
| 265 /* create the module reference */ | |
|
1570
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
266 Py_INCREF ((PyObject *)&PyOverlay_Type); |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
267 if (PyModule_AddObject (module, "Overlay", |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
268 (PyObject *)&PyOverlay_Type) == -1) { |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
269 Py_DECREF ((PyObject *)&PyOverlay_Type); |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
270 DECREF_MOD (module); |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
271 MODINIT_ERROR; |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
272 } |
|
b14591f81d72
adapt overlay for python 3.1; untested though importing does crash anything
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
273 MODINIT_RETURN (module); |
| 539 | 274 } |
