first commit

This commit is contained in:
Florian Schmitt 2024-10-08 15:38:46 +03:00
commit 2e5df21095
2308 changed files with 453496 additions and 0 deletions

View file

@ -0,0 +1,21 @@
#define NO_PYGAME_C_API
#include "_surface.h"
/* The structure passed to the low level blit functions */
typedef struct {
int width;
int height;
Uint8 *s_pixels;
int s_pxskip;
int s_skip;
Uint8 *d_pixels;
int d_pxskip;
int d_skip;
SDL_PixelFormat *src;
SDL_PixelFormat *dst;
Uint8 src_blanket_alpha;
int src_has_colorkey;
Uint32 src_colorkey;
SDL_BlendMode src_blend;
SDL_BlendMode dst_blend;
} SDL_BlitInfo;

View file

@ -0,0 +1,26 @@
/*
pygame - Python Game Library
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _CAMERA_H
#define _CAMERA_H
#include "_pygame.h"
#include "camera.h"
#endif

View file

@ -0,0 +1,374 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
/* This will use PYGAMEAPI_EXTERN_SLOTS instead
* of PYGAMEAPI_DEFINE_SLOTS for base modules.
*/
#ifndef _PYGAME_INTERNAL_H
#define _PYGAME_INTERNAL_H
#include "pgplatform.h"
/*
If PY_SSIZE_T_CLEAN is defined before including Python.h, length is a
Py_ssize_t rather than an int for all # variants of formats (s#, y#, etc.)
*/
#define PY_SSIZE_T_CLEAN
#include <Python.h>
/* Ensure PyPy-specific code is not in use when running on GraalPython (PR
* #2580) */
#if defined(GRAALVM_PYTHON) && defined(PYPY_VERSION)
#undef PYPY_VERSION
#endif
#include <SDL.h>
/* SDL 1.2 constants removed from SDL 2 */
typedef enum {
SDL_HWSURFACE = 0,
SDL_RESIZABLE = SDL_WINDOW_RESIZABLE,
SDL_ASYNCBLIT = 0,
SDL_OPENGL = SDL_WINDOW_OPENGL,
SDL_OPENGLBLIT = 0,
SDL_ANYFORMAT = 0,
SDL_HWPALETTE = 0,
SDL_DOUBLEBUF = 0,
SDL_FULLSCREEN = SDL_WINDOW_FULLSCREEN,
SDL_HWACCEL = 0,
SDL_SRCCOLORKEY = 0,
SDL_RLEACCELOK = 0,
SDL_SRCALPHA = 0,
SDL_NOFRAME = SDL_WINDOW_BORDERLESS,
SDL_GL_SWAP_CONTROL = 0,
TIMER_RESOLUTION = 0
} PygameVideoFlags;
/* the wheel button constants were removed from SDL 2 */
typedef enum {
PGM_BUTTON_LEFT = SDL_BUTTON_LEFT,
PGM_BUTTON_RIGHT = SDL_BUTTON_RIGHT,
PGM_BUTTON_MIDDLE = SDL_BUTTON_MIDDLE,
PGM_BUTTON_WHEELUP = 4,
PGM_BUTTON_WHEELDOWN = 5,
PGM_BUTTON_X1 = SDL_BUTTON_X1 + 2,
PGM_BUTTON_X2 = SDL_BUTTON_X2 + 2,
PGM_BUTTON_KEEP = 0x80
} PygameMouseFlags;
typedef enum {
/* Any SDL_* events here are for backward compatibility. */
SDL_NOEVENT = 0,
SDL_ACTIVEEVENT = SDL_USEREVENT,
SDL_VIDEORESIZE,
SDL_VIDEOEXPOSE,
PGE_MIDIIN,
PGE_MIDIOUT,
PGE_KEYREPEAT, /* Special internal pygame event, for managing key-presses
*/
/* DO NOT CHANGE THE ORDER OF EVENTS HERE */
PGE_WINDOWSHOWN,
PGE_WINDOWHIDDEN,
PGE_WINDOWEXPOSED,
PGE_WINDOWMOVED,
PGE_WINDOWRESIZED,
PGE_WINDOWSIZECHANGED,
PGE_WINDOWMINIMIZED,
PGE_WINDOWMAXIMIZED,
PGE_WINDOWRESTORED,
PGE_WINDOWENTER,
PGE_WINDOWLEAVE,
PGE_WINDOWFOCUSGAINED,
PGE_WINDOWFOCUSLOST,
PGE_WINDOWCLOSE,
PGE_WINDOWTAKEFOCUS,
PGE_WINDOWHITTEST,
PGE_WINDOWICCPROFCHANGED,
PGE_WINDOWDISPLAYCHANGED,
/* Here we define PGPOST_* events, events that act as a one-to-one
* proxy for SDL events (and some extra events too!), the proxy is used
* internally when pygame users use event.post()
*
* At a first glance, these may look redundant, but they are really
* important, especially with event blocking. If proxy events are
* not there, blocked events dont make it to our event filter, and
* that can break a lot of stuff.
*
* IMPORTANT NOTE: Do not post events directly with these proxy types,
* use the appropriate functions from event.c, that handle these proxy
* events for you.
* Proxy events are for internal use only */
PGPOST_EVENTBEGIN, /* mark start of proxy-events */
PGPOST_ACTIVEEVENT = PGPOST_EVENTBEGIN,
PGPOST_APP_TERMINATING,
PGPOST_APP_LOWMEMORY,
PGPOST_APP_WILLENTERBACKGROUND,
PGPOST_APP_DIDENTERBACKGROUND,
PGPOST_APP_WILLENTERFOREGROUND,
PGPOST_APP_DIDENTERFOREGROUND,
PGPOST_AUDIODEVICEADDED,
PGPOST_AUDIODEVICEREMOVED,
PGPOST_CLIPBOARDUPDATE,
PGPOST_CONTROLLERAXISMOTION,
PGPOST_CONTROLLERBUTTONDOWN,
PGPOST_CONTROLLERBUTTONUP,
PGPOST_CONTROLLERDEVICEADDED,
PGPOST_CONTROLLERDEVICEREMOVED,
PGPOST_CONTROLLERDEVICEREMAPPED,
PGPOST_CONTROLLERTOUCHPADDOWN,
PGPOST_CONTROLLERTOUCHPADMOTION,
PGPOST_CONTROLLERTOUCHPADUP,
PGPOST_CONTROLLERSENSORUPDATE,
PGPOST_DOLLARGESTURE,
PGPOST_DOLLARRECORD,
PGPOST_DROPFILE,
PGPOST_DROPTEXT,
PGPOST_DROPBEGIN,
PGPOST_DROPCOMPLETE,
PGPOST_FINGERMOTION,
PGPOST_FINGERDOWN,
PGPOST_FINGERUP,
PGPOST_KEYDOWN,
PGPOST_KEYMAPCHANGED,
PGPOST_KEYUP,
PGPOST_JOYAXISMOTION,
PGPOST_JOYBALLMOTION,
PGPOST_JOYHATMOTION,
PGPOST_JOYBUTTONDOWN,
PGPOST_JOYBUTTONUP,
PGPOST_JOYDEVICEADDED,
PGPOST_JOYDEVICEREMOVED,
PGPOST_LOCALECHANGED,
PGPOST_MIDIIN,
PGPOST_MIDIOUT,
PGPOST_MOUSEMOTION,
PGPOST_MOUSEBUTTONDOWN,
PGPOST_MOUSEBUTTONUP,
PGPOST_MOUSEWHEEL,
PGPOST_MULTIGESTURE,
PGPOST_NOEVENT,
PGPOST_QUIT,
PGPOST_RENDER_TARGETS_RESET,
PGPOST_RENDER_DEVICE_RESET,
PGPOST_SYSWMEVENT,
PGPOST_TEXTEDITING,
PGPOST_TEXTINPUT,
PGPOST_VIDEORESIZE,
PGPOST_VIDEOEXPOSE,
PGPOST_WINDOWSHOWN,
PGPOST_WINDOWHIDDEN,
PGPOST_WINDOWEXPOSED,
PGPOST_WINDOWMOVED,
PGPOST_WINDOWRESIZED,
PGPOST_WINDOWSIZECHANGED,
PGPOST_WINDOWMINIMIZED,
PGPOST_WINDOWMAXIMIZED,
PGPOST_WINDOWRESTORED,
PGPOST_WINDOWENTER,
PGPOST_WINDOWLEAVE,
PGPOST_WINDOWFOCUSGAINED,
PGPOST_WINDOWFOCUSLOST,
PGPOST_WINDOWCLOSE,
PGPOST_WINDOWTAKEFOCUS,
PGPOST_WINDOWHITTEST,
PGPOST_WINDOWICCPROFCHANGED,
PGPOST_WINDOWDISPLAYCHANGED,
PGE_USEREVENT, /* this event must stay in this position only */
PG_NUMEVENTS =
SDL_LASTEVENT /* Not an event. Indicates end of user events. */
} PygameEventCode;
/* SDL1 ACTIVEEVENT state attribute can take the following values */
/* These constant values are directly picked from SDL1 source */
#define SDL_APPMOUSEFOCUS 0x01
#define SDL_APPINPUTFOCUS 0x02
#define SDL_APPACTIVE 0x04
/* Surface flags: based on SDL 1.2 flags */
typedef enum {
PGS_SWSURFACE = 0x00000000,
PGS_HWSURFACE = 0x00000001,
PGS_ASYNCBLIT = 0x00000004,
PGS_ANYFORMAT = 0x10000000,
PGS_HWPALETTE = 0x20000000,
PGS_DOUBLEBUF = 0x40000000,
PGS_FULLSCREEN = 0x80000000,
PGS_SCALED = 0x00000200,
PGS_OPENGL = 0x00000002,
PGS_OPENGLBLIT = 0x0000000A,
PGS_RESIZABLE = 0x00000010,
PGS_NOFRAME = 0x00000020,
PGS_SHOWN = 0x00000040, /* Added from SDL 2 */
PGS_HIDDEN = 0x00000080, /* Added from SDL 2 */
PGS_HWACCEL = 0x00000100,
PGS_SRCCOLORKEY = 0x00001000,
PGS_RLEACCELOK = 0x00002000,
PGS_RLEACCEL = 0x00004000,
PGS_SRCALPHA = 0x00010000,
PGS_PREALLOC = 0x01000000
} PygameSurfaceFlags;
// TODO Implement check below in a way that does not break CI
/* New buffer protocol (PEP 3118) implemented on all supported Py versions.
#if !defined(Py_TPFLAGS_HAVE_NEWBUFFER)
#error No support for PEP 3118/Py_TPFLAGS_HAVE_NEWBUFFER. Please use a
supported Python version. #endif */
#define RAISE(x, y) (PyErr_SetString((x), (y)), NULL)
#define DEL_ATTR_NOT_SUPPORTED_CHECK(name, value) \
do { \
if (!value) { \
PyErr_Format(PyExc_AttributeError, "Cannot delete attribute %s", \
name); \
return -1; \
} \
} while (0)
#define DEL_ATTR_NOT_SUPPORTED_CHECK_NO_NAME(value) \
do { \
if (!value) { \
PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute"); \
return -1; \
} \
} while (0)
/*
* Initialization checks
*/
#define VIDEO_INIT_CHECK() \
if (!SDL_WasInit(SDL_INIT_VIDEO)) \
return RAISE(pgExc_SDLError, "video system not initialized")
#define JOYSTICK_INIT_CHECK() \
if (!SDL_WasInit(SDL_INIT_JOYSTICK)) \
return RAISE(pgExc_SDLError, "joystick system not initialized")
/* thread check */
#ifdef WITH_THREAD
#define PG_CHECK_THREADS() (1)
#else /* ~WITH_THREAD */
#define PG_CHECK_THREADS() \
(RAISE(PyExc_NotImplementedError, "Python built without thread support"))
#endif /* ~WITH_THREAD */
#define PyType_Init(x) (((x).ob_type) = &PyType_Type)
/* CPython 3.6 had initial and undocumented FASTCALL support, but we play it
* safe by not relying on implementation details */
#if PY_VERSION_HEX < 0x03070000
/* Macro for naming a pygame fastcall wrapper function */
#define PG_FASTCALL_NAME(func) _##func##_fastcall_wrap
/* used to forward declare compat functions */
#define PG_DECLARE_FASTCALL_FUNC(func, self_type) \
static PyObject *PG_FASTCALL_NAME(func)(self_type * self, PyObject * args)
/* Using this macro on a function defined with the FASTCALL calling convention
* adds a wrapper definition that uses regular python VARARGS convention.
* Since it is guaranteed that the 'args' object is a tuple, we can directly
* call PySequence_Fast_ITEMS and PyTuple_GET_SIZE on it (which are macros that
* assume the same, and don't do error checking) */
#define PG_WRAP_FASTCALL_FUNC(func, self_type) \
PG_DECLARE_FASTCALL_FUNC(func, self_type) \
{ \
return func(self, (PyObject *const *)PySequence_Fast_ITEMS(args), \
PyTuple_GET_SIZE(args)); \
}
#define PG_FASTCALL METH_VARARGS
#else /* PY_VERSION_HEX >= 0x03070000 */
/* compat macros are no-op on python versions that support fastcall */
#define PG_FASTCALL_NAME(func) func
#define PG_DECLARE_FASTCALL_FUNC(func, self_type)
#define PG_WRAP_FASTCALL_FUNC(func, self_type)
#define PG_FASTCALL METH_FASTCALL
#endif /* PY_VERSION_HEX >= 0x03070000 */
/*
* event module internals
*/
struct pgEventObject {
PyObject_HEAD int type;
PyObject *dict;
};
/*
* surflock module internals
*/
typedef struct {
PyObject_HEAD PyObject *surface;
PyObject *lockobj;
PyObject *weakrefs;
} pgLifetimeLockObject;
/*
* surface module internals
*/
struct pgSubSurface_Data {
PyObject *owner;
int pixeloffset;
int offsetx, offsety;
};
/*
* color module internals
*/
struct pgColorObject {
PyObject_HEAD Uint8 data[4];
Uint8 len;
};
/*
* include public API
*/
#include "include/_pygame.h"
/* Slot counts.
* Remember to keep these constants up to date.
*/
#define PYGAMEAPI_RECT_NUMSLOTS 5
#define PYGAMEAPI_JOYSTICK_NUMSLOTS 2
#define PYGAMEAPI_DISPLAY_NUMSLOTS 2
#define PYGAMEAPI_SURFACE_NUMSLOTS 4
#define PYGAMEAPI_SURFLOCK_NUMSLOTS 8
#define PYGAMEAPI_RWOBJECT_NUMSLOTS 6
#define PYGAMEAPI_PIXELARRAY_NUMSLOTS 2
#define PYGAMEAPI_COLOR_NUMSLOTS 5
#define PYGAMEAPI_MATH_NUMSLOTS 2
#define PYGAMEAPI_BASE_NUMSLOTS 27
#define PYGAMEAPI_EVENT_NUMSLOTS 6
#endif /* _PYGAME_INTERNAL_H */

View file

@ -0,0 +1,30 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
Copyright (C) 2007 Marcus von Appen
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
#ifndef _SURFACE_H
#define _SURFACE_H
#include "_pygame.h"
#include "surface.h"
#endif

View file

@ -0,0 +1,218 @@
#ifndef CAMERA_H
#define CAMERA_H
/*
pygame - Python Game Library
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "pygame.h"
#include "pgcompat.h"
#include "doc/camera_doc.h"
#if defined(__unix__)
#include <structmember.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h> /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
/* on freebsd there is no asm/types */
#ifdef __linux__
#include <asm/types.h> /* for videodev2.h */
#include <linux/videodev2.h>
#endif
/* on openbsd and netbsd we need to include videoio.h */
#if defined(__OpenBSD__) || defined(__NetBSD__)
#include <sys/videoio.h>
#endif
#ifdef __FreeBSD__
#include <linux/videodev2.h>
#endif
#endif /* defined(__unix__) */
#if defined(__WIN32__)
#ifdef __MINGW32__
#undef WINVER
/** _WIN32_WINNT_WINBLUE sets minimum platform SDK to Windows 8.1. */
#define WINVER _WIN32_WINNT_WINBLUE
#endif
#include <mfapi.h>
#include <mfobjects.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#include <combaseapi.h>
#include <mftransform.h>
#endif
/* some constants used which are not defined on non-v4l machines. */
#ifndef V4L2_PIX_FMT_RGB24
#define V4L2_PIX_FMT_RGB24 'RGB3'
#endif
#ifndef V4L2_PIX_FMT_RGB444
#define V4L2_PIX_FMT_RGB444 'R444'
#endif
#ifndef V4L2_PIX_FMT_YUYV
#define V4L2_PIX_FMT_YUYV 'YUYV'
#endif
#ifndef V4L2_PIX_FMT_XBGR32
#define V4L2_PIX_FMT_XBGR32 'XR24'
#endif
#define CLEAR(x) memset(&(x), 0, sizeof(x))
#define SAT(c) \
if (c & (~255)) { \
if (c < 0) \
c = 0; \
else \
c = 255; \
}
#define SAT2(c) ((c) & (~255) ? ((c) < 0 ? 0 : 255) : (c))
#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480
#define RGB_OUT 1
#define YUV_OUT 2
#define HSV_OUT 4
#define CAM_V4L \
1 /* deprecated. the incomplete support in pygame was removed */
#define CAM_V4L2 2
struct buffer {
void *start;
size_t length;
};
#if defined(__unix__)
typedef struct pgCameraObject {
PyObject_HEAD char *device_name;
int camera_type;
unsigned long pixelformat;
unsigned int color_out;
struct buffer *buffers;
unsigned int n_buffers;
int width;
int height;
int size;
int hflip;
int vflip;
int brightness;
int fd;
} pgCameraObject;
#else
/* generic definition.
*/
typedef struct pgCameraObject {
PyObject_HEAD char *device_name;
int camera_type;
unsigned long pixelformat;
unsigned int color_out;
struct buffer *buffers;
unsigned int n_buffers;
int width;
int height;
int size;
int hflip;
int vflip;
int brightness;
int fd;
} pgCameraObject;
#endif
/* internal functions for colorspace conversion */
void
colorspace(SDL_Surface *src, SDL_Surface *dst, int cspace);
void
rgb24_to_rgb(const void *src, void *dst, int length, SDL_PixelFormat *format);
void
bgr32_to_rgb(const void *src, void *dst, int length, SDL_PixelFormat *format);
void
rgb444_to_rgb(const void *src, void *dst, int length, SDL_PixelFormat *format);
void
rgb_to_yuv(const void *src, void *dst, int length, unsigned long source,
SDL_PixelFormat *format);
void
rgb_to_hsv(const void *src, void *dst, int length, unsigned long source,
SDL_PixelFormat *format);
void
yuyv_to_rgb(const void *src, void *dst, int length, SDL_PixelFormat *format);
void
yuyv_to_yuv(const void *src, void *dst, int length, SDL_PixelFormat *format);
void
uyvy_to_rgb(const void *src, void *dst, int length, SDL_PixelFormat *format);
void
uyvy_to_yuv(const void *src, void *dst, int length, SDL_PixelFormat *format);
void
sbggr8_to_rgb(const void *src, void *dst, int width, int height,
SDL_PixelFormat *format);
void
yuv420_to_rgb(const void *src, void *dst, int width, int height,
SDL_PixelFormat *format);
void
yuv420_to_yuv(const void *src, void *dst, int width, int height,
SDL_PixelFormat *format);
#if defined(__unix__)
/* internal functions specific to v4l2 */
char **
v4l2_list_cameras(int *num_devices);
int
v4l2_get_control(int fd, int id, int *value);
int
v4l2_set_control(int fd, int id, int value);
PyObject *
v4l2_read_raw(pgCameraObject *self);
int
v4l2_xioctl(int fd, int request, void *arg);
int
v4l2_process_image(pgCameraObject *self, const void *image, int buffer_size,
SDL_Surface *surf);
int
v4l2_query_buffer(pgCameraObject *self);
int
v4l2_read_frame(pgCameraObject *self, SDL_Surface *surf, int *errno_code);
int
v4l2_stop_capturing(pgCameraObject *self);
int
v4l2_start_capturing(pgCameraObject *self);
int
v4l2_uninit_device(pgCameraObject *self);
int
v4l2_init_mmap(pgCameraObject *self);
int
v4l2_init_device(pgCameraObject *self);
int
v4l2_close_device(pgCameraObject *self);
int
v4l2_open_device(pgCameraObject *self);
#endif
#endif /* !CAMERA_H */

View file

@ -0,0 +1,15 @@
#ifndef PGFONT_INTERNAL_H
#define PGFONT_INTERNAL_H
#include <SDL_ttf.h>
/* test font initialization */
#define FONT_INIT_CHECK() \
if (!(*(int *)PyFONT_C_API[2])) \
return RAISE(pgExc_SDLError, "font system not initialized")
#include "include/pygame_font.h"
#define PYGAMEAPI_FONT_NUMSLOTS 3
#endif /* ~PGFONT_INTERNAL_H */

View file

@ -0,0 +1,114 @@
/*
pygame - Python Game Library
Copyright (C) 2009 Vicent Marti
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _PYGAME_FREETYPE_INTERNAL_H_
#define _PYGAME_FREETYPE_INTERNAL_H_
#include "pgcompat.h"
#include "pgplatform.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_CACHE_H
#include FT_XFREE86_H
#include FT_TRIGONOMETRY_H
/**********************************************************
* Global module constants
**********************************************************/
/* Render styles */
#define FT_STYLE_NORMAL 0x00
#define FT_STYLE_STRONG 0x01
#define FT_STYLE_OBLIQUE 0x02
#define FT_STYLE_UNDERLINE 0x04
#define FT_STYLE_WIDE 0x08
#define FT_STYLE_DEFAULT 0xFF
/* Bounding box modes */
#define FT_BBOX_EXACT FT_GLYPH_BBOX_SUBPIXELS
#define FT_BBOX_EXACT_GRIDFIT FT_GLYPH_BBOX_GRIDFIT
#define FT_BBOX_PIXEL FT_GLYPH_BBOX_TRUNCATE
#define FT_BBOX_PIXEL_GRIDFIT FT_GLYPH_BBOX_PIXELS
/* Rendering flags */
#define FT_RFLAG_NONE (0)
#define FT_RFLAG_ANTIALIAS (1 << 0)
#define FT_RFLAG_AUTOHINT (1 << 1)
#define FT_RFLAG_VERTICAL (1 << 2)
#define FT_RFLAG_HINTED (1 << 3)
#define FT_RFLAG_KERNING (1 << 4)
#define FT_RFLAG_TRANSFORM (1 << 5)
#define FT_RFLAG_PAD (1 << 6)
#define FT_RFLAG_ORIGIN (1 << 7)
#define FT_RFLAG_UCS4 (1 << 8)
#define FT_RFLAG_USE_BITMAP_STRIKES (1 << 9)
#define FT_RFLAG_DEFAULTS \
(FT_RFLAG_HINTED | FT_RFLAG_USE_BITMAP_STRIKES | FT_RFLAG_ANTIALIAS)
#define FT_RENDER_NEWBYTEARRAY 0x0
#define FT_RENDER_NEWSURFACE 0x1
#define FT_RENDER_EXISTINGSURFACE 0x2
/**********************************************************
* Global module types
**********************************************************/
typedef struct _scale_s {
FT_UInt x, y;
} Scale_t;
typedef FT_Angle Angle_t;
struct fontinternals_;
struct freetypeinstance_;
typedef struct {
FT_Long font_index;
FT_Open_Args open_args;
} pgFontId;
typedef struct {
PyObject_HEAD pgFontId id;
PyObject *path;
int is_scalable;
int is_bg_col_set;
Scale_t face_size;
FT_Int16 style;
FT_Int16 render_flags;
double strength;
double underline_adjustment;
FT_UInt resolution;
Angle_t rotation;
FT_Matrix transform;
FT_Byte fgcolor[4];
FT_Byte bgcolor[4];
struct freetypeinstance_ *freetype; /* Personal reference */
struct fontinternals_ *_internals;
} pgFontObject;
#define pgFont_IS_ALIVE(o) (((pgFontObject *)(o))->_internals != 0)
/* import public API */
#include "include/pygame_freetype.h"
#define PYGAMEAPI_FREETYPE_NUMSLOTS 2
#endif /* ~_PYGAME_FREETYPE_INTERNAL_H_ */

View file

@ -0,0 +1,949 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
#ifndef _PYGAME_H
#define _PYGAME_H
/** This header file includes all the definitions for the
** base pygame extensions. This header only requires
** Python includes (and SDL.h for functions that use SDL types).
** The reason for functions prototyped with #define's is
** to allow for maximum Python portability. It also uses
** Python as the runtime linker, which allows for late binding.
'' For more information on this style of development, read
** the Python docs on this subject.
** http://www.python.org/doc/current/ext/using-cobjects.html
**
** If using this to build your own derived extensions,
** you'll see that the functions available here are mainly
** used to help convert between python objects and SDL objects.
** Since this library doesn't add a lot of functionality to
** the SDL library, it doesn't need to offer a lot either.
**
** When initializing your extension module, you must manually
** import the modules you want to use. (this is the part about
** using python as the runtime linker). Each module has its
** own import_xxx() routine. You need to perform this import
** after you have initialized your own module, and before
** you call any routines from that module. Since every module
** in pygame does this, there are plenty of examples.
**
** The base module does include some useful conversion routines
** that you are free to use in your own extension.
**/
#include "pgplatform.h"
#include <Python.h>
/* version macros (defined since version 1.9.5) */
#define PG_MAJOR_VERSION 2
#define PG_MINOR_VERSION 6
#define PG_PATCH_VERSION 0
#define PG_VERSIONNUM(MAJOR, MINOR, PATCH) \
(1000 * (MAJOR) + 100 * (MINOR) + (PATCH))
#define PG_VERSION_ATLEAST(MAJOR, MINOR, PATCH) \
(PG_VERSIONNUM(PG_MAJOR_VERSION, PG_MINOR_VERSION, PG_PATCH_VERSION) >= \
PG_VERSIONNUM(MAJOR, MINOR, PATCH))
#include "pgcompat.h"
/* Flag indicating a pg_buffer; used for assertions within callbacks */
#ifndef NDEBUG
#define PyBUF_PYGAME 0x4000
#endif
#define PyBUF_HAS_FLAG(f, F) (((f) & (F)) == (F))
/* Array information exchange struct C type; inherits from Py_buffer
*
* Pygame uses its own Py_buffer derived C struct as an internal representation
* of an imported array buffer. The extended Py_buffer allows for a
* per-instance release callback,
*/
typedef void (*pybuffer_releaseproc)(Py_buffer *);
typedef struct pg_bufferinfo_s {
Py_buffer view;
PyObject *consumer; /* Input: Borrowed reference */
pybuffer_releaseproc release_buffer;
} pg_buffer;
#include "pgimport.h"
/*
* BASE module
*/
#ifndef PYGAMEAPI_BASE_INTERNAL
#define pgExc_SDLError ((PyObject *)PYGAMEAPI_GET_SLOT(base, 0))
#define pg_RegisterQuit \
(*(void (*)(void (*)(void)))PYGAMEAPI_GET_SLOT(base, 1))
/**
* \brief Convert number like object *obj* to C int and in *val*.
*
* \param obj The Python object to convert.
* \param val A pointer to the C integer to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*
* \note This function will clear any Python errors.
* \note This function will convert floats to integers.
*/
#define pg_IntFromObj \
(*(int (*)(PyObject *, int *))PYGAMEAPI_GET_SLOT(base, 2))
/**
* \brief Convert number like object at position *i* in sequence *obj*
* to C int and place in argument *val*.
*
* \param obj The Python object to convert.
* \param i The index of the object to convert.
* \param val A pointer to the C integer to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*
* \note This function will clear any Python errors.
* \note This function will convert floats to integers.
*/
#define pg_IntFromObjIndex \
(*(int (*)(PyObject *, int, int *))PYGAMEAPI_GET_SLOT(base, 3))
/**
* \brief Convert the two number like objects in length 2 sequence *obj* to C
* int and place in arguments *val1* and *val2*.
*
* \param obj The Python two element sequence object to convert.
* \param val A pointer to the C integer to store the result.
* \param val2 A pointer to the C integer to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*
* \note This function will clear any Python errors.
* \note This function will convert floats to integers.
*/
#define pg_TwoIntsFromObj \
(*(int (*)(PyObject *, int *, int *))PYGAMEAPI_GET_SLOT(base, 4))
/**
* \brief Convert number like object *obj* to C float and in *val*.
*
* \param obj The Python object to convert.
* \param val A pointer to the C float to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*
* \note This function will clear any Python errors.
*/
#define pg_FloatFromObj \
(*(int (*)(PyObject *, float *))PYGAMEAPI_GET_SLOT(base, 5))
/**
* \brief Convert number like object at position *i* in sequence *obj* to C
* float and place in argument *val*.
*
* \param obj The Python object to convert.
* \param i The index of the object to convert.
* \param val A pointer to the C float to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*
* \note This function will clear any Python errors.
*/
#define pg_FloatFromObjIndex \
(*(int (*)(PyObject *, int, float *))PYGAMEAPI_GET_SLOT(base, 6))
/**
* \brief Convert the two number like objects in length 2 sequence *obj* to C
* float and place in arguments *val1* and *val2*.
*
* \param obj The Python two element sequence object to convert.
* \param val A pointer to the C float to store the result.
* \param val2 A pointer to the C float to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*
* \note This function will clear any Python errors.
*/
#define pg_TwoFloatsFromObj \
(*(int (*)(PyObject *, float *, float *))PYGAMEAPI_GET_SLOT(base, 7))
/**
* \brief Convert number like object *obj* to C Uint32 and in *val*.
*
* \param obj The Python object to convert.
* \param val A pointer to the C int to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*/
#define pg_UintFromObj \
(*(int (*)(PyObject *, Uint32 *))PYGAMEAPI_GET_SLOT(base, 8))
/**
* \brief Convert number like object at position *i* in sequence *obj* to C
* Uint32 and place in argument *val*.
*
* \param obj The Python object to convert.
* \param i The index of the object to convert.
* \param val A pointer to the C int to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*/
#define pg_UintFromObjIndex \
(*(int (*)(PyObject *, int, Uint32 *))PYGAMEAPI_GET_SLOT(base, 9))
/**
* \brief Initialize all of the pygame modules.
* \returns 1 on success, 0 on failure with PyErr set.
*/
#define pg_mod_autoinit (*(int (*)(const char *))PYGAMEAPI_GET_SLOT(base, 10))
/**
* \brief Quit all of the pygame modules.
*/
#define pg_mod_autoquit (*(void (*)(const char *))PYGAMEAPI_GET_SLOT(base, 11))
/**
* \brief Convert the color represented by object *obj* into a red, green,
* blue, alpha length 4 C array *RGBA*.
*
* The object must be a length 3 or 4 sequence of numbers having values between
* 0 and 255 inclusive. For a length 3 sequence an alpha value of 255 is
* assumed.
*
* \param obj The Python object to convert.
* \param RGBA A pointer to the C array to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*/
#define pg_RGBAFromObj \
(*(int (*)(PyObject *, Uint8 *))PYGAMEAPI_GET_SLOT(base, 12))
/**
* \brief Given a Py_buffer, return a python dictionary representing the array
* interface.
*
* \param view_p A pointer to the Py_buffer to convert to a dictionary.
*
* \returns A Python dictionary representing the array interface of the object.
*/
#define pgBuffer_AsArrayInterface \
(*(PyObject * (*)(Py_buffer *)) PYGAMEAPI_GET_SLOT(base, 13))
/**
* \brief Given a Py_buffer, return a python capsule representing the array
* interface.
*
* \param view_p A pointer to the Py_buffer to convert to a capsule.
*
* \returns A Python capsule representing the array interface of the object.
*/
#define pgBuffer_AsArrayStruct \
(*(PyObject * (*)(Py_buffer *)) PYGAMEAPI_GET_SLOT(base, 14))
/**
* \brief Get a buffer object from a given Python object.
*
* \param obj The Python object to get the buffer from.
* \param pg_view_p A pointer to a pg_buffer struct to store the buffer in.
* \param flags The desired buffer access mode.
*
* \returns 0 on success, -1 on failure.
*
* \note This function attempts to get a buffer object from a given Python
* object. If the object supports the buffer protocol, it will be used to
* create the buffer. If not, it will try to get an array interface or
* dictionary representation of the object and use that to create the buffer.
* If none of these methods work, it will raise a ValueError.
*
*/
#define pgObject_GetBuffer \
(*(int (*)(PyObject *, pg_buffer *, int))PYGAMEAPI_GET_SLOT(base, 15))
/**
* \brief Release a pg_buffer object.
*
* \param pg_view_p The pg_buffer object to release.
*
* \note This function releases a pg_buffer object.
* \note some calls to this function expect this function to not clear
* previously set errors.
*/
#define pgBuffer_Release (*(void (*)(pg_buffer *))PYGAMEAPI_GET_SLOT(base, 16))
/**
* \brief Write the array interface dictionary buffer description *dict* into a
* Pygame buffer description struct *pg_view_p*.
*
* \param pg_view_p The Pygame buffer description struct to write into.
* \param dict The array interface dictionary to read from.
* \param flags The PyBUF flags describing the view type requested.
*
* \returns 0 on success, or -1 on failure.
*/
#define pgDict_AsBuffer \
(*(int (*)(pg_buffer *, PyObject *, int))PYGAMEAPI_GET_SLOT(base, 17))
#define pgExc_BufferError ((PyObject *)PYGAMEAPI_GET_SLOT(base, 18))
/**
* \brief Get the default SDL window created by a pygame.display.set_mode()
* call, or *NULL*.
*
* \return The default window, or *NULL* if no window has been created.
*/
#define pg_GetDefaultWindow \
(*(SDL_Window * (*)(void)) PYGAMEAPI_GET_SLOT(base, 19))
/**
* \brief Set the default SDL window created by a pygame.display.set_mode()
* call. The previous window, if any, is destroyed. Argument *win* may be
* *NULL*. This function is called by pygame.display.set_mode().
*
* \param win The new default window. May be NULL.
*/
#define pg_SetDefaultWindow \
(*(void (*)(SDL_Window *))PYGAMEAPI_GET_SLOT(base, 20))
/**
* \brief Return a borrowed reference to the Pygame default window display
* surface, or *NULL* if no default window is open.
*
* \return The default renderer, or *NULL* if no renderer has been created.
*/
#define pg_GetDefaultWindowSurface \
(*(pgSurfaceObject * (*)(void)) PYGAMEAPI_GET_SLOT(base, 21))
/**
* \brief Set the Pygame default window display surface. The previous
* surface, if any, is destroyed. Argument *screen* may be *NULL*. This
* function is called by pygame.display.set_mode().
*
* \param screen The new default window display surface. May be NULL.
*/
#define pg_SetDefaultWindowSurface \
(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(base, 22))
/**
* \returns NULL if the environment variable PYGAME_BLEND_ALPHA_SDL2 is not
* set, otherwise returns a pointer to the environment variable.
*/
#define pg_EnvShouldBlendAlphaSDL2 \
(*(char *(*)(void))PYGAMEAPI_GET_SLOT(base, 23))
/**
* \brief Convert number like object *obj* to C double and in *val*.
*
* \param obj The Python object to convert.
* \param val A pointer to the C double to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*
* \note This function will clear any Python errors.
*/
#define pg_DoubleFromObj \
(*(int (*)(PyObject *, double *))PYGAMEAPI_GET_SLOT(base, 24))
/**
* \brief Convert number like object at position *i* in sequence *obj* to C
* double and place in argument *val*.
*
* \param obj The Python object to convert.
* \param i The index of the object to convert.
* \param val A pointer to the C double to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*
* \note This function will clear any Python errors.
*/
#define pg_DoubleFromObjIndex \
(*(int (*)(PyObject *, int, double *))PYGAMEAPI_GET_SLOT(base, 25))
/**
* \brief Convert the two number like objects in length 2 sequence *obj* to C
* double and place in arguments *val1* and *val2*.
*
* \param obj The Python two element sequence object to convert.
* \param val A pointer to the C double to store the result.
* \param val2 A pointer to the C double to store the result.
* \returns 1 if the conversion was successful, 0 otherwise.
*/
#define pg_TwoDoublesFromObj \
(*(int (*)(PyObject *, double *, double *))PYGAMEAPI_GET_SLOT(base, 26))
#define import_pygame_base() IMPORT_PYGAME_MODULE(base)
#endif /* ~PYGAMEAPI_BASE_INTERNAL */
typedef struct {
/**
* \brief The SDL rect wrapped by this object.
*/
PyObject_HEAD SDL_Rect r;
/**
* \brief A list of weak references to this rect.
*/
PyObject *weakreflist;
} pgRectObject;
/**
* \brief Convert a pgRectObject to an SDL_Rect.
*
* \param obj A pgRectObject instance.
* \returns the SDL_Rect field of *obj*, a pgRect_Type instance.
*
* \note SDL_Rect pgRect_AsRect(PyObject *obj)
*/
#define pgRect_AsRect(x) (((pgRectObject *)x)->r)
#ifndef PYGAMEAPI_RECT_INTERNAL
/**
* \brief The Pygame rectangle object type pygame.Rect.
*/
#define pgRect_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(rect, 0))
/**
* \brief Check if *obj* is a `pygame.Rect` instance.
*
* \returns true if *obj* is a `pygame.Rect` instance
*/
#define pgRect_Check(obj) ((obj)->ob_type == &pgRect_Type)
/**
* \brief Create a new `pygame.Rect` instance.
*
* \param r A pointer to an SDL_Rect struct.
* \returns a new `pygame.Rect` object for the SDL_Rect *r*.
* Returns *NULL* on error.
*
* \note PyObject* pgRect_New(SDL_Rect *r)
*/
#define pgRect_New (*(PyObject * (*)(SDL_Rect *)) PYGAMEAPI_GET_SLOT(rect, 1))
/**
* \brief Create a new `pygame.Rect` instance from x, y, w, h.
*
* \param x The x coordinate of the rectangle.
* \param y The y coordinate of the rectangle.
* \param w The width of the rectangle.
* \param h The height of the rectangle.
* \returns a new `pygame.Rect` object. Returns *NULL* on error.
*
* \note PyObject* pgRect_New4(int x, int y, int w, int h)
*/
#define pgRect_New4 \
(*(PyObject * (*)(int, int, int, int)) PYGAMEAPI_GET_SLOT(rect, 2))
/**
* \brief Convert a Python object to a `pygame.Rect` instance.
*
* \param obj A Python object.
* A rectangle can be a length 4 sequence integers (x, y, w, h), or a length 2
* sequence of position (x, y) and size (w, h), or a length 1 tuple containing
* a rectangle representation, or have a method *rect* that returns a
* rectangle.
*
* \param temp A pointer to an SDL_Rect struct to store the result in.
* \returns a pointer to the SDL_Rect field of the `pygame.Rect` instance
* *obj*. Returns *NULL* on error.
*
* \note This function will clear any Python errors.
* \note SDL_Rect* pgRect_FromObject(PyObject *obj, SDL_Rect *temp)
*/
#define pgRect_FromObject \
(*(SDL_Rect * (*)(PyObject *, SDL_Rect *)) PYGAMEAPI_GET_SLOT(rect, 3))
/**
* \brief Normalize a `pygame.Rect` instance. A rect with a negative size
* (negative width and/or height) will be adjusted to have a positive size.
*
* \param rect A pointer to a `pygame.Rect` instance.
* \returns *rect* normalized with positive values only.
*
* \note void pgRect_Normalize(SDL_Rect *rect)
*/
#define pgRect_Normalize (*(void (*)(SDL_Rect *))PYGAMEAPI_GET_SLOT(rect, 4))
#define import_pygame_rect() IMPORT_PYGAME_MODULE(rect)
#endif /* ~PYGAMEAPI_RECT_INTERNAL */
/*
* JOYSTICK module
*/
typedef struct pgJoystickObject {
PyObject_HEAD int id;
SDL_Joystick *joy;
/* Joysticks form an intrusive linked list.
*
* Note that we don't maintain refcounts for these so they are weakrefs
* from the Python side.
*/
struct pgJoystickObject *next;
struct pgJoystickObject *prev;
} pgJoystickObject;
#define pgJoystick_AsID(x) (((pgJoystickObject *)x)->id)
#define pgJoystick_AsSDL(x) (((pgJoystickObject *)x)->joy)
#ifndef PYGAMEAPI_JOYSTICK_INTERNAL
#define pgJoystick_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(joystick, 0))
#define pgJoystick_Check(x) ((x)->ob_type == &pgJoystick_Type)
#define pgJoystick_New (*(PyObject * (*)(int)) PYGAMEAPI_GET_SLOT(joystick, 1))
#define import_pygame_joystick() IMPORT_PYGAME_MODULE(joystick)
#endif
/*
* DISPLAY module
*/
typedef struct {
Uint32 hw_available : 1;
Uint32 wm_available : 1;
Uint32 blit_hw : 1;
Uint32 blit_hw_CC : 1;
Uint32 blit_hw_A : 1;
Uint32 blit_sw : 1;
Uint32 blit_sw_CC : 1;
Uint32 blit_sw_A : 1;
Uint32 blit_fill : 1;
Uint32 video_mem;
SDL_PixelFormat *vfmt;
SDL_PixelFormat vfmt_data;
int current_w;
int current_h;
} pg_VideoInfo;
/**
* A pygame object that wraps an SDL_VideoInfo struct.
* The object returned by `pygame.display.Info()`
*/
typedef struct {
PyObject_HEAD pg_VideoInfo info;
} pgVidInfoObject;
/**
* \brief Convert a pgVidInfoObject to an SDL_VideoInfo.
*
* \note SDL_VideoInfo pgVidInfo_AsVidInfo(PyObject *obj)
*
* \returns the SDL_VideoInfo field of *obj*, a pgVidInfo_Type instance.
* \param obj A pgVidInfo_Type instance.
*
* \note Does not check that *obj* is not `NULL` or an `pgVidInfoObject`
* object.
*/
#define pgVidInfo_AsVidInfo(x) (((pgVidInfoObject *)x)->info)
#ifndef PYGAMEAPI_DISPLAY_INTERNAL
/**
* \brief The pgVidInfoObject object Python type.
* \note pgVideoInfo_Type is used for the `pygame.display.Info()` object.
*/
#define pgVidInfo_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(display, 0))
/**
* \brief Check if *obj* is a pgVidInfoObject.
*
* \returns true if *x* is a `pgVidInfo_Type` instance
* \note Will return false if *x* is a subclass of `pgVidInfo_Type`.
* \note This macro does not check that *x* is not ``NULL``.
* \note int pgVidInfo_Check(PyObject *x)
*/
#define pgVidInfo_Check(x) ((x)->ob_type == &pgVidInfo_Type)
/**
* \brief Create a new pgVidInfoObject.
*
* \param i A pointer to an SDL_VideoInfo struct.
* \returns a new `pgVidInfoObject` object for the SDL_VideoInfo *i*.
*
* \note PyObject* pgVidInfo_New(SDL_VideoInfo *i)
* \note On failure, raise a Python exception and return `NULL`.
*/
#define pgVidInfo_New \
(*(PyObject * (*)(pg_VideoInfo *)) PYGAMEAPI_GET_SLOT(display, 1))
#define import_pygame_display() IMPORT_PYGAME_MODULE(display)
#endif /* ~PYGAMEAPI_DISPLAY_INTERNAL */
/*
* SURFACE module
*/
struct pgSubSurface_Data;
struct SDL_Surface;
/**
* \brief A pygame object that wraps an SDL_Surface. A `pygame.Surface`
* instance.
*/
typedef struct {
PyObject_HEAD struct SDL_Surface *surf;
/**
* \brief If true, the surface will be freed when the python object is
* destroyed.
*/
int owner;
/**
* \brief The subsurface data for this surface (if a subsurface).
*/
struct pgSubSurface_Data *subsurface;
/**
* \brief A list of weak references to this surface.
*/
PyObject *weakreflist;
/**
* \brief A list of locks for this surface.
*/
PyObject *locklist;
/**
* \brief Usually a buffer object which the surface gets its data from.
*/
PyObject *dependency;
} pgSurfaceObject;
/**
* \brief Convert a `pygame.Surface` instance to an SDL_Surface.
*
* \param x A `pygame.Surface` instance.
* \returns the SDL_Surface field of *x*, a `pygame.Surface` instance.
*
* \note SDL_Surface* pgSurface_AsSurface(PyObject *x)
*/
#define pgSurface_AsSurface(x) (((pgSurfaceObject *)x)->surf)
#ifndef PYGAMEAPI_SURFACE_INTERNAL
/**
* \brief The `pygame.Surface` object Python type.
*/
#define pgSurface_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(surface, 0))
/**
* \brief Check if *x* is a `pygame.Surface` instance.
*
* \param x The object to check.
* \returns true if *x* is a `pygame.Surface` instance
*
* \note Will return false if *x* is a subclass of `pygame.Surface`.
* \note This macro does not check that *x* is not ``NULL``.
* \note int pgSurface_Check(PyObject *x)
*/
#define pgSurface_Check(x) \
(PyObject_IsInstance((x), (PyObject *)&pgSurface_Type))
/**
* \brief Create a new `pygame.Surface` instance.
*
* \param s The SDL surface to wrap in a python object.
* \param owner If true, the surface will be freed when the python object is
* destroyed. \returns A new new pygame surface instance for SDL surface *s*.
* Returns *NULL* on error.
*
* \note pgSurfaceObject* pgSurface_New2(SDL_Surface *s, int owner)
*/
#define pgSurface_New2 \
(*(pgSurfaceObject * (*)(SDL_Surface *, int)) \
PYGAMEAPI_GET_SLOT(surface, 1))
/**
* \brief Sets the SDL surface for a `pygame.Surface` instance.
*
* \param self The `pygame.Surface` instance to set the surface for.
* \param s The SDL surface to set.
* \param owner If true, the surface will be freed when the python object is
* destroyed. \returns 0 on success, -1 on failure.
*
* \note int pgSurface_SetSurface(pgSurfaceObject *self, SDL_Surface *s, int
* owner)
*/
#define pgSurface_SetSurface \
(*(int (*)(pgSurfaceObject *, SDL_Surface *, int))PYGAMEAPI_GET_SLOT( \
surface, 3))
/**
* \brief Blit one surface onto another.
*
* \param dstobj The destination surface.
* \param srcobj The source surface.
* \param dstrect The destination rectangle.
* \param srcrect The source rectangle.
* \param the_args The blit flags.
* \return 0 for success, -1 or -2 for error.
*
* \note Is accessible through the C api.
* \note int pgSurface_Blit(PyObject *dstobj, PyObject *srcobj, SDL_Rect
* *dstrect, SDL_Rect *srcrect, int the_args)
*/
#define pgSurface_Blit \
(*(int (*)(pgSurfaceObject *, pgSurfaceObject *, SDL_Rect *, SDL_Rect *, \
int))PYGAMEAPI_GET_SLOT(surface, 2))
#define import_pygame_surface() \
do { \
IMPORT_PYGAME_MODULE(surface); \
if (PyErr_Occurred() != NULL) \
break; \
IMPORT_PYGAME_MODULE(surflock); \
} while (0)
#define pgSurface_New(surface) pgSurface_New2((surface), 1)
#define pgSurface_NewNoOwn(surface) pgSurface_New2((surface), 0)
#endif /* ~PYGAMEAPI_SURFACE_INTERNAL */
/*
* SURFLOCK module
* auto imported/initialized by surface
*/
#ifndef PYGAMEAPI_SURFLOCK_INTERNAL
#define pgLifetimeLock_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(surflock, 0))
#define pgLifetimeLock_Check(x) ((x)->ob_type == &pgLifetimeLock_Type)
#define pgSurface_Prep(x) \
if ((x)->subsurface) \
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 1)))(x)
#define pgSurface_Unprep(x) \
if ((x)->subsurface) \
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 2)))(x)
#define pgSurface_Lock \
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 3))
#define pgSurface_Unlock \
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 4))
#define pgSurface_LockBy \
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surflock, 5))
#define pgSurface_UnlockBy \
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surflock, 6))
#define pgSurface_LockLifetime \
(*(PyObject * (*)(PyObject *, PyObject *)) PYGAMEAPI_GET_SLOT(surflock, 7))
#endif
/*
* EVENT module
*/
typedef struct pgEventObject pgEventObject;
#ifndef PYGAMEAPI_EVENT_INTERNAL
#define pgEvent_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(event, 0))
#define pgEvent_Check(x) ((x)->ob_type == &pgEvent_Type)
#define pgEvent_New \
(*(PyObject * (*)(SDL_Event *)) PYGAMEAPI_GET_SLOT(event, 1))
#define pgEvent_New2 \
(*(PyObject * (*)(int, PyObject *)) PYGAMEAPI_GET_SLOT(event, 2))
#define pgEvent_FillUserEvent \
(*(int (*)(pgEventObject *, SDL_Event *))PYGAMEAPI_GET_SLOT(event, 3))
#define pg_EnableKeyRepeat (*(int (*)(int, int))PYGAMEAPI_GET_SLOT(event, 4))
#define pg_GetKeyRepeat (*(void (*)(int *, int *))PYGAMEAPI_GET_SLOT(event, 5))
#define import_pygame_event() IMPORT_PYGAME_MODULE(event)
#endif
/*
* RWOBJECT module
* the rwobject are only needed for C side work, not accessible from python.
*/
#ifndef PYGAMEAPI_RWOBJECT_INTERNAL
#define pgRWops_FromObject \
(*(SDL_RWops * (*)(PyObject *, char **)) PYGAMEAPI_GET_SLOT(rwobject, 0))
#define pgRWops_IsFileObject \
(*(int (*)(SDL_RWops *))PYGAMEAPI_GET_SLOT(rwobject, 1))
#define pg_EncodeFilePath \
(*(PyObject * (*)(PyObject *, PyObject *)) PYGAMEAPI_GET_SLOT(rwobject, 2))
#define pg_EncodeString \
(*(PyObject * (*)(PyObject *, const char *, const char *, PyObject *)) \
PYGAMEAPI_GET_SLOT(rwobject, 3))
#define pgRWops_FromFileObject \
(*(SDL_RWops * (*)(PyObject *)) PYGAMEAPI_GET_SLOT(rwobject, 4))
#define pgRWops_ReleaseObject \
(*(int (*)(SDL_RWops *))PYGAMEAPI_GET_SLOT(rwobject, 5))
#define import_pygame_rwobject() IMPORT_PYGAME_MODULE(rwobject)
#endif
/*
* PixelArray module
*/
#ifndef PYGAMEAPI_PIXELARRAY_INTERNAL
#define PyPixelArray_Type ((PyTypeObject *)PYGAMEAPI_GET_SLOT(pixelarray, 0))
#define PyPixelArray_Check(x) ((x)->ob_type == &PyPixelArray_Type)
#define PyPixelArray_New (*(PyObject * (*)) PYGAMEAPI_GET_SLOT(pixelarray, 1))
#define import_pygame_pixelarray() IMPORT_PYGAME_MODULE(pixelarray)
#endif /* PYGAMEAPI_PIXELARRAY_INTERNAL */
/*
* Color module
*/
typedef struct pgColorObject pgColorObject;
#ifndef PYGAMEAPI_COLOR_INTERNAL
#define pgColor_Type (*(PyObject *)PYGAMEAPI_GET_SLOT(color, 0))
#define pgColor_Check(x) ((x)->ob_type == &pgColor_Type)
#define pgColor_New (*(PyObject * (*)(Uint8 *)) PYGAMEAPI_GET_SLOT(color, 1))
#define pgColor_NewLength \
(*(PyObject * (*)(Uint8 *, Uint8)) PYGAMEAPI_GET_SLOT(color, 3))
#define pg_RGBAFromColorObj \
(*(int (*)(PyObject *, Uint8 *))PYGAMEAPI_GET_SLOT(color, 2))
#define pg_RGBAFromFuzzyColorObj \
(*(int (*)(PyObject *, Uint8 *))PYGAMEAPI_GET_SLOT(color, 4))
#define pgColor_AsArray(x) (((pgColorObject *)x)->data)
#define pgColor_NumComponents(x) (((pgColorObject *)x)->len)
#define import_pygame_color() IMPORT_PYGAME_MODULE(color)
#endif /* PYGAMEAPI_COLOR_INTERNAL */
/*
* Math module
*/
#ifndef PYGAMEAPI_MATH_INTERNAL
#define pgVector2_Check(x) \
((x)->ob_type == (PyTypeObject *)PYGAMEAPI_GET_SLOT(math, 0))
#define pgVector3_Check(x) \
((x)->ob_type == (PyTypeObject *)PYGAMEAPI_GET_SLOT(math, 1))
/*
#define pgVector2_New \
(*(PyObject*(*)) \
PYGAMEAPI_GET_SLOT(PyGAME_C_API, 1))
*/
#define import_pygame_math() IMPORT_PYGAME_MODULE(math)
#endif /* PYGAMEAPI_MATH_INTERNAL */
#define IMPORT_PYGAME_MODULE _IMPORT_PYGAME_MODULE
/*
* base pygame API slots
* disable slots with NO_PYGAME_C_API
*/
#ifdef PYGAME_H
PYGAMEAPI_DEFINE_SLOTS(base);
PYGAMEAPI_DEFINE_SLOTS(rect);
PYGAMEAPI_DEFINE_SLOTS(cdrom);
PYGAMEAPI_DEFINE_SLOTS(joystick);
PYGAMEAPI_DEFINE_SLOTS(display);
PYGAMEAPI_DEFINE_SLOTS(surface);
PYGAMEAPI_DEFINE_SLOTS(surflock);
PYGAMEAPI_DEFINE_SLOTS(event);
PYGAMEAPI_DEFINE_SLOTS(rwobject);
PYGAMEAPI_DEFINE_SLOTS(pixelarray);
PYGAMEAPI_DEFINE_SLOTS(color);
PYGAMEAPI_DEFINE_SLOTS(math);
#else /* ~PYGAME_H */
PYGAMEAPI_EXTERN_SLOTS(base);
PYGAMEAPI_EXTERN_SLOTS(rect);
PYGAMEAPI_EXTERN_SLOTS(cdrom);
PYGAMEAPI_EXTERN_SLOTS(joystick);
PYGAMEAPI_EXTERN_SLOTS(display);
PYGAMEAPI_EXTERN_SLOTS(surface);
PYGAMEAPI_EXTERN_SLOTS(surflock);
PYGAMEAPI_EXTERN_SLOTS(event);
PYGAMEAPI_EXTERN_SLOTS(rwobject);
PYGAMEAPI_EXTERN_SLOTS(pixelarray);
PYGAMEAPI_EXTERN_SLOTS(color);
PYGAMEAPI_EXTERN_SLOTS(math);
#endif /* ~PYGAME_H */
#endif /* PYGAME_H */
/* Use the end of this file for other cross module inline utility
* functions There seems to be no good reason to stick to macro only
* functions in Python 3.
*/
static PG_INLINE PyObject *
pg_tuple_couple_from_values_int(int val1, int val2)
{
/* This function turns two input integers into a python tuple object.
* Currently, 5th November 2022, this is faster than using Py_BuildValue
* to do the same thing.
*/
PyObject *tup = PyTuple_New(2);
if (!tup) {
return NULL;
}
PyObject *tmp = PyLong_FromLong(val1);
if (!tmp) {
Py_DECREF(tup);
return NULL;
}
PyTuple_SET_ITEM(tup, 0, tmp);
tmp = PyLong_FromLong(val2);
if (!tmp) {
Py_DECREF(tup);
return NULL;
}
PyTuple_SET_ITEM(tup, 1, tmp);
return tup;
}
static PG_INLINE PyObject *
pg_tuple_triple_from_values_int(int val1, int val2, int val3)
{
/* This function turns three input integers into a python tuple object.
* Currently, 5th November 2022, this is faster than using Py_BuildValue
* to do the same thing.
*/
PyObject *tup = PyTuple_New(3);
if (!tup) {
return NULL;
}
PyObject *tmp = PyLong_FromLong(val1);
if (!tmp) {
Py_DECREF(tup);
return NULL;
}
PyTuple_SET_ITEM(tup, 0, tmp);
tmp = PyLong_FromLong(val2);
if (!tmp) {
Py_DECREF(tup);
return NULL;
}
PyTuple_SET_ITEM(tup, 1, tmp);
tmp = PyLong_FromLong(val3);
if (!tmp) {
Py_DECREF(tup);
return NULL;
}
PyTuple_SET_ITEM(tup, 2, tmp);
return tup;
}

View file

@ -0,0 +1,171 @@
/*
Bitmask 1.7 - A pixel-perfect collision detection library.
Copyright (C) 2002-2005 Ulf Ekstrom except for the bitcount
function which is copyright (C) Donald W. Gillies, 1992.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef BITMASK_H
#define BITMASK_H
#ifdef __cplusplus
extern "C" {
#endif
#include <limits.h>
/* Define INLINE for different compilers. If your compiler does not
support inlining then there might be a performance hit in
bitmask_overlap_area().
*/
#ifndef INLINE
#ifdef __GNUC__
#define INLINE inline
#else
#ifdef _MSC_VER
#define INLINE __inline
#else
#define INLINE
#endif
#endif
#endif
#define BITMASK_W unsigned long int
#define BITMASK_W_LEN (sizeof(BITMASK_W) * CHAR_BIT)
#define BITMASK_W_MASK (BITMASK_W_LEN - 1)
#define BITMASK_N(n) ((BITMASK_W)1 << (n))
typedef struct bitmask {
int w, h;
BITMASK_W bits[1];
} bitmask_t;
/* Creates a bitmask of width w and height h, where
w and h must both be greater than or equal to 0.
The mask is automatically cleared when created.
*/
bitmask_t *
bitmask_create(int w, int h);
/* Frees all the memory allocated by bitmask_create for m. */
void
bitmask_free(bitmask_t *m);
/* Create a copy of the given bitmask. */
bitmask_t *
bitmask_copy(bitmask_t *m);
/* Clears all bits in the mask */
void
bitmask_clear(bitmask_t *m);
/* Sets all bits in the mask */
void
bitmask_fill(bitmask_t *m);
/* Flips all bits in the mask */
void
bitmask_invert(bitmask_t *m);
/* Counts the bits in the mask */
unsigned int
bitmask_count(bitmask_t *m);
/* Returns nonzero if the bit at (x,y) is set. Coordinates start at
(0,0) */
static INLINE int
bitmask_getbit(const bitmask_t *m, int x, int y)
{
return (m->bits[x / BITMASK_W_LEN * m->h + y] &
BITMASK_N(x & BITMASK_W_MASK)) != 0;
}
/* Sets the bit at (x,y) */
static INLINE void
bitmask_setbit(bitmask_t *m, int x, int y)
{
m->bits[x / BITMASK_W_LEN * m->h + y] |= BITMASK_N(x & BITMASK_W_MASK);
}
/* Clears the bit at (x,y) */
static INLINE void
bitmask_clearbit(bitmask_t *m, int x, int y)
{
m->bits[x / BITMASK_W_LEN * m->h + y] &= ~BITMASK_N(x & BITMASK_W_MASK);
}
/* Returns nonzero if the masks overlap with the given offset.
The overlap tests uses the following offsets (which may be negative):
+----+----------..
|A | yoffset
| +-+----------..
+--|B
|xoffset
| |
: :
*/
int
bitmask_overlap(const bitmask_t *a, const bitmask_t *b, int xoffset,
int yoffset);
/* Like bitmask_overlap(), but will also give a point of intersection.
x and y are given in the coordinates of mask a, and are untouched
if there is no overlap. */
int
bitmask_overlap_pos(const bitmask_t *a, const bitmask_t *b, int xoffset,
int yoffset, int *x, int *y);
/* Returns the number of overlapping 'pixels' */
int
bitmask_overlap_area(const bitmask_t *a, const bitmask_t *b, int xoffset,
int yoffset);
/* Fills a mask with the overlap of two other masks. A bitwise AND. */
void
bitmask_overlap_mask(const bitmask_t *a, const bitmask_t *b, bitmask_t *c,
int xoffset, int yoffset);
/* Draws mask b onto mask a (bitwise OR). Can be used to compose large
(game background?) mask from several submasks, which may speed up
the testing. */
void
bitmask_draw(bitmask_t *a, const bitmask_t *b, int xoffset, int yoffset);
void
bitmask_erase(bitmask_t *a, const bitmask_t *b, int xoffset, int yoffset);
/* Return a new scaled bitmask, with dimensions w*h. The quality of the
scaling may not be perfect for all circumstances, but it should
be reasonable. If either w or h is 0 a clear 1x1 mask is returned. */
bitmask_t *
bitmask_scale(const bitmask_t *m, int w, int h);
/* Convolve b into a, drawing the output into o, shifted by offset. If offset
* is 0, then the (x,y) bit will be set if and only if
* bitmask_overlap(a, b, x - b->w - 1, y - b->h - 1) returns true.
*
* Modifies bits o[xoffset ... xoffset + a->w + b->w - 1)
* [yoffset ... yoffset + a->h + b->h - 1). */
void
bitmask_convolve(const bitmask_t *a, const bitmask_t *b, bitmask_t *o,
int xoffset, int yoffset);
#ifdef __cplusplus
} /* End of extern "C" { */
#endif
#endif

View file

@ -0,0 +1,102 @@
#if !defined(PGCOMPAT_H)
#define PGCOMPAT_H
#include <Python.h>
/* In CPython, Py_Exit finalises the python interpreter before calling C exit()
* This does not exist on PyPy, so use exit() directly here */
#ifdef PYPY_VERSION
#define PG_EXIT(n) exit(n)
#else
#define PG_EXIT(n) Py_Exit(n)
#endif
/* define common types where SDL is not included */
#ifndef SDL_VERSION_ATLEAST
#ifdef _MSC_VER
typedef unsigned __int8 uint8_t;
typedef unsigned __int32 uint32_t;
#else
#include <stdint.h>
#endif
typedef uint32_t Uint32;
typedef uint8_t Uint8;
#endif /* no SDL */
#if defined(SDL_VERSION_ATLEAST)
#ifndef SDL_WINDOW_VULKAN
#define SDL_WINDOW_VULKAN 0
#endif
#ifndef SDL_WINDOW_ALWAYS_ON_TOP
#define SDL_WINDOW_ALWAYS_ON_TOP 0
#endif
#ifndef SDL_WINDOW_SKIP_TASKBAR
#define SDL_WINDOW_SKIP_TASKBAR 0
#endif
#ifndef SDL_WINDOW_UTILITY
#define SDL_WINDOW_UTILITY 0
#endif
#ifndef SDL_WINDOW_TOOLTIP
#define SDL_WINDOW_TOOLTIP 0
#endif
#ifndef SDL_WINDOW_POPUP_MENU
#define SDL_WINDOW_POPUP_MENU 0
#endif
#ifndef SDL_WINDOW_INPUT_GRABBED
#define SDL_WINDOW_INPUT_GRABBED 0
#endif
#ifndef SDL_WINDOW_INPUT_FOCUS
#define SDL_WINDOW_INPUT_FOCUS 0
#endif
#ifndef SDL_WINDOW_MOUSE_FOCUS
#define SDL_WINDOW_MOUSE_FOCUS 0
#endif
#ifndef SDL_WINDOW_FOREIGN
#define SDL_WINDOW_FOREIGN 0
#endif
#ifndef SDL_WINDOW_ALLOW_HIGHDPI
#define SDL_WINDOW_ALLOW_HIGHDPI 0
#endif
#ifndef SDL_WINDOW_MOUSE_CAPTURE
#define SDL_WINDOW_MOUSE_CAPTURE 0
#endif
#ifndef SDL_WINDOW_ALWAYS_ON_TOP
#define SDL_WINDOW_ALWAYS_ON_TOP 0
#endif
#ifndef SDL_WINDOW_SKIP_TASKBAR
#define SDL_WINDOW_SKIP_TASKBAR 0
#endif
#ifndef SDL_WINDOW_UTILITY
#define SDL_WINDOW_UTILITY 0
#endif
#ifndef SDL_WINDOW_TOOLTIP
#define SDL_WINDOW_TOOLTIP 0
#endif
#ifndef SDL_WINDOW_POPUP_MENU
#define SDL_WINDOW_POPUP_MENU 0
#endif
#ifndef SDL_MOUSEWHEEL_FLIPPED
#define NO_SDL_MOUSEWHEEL_FLIPPED
#endif
#endif /* defined(SDL_VERSION_ATLEAST) */
#endif /* ~defined(PGCOMPAT_H) */

View file

@ -0,0 +1,67 @@
#ifndef PGIMPORT_H
#define PGIMPORT_H
/* Prefix when importing module */
#define IMPPREFIX "pygame."
#include "pgcompat.h"
#define PYGAMEAPI_LOCAL_ENTRY "_PYGAME_C_API"
#define PG_CAPSULE_NAME(m) (IMPPREFIX m "." PYGAMEAPI_LOCAL_ENTRY)
/*
* fill API slots defined by PYGAMEAPI_DEFINE_SLOTS/PYGAMEAPI_EXTERN_SLOTS
*/
#define _IMPORT_PYGAME_MODULE(module) \
{ \
PyObject *_mod_##module = PyImport_ImportModule(IMPPREFIX #module); \
\
if (_mod_##module != NULL) { \
PyObject *_c_api = \
PyObject_GetAttrString(_mod_##module, PYGAMEAPI_LOCAL_ENTRY); \
\
Py_DECREF(_mod_##module); \
if (_c_api != NULL && PyCapsule_CheckExact(_c_api)) { \
void **localptr = (void **)PyCapsule_GetPointer( \
_c_api, PG_CAPSULE_NAME(#module)); \
_PGSLOTS_##module = localptr; \
} \
Py_XDECREF(_c_api); \
} \
}
#define PYGAMEAPI_IS_IMPORTED(module) (_PGSLOTS_##module != NULL)
/*
* source file must include one of these in order to use _IMPORT_PYGAME_MODULE.
* this is set by import_pygame_*() functions.
* disable with NO_PYGAME_C_API
*/
#define PYGAMEAPI_DEFINE_SLOTS(module) void **_PGSLOTS_##module = NULL
#define PYGAMEAPI_EXTERN_SLOTS(module) extern void **_PGSLOTS_##module
#define PYGAMEAPI_GET_SLOT(module, index) _PGSLOTS_##module[(index)]
/*
* disabled API with NO_PYGAME_C_API; do nothing instead
*/
#ifdef NO_PYGAME_C_API
#undef PYGAMEAPI_DEFINE_SLOTS
#undef PYGAMEAPI_EXTERN_SLOTS
#define PYGAMEAPI_DEFINE_SLOTS(module)
#define PYGAMEAPI_EXTERN_SLOTS(module)
/* intentionally leave this defined to cause a compiler error *
#define PYGAMEAPI_GET_SLOT(api_root, index)
#undef PYGAMEAPI_GET_SLOT*/
#undef _IMPORT_PYGAME_MODULE
#define _IMPORT_PYGAME_MODULE(module)
#endif /* NO_PYGAME_C_API */
#define encapsulate_api(ptr, module) \
PyCapsule_New(ptr, PG_CAPSULE_NAME(module), NULL)
#endif /* ~PGIMPORT_H */

View file

@ -0,0 +1,83 @@
/* platform/compiler adjustments */
#ifndef PG_PLATFORM_H
#define PG_PLATFORM_H
#if defined(HAVE_SNPRINTF) /* defined in python.h (pyerrors.h) and SDL.h \
(SDL_config.h) */
#undef HAVE_SNPRINTF /* remove GCC redefine warning */
#endif /* HAVE_SNPRINTF */
#ifndef PG_INLINE
#if defined(__clang__)
#define PG_INLINE __inline__ __attribute__((__unused__))
#elif defined(__GNUC__)
#define PG_INLINE __inline__
#elif defined(_MSC_VER)
#define PG_INLINE __inline
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define PG_INLINE inline
#else
#define PG_INLINE
#endif
#endif /* ~PG_INLINE */
// Worth trying this on MSVC/win32 builds to see if provides any speed up
#ifndef PG_FORCEINLINE
#if defined(__clang__)
#define PG_FORCEINLINE __inline__ __attribute__((__unused__))
#elif defined(__GNUC__)
#define PG_FORCEINLINE __inline__
#elif defined(_MSC_VER)
#define PG_FORCEINLINE __forceinline
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define PG_FORCEINLINE inline
#else
#define PG_FORCEINLINE
#endif
#endif /* ~PG_FORCEINLINE */
/* This is unconditionally defined in Python.h */
#if defined(_POSIX_C_SOURCE)
#undef _POSIX_C_SOURCE
#endif
#if defined(HAVE_SNPRINTF)
#undef HAVE_SNPRINTF
#endif
/* SDL needs WIN32 */
#if !defined(WIN32) && \
(defined(MS_WIN32) || defined(_WIN32) || defined(__WIN32) || \
defined(__WIN32__) || defined(_WINDOWS))
#define WIN32
#endif
#ifndef PG_TARGET_SSE4_2
#if defined(__clang__) || \
(defined(__GNUC__) && \
((__GNUC__ == 4 && __GNUC_MINOR__ >= 9) || __GNUC__ >= 5))
// The old gcc 4.8 on centos used by manylinux1 does not seem to get sse4.2
// intrinsics
#define PG_FUNCTION_TARGET_SSE4_2 __attribute__((target("sse4.2")))
// No else; we define the fallback later
#endif
#endif /* ~PG_TARGET_SSE4_2 */
#ifdef PG_FUNCTION_TARGET_SSE4_2
#if !defined(__SSE4_2__) && !defined(PG_COMPILE_SSE4_2)
#if defined(__x86_64__) || defined(__i386__)
#define PG_COMPILE_SSE4_2 1
#endif
#endif
#endif /* ~PG_TARGET_SSE4_2 */
/* Fallback definition of target attribute */
#ifndef PG_FUNCTION_TARGET_SSE4_2
#define PG_FUNCTION_TARGET_SSE4_2
#endif
#ifndef PG_COMPILE_SSE4_2
#define PG_COMPILE_SSE4_2 0
#endif
#endif /* ~PG_PLATFORM_H */

View file

@ -0,0 +1,34 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
/* To allow the Pygame C api to be globally shared by all code within an
* extension module built from multiple C files, only include the pygame.h
* header within the top level C file, the one which calls the
* 'import_pygame_*' macros. All other C source files of the module should
* include _pygame.h instead.
*/
#ifndef PYGAME_H
#define PYGAME_H
#include "_pygame.h"
#endif

View file

@ -0,0 +1,56 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
Copyright (C) 2007 Rene Dudfield, Richard Goedeken
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
/* Bufferproxy module C api. */
#if !defined(PG_BUFPROXY_HEADER)
#define PG_BUFPROXY_HEADER
#include <Python.h>
typedef PyObject *(*_pgbufproxy_new_t)(PyObject *, getbufferproc);
typedef PyObject *(*_pgbufproxy_get_obj_t)(PyObject *);
typedef int (*_pgbufproxy_trip_t)(PyObject *);
#ifndef PYGAMEAPI_BUFPROXY_INTERNAL
#include "pgimport.h"
PYGAMEAPI_DEFINE_SLOTS(bufferproxy);
#define pgBufproxy_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(bufferproxy, 0))
#define pgBufproxy_Check(x) ((x)->ob_type == &pgBufproxy_Type)
#define pgBufproxy_New (*(_pgbufproxy_new_t)PYGAMEAPI_GET_SLOT(bufferproxy, 1))
#define pgBufproxy_GetParent \
(*(_pgbufproxy_get_obj_t)PYGAMEAPI_GET_SLOT(bufferproxy, 2))
#define pgBufproxy_Trip \
(*(_pgbufproxy_trip_t)PYGAMEAPI_GET_SLOT(bufferproxy, 3))
#define import_pygame_bufferproxy() _IMPORT_PYGAME_MODULE(bufferproxy)
#endif /* ~PYGAMEAPI_BUFPROXY_INTERNAL */
#endif /* ~defined(PG_BUFPROXY_HEADER) */

View file

@ -0,0 +1,50 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
#include <Python.h>
#include "pgplatform.h"
struct TTF_Font;
typedef struct {
PyObject_HEAD TTF_Font *font;
PyObject *weakreflist;
unsigned int ttf_init_generation;
} PyFontObject;
#define PyFont_AsFont(x) (((PyFontObject *)x)->font)
#ifndef PYGAMEAPI_FONT_INTERNAL
#include "pgimport.h"
PYGAMEAPI_DEFINE_SLOTS(font);
#define PyFont_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(font, 0))
#define PyFont_Check(x) ((x)->ob_type == &PyFont_Type)
#define PyFont_New (*(PyObject * (*)(TTF_Font *)) PYGAMEAPI_GET_SLOT(font, 1))
/*slot 2 taken by FONT_INIT_CHECK*/
#define import_pygame_font() _IMPORT_PYGAME_MODULE(font)
#endif

View file

@ -0,0 +1,42 @@
/*
pygame - Python Game Library
Copyright (C) 2009 Vicent Marti
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PYGAME_FREETYPE_H_
#define PYGAME_FREETYPE_H_
#include "pgplatform.h"
#include "pgimport.h"
#include "pgcompat.h"
#ifndef PYGAME_FREETYPE_INTERNAL
PYGAMEAPI_DEFINE_SLOTS(_freetype);
#define pgFont_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(_freetype, 0))
#define pgFont_Check(x) ((x)->ob_type == &pgFont_Type)
#define pgFont_New \
(*(PyObject * (*)(const char *, long)) PYGAMEAPI_GET_SLOT(_freetype, 1))
#define import_pygame_freetype() _IMPORT_PYGAME_MODULE(_freetype)
#endif /* PYGAME_FREETYPE_INTERNAL */
#endif /* PYGAME_FREETYPE_H_ */

View file

@ -0,0 +1,45 @@
/*
pygame - Python Game Library
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PGMASK_H
#define PGMASK_H
#include <Python.h>
#include "bitmask.h"
typedef struct {
PyObject_HEAD bitmask_t *mask;
void *bufdata;
} pgMaskObject;
#define pgMask_AsBitmap(x) (((pgMaskObject *)x)->mask)
#ifndef PYGAMEAPI_MASK_INTERNAL
#include "pgimport.h"
PYGAMEAPI_DEFINE_SLOTS(mask);
#define pgMask_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(mask, 0))
#define pgMask_Check(x) ((x)->ob_type == &pgMask_Type)
#define import_pygame_mask() _IMPORT_PYGAME_MODULE(mask)
#endif /* ~PYGAMEAPI_MASK_INTERNAL */
#endif /* ~PGMASK_H */

View file

@ -0,0 +1,71 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
#ifndef PGMIXER_H
#define PGMIXER_H
#include <Python.h>
#include <structmember.h>
#include "pgcompat.h"
struct Mix_Chunk;
typedef struct {
PyObject_HEAD Mix_Chunk *chunk;
Uint8 *mem;
PyObject *weakreflist;
} pgSoundObject;
typedef struct {
PyObject_HEAD int chan;
} pgChannelObject;
#define pgSound_AsChunk(x) (((pgSoundObject *)x)->chunk)
#define pgChannel_AsInt(x) (((pgChannelObject *)x)->chan)
#include "pgimport.h"
#ifndef PYGAMEAPI_MIXER_INTERNAL
PYGAMEAPI_DEFINE_SLOTS(mixer);
#define pgSound_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(mixer, 0))
#define pgSound_Check(x) ((x)->ob_type == &pgSound_Type)
#define pgSound_New \
(*(PyObject * (*)(Mix_Chunk *)) PYGAMEAPI_GET_SLOT(mixer, 1))
#define pgSound_Play \
(*(PyObject * (*)(PyObject *, PyObject *)) PYGAMEAPI_GET_SLOT(mixer, 2))
#define pgChannel_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(mixer, 3))
#define pgChannel_Check(x) ((x)->ob_type == &pgChannel_Type)
#define pgChannel_New (*(PyObject * (*)(int)) PYGAMEAPI_GET_SLOT(mixer, 4))
#define import_pygame_mixer() _IMPORT_PYGAME_MODULE(mixer)
#endif /* PYGAMEAPI_MIXER_INTERNAL */
#endif /* ~PGMIXER_H */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,7 @@
#ifndef PGMASK_INTERNAL_H
#define PGMASK_INTERNAL_H
#include "include/pygame_mask.h"
#define PYGAMEAPI_MASK_NUMSLOTS 1
#endif /* ~PGMASK_INTERNAL_H */

View file

@ -0,0 +1,14 @@
#ifndef MIXER_INTERNAL_H
#define MIXER_INTERNAL_H
#include <SDL_mixer.h>
/* test mixer initializations */
#define MIXER_INIT_CHECK() \
if (!SDL_WasInit(SDL_INIT_AUDIO)) \
return RAISE(pgExc_SDLError, "mixer not initialized")
#define PYGAMEAPI_MIXER_NUMSLOTS 5
#include "include/pygame_mixer.h"
#endif /* ~MIXER_INTERNAL_H */

View file

@ -0,0 +1,123 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
#ifndef PALETTE_H
#define PALETTE_H
#include <SDL.h>
/* SDL 2 does not assign a default palette color scheme to a new 8 bit
* surface. Instead, the palette is set all white. This defines the SDL 1.2
* default palette.
*/
static const SDL_Color default_palette_colors[] = {
{0, 0, 0, 255}, {0, 0, 85, 255}, {0, 0, 170, 255},
{0, 0, 255, 255}, {0, 36, 0, 255}, {0, 36, 85, 255},
{0, 36, 170, 255}, {0, 36, 255, 255}, {0, 73, 0, 255},
{0, 73, 85, 255}, {0, 73, 170, 255}, {0, 73, 255, 255},
{0, 109, 0, 255}, {0, 109, 85, 255}, {0, 109, 170, 255},
{0, 109, 255, 255}, {0, 146, 0, 255}, {0, 146, 85, 255},
{0, 146, 170, 255}, {0, 146, 255, 255}, {0, 182, 0, 255},
{0, 182, 85, 255}, {0, 182, 170, 255}, {0, 182, 255, 255},
{0, 219, 0, 255}, {0, 219, 85, 255}, {0, 219, 170, 255},
{0, 219, 255, 255}, {0, 255, 0, 255}, {0, 255, 85, 255},
{0, 255, 170, 255}, {0, 255, 255, 255}, {85, 0, 0, 255},
{85, 0, 85, 255}, {85, 0, 170, 255}, {85, 0, 255, 255},
{85, 36, 0, 255}, {85, 36, 85, 255}, {85, 36, 170, 255},
{85, 36, 255, 255}, {85, 73, 0, 255}, {85, 73, 85, 255},
{85, 73, 170, 255}, {85, 73, 255, 255}, {85, 109, 0, 255},
{85, 109, 85, 255}, {85, 109, 170, 255}, {85, 109, 255, 255},
{85, 146, 0, 255}, {85, 146, 85, 255}, {85, 146, 170, 255},
{85, 146, 255, 255}, {85, 182, 0, 255}, {85, 182, 85, 255},
{85, 182, 170, 255}, {85, 182, 255, 255}, {85, 219, 0, 255},
{85, 219, 85, 255}, {85, 219, 170, 255}, {85, 219, 255, 255},
{85, 255, 0, 255}, {85, 255, 85, 255}, {85, 255, 170, 255},
{85, 255, 255, 255}, {170, 0, 0, 255}, {170, 0, 85, 255},
{170, 0, 170, 255}, {170, 0, 255, 255}, {170, 36, 0, 255},
{170, 36, 85, 255}, {170, 36, 170, 255}, {170, 36, 255, 255},
{170, 73, 0, 255}, {170, 73, 85, 255}, {170, 73, 170, 255},
{170, 73, 255, 255}, {170, 109, 0, 255}, {170, 109, 85, 255},
{170, 109, 170, 255}, {170, 109, 255, 255}, {170, 146, 0, 255},
{170, 146, 85, 255}, {170, 146, 170, 255}, {170, 146, 255, 255},
{170, 182, 0, 255}, {170, 182, 85, 255}, {170, 182, 170, 255},
{170, 182, 255, 255}, {170, 219, 0, 255}, {170, 219, 85, 255},
{170, 219, 170, 255}, {170, 219, 255, 255}, {170, 255, 0, 255},
{170, 255, 85, 255}, {170, 255, 170, 255}, {170, 255, 255, 255},
{255, 0, 0, 255}, {255, 0, 85, 255}, {255, 0, 170, 255},
{255, 0, 255, 255}, {255, 36, 0, 255}, {255, 36, 85, 255},
{255, 36, 170, 255}, {255, 36, 255, 255}, {255, 73, 0, 255},
{255, 73, 85, 255}, {255, 73, 170, 255}, {255, 73, 255, 255},
{255, 109, 0, 255}, {255, 109, 85, 255}, {255, 109, 170, 255},
{255, 109, 255, 255}, {255, 146, 0, 255}, {255, 146, 85, 255},
{255, 146, 170, 255}, {255, 146, 255, 255}, {255, 182, 0, 255},
{255, 182, 85, 255}, {255, 182, 170, 255}, {255, 182, 255, 255},
{255, 219, 0, 255}, {255, 219, 85, 255}, {255, 219, 170, 255},
{255, 219, 255, 255}, {255, 255, 0, 255}, {255, 255, 85, 255},
{255, 255, 170, 255}, {255, 255, 255, 255}, {0, 0, 0, 255},
{0, 0, 85, 255}, {0, 0, 170, 255}, {0, 0, 255, 255},
{0, 36, 0, 255}, {0, 36, 85, 255}, {0, 36, 170, 255},
{0, 36, 255, 255}, {0, 73, 0, 255}, {0, 73, 85, 255},
{0, 73, 170, 255}, {0, 73, 255, 255}, {0, 109, 0, 255},
{0, 109, 85, 255}, {0, 109, 170, 255}, {0, 109, 255, 255},
{0, 146, 0, 255}, {0, 146, 85, 255}, {0, 146, 170, 255},
{0, 146, 255, 255}, {0, 182, 0, 255}, {0, 182, 85, 255},
{0, 182, 170, 255}, {0, 182, 255, 255}, {0, 219, 0, 255},
{0, 219, 85, 255}, {0, 219, 170, 255}, {0, 219, 255, 255},
{0, 255, 0, 255}, {0, 255, 85, 255}, {0, 255, 170, 255},
{0, 255, 255, 255}, {85, 0, 0, 255}, {85, 0, 85, 255},
{85, 0, 170, 255}, {85, 0, 255, 255}, {85, 36, 0, 255},
{85, 36, 85, 255}, {85, 36, 170, 255}, {85, 36, 255, 255},
{85, 73, 0, 255}, {85, 73, 85, 255}, {85, 73, 170, 255},
{85, 73, 255, 255}, {85, 109, 0, 255}, {85, 109, 85, 255},
{85, 109, 170, 255}, {85, 109, 255, 255}, {85, 146, 0, 255},
{85, 146, 85, 255}, {85, 146, 170, 255}, {85, 146, 255, 255},
{85, 182, 0, 255}, {85, 182, 85, 255}, {85, 182, 170, 255},
{85, 182, 255, 255}, {85, 219, 0, 255}, {85, 219, 85, 255},
{85, 219, 170, 255}, {85, 219, 255, 255}, {85, 255, 0, 255},
{85, 255, 85, 255}, {85, 255, 170, 255}, {85, 255, 255, 255},
{170, 0, 0, 255}, {170, 0, 85, 255}, {170, 0, 170, 255},
{170, 0, 255, 255}, {170, 36, 0, 255}, {170, 36, 85, 255},
{170, 36, 170, 255}, {170, 36, 255, 255}, {170, 73, 0, 255},
{170, 73, 85, 255}, {170, 73, 170, 255}, {170, 73, 255, 255},
{170, 109, 0, 255}, {170, 109, 85, 255}, {170, 109, 170, 255},
{170, 109, 255, 255}, {170, 146, 0, 255}, {170, 146, 85, 255},
{170, 146, 170, 255}, {170, 146, 255, 255}, {170, 182, 0, 255},
{170, 182, 85, 255}, {170, 182, 170, 255}, {170, 182, 255, 255},
{170, 219, 0, 255}, {170, 219, 85, 255}, {170, 219, 170, 255},
{170, 219, 255, 255}, {170, 255, 0, 255}, {170, 255, 85, 255},
{170, 255, 170, 255}, {170, 255, 255, 255}, {255, 0, 0, 255},
{255, 0, 85, 255}, {255, 0, 170, 255}, {255, 0, 255, 255},
{255, 36, 0, 255}, {255, 36, 85, 255}, {255, 36, 170, 255},
{255, 36, 255, 255}, {255, 73, 0, 255}, {255, 73, 85, 255},
{255, 73, 170, 255}, {255, 73, 255, 255}, {255, 109, 0, 255},
{255, 109, 85, 255}, {255, 109, 170, 255}, {255, 109, 255, 255},
{255, 146, 0, 255}, {255, 146, 85, 255}, {255, 146, 170, 255},
{255, 146, 255, 255}, {255, 182, 0, 255}, {255, 182, 85, 255},
{255, 182, 170, 255}, {255, 182, 255, 255}, {255, 219, 0, 255},
{255, 219, 85, 255}, {255, 219, 170, 255}, {255, 219, 255, 255},
{255, 255, 0, 255}, {255, 255, 85, 255}, {255, 255, 170, 255},
{255, 255, 255, 255}};
static const int default_palette_size =
(int)(sizeof(default_palette_colors) / sizeof(SDL_Color));
#endif

View file

@ -0,0 +1,26 @@
/* array structure interface version 3 declarations */
#if !defined(PG_ARRAYINTER_HEADER)
#define PG_ARRAYINTER_HEADER
static const int PAI_CONTIGUOUS = 0x01;
static const int PAI_FORTRAN = 0x02;
static const int PAI_ALIGNED = 0x100;
static const int PAI_NOTSWAPPED = 0x200;
static const int PAI_WRITEABLE = 0x400;
static const int PAI_ARR_HAS_DESCR = 0x800;
typedef struct {
int two; /* contains the integer 2 -- simple sanity check */
int nd; /* number of dimensions */
char typekind; /* kind in array -- character code of typestr */
int itemsize; /* size of each element */
int flags; /* flags indicating how the data should be */
/* interpreted */
Py_intptr_t *shape; /* A length-nd array of shape information */
Py_intptr_t *strides; /* A length-nd array of stride information */
void *data; /* A pointer to the first element of the array */
PyObject *descr; /* NULL or a data-description */
} PyArrayInterface;
#endif

View file

@ -0,0 +1,7 @@
#ifndef PG_BUFPROXY_INTERNAL_H
#define PG_BUFPROXY_INTERNAL_H
#include "include/pygame_bufferproxy.h"
#define PYGAMEAPI_BUFPROXY_NUMSLOTS 4
#endif /* ~PG_BUFPROXY_INTERNAL_H */

View file

@ -0,0 +1,27 @@
/* Python 2.x/3.x compatibility tools (internal)
*/
#ifndef PGCOMPAT_INTERNAL_H
#define PGCOMPAT_INTERNAL_H
#include "include/pgcompat.h"
/* Module init function returns new module instance. */
#define MODINIT_DEFINE(mod_name) PyMODINIT_FUNC PyInit_##mod_name(void)
/* Defaults for unicode file path encoding */
#if defined(MS_WIN32)
#define UNICODE_DEF_FS_ERROR "replace"
#else
#define UNICODE_DEF_FS_ERROR "surrogateescape"
#endif
#define RELATIVE_MODULE(m) ("." m)
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#define Slice_GET_INDICES_EX(slice, length, start, stop, step, slicelength) \
PySlice_GetIndicesEx(slice, length, start, stop, step, slicelength)
#endif /* ~PGCOMPAT_INTERNAL_H */

View file

@ -0,0 +1,20 @@
#if !defined(PGOPENGL_H)
#define PGOPENGL_H
/** This header includes definitions of Opengl functions as pointer types for
** use with the SDL function SDL_GL_GetProcAddress.
**/
#if defined(_WIN32)
#define GL_APIENTRY __stdcall
#else
#define GL_APIENTRY
#endif
typedef void(GL_APIENTRY *GL_glReadPixels_Func)(int, int, int, int,
unsigned int, unsigned int,
void *);
typedef void(GL_APIENTRY *GL_glViewport_Func)(int, int, unsigned int,
unsigned int);
#endif

View file

@ -0,0 +1,23 @@
/* platform/compiler adjustments (internal) */
#ifndef PG_PLATFORM_INTERNAL_H
#define PG_PLATFORM_INTERNAL_H
#include "include/pgplatform.h"
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef ABS
#define ABS(a) (((a) < 0) ? -(a) : (a))
#endif
/* warnings */
#define PG_STRINGIZE_HELPER(x) #x
#define PG_STRINGIZE(x) PG_STRINGIZE_HELPER(x)
#define PG_WARN(desc) \
message(__FILE__ "(" PG_STRINGIZE(__LINE__) "): WARNING: " #desc)
#endif /* ~PG_PLATFORM_INTERNAL_H */

View file

@ -0,0 +1,32 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
/* This will use PYGAMEAPI_DEFINE_SLOTS instead
* of PYGAMEAPI_EXTERN_SLOTS for base modules.
*/
#ifndef PYGAME_INTERNAL_H
#define PYGAME_INTERNAL_H
#define PYGAME_H
#include "_pygame.h"
#endif /* ~PYGAME_INTERNAL_H */

View file

@ -0,0 +1,147 @@
/*
pygame - Python Game Library
Copyright (C) 2006, 2007 Rene Dudfield, Marcus von Appen
Originally put in the public domain by Sam Lantinga.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SCRAP_H
#define SCRAP_H
/* This is unconditionally defined in Python.h */
#if defined(_POSIX_C_SOURCE)
#undef _POSIX_C_SOURCE
#endif
#include <Python.h>
/* Handle clipboard text and data in arbitrary formats */
/**
* Predefined supported pygame scrap types.
*/
#define PYGAME_SCRAP_TEXT "text/plain"
#define PYGAME_SCRAP_BMP "image/bmp"
#define PYGAME_SCRAP_PPM "image/ppm"
#define PYGAME_SCRAP_PBM "image/pbm"
/**
* The supported scrap clipboard types.
*
* This is only relevant in a X11 environment, which supports mouse
* selections as well. For Win32 and MacOS environments the default
* clipboard is used, no matter what value is passed.
*/
typedef enum {
SCRAP_CLIPBOARD,
SCRAP_SELECTION /* only supported in X11 environments. */
} ScrapClipType;
/**
* Macro for initialization checks.
*/
#define PYGAME_SCRAP_INIT_CHECK() \
if (!pygame_scrap_initialized()) \
return (PyErr_SetString(pgExc_SDLError, "scrap system not initialized."), \
NULL)
/**
* \brief Checks, whether the pygame scrap module was initialized.
*
* \return 1 if the modules was initialized, 0 otherwise.
*/
extern int
pygame_scrap_initialized(void);
/**
* \brief Initializes the pygame scrap module internals. Call this before any
* other method.
*
* \return 1 on successful initialization, 0 otherwise.
*/
extern int
pygame_scrap_init(void);
/**
* \brief Checks, whether the pygame window lost the clipboard focus or not.
*
* \return 1 if the window lost the focus, 0 otherwise.
*/
extern int
pygame_scrap_lost(void);
/**
* \brief Places content of a specific type into the clipboard.
*
* \note For X11 the following notes are important: The following types
* are reserved for internal usage and thus will throw an error on
* setting them: "TIMESTAMP", "TARGETS", "SDL_SELECTION".
* Setting PYGAME_SCRAP_TEXT ("text/plain") will also automatically
* set the X11 types "STRING" (XA_STRING), "TEXT" and "UTF8_STRING".
*
* For Win32 the following notes are important: Setting
* PYGAME_SCRAP_TEXT ("text/plain") will also automatically set
* the Win32 type "TEXT" (CF_TEXT).
*
* For QNX the following notes are important: Setting
* PYGAME_SCRAP_TEXT ("text/plain") will also automatically set
* the QNX type "TEXT" (Ph_CL_TEXT).
*
* \param type The type of the content.
* \param srclen The length of the content.
* \param src The NULL terminated content.
* \return 1, if the content could be successfully pasted into the clipboard,
* 0 otherwise.
*/
extern int
pygame_scrap_put(char *type, Py_ssize_t srclen, char *src);
/**
* \brief Gets the current content from the clipboard.
*
* \note The received content does not need to be the content previously
* placed in the clipboard using pygame_put_scrap(). See the
* pygame_put_scrap() notes for more details.
*
* \param type The type of the content to receive.
* \param count The size of the returned content.
* \return The content or NULL in case of an error or if no content of the
* specified type was available.
*/
extern char *
pygame_scrap_get(char *type, size_t *count);
/**
* \brief Gets the currently available content types from the clipboard.
*
* \return The different available content types or NULL in case of an
* error or if no content type is available.
*/
extern char **
pygame_scrap_get_types(void);
/**
* \brief Checks whether content for the specified scrap type is currently
* available in the clipboard.
*
* \param type The type to check for.
* \return 1, if there is content and 0 otherwise.
*/
extern int
pygame_scrap_contains(char *type);
#endif /* SCRAP_H */

View file

@ -0,0 +1,84 @@
#define NO_PYGAME_C_API
#include "_surface.h"
#include "_blit_info.h"
#if !defined(PG_ENABLE_ARM_NEON) && defined(__aarch64__)
// arm64 has neon optimisations enabled by default, even when fpu=neon is not
// passed
#define PG_ENABLE_ARM_NEON 1
#endif
int
pg_sse2_at_runtime_but_uncompiled();
int
pg_neon_at_runtime_but_uncompiled();
int
pg_avx2_at_runtime_but_uncompiled();
#if (defined(__SSE2__) || defined(PG_ENABLE_ARM_NEON))
void
alphablit_alpha_sse2_argb_surf_alpha(SDL_BlitInfo *info);
void
alphablit_alpha_sse2_argb_no_surf_alpha(SDL_BlitInfo *info);
void
alphablit_alpha_sse2_argb_no_surf_alpha_opaque_dst(SDL_BlitInfo *info);
void
blit_blend_rgba_mul_sse2(SDL_BlitInfo *info);
void
blit_blend_rgb_mul_sse2(SDL_BlitInfo *info);
void
blit_blend_rgba_add_sse2(SDL_BlitInfo *info);
void
blit_blend_rgb_add_sse2(SDL_BlitInfo *info);
void
blit_blend_rgba_sub_sse2(SDL_BlitInfo *info);
void
blit_blend_rgb_sub_sse2(SDL_BlitInfo *info);
void
blit_blend_rgba_max_sse2(SDL_BlitInfo *info);
void
blit_blend_rgb_max_sse2(SDL_BlitInfo *info);
void
blit_blend_rgba_min_sse2(SDL_BlitInfo *info);
void
blit_blend_rgb_min_sse2(SDL_BlitInfo *info);
void
blit_blend_premultiplied_sse2(SDL_BlitInfo *info);
#endif /* (defined(__SSE2__) || defined(PG_ENABLE_ARM_NEON)) */
/* Deliberately putting these outside of the preprocessor guards as I want to
move to a system of trusting the runtime checks to head to the right
function and having a fallback function there if pygame is not compiled
with the right stuff (this is the strategy used for AVX2 right now.
Potentially I might want to shift both these into a slightly different
file as they are not exactly blits (though v. similar) - or I could rename
the SIMD trilogy of files to replace the word blit with something more
generic like surface_ops*/
void
premul_surf_color_by_alpha_non_simd(SDL_Surface *src, SDL_Surface *dst);
void
premul_surf_color_by_alpha_sse2(SDL_Surface *src, SDL_Surface *dst);
int
pg_has_avx2();
void
blit_blend_rgba_mul_avx2(SDL_BlitInfo *info);
void
blit_blend_rgb_mul_avx2(SDL_BlitInfo *info);
void
blit_blend_rgba_add_avx2(SDL_BlitInfo *info);
void
blit_blend_rgb_add_avx2(SDL_BlitInfo *info);
void
blit_blend_rgba_sub_avx2(SDL_BlitInfo *info);
void
blit_blend_rgb_sub_avx2(SDL_BlitInfo *info);
void
blit_blend_rgba_max_avx2(SDL_BlitInfo *info);
void
blit_blend_rgb_max_avx2(SDL_BlitInfo *info);
void
blit_blend_rgba_min_avx2(SDL_BlitInfo *info);
void
blit_blend_rgb_min_avx2(SDL_BlitInfo *info);

View file

@ -0,0 +1,361 @@
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
Copyright (C) 2007 Marcus von Appen
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
#ifndef SURFACE_H
#define SURFACE_H
/* This is defined in SDL.h */
#if defined(_POSIX_C_SOURCE)
#undef _POSIX_C_SOURCE
#endif
#include <SDL.h>
#include "pygame.h"
/* Blend modes */
#define PYGAME_BLEND_ADD 0x1
#define PYGAME_BLEND_SUB 0x2
#define PYGAME_BLEND_MULT 0x3
#define PYGAME_BLEND_MIN 0x4
#define PYGAME_BLEND_MAX 0x5
#define PYGAME_BLEND_RGB_ADD 0x1
#define PYGAME_BLEND_RGB_SUB 0x2
#define PYGAME_BLEND_RGB_MULT 0x3
#define PYGAME_BLEND_RGB_MIN 0x4
#define PYGAME_BLEND_RGB_MAX 0x5
#define PYGAME_BLEND_RGBA_ADD 0x6
#define PYGAME_BLEND_RGBA_SUB 0x7
#define PYGAME_BLEND_RGBA_MULT 0x8
#define PYGAME_BLEND_RGBA_MIN 0x9
#define PYGAME_BLEND_RGBA_MAX 0x10
#define PYGAME_BLEND_PREMULTIPLIED 0x11
#define PYGAME_BLEND_ALPHA_SDL2 0x12
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define GET_PIXEL_24(b) (b[0] + (b[1] << 8) + (b[2] << 16))
#else
#define GET_PIXEL_24(b) (b[2] + (b[1] << 8) + (b[0] << 16))
#endif
#define GET_PIXEL(pxl, bpp, source) \
switch (bpp) { \
case 2: \
pxl = *((Uint16 *)(source)); \
break; \
case 4: \
pxl = *((Uint32 *)(source)); \
break; \
default: { \
Uint8 *b = (Uint8 *)source; \
pxl = GET_PIXEL_24(b); \
} break; \
}
#define GET_PIXELVALS(_sR, _sG, _sB, _sA, px, fmt, ppa) \
SDL_GetRGBA(px, fmt, &(_sR), &(_sG), &(_sB), &(_sA)); \
if (!ppa) { \
_sA = 255; \
}
#define GET_PIXELVALS_1(sr, sg, sb, sa, _src, _fmt) \
sr = _fmt->palette->colors[*((Uint8 *)(_src))].r; \
sg = _fmt->palette->colors[*((Uint8 *)(_src))].g; \
sb = _fmt->palette->colors[*((Uint8 *)(_src))].b; \
sa = 255;
/* For 1 byte palette pixels */
#define SET_PIXELVAL(px, fmt, _dR, _dG, _dB, _dA) \
*(px) = (Uint8)SDL_MapRGBA(fmt, _dR, _dG, _dB, _dA)
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#define SET_OFFSETS_24(or, og, ob, fmt) \
{ \
or = (fmt->Rshift == 0 ? 0 : fmt->Rshift == 8 ? 1 : 2); \
og = (fmt->Gshift == 0 ? 0 : fmt->Gshift == 8 ? 1 : 2); \
ob = (fmt->Bshift == 0 ? 0 : fmt->Bshift == 8 ? 1 : 2); \
}
#define SET_OFFSETS_32(or, og, ob, fmt) \
{ \
or = (fmt->Rshift == 0 ? 0 \
: fmt->Rshift == 8 ? 1 \
: fmt->Rshift == 16 ? 2 \
: 3); \
og = (fmt->Gshift == 0 ? 0 \
: fmt->Gshift == 8 ? 1 \
: fmt->Gshift == 16 ? 2 \
: 3); \
ob = (fmt->Bshift == 0 ? 0 \
: fmt->Bshift == 8 ? 1 \
: fmt->Bshift == 16 ? 2 \
: 3); \
}
#else
#define SET_OFFSETS_24(or, og, ob, fmt) \
{ \
or = (fmt->Rshift == 0 ? 2 : fmt->Rshift == 8 ? 1 : 0); \
og = (fmt->Gshift == 0 ? 2 : fmt->Gshift == 8 ? 1 : 0); \
ob = (fmt->Bshift == 0 ? 2 : fmt->Bshift == 8 ? 1 : 0); \
}
#define SET_OFFSETS_32(or, og, ob, fmt) \
{ \
or = (fmt->Rshift == 0 ? 3 \
: fmt->Rshift == 8 ? 2 \
: fmt->Rshift == 16 ? 1 \
: 0); \
og = (fmt->Gshift == 0 ? 3 \
: fmt->Gshift == 8 ? 2 \
: fmt->Gshift == 16 ? 1 \
: 0); \
ob = (fmt->Bshift == 0 ? 3 \
: fmt->Bshift == 8 ? 2 \
: fmt->Bshift == 16 ? 1 \
: 0); \
}
#endif
#define CREATE_PIXEL(buf, r, g, b, a, bp, ft) \
switch (bp) { \
case 2: \
*((Uint16 *)(buf)) = ((r >> ft->Rloss) << ft->Rshift) | \
((g >> ft->Gloss) << ft->Gshift) | \
((b >> ft->Bloss) << ft->Bshift) | \
((a >> ft->Aloss) << ft->Ashift); \
break; \
case 4: \
*((Uint32 *)(buf)) = ((r >> ft->Rloss) << ft->Rshift) | \
((g >> ft->Gloss) << ft->Gshift) | \
((b >> ft->Bloss) << ft->Bshift) | \
((a >> ft->Aloss) << ft->Ashift); \
break; \
}
/* Pretty good idea from Tom Duff :-). */
#define LOOP_UNROLLED4(code, n, width) \
n = (width + 3) / 4; \
switch (width & 3) { \
case 0: \
do { \
code; \
case 3: \
code; \
case 2: \
code; \
case 1: \
code; \
} while (--n > 0); \
}
/* Used in the srcbpp == dstbpp == 1 blend functions */
#define REPEAT_3(code) \
code; \
code; \
code;
#define REPEAT_4(code) \
code; \
code; \
code; \
code;
#define BLEND_ADD(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
tmp = dR + sR; \
dR = (tmp <= 255 ? tmp : 255); \
tmp = dG + sG; \
dG = (tmp <= 255 ? tmp : 255); \
tmp = dB + sB; \
dB = (tmp <= 255 ? tmp : 255);
#define BLEND_SUB(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
tmp = dR - sR; \
dR = (tmp >= 0 ? tmp : 0); \
tmp = dG - sG; \
dG = (tmp >= 0 ? tmp : 0); \
tmp = dB - sB; \
dB = (tmp >= 0 ? tmp : 0);
#define BLEND_MULT(sR, sG, sB, sA, dR, dG, dB, dA) \
dR = (dR && sR) ? ((dR * sR) + 255) >> 8 : 0; \
dG = (dG && sG) ? ((dG * sG) + 255) >> 8 : 0; \
dB = (dB && sB) ? ((dB * sB) + 255) >> 8 : 0;
#define BLEND_MIN(sR, sG, sB, sA, dR, dG, dB, dA) \
if (sR < dR) { \
dR = sR; \
} \
if (sG < dG) { \
dG = sG; \
} \
if (sB < dB) { \
dB = sB; \
}
#define BLEND_MAX(sR, sG, sB, sA, dR, dG, dB, dA) \
if (sR > dR) { \
dR = sR; \
} \
if (sG > dG) { \
dG = sG; \
} \
if (sB > dB) { \
dB = sB; \
}
#define BLEND_RGBA_ADD(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
tmp = dR + sR; \
dR = (tmp <= 255 ? tmp : 255); \
tmp = dG + sG; \
dG = (tmp <= 255 ? tmp : 255); \
tmp = dB + sB; \
dB = (tmp <= 255 ? tmp : 255); \
tmp = dA + sA; \
dA = (tmp <= 255 ? tmp : 255);
#define BLEND_RGBA_SUB(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
tmp = dR - sR; \
dR = (tmp >= 0 ? tmp : 0); \
tmp = dG - sG; \
dG = (tmp >= 0 ? tmp : 0); \
tmp = dB - sB; \
dB = (tmp >= 0 ? tmp : 0); \
tmp = dA - sA; \
dA = (tmp >= 0 ? tmp : 0);
#define BLEND_RGBA_MULT(sR, sG, sB, sA, dR, dG, dB, dA) \
dR = (dR && sR) ? ((dR * sR) + 255) >> 8 : 0; \
dG = (dG && sG) ? ((dG * sG) + 255) >> 8 : 0; \
dB = (dB && sB) ? ((dB * sB) + 255) >> 8 : 0; \
dA = (dA && sA) ? ((dA * sA) + 255) >> 8 : 0;
#define BLEND_RGBA_MIN(sR, sG, sB, sA, dR, dG, dB, dA) \
if (sR < dR) { \
dR = sR; \
} \
if (sG < dG) { \
dG = sG; \
} \
if (sB < dB) { \
dB = sB; \
} \
if (sA < dA) { \
dA = sA; \
}
#define BLEND_RGBA_MAX(sR, sG, sB, sA, dR, dG, dB, dA) \
if (sR > dR) { \
dR = sR; \
} \
if (sG > dG) { \
dG = sG; \
} \
if (sB > dB) { \
dB = sB; \
} \
if (sA > dA) { \
dA = sA; \
}
#if 1
/* Choose an alpha blend equation. If the sign is preserved on a right shift
* then use a specialized, faster, equation. Otherwise a more general form,
* where all additions are done before the shift, is needed.
*/
#if (-1 >> 1) < 0
#define ALPHA_BLEND_COMP(sC, dC, sA) ((((sC - dC) * sA + sC) >> 8) + dC)
#else
#define ALPHA_BLEND_COMP(sC, dC, sA) (((dC << 8) + (sC - dC) * sA + sC) >> 8)
#endif
#define ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB, dA) \
do { \
if (dA) { \
dR = ALPHA_BLEND_COMP(sR, dR, sA); \
dG = ALPHA_BLEND_COMP(sG, dG, sA); \
dB = ALPHA_BLEND_COMP(sB, dB, sA); \
dA = sA + dA - ((sA * dA) / 255); \
} \
else { \
dR = sR; \
dG = sG; \
dB = sB; \
dA = sA; \
} \
} while (0)
#define ALPHA_BLEND_PREMULTIPLIED_COMP(sC, dC, sA) \
(sC + dC - ((dC + 1) * sA >> 8))
#define ALPHA_BLEND_PREMULTIPLIED(tmp, sR, sG, sB, sA, dR, dG, dB, dA) \
do { \
dR = ALPHA_BLEND_PREMULTIPLIED_COMP(sR, dR, sA); \
dG = ALPHA_BLEND_PREMULTIPLIED_COMP(sG, dG, sA); \
dB = ALPHA_BLEND_PREMULTIPLIED_COMP(sB, dB, sA); \
dA = ALPHA_BLEND_PREMULTIPLIED_COMP(sA, dA, sA); \
} while (0)
#elif 0
#define ALPHA_BLEND(sR, sG, sB, sA, dR, dG, dB, dA) \
do { \
if (sA) { \
if (dA && sA < 255) { \
int dContrib = dA * (255 - sA) / 255; \
dA = sA + dA - ((sA * dA) / 255); \
dR = (dR * dContrib + sR * sA) / dA; \
dG = (dG * dContrib + sG * sA) / dA; \
dB = (dB * dContrib + sB * sA) / dA; \
} \
else { \
dR = sR; \
dG = sG; \
dB = sB; \
dA = sA; \
} \
} \
} while (0)
#endif
int
surface_fill_blend(SDL_Surface *surface, SDL_Rect *rect, Uint32 color,
int blendargs);
void
surface_respect_clip_rect(SDL_Surface *surface, SDL_Rect *rect);
int
pygame_AlphaBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect, int the_args);
int
pygame_Blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
SDL_Rect *dstrect, int the_args);
int
premul_surf_color_by_alpha(SDL_Surface *src, SDL_Surface *dst);
int
pg_warn_simd_at_runtime_but_uncompiled();
#endif /* SURFACE_H */