From a16dc3e7f958fc80c208e5653bd3e61da619466d Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 2 May 2023 14:09:45 +0100 Subject: [PATCH 01/20] beginning skew work --- buildconfig/stubs/pygame/transform.pyi | 2 + src_c/_sdl2/sdl2.c | 117 +++++++--- src_c/_sdl2/video.c | 72 ++++-- src_c/_sprite.c | 293 +++++++++++++++++-------- src_c/doc/transform_doc.h | 1 + src_c/transform.c | 249 +++++++++++++++++++++ 6 files changed, 592 insertions(+), 142 deletions(-) diff --git a/buildconfig/stubs/pygame/transform.pyi b/buildconfig/stubs/pygame/transform.pyi index 485fd0c263..f7f5b339a1 100644 --- a/buildconfig/stubs/pygame/transform.pyi +++ b/buildconfig/stubs/pygame/transform.pyi @@ -17,6 +17,8 @@ def scale_by( dest_surface: Optional[Surface] = None, ) -> Surface: ... def rotate(surface: Surface, angle: float) -> Surface: ... +def perspective(surface: Surface, x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, x4: int, y4: int,) -> Surface: ... +def skew(surface: Surface, x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, x4: int, y4: int,) -> Surface: ... def rotozoom(surface: Surface, angle: float, scale: float) -> Surface: ... def scale2x(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... def grayscale(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... diff --git a/src_c/_sdl2/sdl2.c b/src_c/_sdl2/sdl2.c index 42508e09e2..615a72a221 100644 --- a/src_c/_sdl2/sdl2.c +++ b/src_c/_sdl2/sdl2.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.29.30 */ +/* Generated by Cython 0.29.34 */ /* BEGIN: Cython Metadata { @@ -22,8 +22,8 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_29_30" -#define CYTHON_HEX_VERSION 0x001D1EF0 +#define CYTHON_ABI "0_29_34" +#define CYTHON_HEX_VERSION 0x001D22F0 #define CYTHON_FUTURE_DIVISION 0 #include #ifndef offsetof @@ -62,6 +62,7 @@ END: Cython Metadata */ #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_NOGIL 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 #undef CYTHON_USE_PYTYPE_LOOKUP @@ -99,12 +100,13 @@ END: Cython Metadata */ #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC - #define CYTHON_UPDATE_DESCRIPTOR_DOC (PYPY_VERSION_HEX >= 0x07030900) + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 #endif #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 1 #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_NOGIL 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif @@ -145,10 +147,56 @@ END: Cython Metadata */ #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 #endif +#elif defined(PY_NOGIL) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_NOGIL 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #ifndef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 1 + #define CYTHON_COMPILING_IN_NOGIL 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif @@ -168,7 +216,7 @@ END: Cython Metadata */ #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) - #define CYTHON_USE_PYLONG_INTERNALS 1 + #define CYTHON_USE_PYLONG_INTERNALS (PY_VERSION_HEX < 0x030C00A5) #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 @@ -207,7 +255,7 @@ END: Cython Metadata */ #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #define CYTHON_USE_DICT_VERSIONS ((PY_VERSION_HEX >= 0x030600B1) && (PY_VERSION_HEX < 0x030C00A5)) #endif #if PY_VERSION_HEX >= 0x030B00A4 #undef CYTHON_USE_EXC_INFO_STACK @@ -517,11 +565,11 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 - #if defined(PyUnicode_IS_READY) - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ - 0 : _PyUnicode_Ready((PyObject *)(op))) + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_READY(op) (0) #else - #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) #endif #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) @@ -530,14 +578,14 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) - #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) - #else - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) - #endif + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) #else - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif #endif #else #define CYTHON_PEP393_ENABLED 0 @@ -1105,18 +1153,18 @@ static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UIN /* GetModuleGlobalName.proto */ #if CYTHON_USE_DICT_VERSIONS -#define __Pyx_GetModuleGlobalName(var, name) {\ +#define __Pyx_GetModuleGlobalName(var, name) do {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ +} while(0) +#define __Pyx_GetModuleGlobalNameUncached(var, name) do {\ PY_UINT64_T __pyx_dict_version;\ PyObject *__pyx_dict_cached_value;\ (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} +} while(0) static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); #else #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) @@ -1848,7 +1896,7 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { } static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -2086,7 +2134,7 @@ if (!__Pyx_RefNanny) { Py_INCREF(__pyx_b); __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_cython_runtime); - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) @@ -2787,7 +2835,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { return __Pyx_PyFunction_FastCall(func, NULL, 0); } #endif -#ifdef __Pyx_CyFunction_USED +#if defined(__Pyx_CyFunction_USED) && defined(NDEBUG) if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) #else if (likely(PyCFunction_Check(func))) @@ -3002,13 +3050,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } PyErr_SetObject(type, value); if (tb) { -#if CYTHON_COMPILING_IN_PYPY - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); - Py_INCREF(tb); - PyErr_Restore(tmp_type, tmp_value, tb); - Py_XDECREF(tmp_tb); -#else +#if CYTHON_FAST_THREAD_STATE PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { @@ -3016,6 +3058,12 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); #endif } bad: @@ -3599,9 +3647,14 @@ static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, P self = PyTuple_GetItem(args, 0); if (unlikely(!self)) { Py_DECREF(new_args); +#if PY_MAJOR_VERSION > 2 PyErr_Format(PyExc_TypeError, "unbound method %.200S() needs an argument", cyfunc->func_qualname); +#else + PyErr_SetString(PyExc_TypeError, + "unbound method needs an argument"); +#endif return NULL; } result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); @@ -3795,7 +3848,7 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK -static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { +static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON diff --git a/src_c/_sdl2/video.c b/src_c/_sdl2/video.c index df0559c7ec..744a1bdfa5 100644 --- a/src_c/_sdl2/video.c +++ b/src_c/_sdl2/video.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.29.33 */ +/* Generated by Cython 0.29.34 */ /* BEGIN: Cython Metadata { @@ -22,8 +22,8 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_29_33" -#define CYTHON_HEX_VERSION 0x001D21F0 +#define CYTHON_ABI "0_29_34" +#define CYTHON_HEX_VERSION 0x001D22F0 #define CYTHON_FUTURE_DIVISION 1 #include #ifndef offsetof @@ -216,7 +216,7 @@ END: Cython Metadata */ #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) - #define CYTHON_USE_PYLONG_INTERNALS 1 + #define CYTHON_USE_PYLONG_INTERNALS (PY_VERSION_HEX < 0x030C00A5) #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 @@ -255,7 +255,7 @@ END: Cython Metadata */ #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #define CYTHON_USE_DICT_VERSIONS ((PY_VERSION_HEX >= 0x030600B1) && (PY_VERSION_HEX < 0x030C00A5)) #endif #if PY_VERSION_HEX >= 0x030B00A4 #undef CYTHON_USE_EXC_INFO_STACK @@ -1674,12 +1674,20 @@ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); /* TypeImport.proto */ #ifndef __PYX_HAVE_RT_ImportType_proto #define __PYX_HAVE_RT_ImportType_proto +#if __STDC_VERSION__ >= 201112L +#include +#endif +#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L +#define __PYX_GET_STRUCT_ALIGNMENT(s) alignof(s) +#else +#define __PYX_GET_STRUCT_ALIGNMENT(s) sizeof(void*) +#endif enum __Pyx_ImportType_CheckSize { __Pyx_ImportType_CheckSize_Error = 0, __Pyx_ImportType_CheckSize_Warn = 1, __Pyx_ImportType_CheckSize_Ignore = 2 }; -static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize check_size); #endif /* PyObject_GenericGetAttrNoDict.proto */ @@ -23940,9 +23948,11 @@ static int __Pyx_modinit_type_init_code(void) { /*--- Type init code ---*/ __pyx_t_1 = PyImport_ImportModule("pygame"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_6pygame_5_sdl2_5video_Color = __Pyx_ImportType(__pyx_t_1, "pygame", "Color", sizeof(pgColorObject), __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_6pygame_5_sdl2_5video_Color = __Pyx_ImportType(__pyx_t_1, "pygame", "Color", sizeof(pgColorObject), __PYX_GET_STRUCT_ALIGNMENT(pgColorObject), + __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_6pygame_5_sdl2_5video_Color) __PYX_ERR(2, 457, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_6pygame_5_sdl2_5video_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __PYX_GET_STRUCT_ALIGNMENT(pgRectObject), + __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_6pygame_5_sdl2_5video_Rect) __PYX_ERR(2, 461, __pyx_L1_error) if (PyType_Ready(&__pyx_type_6pygame_5_sdl2_5video_Window) < 0) __PYX_ERR(0, 192, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 @@ -24054,21 +24064,23 @@ static int __Pyx_modinit_type_import_code(void) { __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 - sizeof(PyTypeObject), + sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT(PyTypeObject), #else - sizeof(PyHeapTypeObject), + sizeof(PyHeapTypeObject), __PYX_GET_STRUCT_ALIGNMENT(PyHeapTypeObject), #endif __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __PYX_GET_STRUCT_ALIGNMENT(PyBoolObject), + __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(4, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __PYX_GET_STRUCT_ALIGNMENT(PyComplexObject), + __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(5, 15, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_RefNannyFinishContext(); @@ -25937,13 +25949,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } PyErr_SetObject(type, value); if (tb) { -#if CYTHON_COMPILING_IN_PYPY - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); - Py_INCREF(tb); - PyErr_Restore(tmp_type, tmp_value, tb); - Py_XDECREF(tmp_tb); -#else +#if CYTHON_FAST_THREAD_STATE PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { @@ -25951,6 +25957,12 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); #endif } bad: @@ -26993,13 +27005,15 @@ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, - size_t size, enum __Pyx_ImportType_CheckSize check_size) + size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize check_size) { PyObject *result = 0; char warning[200]; Py_ssize_t basicsize; + Py_ssize_t itemsize; #ifdef Py_LIMITED_API PyObject *py_basicsize; + PyObject *py_itemsize; #endif result = PyObject_GetAttrString(module, class_name); if (!result) @@ -27012,6 +27026,7 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, } #ifndef Py_LIMITED_API basicsize = ((PyTypeObject *)result)->tp_basicsize; + itemsize = ((PyTypeObject *)result)->tp_itemsize; #else py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); if (!py_basicsize) @@ -27021,8 +27036,23 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, py_basicsize = 0; if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) goto bad; + py_itemsize = PyObject_GetAttrString(result, "__itemsize__"); + if (!py_itemsize) + goto bad; + itemsize = PyLong_AsSsize_t(py_itemsize); + Py_DECREF(py_itemsize); + py_itemsize = 0; + if (itemsize == (Py_ssize_t)-1 && PyErr_Occurred()) + goto bad; #endif - if ((size_t)basicsize < size) { + if (itemsize) { + if (size % alignment) { + alignment = size % alignment; + } + if (itemsize < (Py_ssize_t)alignment) + itemsize = (Py_ssize_t)alignment; + } + if ((size_t)(basicsize + itemsize) < size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", diff --git a/src_c/_sprite.c b/src_c/_sprite.c index 68ae18cc03..f939ee7637 100644 --- a/src_c/_sprite.c +++ b/src_c/_sprite.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.29.30 */ +/* Generated by Cython 0.29.34 */ /* BEGIN: Cython Metadata { @@ -22,8 +22,8 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_29_30" -#define CYTHON_HEX_VERSION 0x001D1EF0 +#define CYTHON_ABI "0_29_34" +#define CYTHON_HEX_VERSION 0x001D22F0 #define CYTHON_FUTURE_DIVISION 1 #include #ifndef offsetof @@ -62,6 +62,7 @@ END: Cython Metadata */ #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_NOGIL 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 #undef CYTHON_USE_PYTYPE_LOOKUP @@ -99,12 +100,13 @@ END: Cython Metadata */ #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC - #define CYTHON_UPDATE_DESCRIPTOR_DOC (PYPY_VERSION_HEX >= 0x07030900) + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 #endif #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 1 #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_NOGIL 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif @@ -145,10 +147,56 @@ END: Cython Metadata */ #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 #endif +#elif defined(PY_NOGIL) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_NOGIL 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #ifndef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 1 + #define CYTHON_COMPILING_IN_NOGIL 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif @@ -168,7 +216,7 @@ END: Cython Metadata */ #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) - #define CYTHON_USE_PYLONG_INTERNALS 1 + #define CYTHON_USE_PYLONG_INTERNALS (PY_VERSION_HEX < 0x030C00A5) #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 @@ -207,7 +255,7 @@ END: Cython Metadata */ #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #define CYTHON_USE_DICT_VERSIONS ((PY_VERSION_HEX >= 0x030600B1) && (PY_VERSION_HEX < 0x030C00A5)) #endif #if PY_VERSION_HEX >= 0x030B00A4 #undef CYTHON_USE_EXC_INFO_STACK @@ -517,11 +565,11 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 - #if defined(PyUnicode_IS_READY) - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ - 0 : _PyUnicode_Ready((PyObject *)(op))) + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_READY(op) (0) #else - #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) #endif #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) @@ -530,14 +578,14 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) - #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) - #else - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) - #endif + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) #else - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif #endif #else #define CYTHON_PEP393_ENABLED 0 @@ -711,6 +759,37 @@ static CYTHON_INLINE float __PYX_NAN() { #include "pythread.h" #include "_pygame.h" #include "SDL.h" + + #if SDL_VERSION_ATLEAST(2, 0, 18) + typedef SDL_FPoint _pgsdlFPoint; + typedef SDL_Vertex _pgsdlVertex; + #else + typedef struct { + float x; + float y; + } _pgsdlFPoint; + + typedef struct { + _pgsdlFPoint position; + SDL_Color color; + _pgsdlFPoint tex_coord; + } _pgsdlVertex; + #endif + + #if SDL_VERSION_ATLEAST(2,0,12) + typedef SDL_ScaleMode _pgsdlScaleMode; + #else + typedef enum { + SDL_ScaleModeNearest, + SDL_ScaleModeLinear, + SDL_ScaleModeBest, + } _pgsdlScaleMode; + + int SDL_SetTextureScaleMode(SDL_Texture * texture, _pgsdlScaleMode scaleMode){ + return 0; + } + #endif + #include "pygame.h" #ifdef _OPENMP #include @@ -947,7 +1026,7 @@ struct __pyx_opt_args_6pygame_5_sdl2_5video_7Texture_draw_internal; struct __pyx_opt_args_6pygame_5_sdl2_5video_7Texture_draw; struct __pyx_opt_args_6pygame_5_sdl2_5video_5Image_draw; -/* "_sdl2/video.pxd":421 +/* "_sdl2/video.pxd":478 * * cpdef object get_viewport(self) * cpdef object blit(self, object source, Rect dest=*, Rect area=*, int special_flags=*) # <<<<<<<<<<<<<< @@ -961,7 +1040,7 @@ struct __pyx_opt_args_6pygame_5_sdl2_5video_8Renderer_blit { int special_flags; }; -/* "_sdl2/video.pxd":430 +/* "_sdl2/video.pxd":487 * cdef readonly int height * * cdef draw_internal(self, SDL_Rect *csrcrect, SDL_Rect *cdstrect, float angle=*, SDL_Point *originptr=*, # <<<<<<<<<<<<<< @@ -976,7 +1055,7 @@ struct __pyx_opt_args_6pygame_5_sdl2_5video_7Texture_draw_internal { int flip_y; }; -/* "_sdl2/video.pxd":432 +/* "_sdl2/video.pxd":489 * cdef draw_internal(self, SDL_Rect *csrcrect, SDL_Rect *cdstrect, float angle=*, SDL_Point *originptr=*, * bint flip_x=*, bint flip_y=*) * cpdef void draw(self, srcrect=*, dstrect=*, float angle=*, origin=*, # <<<<<<<<<<<<<< @@ -993,7 +1072,7 @@ struct __pyx_opt_args_6pygame_5_sdl2_5video_7Texture_draw { int flip_y; }; -/* "_sdl2/video.pxd":448 +/* "_sdl2/video.pxd":505 * cdef public Rect srcrect * * cpdef void draw(self, srcrect=*, dstrect=*) # <<<<<<<<<<<<<< @@ -1030,7 +1109,7 @@ struct __pyx_opt_args_6pygame_7_sprite_12LayeredDirty_add_internal { PyObject *layer; }; -/* "_sdl2/video.pxd":409 +/* "_sdl2/video.pxd":466 * * * cdef class Window: # <<<<<<<<<<<<<< @@ -1044,7 +1123,7 @@ struct __pyx_obj_6pygame_5_sdl2_5video_Window { }; -/* "_sdl2/video.pxd":413 +/* "_sdl2/video.pxd":470 * cdef int _is_borrowed * * cdef class Renderer: # <<<<<<<<<<<<<< @@ -1062,7 +1141,7 @@ struct __pyx_obj_6pygame_5_sdl2_5video_Renderer { }; -/* "_sdl2/video.pxd":423 +/* "_sdl2/video.pxd":480 * cpdef object blit(self, object source, Rect dest=*, Rect area=*, int special_flags=*) * * cdef class Texture: # <<<<<<<<<<<<<< @@ -1080,7 +1159,7 @@ struct __pyx_obj_6pygame_5_sdl2_5video_Texture { }; -/* "_sdl2/video.pxd":435 +/* "_sdl2/video.pxd":492 * bint flip_x=*, bint flip_y=*) * * cdef class Image: # <<<<<<<<<<<<<< @@ -1217,7 +1296,7 @@ struct __pyx_obj_6pygame_7_sprite_GroupSingle { -/* "_sdl2/video.pxd":413 +/* "_sdl2/video.pxd":470 * cdef int _is_borrowed * * cdef class Renderer: # <<<<<<<<<<<<<< @@ -1232,7 +1311,7 @@ struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Renderer { static struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Renderer *__pyx_vtabptr_6pygame_5_sdl2_5video_Renderer; -/* "_sdl2/video.pxd":423 +/* "_sdl2/video.pxd":480 * cpdef object blit(self, object source, Rect dest=*, Rect area=*, int special_flags=*) * * cdef class Texture: # <<<<<<<<<<<<<< @@ -1247,7 +1326,7 @@ struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Texture { static struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Texture *__pyx_vtabptr_6pygame_5_sdl2_5video_Texture; -/* "_sdl2/video.pxd":435 +/* "_sdl2/video.pxd":492 * bint flip_x=*, bint flip_y=*) * * cdef class Image: # <<<<<<<<<<<<<< @@ -1741,18 +1820,18 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice( /* GetModuleGlobalName.proto */ #if CYTHON_USE_DICT_VERSIONS -#define __Pyx_GetModuleGlobalName(var, name) {\ +#define __Pyx_GetModuleGlobalName(var, name) do {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} -#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ +} while(0) +#define __Pyx_GetModuleGlobalNameUncached(var, name) do {\ PY_UINT64_T __pyx_dict_version;\ PyObject *__pyx_dict_cached_value;\ (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} +} while(0) static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); #else #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) @@ -1906,12 +1985,20 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, /* TypeImport.proto */ #ifndef __PYX_HAVE_RT_ImportType_proto #define __PYX_HAVE_RT_ImportType_proto +#if __STDC_VERSION__ >= 201112L +#include +#endif +#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L +#define __PYX_GET_STRUCT_ALIGNMENT(s) alignof(s) +#else +#define __PYX_GET_STRUCT_ALIGNMENT(s) sizeof(void*) +#endif enum __Pyx_ImportType_CheckSize { __Pyx_ImportType_CheckSize_Error = 0, __Pyx_ImportType_CheckSize_Warn = 1, __Pyx_ImportType_CheckSize_Ignore = 2 }; -static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize check_size); #endif /* PyObject_GenericGetAttrNoDict.proto */ @@ -4173,7 +4260,7 @@ static int __pyx_pf_6pygame_7_sprite_6Sprite_3__g_2__set__(struct __pyx_obj_6pyg const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 142, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 142, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -5373,7 +5460,7 @@ static PyObject *__pyx_f_6pygame_7_sprite_13AbstractGroup_sprites(struct __pyx_o if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 336, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 336, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 336, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -9054,7 +9141,7 @@ static int __pyx_pf_6pygame_7_sprite_13AbstractGroup_10spritedict_2__set__(struc const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 329, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 329, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -9162,7 +9249,7 @@ static int __pyx_pf_6pygame_7_sprite_13AbstractGroup_11lostsprites_2__set__(stru const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 330, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 330, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -10272,7 +10359,7 @@ static PyObject *__pyx_f_6pygame_7_sprite_14OrderedUpdates_sprites(struct __pyx_ if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 650, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 650, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 650, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10728,7 +10815,7 @@ static int __pyx_pf_6pygame_7_sprite_14OrderedUpdates_11_spritelist_2__set__(str const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 644, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 644, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -12637,7 +12724,7 @@ static PyObject *__pyx_f_6pygame_7_sprite_14LayeredUpdates_sprites(struct __pyx_ if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 799, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 799, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 799, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -15243,7 +15330,7 @@ static int __pyx_pf_6pygame_7_sprite_14LayeredUpdates_13_spritelayers_2__set__(s const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 674, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 674, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -15351,7 +15438,7 @@ static int __pyx_pf_6pygame_7_sprite_14LayeredUpdates_11_spritelist_2__set__(str const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 675, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 675, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -20057,7 +20144,7 @@ static PyObject *__pyx_f_6pygame_7_sprite_11GroupSingle_sprites(struct __pyx_obj if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1330, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 1330, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 1330, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -27094,7 +27181,7 @@ static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { __pyx_umethod_PyDict_Type_pop.type = (PyObject*)&PyDict_Type; __pyx_umethod_PyDict_Type_values.type = (PyObject*)&PyDict_Type; __pyx_umethod_PyList_Type_remove.type = (PyObject*)&PyList_Type; - if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_float_0_5 = PyFloat_FromDouble(0.5); if (unlikely(!__pyx_float_0_5)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) @@ -27147,7 +27234,8 @@ static int __Pyx_modinit_type_init_code(void) { /*--- Type init code ---*/ __pyx_t_1 = PyImport_ImportModule("pygame"); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_6pygame_7_sprite_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_6pygame_7_sprite_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __PYX_GET_STRUCT_ALIGNMENT(pgRectObject), + __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_6pygame_7_sprite_Rect) __PYX_ERR(0, 116, __pyx_L1_error) __pyx_vtabptr_6pygame_7_sprite_AbstractGroup = &__pyx_vtable_6pygame_7_sprite_AbstractGroup; __pyx_vtable_6pygame_7_sprite_AbstractGroup.sprites = (PyObject *(*)(struct __pyx_obj_6pygame_7_sprite_AbstractGroup *, int __pyx_skip_dispatch))__pyx_f_6pygame_7_sprite_13AbstractGroup_sprites; @@ -27325,42 +27413,50 @@ static int __Pyx_modinit_type_import_code(void) { __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 - sizeof(PyTypeObject), + sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT(PyTypeObject), #else - sizeof(PyHeapTypeObject), + sizeof(PyHeapTypeObject), __PYX_GET_STRUCT_ALIGNMENT(PyHeapTypeObject), #endif __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(2, 9, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __PYX_GET_STRUCT_ALIGNMENT(PyBoolObject), + __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(3, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __PYX_GET_STRUCT_ALIGNMENT(PyComplexObject), + __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(4, 15, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyImport_ImportModule("pygame"); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 400, __pyx_L1_error) + __pyx_t_1 = PyImport_ImportModule("pygame"); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_6pygame_5_sdl2_5video_Color = __Pyx_ImportType(__pyx_t_1, "pygame", "Color", sizeof(pgColorObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Color) __PYX_ERR(5, 400, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Rect) __PYX_ERR(5, 404, __pyx_L1_error) - __pyx_t_2 = PyImport_ImportModule("pygame._sdl2.video"); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 409, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Color = __Pyx_ImportType(__pyx_t_1, "pygame", "Color", sizeof(pgColorObject), __PYX_GET_STRUCT_ALIGNMENT(pgColorObject), + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Color) __PYX_ERR(5, 457, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __PYX_GET_STRUCT_ALIGNMENT(pgRectObject), + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Rect) __PYX_ERR(5, 461, __pyx_L1_error) + __pyx_t_2 = PyImport_ImportModule("pygame._sdl2.video"); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 466, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_ptype_6pygame_5_sdl2_5video_Window = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Window", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Window), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Window) __PYX_ERR(5, 409, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Renderer = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Renderer", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Renderer), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Renderer) __PYX_ERR(5, 413, __pyx_L1_error) - __pyx_vtabptr_6pygame_5_sdl2_5video_Renderer = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Renderer*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Renderer->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Renderer)) __PYX_ERR(5, 413, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Texture = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Texture", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Texture), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Texture) __PYX_ERR(5, 423, __pyx_L1_error) - __pyx_vtabptr_6pygame_5_sdl2_5video_Texture = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Texture*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Texture->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Texture)) __PYX_ERR(5, 423, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Image = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Image", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Image), __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Image) __PYX_ERR(5, 435, __pyx_L1_error) - __pyx_vtabptr_6pygame_5_sdl2_5video_Image = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Image*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Image->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Image)) __PYX_ERR(5, 435, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Window = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Window", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Window), __PYX_GET_STRUCT_ALIGNMENT(struct __pyx_obj_6pygame_5_sdl2_5video_Window), + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Window) __PYX_ERR(5, 466, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Renderer = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Renderer", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Renderer), __PYX_GET_STRUCT_ALIGNMENT(struct __pyx_obj_6pygame_5_sdl2_5video_Renderer), + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Renderer) __PYX_ERR(5, 470, __pyx_L1_error) + __pyx_vtabptr_6pygame_5_sdl2_5video_Renderer = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Renderer*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Renderer->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Renderer)) __PYX_ERR(5, 470, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Texture = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Texture", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Texture), __PYX_GET_STRUCT_ALIGNMENT(struct __pyx_obj_6pygame_5_sdl2_5video_Texture), + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Texture) __PYX_ERR(5, 480, __pyx_L1_error) + __pyx_vtabptr_6pygame_5_sdl2_5video_Texture = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Texture*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Texture->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Texture)) __PYX_ERR(5, 480, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Image = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Image", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Image), __PYX_GET_STRUCT_ALIGNMENT(struct __pyx_obj_6pygame_5_sdl2_5video_Image), + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Image) __PYX_ERR(5, 492, __pyx_L1_error) + __pyx_vtabptr_6pygame_5_sdl2_5video_Image = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Image*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Image->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Image)) __PYX_ERR(5, 492, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_RefNannyFinishContext(); @@ -27564,7 +27660,7 @@ if (!__Pyx_RefNanny) { Py_INCREF(__pyx_b); __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_cython_runtime); - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) @@ -28158,7 +28254,7 @@ if (!__Pyx_RefNanny) { __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pygame/_sprite.pyx":1 - * ## pygame - Python Game Library # <<<<<<<<<<<<<< + * ## pygame-ce - Python Game Library # <<<<<<<<<<<<<< * ## Copyright (C) 2000-2003, 2007 Pete Shinners * ## (C) 2004 Joe Wreschnig */ @@ -28651,9 +28747,7 @@ static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, PyGILState_STATE state; if (nogil) state = PyGILState_Ensure(); -#ifdef _MSC_VER - else state = (PyGILState_STATE)-1; -#endif + else state = (PyGILState_STATE)0; #endif __Pyx_PyThreadState_assign __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); @@ -28725,7 +28819,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { return __Pyx_PyFunction_FastCall(func, NULL, 0); } #endif -#ifdef __Pyx_CyFunction_USED +#if defined(__Pyx_CyFunction_USED) && defined(NDEBUG) if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) #else if (likely(PyCFunction_Check(func))) @@ -28870,10 +28964,8 @@ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { Py_DECREF(retval); __Pyx_RaiseTooManyValuesError(expected); return -1; - } else { - return __Pyx_IterFinish(); } - return 0; + return __Pyx_IterFinish(); } /* RaiseNoneIterError */ @@ -29207,13 +29299,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } PyErr_SetObject(type, value); if (tb) { -#if CYTHON_COMPILING_IN_PYPY - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); - Py_INCREF(tb); - PyErr_Restore(tmp_type, tmp_value, tb); - Py_XDECREF(tmp_tb); -#else +#if CYTHON_FAST_THREAD_STATE PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { @@ -29221,6 +29307,12 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); #endif } bad: @@ -29714,11 +29806,11 @@ static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* if (flag == METH_O) { return (*(cfunc->func))(self, arg); } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) { - if (PY_VERSION_HEX >= 0x030700A0) { + #if PY_VERSION_HEX >= 0x030700A0 return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1); - } else { + #else return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL); - } + #endif } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) { return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL); } @@ -30200,7 +30292,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, /* ObjectGetItem */ #if CYTHON_USE_TYPE_SLOTS static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { - PyObject *runerr; + PyObject *runerr = NULL; Py_ssize_t key_value; PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence; if (unlikely(!(m && m->sq_item))) { @@ -30611,13 +30703,15 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, - size_t size, enum __Pyx_ImportType_CheckSize check_size) + size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize check_size) { PyObject *result = 0; char warning[200]; Py_ssize_t basicsize; + Py_ssize_t itemsize; #ifdef Py_LIMITED_API PyObject *py_basicsize; + PyObject *py_itemsize; #endif result = PyObject_GetAttrString(module, class_name); if (!result) @@ -30630,6 +30724,7 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, } #ifndef Py_LIMITED_API basicsize = ((PyTypeObject *)result)->tp_basicsize; + itemsize = ((PyTypeObject *)result)->tp_itemsize; #else py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); if (!py_basicsize) @@ -30639,8 +30734,23 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, py_basicsize = 0; if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) goto bad; + py_itemsize = PyObject_GetAttrString(result, "__itemsize__"); + if (!py_itemsize) + goto bad; + itemsize = PyLong_AsSsize_t(py_itemsize); + Py_DECREF(py_itemsize); + py_itemsize = 0; + if (itemsize == (Py_ssize_t)-1 && PyErr_Occurred()) + goto bad; #endif - if ((size_t)basicsize < size) { + if (itemsize) { + if (size % alignment) { + alignment = size % alignment; + } + if (itemsize < (Py_ssize_t)alignment) + itemsize = (Py_ssize_t)alignment; + } + if ((size_t)(basicsize + itemsize) < size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", @@ -31497,9 +31607,14 @@ static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, P self = PyTuple_GetItem(args, 0); if (unlikely(!self)) { Py_DECREF(new_args); +#if PY_MAJOR_VERSION > 2 PyErr_Format(PyExc_TypeError, "unbound method %.200S() needs an argument", cyfunc->func_qualname); +#else + PyErr_SetString(PyExc_TypeError, + "unbound method needs an argument"); +#endif return NULL; } result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); @@ -31752,7 +31867,7 @@ static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) { /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK -static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { +static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON diff --git a/src_c/doc/transform_doc.h b/src_c/doc/transform_doc.h index 04effd9d92..321db457b5 100644 --- a/src_c/doc/transform_doc.h +++ b/src_c/doc/transform_doc.h @@ -4,6 +4,7 @@ #define DOC_TRANSFORM_SCALE "scale(surface, size, dest_surface=None) -> Surface\nresize to new resolution" #define DOC_TRANSFORM_SCALEBY "scale_by(surface, factor, dest_surface=None) -> Surface\nresize to new resolution, using scalar(s)" #define DOC_TRANSFORM_ROTATE "rotate(surface, angle) -> Surface\nrotate an image" +#define DOC_TRANSFORM_SKEW "skew(surface, points) -> skew wow!!!" #define DOC_TRANSFORM_ROTOZOOM "rotozoom(surface, angle, scale) -> Surface\nfiltered scale and rotation" #define DOC_TRANSFORM_SCALE2X "scale2x(surface, dest_surface=None) -> Surface\nspecialized image doubler" #define DOC_TRANSFORM_SMOOTHSCALE "smoothscale(surface, size, dest_surface=None) -> Surface\nscale a surface to an arbitrary size smoothly" diff --git a/src_c/transform.c b/src_c/transform.c index c251f55130..b5580899f4 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -407,6 +407,168 @@ rotate(SDL_Surface *src, SDL_Surface *dst, Uint32 bgcolor, double sangle, } } + +static void +skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point* dst) +{ + int dx, dy, dx1, dx2, dy1, dy2, leftx, rightx, bottomy, topy, x1, x2, y1, y2, i1, i2, diffx, diffy, err, err1, err2, e, e1, e2, sx1, sx2, sx, sy1, sy2, sy; + float scale_x, scale_y, y_length; + // Necessitates at least two parallel sides + + SDL_Point srcpoint[4] = { {0, 0}, {src->w, 0}, {src->w, src->h}, {0, src->h} }; + + // sort points to top left, top right, bot right, bot left, + // Assume sorted due to + // bias to toppest + + //check all points are in dest surface & parallel requirement + // quicker axis aligned skew option ? + printf("im here\n"); + dx1 = dst[1].x - dst[0].x; + dx2 = dst[2].x - dst[3].x; + + dy1 = dst[1].y - dst[0].y; + dy2 = dst[2].y - dst[3].y; + + leftx = dst[0].x - dst[3].x; + rightx = dst[1].x - dst[2].x; + + topy = dst[1].y - dst[0].y; + bottomy = dst[2].y - dst[3].y; + + diffx = dst[1].x - dst[0].x; + diffy = dst[1].y - dst[0].y; + printf("%d\n", leftx); + printf("%d\n", rightx); + printf("w%d\n", new_surf->w); + printf("h%d\n", new_surf->h); + + SDL_Point* start_points = (SDL_Point*) malloc(diffx * sizeof(SDL_Point)); + SDL_Point* end_points = (SDL_Point*) malloc(diffx * sizeof(SDL_Point)); + if (leftx != rightx && topy != bottomy) { + // not aligned, raise error + ; + } + + if (leftx == 0 || topy == 0) { + // quicker version + ; + } + + // need actual gradient checker + if (1) { + // mark by x change to ensure equality + x1 = dst[0].x; + y1 = dst[1].y; + x2 = dst[3].x; + y2 = dst[3].y; + i1 = 0; + i2 = 0; + // initialize top line vars + dx1 = abs(dst[1].x - dst[0].x); + dy1 = -abs(dst[1].y - dst[0].y); + sx1 = dst[1].x > dst[0].x ? 1 : -1; + sy1 = dst[1].y > dst[0].y ? 1 : -1; + err1 = dx1 + dy1; + + // initialize bottom line vars + dx2 = dx1; + dy2 = -abs(dst[2].y - dst[3].y); + sx2 = sx1; + sy2 = dst[2].y > dst[3].y ? 1 : -1; + err2 = dx2 + dy2; + + // Starting values before iteration + SDL_Point p; + p.x = x1; + p.y = y1; + start_points[i1++] = p; + p.x = x2; + p.y = y2; + end_points[i2++] = p; + + while (x1 != dst[1].x + 1 && x2 != dst[2].x) { + // x1 y1 start + e1 = err1 * 2; + e2 = err2 * 2; + if (e1 >= dy1) { + err1 += dy1; + x1 += sx1; + SDL_Point p; + p.x = x1; + p.y = y1; + start_points[i1++] = p; + } + if (e1 <= dx1) { + err1 += dx1; + y1 += sy1; + if (start_points[i1].y > y1) { + start_points[i1].y = y1; + } + } + if (e2 >= dy2) { + err2 += dy2; + x2 += sx2; + SDL_Point p; + p.x = x2; + p.y = y2; + end_points[i2++] = p; + } + if (e2 <= dx2) { + err2 += dx2; + y2 += sy2; + if (end_points[i2].y < y2) { + end_points[i2].y = y2; + } + } + } + + // record top bottom starting y/x values + // draw fill poly method + // top length / bottom length times bottom length times from y top over y length at point + // can get y length from diff between /=/ / + + // prob worked + + // scale x by diffx / w ??? + + Uint8* src_pixels = (Uint8*) src->pixels; + Uint8* dst_pixels = (Uint8*) new_surf->pixels; + + scale_x = src->w / (float) diffx; + for(int i = 0; i < diffx; i++) { + x1 = start_points[i].x; + y1 = start_points[i].y; + x2 = end_points[i].x; + y2 = end_points[i].y; + y_length = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2)); + scale_y = src->h / y_length; + dx = abs(x2 - x1); + dy = -abs(y2 - y1); + sx = x2 > x1 ? 1 : -1; + sy = y2 > y1 ? 1 : -1; + err = dx + dy; + while (y1 <= y2 || x1 != x2) { + //Nearest neighbor + scale_x = src->w / (diffx + ((sqrt(pow((x1 - start_points[i].x), 2) + pow((y1 - start_points[i].y), 2))) / y_length) * ((dst[2].x - dst[3].x) - diffx)); + *((Uint32 *)(dst_pixels +(int)(y1 * new_surf->pitch + x1 * new_surf->format->BytesPerPixel))) = *((Uint32 *)(src_pixels +(int)((int)((y1 - start_points[i].y) * scale_y) * src->pitch + (int)(i * scale_x) * src->format->BytesPerPixel))); + + e = err * 2; + if (e >= dy) { + err += dy; + x1 += sx; + } + if (e <= dx) { + err += dx; + y1 += sy; + } + } + } + + } + printf("wow"); +} + static SDL_Surface * scale_to(pgSurfaceObject *srcobj, pgSurfaceObject *dstobj, int width, int height) @@ -682,6 +844,91 @@ surf_rotate(PyObject *self, PyObject *args, PyObject *kwargs) return (PyObject *)pgSurface_New(newsurf); } + +static PyObject * +surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) +{ + pgSurfaceObject *surfobj; + SDL_Surface *surf, *newsurf; + + int x1, y1, x2, y2, x3, y3, x4, y4; + double x, y, cx, cy, sx, sy; + int start, width, top, height; + int nxmax, nymax; + Uint32 bgcolor; + static char *keywords[] = {"surface", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!iiiiiiii", keywords, + &pgSurface_Type, &surfobj, &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) + return NULL; + surf = pgSurface_AsSurface(surfobj); + SURF_INIT_CHECK(surf) + + if (surf->w < 1 || surf->h < 1) { + Py_INCREF(surfobj); + return (PyObject *)surfobj; + } + + if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) + return RAISE(PyExc_ValueError, + "unsupported Surface bit depth for transform"); + start = MIN(MIN(x1, x2), MIN(x3, x4)); + width = MAX(MAX(x1, x2), MAX(x3, x4)) - start; + top = MIN(MIN(y1, y2), MIN(y3, y4)); + height = MAX(MAX(y1, y2), MAX(y3, y4)) - top; + printf("we made it"); + newsurf = SDL_CreateRGBSurfaceWithFormat(0, surf->w, surf->h, 32, surf->format->format); + printf("%d\n", newsurf->w); + printf("%d\n", surf->w); + + if (!newsurf) + return NULL; + + /* get the background color */ + if (SDL_GetColorKey(surf, &bgcolor) != 0) { + SDL_LockSurface(surf); + switch (surf->format->BytesPerPixel) { + case 1: + bgcolor = *(Uint8 *)surf->pixels; + break; + case 2: + bgcolor = *(Uint16 *)surf->pixels; + break; + case 4: + bgcolor = *(Uint32 *)surf->pixels; + break; + default: /*case 3:*/ +#if SDL_BYTEORDER == SDL_LIL_ENDIAN + bgcolor = (((Uint8 *)surf->pixels)[0]) + + (((Uint8 *)surf->pixels)[1] << 8) + + (((Uint8 *)surf->pixels)[2] << 16); +#else + bgcolor = (((Uint8 *)surf->pixels)[2]) + + (((Uint8 *)surf->pixels)[1] << 8) + + (((Uint8 *)surf->pixels)[0] << 16); +#endif + } + SDL_UnlockSurface(surf); + bgcolor &= ~surf->format->Amask; + } + + SDL_LockSurface(newsurf); + SDL_LockSurface(surf); + pgSurface_Lock(surfobj); + SDL_Point points[4] = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}; + Py_BEGIN_ALLOW_THREADS; + printf("helop\n"); + + skew(surf, newsurf, bgcolor, points); + Py_END_ALLOW_THREADS; + pgSurface_Unlock(surfobj); + SDL_UnlockSurface(newsurf); + SDL_UnlockSurface(surf); + + + return (PyObject *)pgSurface_New(newsurf); +} + static PyObject * surf_flip(PyObject *self, PyObject *args, PyObject *kwargs) { @@ -3324,6 +3571,8 @@ static PyMethodDef _transform_methods[] = { DOC_TRANSFORM_SCALEBY}, {"rotate", (PyCFunction)surf_rotate, METH_VARARGS | METH_KEYWORDS, DOC_TRANSFORM_ROTATE}, + {"skew", (PyCFunction)surf_skew, METH_VARARGS | METH_KEYWORDS, + DOC_TRANSFORM_SKEW}, {"flip", (PyCFunction)surf_flip, METH_VARARGS | METH_KEYWORDS, DOC_TRANSFORM_FLIP}, {"rotozoom", (PyCFunction)surf_rotozoom, METH_VARARGS | METH_KEYWORDS, From f0e013f9f19f953cf0aae2c2ca90d0c220148118 Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Wed, 3 May 2023 12:33:43 +0100 Subject: [PATCH 02/20] further developments --- src_c/transform.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/src_c/transform.c b/src_c/transform.c index b5580899f4..a69e98f7d5 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -459,7 +459,7 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point* dst) if (1) { // mark by x change to ensure equality x1 = dst[0].x; - y1 = dst[1].y; + y1 = dst[0].y; x2 = dst[3].x; y2 = dst[3].y; i1 = 0; @@ -527,13 +527,75 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point* dst) // draw fill poly method // top length / bottom length times bottom length times from y top over y length at point // can get y length from diff between /=/ / + // actually use side length since we know that sides will be parallel thus there can be a known scaling + // but how to work out equivalent start points ????? + // gradient is consistent parallel to vertical lines + // this is the key + // prob worked // scale x by diffx / w ??? + // can get dist from top of left points list to bottom of list + SDL_Point* left_points = (SDL_Point*) malloc((dst[0].y - dst[3].y) * sizeof(SDL_Point)); + // take how far down the y axis point by looking at how far down relative to y line is + // line to get to its equivalent left point which can thus get the point of the right side, giving the y_scale factor needed + + x1 = dst[0].x; + y1 = dst[0].y; + x2 = dst[3].x; + y2 = dst[3].y; + i1 = 0; + // initialize top line vars + dx1 = abs(dst[3].x - dst[0].x); + dy1 = -abs(dst[3].y - dst[0].y); + sx1 = dst[3].x > dst[0].x ? 1 : -1; + sy1 = dst[3].y > dst[0].y ? 1 : -1; + err1 = dx1 + dy1; + + SDL_Point p; + p.x = x1; + p.y = y1; + left_points[i1++] = p; + + while (x1 != dst[3].x && y1 != dst[3].y) { + // x1 y1 start + e1 = err1 * 2; + if (e1 >= dy1) { + err1 += dy1; + x1 += sx1; + if (left_points[i1].x < x1) { + left_points[i1].x = x1; + } + } + if (e1 <= dx1) { + err1 += dx1; + y1 += sy1; + SDL_Point p; + p.x = x1; + p.y = y1; + left_points[i1++] = p; + + } + } + Uint8* src_pixels = (Uint8*) src->pixels; Uint8* dst_pixels = (Uint8*) new_surf->pixels; + bottom = 0; + top = diffy - 1; + while (true) { + vertical_length = sqrt(pow(left_points[top].x - left_points[bottom].x, 2) + pow(left_points[top].y - left_points[bottom].y, 2)); + for (int i = bottom; i<= top; i++) { + scale_y = sqrt(pow(left_points[i].x - left_points[bottom].x, 2) + pow(left_points[i].y - left_points[bottom].y, 2)) / vertical_length; + y = scale_y * src->h; + leftp = SDL_Point p; + leftp.x = scale_y * (dst[3].x - dst[0].x) + dst[0].x; + leftp.y = scale_y * (dst[3].y - dst[0].y) + dst[0].y; + rightp.x = scale_y * (dst[2].x - dst[1].x) + dst[1].x; + rightp.y = scale_y * (dst[2].y - dst[1].y) + dst[1].y; + } + } scale_x = src->w / (float) diffx; for(int i = 0; i < diffx; i++) { @@ -566,6 +628,9 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point* dst) } } + free(start_points); + free(end_points); + free(left_points); printf("wow"); } From 64aad78fe9bebd58e00500318bad84406f86a43e Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Thu, 4 May 2023 12:19:05 +0100 Subject: [PATCH 03/20] adapted algorithm to handle all quad cases --- src_c/transform.c | 254 ++++++++++++---------------------------------- 1 file changed, 64 insertions(+), 190 deletions(-) diff --git a/src_c/transform.c b/src_c/transform.c index a69e98f7d5..b9b12d38bf 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -411,227 +411,105 @@ rotate(SDL_Surface *src, SDL_Surface *dst, Uint32 bgcolor, double sangle, static void skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point* dst) { - int dx, dy, dx1, dx2, dy1, dy2, leftx, rightx, bottomy, topy, x1, x2, y1, y2, i1, i2, diffx, diffy, err, err1, err2, e, e1, e2, sx1, sx2, sx, sy1, sy2, sy; - float scale_x, scale_y, y_length; - // Necessitates at least two parallel sides + int dx1, dx2, dy1, dy2, leftx, rightx, bottomy, topy, x1, x2, y1, y2, diffx, diffy, err1, err2, e1, e2, sx1, sx2, sy1, sy2; + int end_x, end_y; + SDL_Point start, end, smallstart, smallend; + float scale_x, scale_y, end_scale, width, small_length, long_length; SDL_Point srcpoint[4] = { {0, 0}, {src->w, 0}, {src->w, src->h}, {0, src->h} }; - // sort points to top left, top right, bot right, bot left, - // Assume sorted due to - // bias to toppest //check all points are in dest surface & parallel requirement // quicker axis aligned skew option ? - printf("im here\n"); - dx1 = dst[1].x - dst[0].x; - dx2 = dst[2].x - dst[3].x; - - dy1 = dst[1].y - dst[0].y; - dy2 = dst[2].y - dst[3].y; leftx = dst[0].x - dst[3].x; rightx = dst[1].x - dst[2].x; - topy = dst[1].y - dst[0].y; - bottomy = dst[2].y - dst[3].y; - - diffx = dst[1].x - dst[0].x; - diffy = dst[1].y - dst[0].y; - printf("%d\n", leftx); - printf("%d\n", rightx); - printf("w%d\n", new_surf->w); - printf("h%d\n", new_surf->h); - - SDL_Point* start_points = (SDL_Point*) malloc(diffx * sizeof(SDL_Point)); - SDL_Point* end_points = (SDL_Point*) malloc(diffx * sizeof(SDL_Point)); - if (leftx != rightx && topy != bottomy) { - // not aligned, raise error - ; - } - if (leftx == 0 || topy == 0) { - // quicker version + // use quicker axis aligned version ; } - // need actual gradient checker + if (sqrt(pow(dst[2].x - dst[1].x, 2) + pow(dst[2].y - dst[1].y, 2)) > sqrt(pow(dst[3].x - dst[0].x, 2) + pow(dst[3].y - dst[0].y, 2))){ + start = dst[1]; + end = dst[2]; + smallstart = dst[0]; + smallend = dst[3]; + } + else { + start = dst[0]; + end = dst[3]; + smallstart = dst[1]; + smallend = dst[2]; + } + + small_length = sqrt(pow(smallend.x - smallstart.x, 2) + pow(smallend.y - smallstart.y, 2)); + long_length = sqrt(pow(end.x - start.x, 2) + pow(end.y - start.y, 2)); if (1) { - // mark by x change to ensure equality - x1 = dst[0].x; - y1 = dst[0].y; - x2 = dst[3].x; - y2 = dst[3].y; - i1 = 0; - i2 = 0; - // initialize top line vars - dx1 = abs(dst[1].x - dst[0].x); - dy1 = -abs(dst[1].y - dst[0].y); - sx1 = dst[1].x > dst[0].x ? 1 : -1; - sy1 = dst[1].y > dst[0].y ? 1 : -1; + x1 = start.x; + y1 = start.y; + + dx1 = abs(end.x - start.x); + dy1 = -abs(end.y - start.y); + sx1 = end.x > start.x ? 1 : -1; + sy1 = end.y > start.y ? 1 : -1; err1 = dx1 + dy1; - // initialize bottom line vars - dx2 = dx1; - dy2 = -abs(dst[2].y - dst[3].y); - sx2 = sx1; - sy2 = dst[2].y > dst[3].y ? 1 : -1; - err2 = dx2 + dy2; - - // Starting values before iteration - SDL_Point p; - p.x = x1; - p.y = y1; - start_points[i1++] = p; - p.x = x2; - p.y = y2; - end_points[i2++] = p; - - while (x1 != dst[1].x + 1 && x2 != dst[2].x) { - // x1 y1 start - e1 = err1 * 2; - e2 = err2 * 2; - if (e1 >= dy1) { - err1 += dy1; - x1 += sx1; - SDL_Point p; - p.x = x1; - p.y = y1; - start_points[i1++] = p; - } - if (e1 <= dx1) { - err1 += dx1; - y1 += sy1; - if (start_points[i1].y > y1) { - start_points[i1].y = y1; - } + Uint8* src_pixels = (Uint8*) src->pixels; + Uint8* dst_pixels = (Uint8*) new_surf->pixels; + + while (x1 != end.x || y1 != end.y) { + x2 = x1; + y2 = y1; + end_scale = sqrt(pow(x1 - start.x, 2) + pow(y1 - start.y, 2)) / long_length; + scale_y = end_scale * src->h; + if (start.x == dst[0].x) { + end_x = (smallend.x - smallstart.x) * end_scale + smallstart.x; + end_y = (smallend.y - smallstart.y) * end_scale + smallstart.y; } - if (e2 >= dy2) { - err2 += dy2; - x2 += sx2; - SDL_Point p; - p.x = x2; - p.y = y2; - end_points[i2++] = p; + else { + end_x = round((smallend.x - smallstart.x) * end_scale) + smallstart.x; + end_y = round((smallend.y - smallstart.y) * end_scale) + smallstart.y; } - if (e2 <= dx2) { - err2 += dx2; - y2 += sy2; - if (end_points[i2].y < y2) { - end_points[i2].y = y2; + + width = sqrt(pow(end_x - x1, 2) + pow(end_y - y1, 2)); + dx2 = abs(end_x - x1); + dy2 = -abs(end_y - y1); + sx2 = end_x > x1 ? 1: -1; + sy2 = end_y > y1 ? 1 : -1; + err2 = dx2 + dy2; + while (x2 != end_x || y2 != end_y) { + // Using Nearest neighbor + scale_x = src->w * sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) / width; + *((Uint32 *)(dst_pixels +(int)(y2 * new_surf->pitch + x2 * new_surf->format->BytesPerPixel))) = *((Uint32 *)(src_pixels +(int)((int)(scale_y) * src->pitch + (int)(scale_x) * src->format->BytesPerPixel))); + e2 = err2 * 2; + if (e2 >= dy2) { + err2 += dy2; + x2 += sx2; + } + if (e2 <= dx2) { + err2 += dx2; + // extra assign for when y2 changes at the same time as x1 changes to prevent missing pixels + scale_x = src->w * sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) / width; + *((Uint32 *)(dst_pixels +(int)(y2 * new_surf->pitch + x2 * new_surf->format->BytesPerPixel))) = *((Uint32 *)(src_pixels +(int)((int)(scale_y) * src->pitch + (int)(scale_x) * src->format->BytesPerPixel))); + + y2 += sy2; } } - } - // record top bottom starting y/x values - // draw fill poly method - // top length / bottom length times bottom length times from y top over y length at point - // can get y length from diff between /=/ / - // actually use side length since we know that sides will be parallel thus there can be a known scaling - // but how to work out equivalent start points ????? - // gradient is consistent parallel to vertical lines - // this is the key - - - // prob worked - - // scale x by diffx / w ??? - // can get dist from top of left points list to bottom of list - SDL_Point* left_points = (SDL_Point*) malloc((dst[0].y - dst[3].y) * sizeof(SDL_Point)); - // take how far down the y axis point by looking at how far down relative to y line is - // line to get to its equivalent left point which can thus get the point of the right side, giving the y_scale factor needed - - x1 = dst[0].x; - y1 = dst[0].y; - x2 = dst[3].x; - y2 = dst[3].y; - i1 = 0; - // initialize top line vars - dx1 = abs(dst[3].x - dst[0].x); - dy1 = -abs(dst[3].y - dst[0].y); - sx1 = dst[3].x > dst[0].x ? 1 : -1; - sy1 = dst[3].y > dst[0].y ? 1 : -1; - err1 = dx1 + dy1; - SDL_Point p; - p.x = x1; - p.y = y1; - left_points[i1++] = p; - while (x1 != dst[3].x && y1 != dst[3].y) { - // x1 y1 start e1 = err1 * 2; if (e1 >= dy1) { err1 += dy1; x1 += sx1; - if (left_points[i1].x < x1) { - left_points[i1].x = x1; - } } if (e1 <= dx1) { err1 += dx1; y1 += sy1; - SDL_Point p; - p.x = x1; - p.y = y1; - left_points[i1++] = p; - } } - - - Uint8* src_pixels = (Uint8*) src->pixels; - Uint8* dst_pixels = (Uint8*) new_surf->pixels; - bottom = 0; - top = diffy - 1; - while (true) { - vertical_length = sqrt(pow(left_points[top].x - left_points[bottom].x, 2) + pow(left_points[top].y - left_points[bottom].y, 2)); - for (int i = bottom; i<= top; i++) { - scale_y = sqrt(pow(left_points[i].x - left_points[bottom].x, 2) + pow(left_points[i].y - left_points[bottom].y, 2)) / vertical_length; - y = scale_y * src->h; - leftp = SDL_Point p; - leftp.x = scale_y * (dst[3].x - dst[0].x) + dst[0].x; - leftp.y = scale_y * (dst[3].y - dst[0].y) + dst[0].y; - rightp.x = scale_y * (dst[2].x - dst[1].x) + dst[1].x; - rightp.y = scale_y * (dst[2].y - dst[1].y) + dst[1].y; - } - } - - scale_x = src->w / (float) diffx; - for(int i = 0; i < diffx; i++) { - x1 = start_points[i].x; - y1 = start_points[i].y; - x2 = end_points[i].x; - y2 = end_points[i].y; - y_length = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2)); - scale_y = src->h / y_length; - dx = abs(x2 - x1); - dy = -abs(y2 - y1); - sx = x2 > x1 ? 1 : -1; - sy = y2 > y1 ? 1 : -1; - err = dx + dy; - while (y1 <= y2 || x1 != x2) { - //Nearest neighbor - scale_x = src->w / (diffx + ((sqrt(pow((x1 - start_points[i].x), 2) + pow((y1 - start_points[i].y), 2))) / y_length) * ((dst[2].x - dst[3].x) - diffx)); - *((Uint32 *)(dst_pixels +(int)(y1 * new_surf->pitch + x1 * new_surf->format->BytesPerPixel))) = *((Uint32 *)(src_pixels +(int)((int)((y1 - start_points[i].y) * scale_y) * src->pitch + (int)(i * scale_x) * src->format->BytesPerPixel))); - - e = err * 2; - if (e >= dy) { - err += dy; - x1 += sx; - } - if (e <= dx) { - err += dx; - y1 += sy; - } - } - } - } - free(start_points); - free(end_points); - free(left_points); - printf("wow"); } static SDL_Surface * @@ -941,10 +819,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) width = MAX(MAX(x1, x2), MAX(x3, x4)) - start; top = MIN(MIN(y1, y2), MIN(y3, y4)); height = MAX(MAX(y1, y2), MAX(y3, y4)) - top; - printf("we made it"); newsurf = SDL_CreateRGBSurfaceWithFormat(0, surf->w, surf->h, 32, surf->format->format); - printf("%d\n", newsurf->w); - printf("%d\n", surf->w); if (!newsurf) return NULL; @@ -982,7 +857,6 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) pgSurface_Lock(surfobj); SDL_Point points[4] = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}; Py_BEGIN_ALLOW_THREADS; - printf("helop\n"); skew(surf, newsurf, bgcolor, points); Py_END_ALLOW_THREADS; From c89db5c344d70062520c5dc30fa7f4e85fbfb6ad Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Fri, 5 May 2023 18:42:36 +0100 Subject: [PATCH 04/20] Improve algorithm, add sequence handling --- buildconfig/stubs/pygame/transform.pyi | 3 +- src_c/doc/transform_doc.h | 2 +- src_c/transform.c | 309 ++++++++++++++++++------- 3 files changed, 233 insertions(+), 81 deletions(-) diff --git a/buildconfig/stubs/pygame/transform.pyi b/buildconfig/stubs/pygame/transform.pyi index f7f5b339a1..2bb844a48a 100644 --- a/buildconfig/stubs/pygame/transform.pyi +++ b/buildconfig/stubs/pygame/transform.pyi @@ -17,8 +17,7 @@ def scale_by( dest_surface: Optional[Surface] = None, ) -> Surface: ... def rotate(surface: Surface, angle: float) -> Surface: ... -def perspective(surface: Surface, x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, x4: int, y4: int,) -> Surface: ... -def skew(surface: Surface, x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, x4: int, y4: int,) -> Surface: ... +def skew(surface: Surface, points: Sequence[Coordinate], adjust_size: Optional[bool], dest_surface: Optional[Surface]) -> Surface: ... def rotozoom(surface: Surface, angle: float, scale: float) -> Surface: ... def scale2x(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... def grayscale(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... diff --git a/src_c/doc/transform_doc.h b/src_c/doc/transform_doc.h index 321db457b5..d376b140bb 100644 --- a/src_c/doc/transform_doc.h +++ b/src_c/doc/transform_doc.h @@ -4,7 +4,7 @@ #define DOC_TRANSFORM_SCALE "scale(surface, size, dest_surface=None) -> Surface\nresize to new resolution" #define DOC_TRANSFORM_SCALEBY "scale_by(surface, factor, dest_surface=None) -> Surface\nresize to new resolution, using scalar(s)" #define DOC_TRANSFORM_ROTATE "rotate(surface, angle) -> Surface\nrotate an image" -#define DOC_TRANSFORM_SKEW "skew(surface, points) -> skew wow!!!" +#define DOC_TRANSFORM_SKEW "skew(surface, points, change_size, dest_surface=None) -> Surface\nmap a surface to new surface based off of the provided points for the new corners" #define DOC_TRANSFORM_ROTOZOOM "rotozoom(surface, angle, scale) -> Surface\nfiltered scale and rotation" #define DOC_TRANSFORM_SCALE2X "scale2x(surface, dest_surface=None) -> Surface\nspecialized image doubler" #define DOC_TRANSFORM_SMOOTHSCALE "smoothscale(surface, size, dest_surface=None) -> Surface\nscale a surface to an arbitrary size smoothly" diff --git a/src_c/transform.c b/src_c/transform.c index b9b12d38bf..ae4f510436 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -407,30 +407,26 @@ rotate(SDL_Surface *src, SDL_Surface *dst, Uint32 bgcolor, double sangle, } } - static void -skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point* dst) +skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, + int offsetx, int offsety) { - int dx1, dx2, dy1, dy2, leftx, rightx, bottomy, topy, x1, x2, y1, y2, diffx, diffy, err1, err2, e1, e2, sx1, sx2, sy1, sy2; - int end_x, end_y; + int dx1, dy1, x1, x2, y1, y2, err1, e1, sx1, sx2, sy1, sy2, length1, + length2, y_change; + float end_x, end_y, dx2, dy2, err2, e2, max_length1, max_length2; SDL_Point start, end, smallstart, smallend; - float scale_x, scale_y, end_scale, width, small_length, long_length; - - SDL_Point srcpoint[4] = { {0, 0}, {src->w, 0}, {src->w, src->h}, {0, src->h} }; - - - //check all points are in dest surface & parallel requirement - // quicker axis aligned skew option ? + float scale_x, scale_y, end_scale; + y_change = 0; + // check all points are in dest surface & parallel requirement + // quicker axis aligned skew option ? - leftx = dst[0].x - dst[3].x; - rightx = dst[1].x - dst[2].x; - - if (leftx == 0 || topy == 0) { - // use quicker axis aligned version - ; + if (dst[0].x - dst[3].x == dst[1].x - dst[2].x == 0) { + // use quicker axis aligned version + ; } - if (sqrt(pow(dst[2].x - dst[1].x, 2) + pow(dst[2].y - dst[1].y, 2)) > sqrt(pow(dst[3].x - dst[0].x, 2) + pow(dst[3].y - dst[0].y, 2))){ + if (sqrt(pow(dst[2].y - dst[1].y, 2) + pow(dst[2].x - dst[1].x, 2)) >= + sqrt(pow(dst[3].y - dst[0].y, 2) + pow(dst[3].x - dst[0].x, 2))) { start = dst[1]; end = dst[2]; smallstart = dst[0]; @@ -443,70 +439,212 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point* dst) smallend = dst[2]; } - small_length = sqrt(pow(smallend.x - smallstart.x, 2) + pow(smallend.y - smallstart.y, 2)); - long_length = sqrt(pow(end.x - start.x, 2) + pow(end.y - start.y, 2)); - if (1) { - x1 = start.x; - y1 = start.y; - - dx1 = abs(end.x - start.x); - dy1 = -abs(end.y - start.y); - sx1 = end.x > start.x ? 1 : -1; - sy1 = end.y > start.y ? 1 : -1; - err1 = dx1 + dy1; + x1 = start.x; + y1 = start.y; + + dx1 = abs(end.x - start.x); + dy1 = -abs(end.y - start.y); + sx1 = end.x > start.x ? 1 : -1; + sy1 = end.y > start.y ? 1 : -1; + err1 = dx1 + dy1; + max_length1 = (float)(dx1 - dy1); + length1 = 0; + Uint8 *src_pixels = (Uint8 *)src->pixels; + Uint8 *dst_pixels = (Uint8 *)new_surf->pixels; + + // First iteration for beginning point + x2 = x1; + y2 = y1; + end_scale = length1 / max_length1; + scale_y = end_scale * (src->h - 1); + + end_x = (smallend.x - smallstart.x) * end_scale + smallstart.x; + end_y = (smallend.y - smallstart.y) * end_scale + smallstart.y; + dx2 = (float)fabs(end_x - x1); + dy2 = (float)-fabs(end_y - y1); + sx2 = end_x > x1 ? 1 : -1; + sy2 = end_y > y1 ? 1 : -1; + err2 = dx2 + dy2; + length2 = 0; + max_length2 = round(dx2 - dy2); + while (1) { + // Using Nearest neighbor + + if (length2 >= max_length2) { + break; + } - Uint8* src_pixels = (Uint8*) src->pixels; - Uint8* dst_pixels = (Uint8*) new_surf->pixels; + e2 = err2 * 2; + if (e2 >= dy2) { + err2 += dy2; + x2 += sx2; + length2 += 1; + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); + } + if (e2 <= dx2) { + err2 += dx2; + y2 += sy2; + length2 += 1; + // extra assign for when y2 changes at the same time as x1 + // changes to prevent missing pixels + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); + } + } - while (x1 != end.x || y1 != end.y) { + while (1) { + if (length1 >= max_length1) + break; + e1 = err1 * 2; + if (e1 >= dy1) { + err1 += dy1; + x1 += sx1; + length1 += 1; x2 = x1; y2 = y1; - end_scale = sqrt(pow(x1 - start.x, 2) + pow(y1 - start.y, 2)) / long_length; - scale_y = end_scale * src->h; - if (start.x == dst[0].x) { - end_x = (smallend.x - smallstart.x) * end_scale + smallstart.x; - end_y = (smallend.y - smallstart.y) * end_scale + smallstart.y; - } - else { - end_x = round((smallend.x - smallstart.x) * end_scale) + smallstart.x; - end_y = round((smallend.y - smallstart.y) * end_scale) + smallstart.y; - } - - width = sqrt(pow(end_x - x1, 2) + pow(end_y - y1, 2)); - dx2 = abs(end_x - x1); - dy2 = -abs(end_y - y1); - sx2 = end_x > x1 ? 1: -1; + end_scale = length1 / max_length1; + scale_y = end_scale * (src->h - 1); + + end_x = (smallend.x - smallstart.x) * end_scale + smallstart.x; + end_y = (smallend.y - smallstart.y) * end_scale + smallstart.y; + dx2 = (float)fabs(end_x - x1); + dy2 = (float)-fabs(end_y - y1); + sx2 = end_x > x1 ? 1 : -1; sy2 = end_y > y1 ? 1 : -1; err2 = dx2 + dy2; - while (x2 != end_x || y2 != end_y) { + length2 = 0; + max_length2 = round(dx2 - dy2); + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); + while (1) { // Using Nearest neighbor - scale_x = src->w * sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) / width; - *((Uint32 *)(dst_pixels +(int)(y2 * new_surf->pitch + x2 * new_surf->format->BytesPerPixel))) = *((Uint32 *)(src_pixels +(int)((int)(scale_y) * src->pitch + (int)(scale_x) * src->format->BytesPerPixel))); e2 = err2 * 2; if (e2 >= dy2) { err2 += dy2; x2 += sx2; + length2 += 1; + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * + new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); + } + if (length2 > max_length2) { + break; } if (e2 <= dx2) { err2 += dx2; - // extra assign for when y2 changes at the same time as x1 changes to prevent missing pixels - scale_x = src->w * sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) / width; - *((Uint32 *)(dst_pixels +(int)(y2 * new_surf->pitch + x2 * new_surf->format->BytesPerPixel))) = *((Uint32 *)(src_pixels +(int)((int)(scale_y) * src->pitch + (int)(scale_x) * src->format->BytesPerPixel))); + // extra assign for when y2 changes at the same time as x1 + // changes to prevent missing pixels + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * + new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); y2 += sy2; + length2 += 1; + } + if (length2 > max_length2) { + break; } } + } + if (e1 <= dx1) { + err1 += dx1; + y1 += sy1; + length1 += 1; + x2 = x1; + y2 = y1; + end_scale = length1 / max_length1; + scale_y = end_scale * (src->h - 1); + + end_x = (smallend.x - smallstart.x) * end_scale + smallstart.x; + end_y = (smallend.y - smallstart.y) * end_scale + smallstart.y; + dx2 = (float)fabs(end_x - x1); + dy2 = (float)-fabs(end_y - y1); + sx2 = end_x > x1 ? 1 : -1; + sy2 = end_y > y1 ? 1 : -1; + err2 = dx2 + dy2; + length2 = 0; + max_length2 = round(dx2 - dy2); + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); + while (1) { + // Using Nearest neighbor + e2 = err2 * 2; + if (e2 >= dy2) { + err2 += dy2; + x2 += sx2; + length2 += 1; + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * + new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); + } + if (length2 > max_length2) { + break; + } + if (e2 <= dx2) { + err2 += dx2; + // extra assign for when y2 changes at the same time as x1 + // changes to prevent missing pixels + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * + new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); - - e1 = err1 * 2; - if (e1 >= dy1) { - err1 += dy1; - x1 += sx1; - } - if (e1 <= dx1) { - err1 += dx1; - y1 += sy1; + y2 += sy2; + length2 += 1; + } + if (length2 > max_length2) { + break; + } } } } @@ -787,42 +925,58 @@ surf_rotate(PyObject *self, PyObject *args, PyObject *kwargs) return (PyObject *)pgSurface_New(newsurf); } - static PyObject * surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) { pgSurfaceObject *surfobj; + pgSurfaceObject *dest_surf = NULL; SDL_Surface *surf, *newsurf; - + int adjust_size = 0; int x1, y1, x2, y2, x3, y3, x4, y4; double x, y, cx, cy, sx, sy; - int start, width, top, height; + int start = 0, width, top = 0, height; int nxmax, nymax; Uint32 bgcolor; - static char *keywords[] = {"surface", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", NULL}; + static char *keywords[] = {"surface", "points", "adjust_size", "dest_surf", + NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!iiiiiiii", keywords, - &pgSurface_Type, &surfobj, &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) + if (!PyArg_ParseTupleAndKeywords( + args, kwargs, "O!((ii)(ii)(ii)(ii))|pO!", keywords, + &pgSurface_Type, &surfobj, &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4, + &adjust_size, &pgSurface_Type, &dest_surf)) return NULL; surf = pgSurface_AsSurface(surfobj); SURF_INIT_CHECK(surf) + if (!dest_surf) { + if (adjust_size) { + start = MIN(MIN(x1, x2), MIN(x3, x4)); + width = MAX(MAX(x1, x2), MAX(x3, x4)) - start; + top = MIN(MIN(y1, y2), MIN(y3, y4)); + height = MAX(MAX(y1, y2), MAX(y3, y4)) - top; + newsurf = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, + surf->format->format); + } + else { + newsurf = SDL_CreateRGBSurfaceWithFormat(0, surf->w, surf->h, 32, + surf->format->format); + } + } + else { + newsurf = pgSurface_AsSurface(dest_surf); + SURF_INIT_CHECK(newsurf) + } if (surf->w < 1 || surf->h < 1) { Py_INCREF(surfobj); return (PyObject *)surfobj; } + if (surf->format->format != newsurf->format->format) { + return RAISE(PyExc_ValueError, "Surface formats do not match"); + } if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) return RAISE(PyExc_ValueError, "unsupported Surface bit depth for transform"); - start = MIN(MIN(x1, x2), MIN(x3, x4)); - width = MAX(MAX(x1, x2), MAX(x3, x4)) - start; - top = MIN(MIN(y1, y2), MIN(y3, y4)); - height = MAX(MAX(y1, y2), MAX(y3, y4)) - top; - newsurf = SDL_CreateRGBSurfaceWithFormat(0, surf->w, surf->h, 32, surf->format->format); - - if (!newsurf) - return NULL; /* get the background color */ if (SDL_GetColorKey(surf, &bgcolor) != 0) { @@ -858,13 +1012,12 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) SDL_Point points[4] = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}; Py_BEGIN_ALLOW_THREADS; - skew(surf, newsurf, bgcolor, points); + skew(surf, newsurf, bgcolor, points, start, top); Py_END_ALLOW_THREADS; pgSurface_Unlock(surfobj); SDL_UnlockSurface(newsurf); SDL_UnlockSurface(surf); - return (PyObject *)pgSurface_New(newsurf); } From f3cdc5c5b78b87879ae326207f37780c589af03d Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Sat, 6 May 2023 15:15:44 +0100 Subject: [PATCH 05/20] Resulting shape improvements --- src_c/transform.c | 218 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 153 insertions(+), 65 deletions(-) diff --git a/src_c/transform.c b/src_c/transform.c index ae4f510436..0b9c9a4024 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -412,11 +412,10 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, int offsetx, int offsety) { int dx1, dy1, x1, x2, y1, y2, err1, e1, sx1, sx2, sy1, sy2, length1, - length2, y_change; + length2, rev; float end_x, end_y, dx2, dy2, err2, e2, max_length1, max_length2; SDL_Point start, end, smallstart, smallend; float scale_x, scale_y, end_scale; - y_change = 0; // check all points are in dest surface & parallel requirement // quicker axis aligned skew option ? @@ -431,12 +430,14 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, end = dst[2]; smallstart = dst[0]; smallend = dst[3]; + rev = 1; } else { start = dst[0]; end = dst[3]; smallstart = dst[1]; smallend = dst[2]; + rev = 0; } x1 = start.x; @@ -466,9 +467,34 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, sy2 = end_y > y1 ? 1 : -1; err2 = dx2 + dy2; length2 = 0; - max_length2 = round(dx2 - dy2); + max_length2 = floor(dx2 - dy2); + if (rev) { + scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + } + else { + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + } + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); while (1) { // Using Nearest neighbor + if (rev) { + scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + } + else { + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + } + + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); if (length2 >= max_length2) { break; @@ -479,32 +505,29 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 += dy2; x2 += sx2; length2 += 1; - scale_x = (float)((src->w - 1) * (length2 / max_length2)); - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); } if (e2 <= dx2) { err2 += dx2; y2 += sy2; length2 += 1; - // extra assign for when y2 changes at the same time as x1 - // changes to prevent missing pixels - scale_x = (float)((src->w - 1) * (length2 / max_length2)); - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + } } while (1) { + if (rev) { + scale_x = (float)((src->w - 1)); + } + else { + scale_x = (float)(0); + } + *((Uint32 *)(dst_pixels + + (int)(y1 * new_surf->pitch + + x1 * new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); if (length1 >= max_length1) break; e1 = err1 * 2; @@ -525,15 +548,7 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, sy2 = end_y > y1 ? 1 : -1; err2 = dx2 + dy2; length2 = 0; - max_length2 = round(dx2 - dy2); - scale_x = (float)((src->w - 1) * (length2 / max_length2)); - - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + max_length2 = floor(dx2- dy2); while (1) { // Using Nearest neighbor e2 = err2 * 2; @@ -541,25 +556,39 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 += dy2; x2 += sx2; length2 += 1; - scale_x = (float)((src->w - 1) * (length2 / max_length2)); + if (length2 != 2) { + if (rev) { + scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + } + else { + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + } - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * - new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * + new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); + } } - if (length2 > max_length2) { + if (length2 >= max_length2) { break; } if (e2 <= dx2) { err2 += dx2; + y2 += sy2; + length2 += 1; // extra assign for when y2 changes at the same time as x1 // changes to prevent missing pixels - scale_x = (float)((src->w - 1) * (length2 / max_length2)); + if (rev) { + scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + } + else { + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + } *((Uint32 *)(dst_pixels + (int)(y2 * new_surf->pitch + x2 * @@ -569,15 +598,23 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, (int)(scale_x)*src->format ->BytesPerPixel))); - y2 += sy2; - length2 += 1; + } - if (length2 > max_length2) { + if (length2 >= max_length2) { break; } } } + if (length1 > max_length1) + break; if (e1 <= dx1) { + if (rev) { + scale_x = (float)((src->w - 1)); + } + else { + scale_x = (float)(0); + } + err1 += dx1; y1 += sy1; length1 += 1; @@ -594,15 +631,9 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, sy2 = end_y > y1 ? 1 : -1; err2 = dx2 + dy2; length2 = 0; - max_length2 = round(dx2 - dy2); - scale_x = (float)((src->w - 1) * (length2 / max_length2)); - - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + max_length2 = floor(dx2 - dy2); + + while (1) { // Using Nearest neighbor @@ -611,25 +642,39 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 += dy2; x2 += sx2; length2 += 1; - scale_x = (float)((src->w - 1) * (length2 / max_length2)); + if (length2 != 2) { + if (rev) { + scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + } + else { + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + } - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * - new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + *((Uint32 *)(dst_pixels + + (int)(y2 * new_surf->pitch + + x2 * + new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); + } } - if (length2 > max_length2) { + if (length2 >= max_length2) { break; } if (e2 <= dx2) { err2 += dx2; + y2 += sy2; + length2 += 1; // extra assign for when y2 changes at the same time as x1 // changes to prevent missing pixels - scale_x = (float)((src->w - 1) * (length2 / max_length2)); + if (rev) { + scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + } + else { + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + } *((Uint32 *)(dst_pixels + (int)(y2 * new_surf->pitch + x2 * @@ -639,15 +684,58 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, (int)(scale_x)*src->format ->BytesPerPixel))); - y2 += sy2; - length2 += 1; + } - if (length2 > max_length2) { + if (length2 >= max_length2) { break; } } } } + + //TODO: ADD FINAL PASS OF BRESENHAM ALONG SMALL LINE + + x1 = smallstart.x; + y1 = smallstart.y; + + dx1 = abs(smallend.x - smallstart.x); + dy1 = -abs(smallend.y - smallstart.y); + sx1 = smallend.x > smallstart.x ? 1 : -1; + sy1 = smallend.y > smallstart.y ? 1 : -1; + err1 = dx1 + dy1; + max_length1 = (float)(dx1 - dy1); + length1 = 0; + if (rev) { + scale_x = (float)((src->w - 1) - (src->w - 1)); + } + else { + scale_x = (float)((src->w - 1)); + } + while (1) { + if (length1 >= max_length1) + break; + scale_y = length1 / max_length1 * (src->h - 1); + /* *((Uint32 *)(dst_pixels + + (int)(y1 * new_surf->pitch + + x1 * + new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format + ->BytesPerPixel))); */ + + e1 = err1 * 2; + if (e1 >= dy1) { + err1 += dy1; + x1 += sx1; + length1 += 1; + } + if (e1 <= dx1) { + err1 += dx1; + y1 += sy1; + length1 += 1; + } + } } static SDL_Surface * From b95bc5ee8a6759f6dadad689dd9303b2a10e6626 Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 9 May 2023 00:07:03 +0100 Subject: [PATCH 06/20] Correct image flipping, resulting shape --- src_c/transform.c | 126 ++++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/src_c/transform.c b/src_c/transform.c index 0b9c9a4024..dc710405c7 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -467,34 +467,35 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, sy2 = end_y > y1 ? 1 : -1; err2 = dx2 + dy2; length2 = 0; - max_length2 = floor(dx2 - dy2); + max_length2 = (float)floor(dx2 - dy2); if (rev) { - scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + scale_x = + (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); } else { scale_x = (float)((src->w - 1) * (length2 / max_length2)); } - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + *((Uint32 *)(dst_pixels + (int)(y2 * new_surf->pitch + + x2 * new_surf->format->BytesPerPixel))) = + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format->BytesPerPixel))); while (1) { // Using Nearest neighbor - if (rev) { - scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); - } - else { - scale_x = (float)((src->w - 1) * (length2 / max_length2)); - } + if (rev) { + scale_x = + (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + } + else { + scale_x = (float)((src->w - 1) * (length2 / max_length2)); + } *((Uint32 *)(dst_pixels + (int)(y2 * new_surf->pitch + x2 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format->BytesPerPixel))); if (length2 >= max_length2) { break; @@ -505,13 +506,11 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 += dy2; x2 += sx2; length2 += 1; - } if (e2 <= dx2) { err2 += dx2; y2 += sy2; length2 += 1; - } } @@ -525,9 +524,9 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, *((Uint32 *)(dst_pixels + (int)(y1 * new_surf->pitch + x1 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + *((Uint32 *)(src_pixels + + (int)((int)(scale_y)*src->pitch + + (int)(scale_x)*src->format->BytesPerPixel))); if (length1 >= max_length1) break; e1 = err1 * 2; @@ -548,7 +547,7 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, sy2 = end_y > y1 ? 1 : -1; err2 = dx2 + dy2; length2 = 0; - max_length2 = floor(dx2- dy2); + max_length2 = (float)(round(dx2) + floor(-dy2)); while (1) { // Using Nearest neighbor e2 = err2 * 2; @@ -556,18 +555,21 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 += dy2; x2 += sx2; length2 += 1; - if (length2 != 2) { - if (rev) { - scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); - } - else { - scale_x = (float)((src->w - 1) * (length2 / max_length2)); - } + if (rev) { + scale_x = + (float)((src->w - 1) - + (src->w - 1) * (length2 / max_length2)); + } + else { + scale_x = + (float)((src->w - 1) * (length2 / max_length2)); + } + if (length1 < (max_length1 - 1) || e2 > dx2) { *((Uint32 *)(dst_pixels + (int)(y2 * new_surf->pitch + - x2 * - new_surf->format->BytesPerPixel))) = + x2 * new_surf->format + ->BytesPerPixel))) = *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + (int)(scale_x)*src->format @@ -584,10 +586,13 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, // extra assign for when y2 changes at the same time as x1 // changes to prevent missing pixels if (rev) { - scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + scale_x = + (float)((src->w - 1) - + (src->w - 1) * (length2 / max_length2)); } else { - scale_x = (float)((src->w - 1) * (length2 / max_length2)); + scale_x = + (float)((src->w - 1) * (length2 / max_length2)); } *((Uint32 *)(dst_pixels + (int)(y2 * new_surf->pitch + @@ -597,10 +602,8 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, (int)((int)(scale_y)*src->pitch + (int)(scale_x)*src->format ->BytesPerPixel))); - - } - if (length2 >= max_length2) { + if (length2 >= (max_length2)) { break; } } @@ -614,7 +617,7 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, else { scale_x = (float)(0); } - + err1 += dx1; y1 += sy1; length1 += 1; @@ -631,8 +634,7 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, sy2 = end_y > y1 ? 1 : -1; err2 = dx2 + dy2; length2 = 0; - max_length2 = floor(dx2 - dy2); - + max_length2 = (float)(round(dx2) + floor(-dy2)); while (1) { // Using Nearest neighbor @@ -642,18 +644,21 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 += dy2; x2 += sx2; length2 += 1; - if (length2 != 2) { - if (rev) { - scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); - } - else { - scale_x = (float)((src->w - 1) * (length2 / max_length2)); - } + if (rev) { + scale_x = + (float)((src->w - 1) - + (src->w - 1) * (length2 / max_length2)); + } + else { + scale_x = + (float)((src->w - 1) * (length2 / max_length2)); + } + if (length1 < (max_length1 - 1) || e2 > dx2) { *((Uint32 *)(dst_pixels + (int)(y2 * new_surf->pitch + - x2 * - new_surf->format->BytesPerPixel))) = + x2 * new_surf->format + ->BytesPerPixel))) = *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + (int)(scale_x)*src->format @@ -670,10 +675,13 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, // extra assign for when y2 changes at the same time as x1 // changes to prevent missing pixels if (rev) { - scale_x = (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); + scale_x = + (float)((src->w - 1) - + (src->w - 1) * (length2 / max_length2)); } else { - scale_x = (float)((src->w - 1) * (length2 / max_length2)); + scale_x = + (float)((src->w - 1) * (length2 / max_length2)); } *((Uint32 *)(dst_pixels + (int)(y2 * new_surf->pitch + @@ -683,8 +691,6 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, (int)((int)(scale_y)*src->pitch + (int)(scale_x)*src->format ->BytesPerPixel))); - - } if (length2 >= max_length2) { break; @@ -693,7 +699,7 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, } } - //TODO: ADD FINAL PASS OF BRESENHAM ALONG SMALL LINE + // TODO: ADD FINAL PASS OF BRESENHAM ALONG SMALL LINE x1 = smallstart.x; y1 = smallstart.y; @@ -715,22 +721,20 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, if (length1 >= max_length1) break; scale_y = length1 / max_length1 * (src->h - 1); - /* *((Uint32 *)(dst_pixels + + *((Uint32 *)(dst_pixels + (int)(y1 * new_surf->pitch + - x1 * - new_surf->format->BytesPerPixel))) = + x1 * new_surf->format->BytesPerPixel))) = *((Uint32 *)(src_pixels + (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); */ + (int)(scale_x)*src->format->BytesPerPixel))); e1 = err1 * 2; - if (e1 >= dy1) { + if (e1 > dy1) { err1 += dy1; x1 += sx1; length1 += 1; } - if (e1 <= dx1) { + if (e1 < dx1) { err1 += dx1; y1 += sy1; length1 += 1; From 043c4deaca6335a2702099ae2e8605b781d2158c Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 9 May 2023 11:41:03 +0100 Subject: [PATCH 07/20] Add docs, fix segfault, proper input handling --- docs/reST/ref/transform.rst | 15 +++ src_c/doc/transform_doc.h | 2 +- src_c/transform.c | 251 ++++++++++++++++++------------------ 3 files changed, 142 insertions(+), 126 deletions(-) diff --git a/docs/reST/ref/transform.rst b/docs/reST/ref/transform.rst index f9c4d123b0..8388a480a7 100644 --- a/docs/reST/ref/transform.rst +++ b/docs/reST/ref/transform.rst @@ -101,6 +101,21 @@ Instead, always begin with the original image and scale to the desired size.) .. ## pygame.transform.rotozoom ## +.. function:: skew + + | :sl:`skew an image to specified points` + | :sg:`skew(surface, points, adjust_size=False, dest_surface=None)` + + This maps an image to a new surface warping the image so that its corners + match the provided points. When no destination surface is provided, the + adjust_size option will change the size of the resulting surface to be the + smallest surface the points are capable of fitting in, otherwhise it will + use the original size of the provided surface. + + .. versionadded:: 2.3.0 + + .. ## pygame.transform.skew ## + .. function:: scale2x | :sl:`specialized image doubler` diff --git a/src_c/doc/transform_doc.h b/src_c/doc/transform_doc.h index d376b140bb..f1f7d6801b 100644 --- a/src_c/doc/transform_doc.h +++ b/src_c/doc/transform_doc.h @@ -4,8 +4,8 @@ #define DOC_TRANSFORM_SCALE "scale(surface, size, dest_surface=None) -> Surface\nresize to new resolution" #define DOC_TRANSFORM_SCALEBY "scale_by(surface, factor, dest_surface=None) -> Surface\nresize to new resolution, using scalar(s)" #define DOC_TRANSFORM_ROTATE "rotate(surface, angle) -> Surface\nrotate an image" -#define DOC_TRANSFORM_SKEW "skew(surface, points, change_size, dest_surface=None) -> Surface\nmap a surface to new surface based off of the provided points for the new corners" #define DOC_TRANSFORM_ROTOZOOM "rotozoom(surface, angle, scale) -> Surface\nfiltered scale and rotation" +#define DOC_TRANSFORM_SKEW "skew(surface, points, adjust_size=False, dest_surface=None)\nskew an image to specified points" #define DOC_TRANSFORM_SCALE2X "scale2x(surface, dest_surface=None) -> Surface\nspecialized image doubler" #define DOC_TRANSFORM_SMOOTHSCALE "smoothscale(surface, size, dest_surface=None) -> Surface\nscale a surface to an arbitrary size smoothly" #define DOC_TRANSFORM_SMOOTHSCALEBY "smoothscale_by(surface, factor, dest_surface=None) -> Surface\nresize to new resolution, using scalar(s)" diff --git a/src_c/transform.c b/src_c/transform.c index dc710405c7..c47ca1cab8 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -407,22 +407,40 @@ rotate(SDL_Surface *src, SDL_Surface *dst, Uint32 bgcolor, double sangle, } } +static PG_INLINE void +_copy_pixel_to(int dst_x, int dst_y, int src_x, int src_y, Uint8 *dst_pixels, + Uint8 *src_pixels, int dst_pitch, int src_pitch, + SDL_PixelFormat *format) +{ + switch (format->BytesPerPixel) { + case 1: + *((Uint8 *)(dst_pixels + dst_y * dst_pitch) + dst_x) = + *((Uint8 *)(src_pixels + src_y * src_pitch) + src_x); + break; + case 2: + *((Uint16 *)(dst_pixels + dst_y * dst_pitch) + dst_x) = + *((Uint16 *)(src_pixels + src_y * src_pitch) + src_x); + break; + case 3:; + memcpy(((Uint8 *)(dst_pixels + dst_y * dst_pitch) + dst_x), + ((Uint8 *)(src_pixels + src_y * src_pitch) + src_x), + 3 * sizeof(Uint8)); + break; + default: /* case 4: */ + *((Uint32 *)(dst_pixels + dst_y * dst_pitch) + dst_x) = + *((Uint32 *)(src_pixels + src_y * src_pitch) + src_x); + break; + } +} + static void -skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, - int offsetx, int offsety) +skew(SDL_Surface *src, SDL_Surface *new_surf, SDL_Point *dst) { int dx1, dy1, x1, x2, y1, y2, err1, e1, sx1, sx2, sy1, sy2, length1, length2, rev; float end_x, end_y, dx2, dy2, err2, e2, max_length1, max_length2; SDL_Point start, end, smallstart, smallend; float scale_x, scale_y, end_scale; - // check all points are in dest surface & parallel requirement - // quicker axis aligned skew option ? - - if (dst[0].x - dst[3].x == dst[1].x - dst[2].x == 0) { - // use quicker axis aligned version - ; - } if (sqrt(pow(dst[2].y - dst[1].y, 2) + pow(dst[2].x - dst[1].x, 2)) >= sqrt(pow(dst[3].y - dst[0].y, 2) + pow(dst[3].x - dst[0].x, 2))) { @@ -440,6 +458,48 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, rev = 0; } + Uint8 *src_pixels = (Uint8 *)src->pixels; + Uint8 *dst_pixels = (Uint8 *)new_surf->pixels; + + // End line drawing (so it doesn't draw over already drawn parts of the + // image + x1 = smallstart.x; + y1 = smallstart.y; + + dx1 = abs(smallend.x - smallstart.x); + dy1 = -abs(smallend.y - smallstart.y); + sx1 = smallend.x > smallstart.x ? 1 : -1; + sy1 = smallend.y > smallstart.y ? 1 : -1; + err1 = dx1 + dy1; + max_length1 = (float)(dx1 - dy1); + length1 = 0; + if (rev) { + scale_x = (float)((src->w - 1) - (src->w - 1)); + } + else { + scale_x = (float)((src->w - 1)); + } + while (1) { + if (length1 >= max_length1) + break; + scale_y = length1 / max_length1 * (src->h - 1); + _copy_pixel_to(x1, y1, (int)(scale_x), (int)(scale_y), dst_pixels, + src_pixels, new_surf->pitch, src->pitch, + new_surf->format); + + e1 = err1 * 2; + if (e1 > dy1) { + err1 += dy1; + x1 += sx1; + length1 += 1; + } + if (e1 < dx1) { + err1 += dx1; + y1 += sy1; + length1 += 1; + } + } + x1 = start.x; y1 = start.y; @@ -450,8 +510,6 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err1 = dx1 + dy1; max_length1 = (float)(dx1 - dy1); length1 = 0; - Uint8 *src_pixels = (Uint8 *)src->pixels; - Uint8 *dst_pixels = (Uint8 *)new_surf->pixels; // First iteration for beginning point x2 = x1; @@ -468,18 +526,8 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 = dx2 + dy2; length2 = 0; max_length2 = (float)floor(dx2 - dy2); - if (rev) { - scale_x = - (float)((src->w - 1) - (src->w - 1) * (length2 / max_length2)); - } - else { - scale_x = (float)((src->w - 1) * (length2 / max_length2)); - } - *((Uint32 *)(dst_pixels + (int)(y2 * new_surf->pitch + - x2 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format->BytesPerPixel))); + _copy_pixel_to(x2, y2, (int)(scale_x), (int)(scale_y), dst_pixels, + src_pixels, new_surf->pitch, src->pitch, new_surf->format); while (1) { // Using Nearest neighbor if (rev) { @@ -490,12 +538,9 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, scale_x = (float)((src->w - 1) * (length2 / max_length2)); } - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format->BytesPerPixel))); + _copy_pixel_to(x2, y2, (int)(scale_x), (int)(scale_y), dst_pixels, + src_pixels, new_surf->pitch, src->pitch, + new_surf->format); if (length2 >= max_length2) { break; @@ -519,14 +564,11 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, scale_x = (float)((src->w - 1)); } else { - scale_x = (float)(0); - } - *((Uint32 *)(dst_pixels + - (int)(y1 * new_surf->pitch + - x1 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format->BytesPerPixel))); + scale_x = 0; + } + _copy_pixel_to(x1, y1, (int)(scale_x), (int)(scale_y), dst_pixels, + src_pixels, new_surf->pitch, src->pitch, + new_surf->format); if (length1 >= max_length1) break; e1 = err1 * 2; @@ -548,6 +590,8 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 = dx2 + dy2; length2 = 0; max_length2 = (float)(round(dx2) + floor(-dy2)); + if (max_length2 == 0) + max_length2 = 1; while (1) { // Using Nearest neighbor e2 = err2 * 2; @@ -565,15 +609,11 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, scale_x = (float)((src->w - 1) * (length2 / max_length2)); } + if (length1 < (max_length1 - 1) || e2 > dx2) { - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * new_surf->format - ->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + _copy_pixel_to(x2, y2, (int)(scale_x), (int)(scale_y), + dst_pixels, src_pixels, new_surf->pitch, + src->pitch, new_surf->format); } } if (length2 >= max_length2) { @@ -594,14 +634,9 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, scale_x = (float)((src->w - 1) * (length2 / max_length2)); } - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * - new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + _copy_pixel_to(x2, y2, (int)(scale_x), (int)(scale_y), + dst_pixels, src_pixels, new_surf->pitch, + src->pitch, new_surf->format); } if (length2 >= (max_length2)) { break; @@ -615,7 +650,7 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, scale_x = (float)((src->w - 1)); } else { - scale_x = (float)(0); + scale_x = 0; } err1 += dx1; @@ -635,7 +670,8 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 = dx2 + dy2; length2 = 0; max_length2 = (float)(round(dx2) + floor(-dy2)); - + if (max_length2 == 0) + max_length2 = 1; while (1) { // Using Nearest neighbor @@ -644,7 +680,6 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, err2 += dy2; x2 += sx2; length2 += 1; - if (rev) { scale_x = (float)((src->w - 1) - @@ -655,14 +690,9 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, (float)((src->w - 1) * (length2 / max_length2)); } if (length1 < (max_length1 - 1) || e2 > dx2) { - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * new_surf->format - ->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + _copy_pixel_to(x2, y2, (int)(scale_x), (int)(scale_y), + dst_pixels, src_pixels, new_surf->pitch, + src->pitch, new_surf->format); } } if (length2 >= max_length2) { @@ -683,14 +713,9 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, scale_x = (float)((src->w - 1) * (length2 / max_length2)); } - *((Uint32 *)(dst_pixels + - (int)(y2 * new_surf->pitch + - x2 * - new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format - ->BytesPerPixel))); + _copy_pixel_to(x2, y2, (int)(scale_x), (int)(scale_y), + dst_pixels, src_pixels, new_surf->pitch, + src->pitch, new_surf->format); } if (length2 >= max_length2) { break; @@ -698,48 +723,6 @@ skew(SDL_Surface *src, SDL_Surface *new_surf, Uint32 bgcolor, SDL_Point *dst, } } } - - // TODO: ADD FINAL PASS OF BRESENHAM ALONG SMALL LINE - - x1 = smallstart.x; - y1 = smallstart.y; - - dx1 = abs(smallend.x - smallstart.x); - dy1 = -abs(smallend.y - smallstart.y); - sx1 = smallend.x > smallstart.x ? 1 : -1; - sy1 = smallend.y > smallstart.y ? 1 : -1; - err1 = dx1 + dy1; - max_length1 = (float)(dx1 - dy1); - length1 = 0; - if (rev) { - scale_x = (float)((src->w - 1) - (src->w - 1)); - } - else { - scale_x = (float)((src->w - 1)); - } - while (1) { - if (length1 >= max_length1) - break; - scale_y = length1 / max_length1 * (src->h - 1); - *((Uint32 *)(dst_pixels + - (int)(y1 * new_surf->pitch + - x1 * new_surf->format->BytesPerPixel))) = - *((Uint32 *)(src_pixels + - (int)((int)(scale_y)*src->pitch + - (int)(scale_x)*src->format->BytesPerPixel))); - - e1 = err1 * 2; - if (e1 > dy1) { - err1 += dy1; - x1 += sx1; - length1 += 1; - } - if (e1 < dx1) { - err1 += dx1; - y1 += sy1; - length1 += 1; - } - } } static SDL_Surface * @@ -1017,6 +1000,15 @@ surf_rotate(PyObject *self, PyObject *args, PyObject *kwargs) return (PyObject *)pgSurface_New(newsurf); } +static int +check_inside(SDL_Surface *surf, SDL_Point p) +{ + if (p.x >= 0 && p.x <= surf->w && p.y >= 0 && p.y <= surf->h) + return 1; + else + return 0; +} + static PyObject * surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) { @@ -1025,9 +1017,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) SDL_Surface *surf, *newsurf; int adjust_size = 0; int x1, y1, x2, y2, x3, y3, x4, y4; - double x, y, cx, cy, sx, sy; int start = 0, width, top = 0, height; - int nxmax, nymax; Uint32 bgcolor; static char *keywords[] = {"surface", "points", "adjust_size", "dest_surf", NULL}; @@ -1063,16 +1053,31 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) return (PyObject *)surfobj; } if (surf->format->format != newsurf->format->format) { - return RAISE(PyExc_ValueError, "Surface formats do not match"); + return RAISE(PyExc_ValueError, "surface formats do not match"); } if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) return RAISE(PyExc_ValueError, "unsupported Surface bit depth for transform"); + SDL_Point points[4] = {{x1 - start, y1 - top}, + {x2 - start, y2 - top}, + {x3 - start, y3 - top}, + {x4 - start, y4 - top}}; + if (!(check_inside(newsurf, points[0]) && + check_inside(newsurf, points[1]) && + check_inside(newsurf, points[2]) && + check_inside(newsurf, points[3]))) { + return RAISE(PyExc_ValueError, + "points are not within destination surface"); + } + + SDL_LockSurface(newsurf); + SDL_LockSurface(surf); + pgSurface_Lock(surfobj); + /* get the background color */ if (SDL_GetColorKey(surf, &bgcolor) != 0) { - SDL_LockSurface(surf); switch (surf->format->BytesPerPixel) { case 1: bgcolor = *(Uint8 *)surf->pixels; @@ -1094,17 +1099,13 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) (((Uint8 *)surf->pixels)[0] << 16); #endif } - SDL_UnlockSurface(surf); bgcolor &= ~surf->format->Amask; } - SDL_LockSurface(newsurf); - SDL_LockSurface(surf); - pgSurface_Lock(surfobj); - SDL_Point points[4] = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}; - Py_BEGIN_ALLOW_THREADS; + SDL_FillRect(newsurf, NULL, bgcolor); - skew(surf, newsurf, bgcolor, points, start, top); + Py_BEGIN_ALLOW_THREADS; + skew(surf, newsurf, points); Py_END_ALLOW_THREADS; pgSurface_Unlock(surfobj); SDL_UnlockSurface(newsurf); From f78937176e6e337e0f1841c4dcf432936a27664c Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 9 May 2023 13:53:04 +0100 Subject: [PATCH 08/20] Revert cython changes --- src_c/_sdl2/sdl2.c | 117 +++++------------- src_c/_sdl2/video.c | 72 ++++------- src_c/_sprite.c | 293 ++++++++++++++------------------------------ 3 files changed, 142 insertions(+), 340 deletions(-) diff --git a/src_c/_sdl2/sdl2.c b/src_c/_sdl2/sdl2.c index 615a72a221..42508e09e2 100644 --- a/src_c/_sdl2/sdl2.c +++ b/src_c/_sdl2/sdl2.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.29.34 */ +/* Generated by Cython 0.29.30 */ /* BEGIN: Cython Metadata { @@ -22,8 +22,8 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_29_34" -#define CYTHON_HEX_VERSION 0x001D22F0 +#define CYTHON_ABI "0_29_30" +#define CYTHON_HEX_VERSION 0x001D1EF0 #define CYTHON_FUTURE_DIVISION 0 #include #ifndef offsetof @@ -62,7 +62,6 @@ END: Cython Metadata */ #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 0 - #define CYTHON_COMPILING_IN_NOGIL 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 #undef CYTHON_USE_PYTYPE_LOOKUP @@ -100,13 +99,12 @@ END: Cython Metadata */ #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC - #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #define CYTHON_UPDATE_DESCRIPTOR_DOC (PYPY_VERSION_HEX >= 0x07030900) #endif #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 1 #define CYTHON_COMPILING_IN_CPYTHON 0 - #define CYTHON_COMPILING_IN_NOGIL 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif @@ -147,56 +145,10 @@ END: Cython Metadata */ #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 #endif -#elif defined(PY_NOGIL) - #define CYTHON_COMPILING_IN_PYPY 0 - #define CYTHON_COMPILING_IN_PYSTON 0 - #define CYTHON_COMPILING_IN_CPYTHON 0 - #define CYTHON_COMPILING_IN_NOGIL 1 - #ifndef CYTHON_USE_TYPE_SLOTS - #define CYTHON_USE_TYPE_SLOTS 1 - #endif - #undef CYTHON_USE_PYTYPE_LOOKUP - #define CYTHON_USE_PYTYPE_LOOKUP 0 - #ifndef CYTHON_USE_ASYNC_SLOTS - #define CYTHON_USE_ASYNC_SLOTS 1 - #endif - #undef CYTHON_USE_PYLIST_INTERNALS - #define CYTHON_USE_PYLIST_INTERNALS 0 - #ifndef CYTHON_USE_UNICODE_INTERNALS - #define CYTHON_USE_UNICODE_INTERNALS 1 - #endif - #undef CYTHON_USE_UNICODE_WRITER - #define CYTHON_USE_UNICODE_WRITER 0 - #undef CYTHON_USE_PYLONG_INTERNALS - #define CYTHON_USE_PYLONG_INTERNALS 0 - #ifndef CYTHON_AVOID_BORROWED_REFS - #define CYTHON_AVOID_BORROWED_REFS 0 - #endif - #ifndef CYTHON_ASSUME_SAFE_MACROS - #define CYTHON_ASSUME_SAFE_MACROS 1 - #endif - #ifndef CYTHON_UNPACK_METHODS - #define CYTHON_UNPACK_METHODS 1 - #endif - #undef CYTHON_FAST_THREAD_STATE - #define CYTHON_FAST_THREAD_STATE 0 - #undef CYTHON_FAST_PYCALL - #define CYTHON_FAST_PYCALL 0 - #ifndef CYTHON_PEP489_MULTI_PHASE_INIT - #define CYTHON_PEP489_MULTI_PHASE_INIT 1 - #endif - #ifndef CYTHON_USE_TP_FINALIZE - #define CYTHON_USE_TP_FINALIZE 1 - #endif - #undef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS 0 - #undef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 1 - #define CYTHON_COMPILING_IN_NOGIL 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif @@ -216,7 +168,7 @@ END: Cython Metadata */ #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) - #define CYTHON_USE_PYLONG_INTERNALS (PY_VERSION_HEX < 0x030C00A5) + #define CYTHON_USE_PYLONG_INTERNALS 1 #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 @@ -255,7 +207,7 @@ END: Cython Metadata */ #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS ((PY_VERSION_HEX >= 0x030600B1) && (PY_VERSION_HEX < 0x030C00A5)) + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) #endif #if PY_VERSION_HEX >= 0x030B00A4 #undef CYTHON_USE_EXC_INFO_STACK @@ -565,11 +517,11 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 - #if PY_VERSION_HEX >= 0x030C0000 - #define __Pyx_PyUnicode_READY(op) (0) + #if defined(PyUnicode_IS_READY) + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) #else - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ - 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_READY(op) (0) #endif #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) @@ -578,14 +530,14 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) - #if PY_VERSION_HEX >= 0x030C0000 - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) #else - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) - #else - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) - #endif + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) #endif #else #define CYTHON_PEP393_ENABLED 0 @@ -1153,18 +1105,18 @@ static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UIN /* GetModuleGlobalName.proto */ #if CYTHON_USE_DICT_VERSIONS -#define __Pyx_GetModuleGlobalName(var, name) do {\ +#define __Pyx_GetModuleGlobalName(var, name) {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} while(0) -#define __Pyx_GetModuleGlobalNameUncached(var, name) do {\ +} +#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ PY_UINT64_T __pyx_dict_version;\ PyObject *__pyx_dict_cached_value;\ (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} while(0) +} static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); #else #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) @@ -1896,7 +1848,7 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { } static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); return 0; __pyx_L1_error:; return -1; @@ -2134,7 +2086,7 @@ if (!__Pyx_RefNanny) { Py_INCREF(__pyx_b); __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_cython_runtime); - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) @@ -2835,7 +2787,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { return __Pyx_PyFunction_FastCall(func, NULL, 0); } #endif -#if defined(__Pyx_CyFunction_USED) && defined(NDEBUG) +#ifdef __Pyx_CyFunction_USED if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) #else if (likely(PyCFunction_Check(func))) @@ -3050,7 +3002,13 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } PyErr_SetObject(type, value); if (tb) { -#if CYTHON_FAST_THREAD_STATE +#if CYTHON_COMPILING_IN_PYPY + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#else PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { @@ -3058,12 +3016,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } -#else - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); - Py_INCREF(tb); - PyErr_Restore(tmp_type, tmp_value, tb); - Py_XDECREF(tmp_tb); #endif } bad: @@ -3647,14 +3599,9 @@ static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, P self = PyTuple_GetItem(args, 0); if (unlikely(!self)) { Py_DECREF(new_args); -#if PY_MAJOR_VERSION > 2 PyErr_Format(PyExc_TypeError, "unbound method %.200S() needs an argument", cyfunc->func_qualname); -#else - PyErr_SetString(PyExc_TypeError, - "unbound method needs an argument"); -#endif return NULL; } result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); @@ -3848,7 +3795,7 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK -static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { +static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON diff --git a/src_c/_sdl2/video.c b/src_c/_sdl2/video.c index 744a1bdfa5..df0559c7ec 100644 --- a/src_c/_sdl2/video.c +++ b/src_c/_sdl2/video.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.29.34 */ +/* Generated by Cython 0.29.33 */ /* BEGIN: Cython Metadata { @@ -22,8 +22,8 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_29_34" -#define CYTHON_HEX_VERSION 0x001D22F0 +#define CYTHON_ABI "0_29_33" +#define CYTHON_HEX_VERSION 0x001D21F0 #define CYTHON_FUTURE_DIVISION 1 #include #ifndef offsetof @@ -216,7 +216,7 @@ END: Cython Metadata */ #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) - #define CYTHON_USE_PYLONG_INTERNALS (PY_VERSION_HEX < 0x030C00A5) + #define CYTHON_USE_PYLONG_INTERNALS 1 #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 @@ -255,7 +255,7 @@ END: Cython Metadata */ #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS ((PY_VERSION_HEX >= 0x030600B1) && (PY_VERSION_HEX < 0x030C00A5)) + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) #endif #if PY_VERSION_HEX >= 0x030B00A4 #undef CYTHON_USE_EXC_INFO_STACK @@ -1674,20 +1674,12 @@ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); /* TypeImport.proto */ #ifndef __PYX_HAVE_RT_ImportType_proto #define __PYX_HAVE_RT_ImportType_proto -#if __STDC_VERSION__ >= 201112L -#include -#endif -#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L -#define __PYX_GET_STRUCT_ALIGNMENT(s) alignof(s) -#else -#define __PYX_GET_STRUCT_ALIGNMENT(s) sizeof(void*) -#endif enum __Pyx_ImportType_CheckSize { __Pyx_ImportType_CheckSize_Error = 0, __Pyx_ImportType_CheckSize_Warn = 1, __Pyx_ImportType_CheckSize_Ignore = 2 }; -static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize check_size); +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); #endif /* PyObject_GenericGetAttrNoDict.proto */ @@ -23948,11 +23940,9 @@ static int __Pyx_modinit_type_init_code(void) { /*--- Type init code ---*/ __pyx_t_1 = PyImport_ImportModule("pygame"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_6pygame_5_sdl2_5video_Color = __Pyx_ImportType(__pyx_t_1, "pygame", "Color", sizeof(pgColorObject), __PYX_GET_STRUCT_ALIGNMENT(pgColorObject), - __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_6pygame_5_sdl2_5video_Color = __Pyx_ImportType(__pyx_t_1, "pygame", "Color", sizeof(pgColorObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_6pygame_5_sdl2_5video_Color) __PYX_ERR(2, 457, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __PYX_GET_STRUCT_ALIGNMENT(pgRectObject), - __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_6pygame_5_sdl2_5video_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_6pygame_5_sdl2_5video_Rect) __PYX_ERR(2, 461, __pyx_L1_error) if (PyType_Ready(&__pyx_type_6pygame_5_sdl2_5video_Window) < 0) __PYX_ERR(0, 192, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 @@ -24064,23 +24054,21 @@ static int __Pyx_modinit_type_import_code(void) { __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 - sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT(PyTypeObject), + sizeof(PyTypeObject), #else - sizeof(PyHeapTypeObject), __PYX_GET_STRUCT_ALIGNMENT(PyHeapTypeObject), + sizeof(PyHeapTypeObject), #endif __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(3, 9, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __PYX_GET_STRUCT_ALIGNMENT(PyBoolObject), - __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(4, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __PYX_GET_STRUCT_ALIGNMENT(PyComplexObject), - __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(5, 15, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_RefNannyFinishContext(); @@ -25949,7 +25937,13 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } PyErr_SetObject(type, value); if (tb) { -#if CYTHON_FAST_THREAD_STATE +#if CYTHON_COMPILING_IN_PYPY + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#else PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { @@ -25957,12 +25951,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } -#else - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); - Py_INCREF(tb); - PyErr_Restore(tmp_type, tmp_value, tb); - Py_XDECREF(tmp_tb); #endif } bad: @@ -27005,15 +26993,13 @@ static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, - size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize check_size) + size_t size, enum __Pyx_ImportType_CheckSize check_size) { PyObject *result = 0; char warning[200]; Py_ssize_t basicsize; - Py_ssize_t itemsize; #ifdef Py_LIMITED_API PyObject *py_basicsize; - PyObject *py_itemsize; #endif result = PyObject_GetAttrString(module, class_name); if (!result) @@ -27026,7 +27012,6 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, } #ifndef Py_LIMITED_API basicsize = ((PyTypeObject *)result)->tp_basicsize; - itemsize = ((PyTypeObject *)result)->tp_itemsize; #else py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); if (!py_basicsize) @@ -27036,23 +27021,8 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, py_basicsize = 0; if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) goto bad; - py_itemsize = PyObject_GetAttrString(result, "__itemsize__"); - if (!py_itemsize) - goto bad; - itemsize = PyLong_AsSsize_t(py_itemsize); - Py_DECREF(py_itemsize); - py_itemsize = 0; - if (itemsize == (Py_ssize_t)-1 && PyErr_Occurred()) - goto bad; #endif - if (itemsize) { - if (size % alignment) { - alignment = size % alignment; - } - if (itemsize < (Py_ssize_t)alignment) - itemsize = (Py_ssize_t)alignment; - } - if ((size_t)(basicsize + itemsize) < size) { + if ((size_t)basicsize < size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", diff --git a/src_c/_sprite.c b/src_c/_sprite.c index f939ee7637..68ae18cc03 100644 --- a/src_c/_sprite.c +++ b/src_c/_sprite.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.29.34 */ +/* Generated by Cython 0.29.30 */ /* BEGIN: Cython Metadata { @@ -22,8 +22,8 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_29_34" -#define CYTHON_HEX_VERSION 0x001D22F0 +#define CYTHON_ABI "0_29_30" +#define CYTHON_HEX_VERSION 0x001D1EF0 #define CYTHON_FUTURE_DIVISION 1 #include #ifndef offsetof @@ -62,7 +62,6 @@ END: Cython Metadata */ #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 0 - #define CYTHON_COMPILING_IN_NOGIL 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 #undef CYTHON_USE_PYTYPE_LOOKUP @@ -100,13 +99,12 @@ END: Cython Metadata */ #undef CYTHON_USE_EXC_INFO_STACK #define CYTHON_USE_EXC_INFO_STACK 0 #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC - #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #define CYTHON_UPDATE_DESCRIPTOR_DOC (PYPY_VERSION_HEX >= 0x07030900) #endif #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 1 #define CYTHON_COMPILING_IN_CPYTHON 0 - #define CYTHON_COMPILING_IN_NOGIL 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif @@ -147,56 +145,10 @@ END: Cython Metadata */ #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 #endif -#elif defined(PY_NOGIL) - #define CYTHON_COMPILING_IN_PYPY 0 - #define CYTHON_COMPILING_IN_PYSTON 0 - #define CYTHON_COMPILING_IN_CPYTHON 0 - #define CYTHON_COMPILING_IN_NOGIL 1 - #ifndef CYTHON_USE_TYPE_SLOTS - #define CYTHON_USE_TYPE_SLOTS 1 - #endif - #undef CYTHON_USE_PYTYPE_LOOKUP - #define CYTHON_USE_PYTYPE_LOOKUP 0 - #ifndef CYTHON_USE_ASYNC_SLOTS - #define CYTHON_USE_ASYNC_SLOTS 1 - #endif - #undef CYTHON_USE_PYLIST_INTERNALS - #define CYTHON_USE_PYLIST_INTERNALS 0 - #ifndef CYTHON_USE_UNICODE_INTERNALS - #define CYTHON_USE_UNICODE_INTERNALS 1 - #endif - #undef CYTHON_USE_UNICODE_WRITER - #define CYTHON_USE_UNICODE_WRITER 0 - #undef CYTHON_USE_PYLONG_INTERNALS - #define CYTHON_USE_PYLONG_INTERNALS 0 - #ifndef CYTHON_AVOID_BORROWED_REFS - #define CYTHON_AVOID_BORROWED_REFS 0 - #endif - #ifndef CYTHON_ASSUME_SAFE_MACROS - #define CYTHON_ASSUME_SAFE_MACROS 1 - #endif - #ifndef CYTHON_UNPACK_METHODS - #define CYTHON_UNPACK_METHODS 1 - #endif - #undef CYTHON_FAST_THREAD_STATE - #define CYTHON_FAST_THREAD_STATE 0 - #undef CYTHON_FAST_PYCALL - #define CYTHON_FAST_PYCALL 0 - #ifndef CYTHON_PEP489_MULTI_PHASE_INIT - #define CYTHON_PEP489_MULTI_PHASE_INIT 1 - #endif - #ifndef CYTHON_USE_TP_FINALIZE - #define CYTHON_USE_TP_FINALIZE 1 - #endif - #undef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS 0 - #undef CYTHON_USE_EXC_INFO_STACK - #define CYTHON_USE_EXC_INFO_STACK 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 0 #define CYTHON_COMPILING_IN_CPYTHON 1 - #define CYTHON_COMPILING_IN_NOGIL 0 #ifndef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 1 #endif @@ -216,7 +168,7 @@ END: Cython Metadata */ #undef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 0 #elif !defined(CYTHON_USE_PYLONG_INTERNALS) - #define CYTHON_USE_PYLONG_INTERNALS (PY_VERSION_HEX < 0x030C00A5) + #define CYTHON_USE_PYLONG_INTERNALS 1 #endif #ifndef CYTHON_USE_PYLIST_INTERNALS #define CYTHON_USE_PYLIST_INTERNALS 1 @@ -255,7 +207,7 @@ END: Cython Metadata */ #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif #ifndef CYTHON_USE_DICT_VERSIONS - #define CYTHON_USE_DICT_VERSIONS ((PY_VERSION_HEX >= 0x030600B1) && (PY_VERSION_HEX < 0x030C00A5)) + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) #endif #if PY_VERSION_HEX >= 0x030B00A4 #undef CYTHON_USE_EXC_INFO_STACK @@ -565,11 +517,11 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 - #if PY_VERSION_HEX >= 0x030C0000 - #define __Pyx_PyUnicode_READY(op) (0) + #if defined(PyUnicode_IS_READY) + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) #else - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ - 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_READY(op) (0) #endif #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) @@ -578,14 +530,14 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) - #if PY_VERSION_HEX >= 0x030C0000 - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) #else - #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) - #else - #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) - #endif + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) #endif #else #define CYTHON_PEP393_ENABLED 0 @@ -759,37 +711,6 @@ static CYTHON_INLINE float __PYX_NAN() { #include "pythread.h" #include "_pygame.h" #include "SDL.h" - - #if SDL_VERSION_ATLEAST(2, 0, 18) - typedef SDL_FPoint _pgsdlFPoint; - typedef SDL_Vertex _pgsdlVertex; - #else - typedef struct { - float x; - float y; - } _pgsdlFPoint; - - typedef struct { - _pgsdlFPoint position; - SDL_Color color; - _pgsdlFPoint tex_coord; - } _pgsdlVertex; - #endif - - #if SDL_VERSION_ATLEAST(2,0,12) - typedef SDL_ScaleMode _pgsdlScaleMode; - #else - typedef enum { - SDL_ScaleModeNearest, - SDL_ScaleModeLinear, - SDL_ScaleModeBest, - } _pgsdlScaleMode; - - int SDL_SetTextureScaleMode(SDL_Texture * texture, _pgsdlScaleMode scaleMode){ - return 0; - } - #endif - #include "pygame.h" #ifdef _OPENMP #include @@ -1026,7 +947,7 @@ struct __pyx_opt_args_6pygame_5_sdl2_5video_7Texture_draw_internal; struct __pyx_opt_args_6pygame_5_sdl2_5video_7Texture_draw; struct __pyx_opt_args_6pygame_5_sdl2_5video_5Image_draw; -/* "_sdl2/video.pxd":478 +/* "_sdl2/video.pxd":421 * * cpdef object get_viewport(self) * cpdef object blit(self, object source, Rect dest=*, Rect area=*, int special_flags=*) # <<<<<<<<<<<<<< @@ -1040,7 +961,7 @@ struct __pyx_opt_args_6pygame_5_sdl2_5video_8Renderer_blit { int special_flags; }; -/* "_sdl2/video.pxd":487 +/* "_sdl2/video.pxd":430 * cdef readonly int height * * cdef draw_internal(self, SDL_Rect *csrcrect, SDL_Rect *cdstrect, float angle=*, SDL_Point *originptr=*, # <<<<<<<<<<<<<< @@ -1055,7 +976,7 @@ struct __pyx_opt_args_6pygame_5_sdl2_5video_7Texture_draw_internal { int flip_y; }; -/* "_sdl2/video.pxd":489 +/* "_sdl2/video.pxd":432 * cdef draw_internal(self, SDL_Rect *csrcrect, SDL_Rect *cdstrect, float angle=*, SDL_Point *originptr=*, * bint flip_x=*, bint flip_y=*) * cpdef void draw(self, srcrect=*, dstrect=*, float angle=*, origin=*, # <<<<<<<<<<<<<< @@ -1072,7 +993,7 @@ struct __pyx_opt_args_6pygame_5_sdl2_5video_7Texture_draw { int flip_y; }; -/* "_sdl2/video.pxd":505 +/* "_sdl2/video.pxd":448 * cdef public Rect srcrect * * cpdef void draw(self, srcrect=*, dstrect=*) # <<<<<<<<<<<<<< @@ -1109,7 +1030,7 @@ struct __pyx_opt_args_6pygame_7_sprite_12LayeredDirty_add_internal { PyObject *layer; }; -/* "_sdl2/video.pxd":466 +/* "_sdl2/video.pxd":409 * * * cdef class Window: # <<<<<<<<<<<<<< @@ -1123,7 +1044,7 @@ struct __pyx_obj_6pygame_5_sdl2_5video_Window { }; -/* "_sdl2/video.pxd":470 +/* "_sdl2/video.pxd":413 * cdef int _is_borrowed * * cdef class Renderer: # <<<<<<<<<<<<<< @@ -1141,7 +1062,7 @@ struct __pyx_obj_6pygame_5_sdl2_5video_Renderer { }; -/* "_sdl2/video.pxd":480 +/* "_sdl2/video.pxd":423 * cpdef object blit(self, object source, Rect dest=*, Rect area=*, int special_flags=*) * * cdef class Texture: # <<<<<<<<<<<<<< @@ -1159,7 +1080,7 @@ struct __pyx_obj_6pygame_5_sdl2_5video_Texture { }; -/* "_sdl2/video.pxd":492 +/* "_sdl2/video.pxd":435 * bint flip_x=*, bint flip_y=*) * * cdef class Image: # <<<<<<<<<<<<<< @@ -1296,7 +1217,7 @@ struct __pyx_obj_6pygame_7_sprite_GroupSingle { -/* "_sdl2/video.pxd":470 +/* "_sdl2/video.pxd":413 * cdef int _is_borrowed * * cdef class Renderer: # <<<<<<<<<<<<<< @@ -1311,7 +1232,7 @@ struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Renderer { static struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Renderer *__pyx_vtabptr_6pygame_5_sdl2_5video_Renderer; -/* "_sdl2/video.pxd":480 +/* "_sdl2/video.pxd":423 * cpdef object blit(self, object source, Rect dest=*, Rect area=*, int special_flags=*) * * cdef class Texture: # <<<<<<<<<<<<<< @@ -1326,7 +1247,7 @@ struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Texture { static struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Texture *__pyx_vtabptr_6pygame_5_sdl2_5video_Texture; -/* "_sdl2/video.pxd":492 +/* "_sdl2/video.pxd":435 * bint flip_x=*, bint flip_y=*) * * cdef class Image: # <<<<<<<<<<<<<< @@ -1820,18 +1741,18 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice( /* GetModuleGlobalName.proto */ #if CYTHON_USE_DICT_VERSIONS -#define __Pyx_GetModuleGlobalName(var, name) do {\ +#define __Pyx_GetModuleGlobalName(var, name) {\ static PY_UINT64_T __pyx_dict_version = 0;\ static PyObject *__pyx_dict_cached_value = NULL;\ (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} while(0) -#define __Pyx_GetModuleGlobalNameUncached(var, name) do {\ +} +#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ PY_UINT64_T __pyx_dict_version;\ PyObject *__pyx_dict_cached_value;\ (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ -} while(0) +} static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); #else #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) @@ -1985,20 +1906,12 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, /* TypeImport.proto */ #ifndef __PYX_HAVE_RT_ImportType_proto #define __PYX_HAVE_RT_ImportType_proto -#if __STDC_VERSION__ >= 201112L -#include -#endif -#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L -#define __PYX_GET_STRUCT_ALIGNMENT(s) alignof(s) -#else -#define __PYX_GET_STRUCT_ALIGNMENT(s) sizeof(void*) -#endif enum __Pyx_ImportType_CheckSize { __Pyx_ImportType_CheckSize_Error = 0, __Pyx_ImportType_CheckSize_Warn = 1, __Pyx_ImportType_CheckSize_Ignore = 2 }; -static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize check_size); +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); #endif /* PyObject_GenericGetAttrNoDict.proto */ @@ -4260,7 +4173,7 @@ static int __pyx_pf_6pygame_7_sprite_6Sprite_3__g_2__set__(struct __pyx_obj_6pyg const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 142, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 142, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -5460,7 +5373,7 @@ static PyObject *__pyx_f_6pygame_7_sprite_13AbstractGroup_sprites(struct __pyx_o if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 336, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 336, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 336, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -9141,7 +9054,7 @@ static int __pyx_pf_6pygame_7_sprite_13AbstractGroup_10spritedict_2__set__(struc const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 329, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 329, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -9249,7 +9162,7 @@ static int __pyx_pf_6pygame_7_sprite_13AbstractGroup_11lostsprites_2__set__(stru const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 330, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 330, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -10359,7 +10272,7 @@ static PyObject *__pyx_f_6pygame_7_sprite_14OrderedUpdates_sprites(struct __pyx_ if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 650, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 650, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 650, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10815,7 +10728,7 @@ static int __pyx_pf_6pygame_7_sprite_14OrderedUpdates_11_spritelist_2__set__(str const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 644, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 644, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -12724,7 +12637,7 @@ static PyObject *__pyx_f_6pygame_7_sprite_14LayeredUpdates_sprites(struct __pyx_ if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 799, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 799, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 799, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -15330,7 +15243,7 @@ static int __pyx_pf_6pygame_7_sprite_14LayeredUpdates_13_spritelayers_2__set__(s const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 674, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 674, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -15438,7 +15351,7 @@ static int __pyx_pf_6pygame_7_sprite_14LayeredUpdates_11_spritelist_2__set__(str const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 675, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 675, __pyx_L1_error) __pyx_t_1 = __pyx_v_value; __Pyx_INCREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); @@ -20144,7 +20057,7 @@ static PyObject *__pyx_f_6pygame_7_sprite_11GroupSingle_sprites(struct __pyx_obj if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1330, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||((void)PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 1330, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 1330, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -27181,7 +27094,7 @@ static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { __pyx_umethod_PyDict_Type_pop.type = (PyObject*)&PyDict_Type; __pyx_umethod_PyDict_Type_values.type = (PyObject*)&PyDict_Type; __pyx_umethod_PyList_Type_remove.type = (PyObject*)&PyList_Type; - if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); __pyx_float_0_5 = PyFloat_FromDouble(0.5); if (unlikely(!__pyx_float_0_5)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) @@ -27234,8 +27147,7 @@ static int __Pyx_modinit_type_init_code(void) { /*--- Type init code ---*/ __pyx_t_1 = PyImport_ImportModule("pygame"); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_6pygame_7_sprite_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __PYX_GET_STRUCT_ALIGNMENT(pgRectObject), - __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_6pygame_7_sprite_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_6pygame_7_sprite_Rect) __PYX_ERR(0, 116, __pyx_L1_error) __pyx_vtabptr_6pygame_7_sprite_AbstractGroup = &__pyx_vtable_6pygame_7_sprite_AbstractGroup; __pyx_vtable_6pygame_7_sprite_AbstractGroup.sprites = (PyObject *(*)(struct __pyx_obj_6pygame_7_sprite_AbstractGroup *, int __pyx_skip_dispatch))__pyx_f_6pygame_7_sprite_13AbstractGroup_sprites; @@ -27413,50 +27325,42 @@ static int __Pyx_modinit_type_import_code(void) { __Pyx_GOTREF(__pyx_t_1); __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 - sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT(PyTypeObject), + sizeof(PyTypeObject), #else - sizeof(PyHeapTypeObject), __PYX_GET_STRUCT_ALIGNMENT(PyHeapTypeObject), + sizeof(PyHeapTypeObject), #endif __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(2, 9, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __PYX_GET_STRUCT_ALIGNMENT(PyBoolObject), - __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(3, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 15, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __PYX_GET_STRUCT_ALIGNMENT(PyComplexObject), - __Pyx_ImportType_CheckSize_Warn); + __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn); if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(4, 15, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyImport_ImportModule("pygame"); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 457, __pyx_L1_error) + __pyx_t_1 = PyImport_ImportModule("pygame"); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 400, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_ptype_6pygame_5_sdl2_5video_Color = __Pyx_ImportType(__pyx_t_1, "pygame", "Color", sizeof(pgColorObject), __PYX_GET_STRUCT_ALIGNMENT(pgColorObject), - __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Color) __PYX_ERR(5, 457, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __PYX_GET_STRUCT_ALIGNMENT(pgRectObject), - __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Rect) __PYX_ERR(5, 461, __pyx_L1_error) - __pyx_t_2 = PyImport_ImportModule("pygame._sdl2.video"); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 466, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Color = __Pyx_ImportType(__pyx_t_1, "pygame", "Color", sizeof(pgColorObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Color) __PYX_ERR(5, 400, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Rect = __Pyx_ImportType(__pyx_t_1, "pygame", "Rect", sizeof(pgRectObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Rect) __PYX_ERR(5, 404, __pyx_L1_error) + __pyx_t_2 = PyImport_ImportModule("pygame._sdl2.video"); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_ptype_6pygame_5_sdl2_5video_Window = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Window", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Window), __PYX_GET_STRUCT_ALIGNMENT(struct __pyx_obj_6pygame_5_sdl2_5video_Window), - __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Window) __PYX_ERR(5, 466, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Renderer = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Renderer", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Renderer), __PYX_GET_STRUCT_ALIGNMENT(struct __pyx_obj_6pygame_5_sdl2_5video_Renderer), - __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Renderer) __PYX_ERR(5, 470, __pyx_L1_error) - __pyx_vtabptr_6pygame_5_sdl2_5video_Renderer = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Renderer*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Renderer->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Renderer)) __PYX_ERR(5, 470, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Texture = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Texture", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Texture), __PYX_GET_STRUCT_ALIGNMENT(struct __pyx_obj_6pygame_5_sdl2_5video_Texture), - __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Texture) __PYX_ERR(5, 480, __pyx_L1_error) - __pyx_vtabptr_6pygame_5_sdl2_5video_Texture = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Texture*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Texture->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Texture)) __PYX_ERR(5, 480, __pyx_L1_error) - __pyx_ptype_6pygame_5_sdl2_5video_Image = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Image", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Image), __PYX_GET_STRUCT_ALIGNMENT(struct __pyx_obj_6pygame_5_sdl2_5video_Image), - __Pyx_ImportType_CheckSize_Warn); - if (!__pyx_ptype_6pygame_5_sdl2_5video_Image) __PYX_ERR(5, 492, __pyx_L1_error) - __pyx_vtabptr_6pygame_5_sdl2_5video_Image = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Image*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Image->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Image)) __PYX_ERR(5, 492, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Window = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Window", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Window), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Window) __PYX_ERR(5, 409, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Renderer = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Renderer", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Renderer), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Renderer) __PYX_ERR(5, 413, __pyx_L1_error) + __pyx_vtabptr_6pygame_5_sdl2_5video_Renderer = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Renderer*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Renderer->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Renderer)) __PYX_ERR(5, 413, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Texture = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Texture", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Texture), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Texture) __PYX_ERR(5, 423, __pyx_L1_error) + __pyx_vtabptr_6pygame_5_sdl2_5video_Texture = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Texture*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Texture->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Texture)) __PYX_ERR(5, 423, __pyx_L1_error) + __pyx_ptype_6pygame_5_sdl2_5video_Image = __Pyx_ImportType(__pyx_t_2, "pygame._sdl2.video", "Image", sizeof(struct __pyx_obj_6pygame_5_sdl2_5video_Image), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_6pygame_5_sdl2_5video_Image) __PYX_ERR(5, 435, __pyx_L1_error) + __pyx_vtabptr_6pygame_5_sdl2_5video_Image = (struct __pyx_vtabstruct_6pygame_5_sdl2_5video_Image*)__Pyx_GetVtable(__pyx_ptype_6pygame_5_sdl2_5video_Image->tp_dict); if (unlikely(!__pyx_vtabptr_6pygame_5_sdl2_5video_Image)) __PYX_ERR(5, 435, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_RefNannyFinishContext(); @@ -27660,7 +27564,7 @@ if (!__Pyx_RefNanny) { Py_INCREF(__pyx_b); __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_cython_runtime); - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) @@ -28254,7 +28158,7 @@ if (!__Pyx_RefNanny) { __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "pygame/_sprite.pyx":1 - * ## pygame-ce - Python Game Library # <<<<<<<<<<<<<< + * ## pygame - Python Game Library # <<<<<<<<<<<<<< * ## Copyright (C) 2000-2003, 2007 Pete Shinners * ## (C) 2004 Joe Wreschnig */ @@ -28747,7 +28651,9 @@ static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, PyGILState_STATE state; if (nogil) state = PyGILState_Ensure(); - else state = (PyGILState_STATE)0; +#ifdef _MSC_VER + else state = (PyGILState_STATE)-1; +#endif #endif __Pyx_PyThreadState_assign __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); @@ -28819,7 +28725,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { return __Pyx_PyFunction_FastCall(func, NULL, 0); } #endif -#if defined(__Pyx_CyFunction_USED) && defined(NDEBUG) +#ifdef __Pyx_CyFunction_USED if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) #else if (likely(PyCFunction_Check(func))) @@ -28964,8 +28870,10 @@ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { Py_DECREF(retval); __Pyx_RaiseTooManyValuesError(expected); return -1; + } else { + return __Pyx_IterFinish(); } - return __Pyx_IterFinish(); + return 0; } /* RaiseNoneIterError */ @@ -29299,7 +29207,13 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } PyErr_SetObject(type, value); if (tb) { -#if CYTHON_FAST_THREAD_STATE +#if CYTHON_COMPILING_IN_PYPY + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#else PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { @@ -29307,12 +29221,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } -#else - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); - Py_INCREF(tb); - PyErr_Restore(tmp_type, tmp_value, tb); - Py_XDECREF(tmp_tb); #endif } bad: @@ -29806,11 +29714,11 @@ static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* if (flag == METH_O) { return (*(cfunc->func))(self, arg); } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) { - #if PY_VERSION_HEX >= 0x030700A0 + if (PY_VERSION_HEX >= 0x030700A0) { return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1); - #else + } else { return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL); - #endif + } } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) { return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL); } @@ -30292,7 +30200,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, /* ObjectGetItem */ #if CYTHON_USE_TYPE_SLOTS static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { - PyObject *runerr = NULL; + PyObject *runerr; Py_ssize_t key_value; PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence; if (unlikely(!(m && m->sq_item))) { @@ -30703,15 +30611,13 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, - size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize check_size) + size_t size, enum __Pyx_ImportType_CheckSize check_size) { PyObject *result = 0; char warning[200]; Py_ssize_t basicsize; - Py_ssize_t itemsize; #ifdef Py_LIMITED_API PyObject *py_basicsize; - PyObject *py_itemsize; #endif result = PyObject_GetAttrString(module, class_name); if (!result) @@ -30724,7 +30630,6 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, } #ifndef Py_LIMITED_API basicsize = ((PyTypeObject *)result)->tp_basicsize; - itemsize = ((PyTypeObject *)result)->tp_itemsize; #else py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); if (!py_basicsize) @@ -30734,23 +30639,8 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, py_basicsize = 0; if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) goto bad; - py_itemsize = PyObject_GetAttrString(result, "__itemsize__"); - if (!py_itemsize) - goto bad; - itemsize = PyLong_AsSsize_t(py_itemsize); - Py_DECREF(py_itemsize); - py_itemsize = 0; - if (itemsize == (Py_ssize_t)-1 && PyErr_Occurred()) - goto bad; #endif - if (itemsize) { - if (size % alignment) { - alignment = size % alignment; - } - if (itemsize < (Py_ssize_t)alignment) - itemsize = (Py_ssize_t)alignment; - } - if ((size_t)(basicsize + itemsize) < size) { + if ((size_t)basicsize < size) { PyErr_Format(PyExc_ValueError, "%.200s.%.200s size changed, may indicate binary incompatibility. " "Expected %zd from C header, got %zd from PyObject", @@ -31607,14 +31497,9 @@ static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, P self = PyTuple_GetItem(args, 0); if (unlikely(!self)) { Py_DECREF(new_args); -#if PY_MAJOR_VERSION > 2 PyErr_Format(PyExc_TypeError, "unbound method %.200S() needs an argument", cyfunc->func_qualname); -#else - PyErr_SetString(PyExc_TypeError, - "unbound method needs an argument"); -#endif return NULL; } result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); @@ -31867,7 +31752,7 @@ static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) { /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK -static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { +static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON From e42664afb5d75c77585832e25c507652fe6f7fd0 Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 9 May 2023 17:06:06 +0100 Subject: [PATCH 09/20] Add background colour option, fix size bug --- buildconfig/stubs/pygame/transform.pyi | 2 +- docs/reST/ref/transform.rst | 7 ++- src_c/doc/transform_doc.h | 2 +- src_c/transform.c | 77 ++++++++++++++------------ 4 files changed, 50 insertions(+), 38 deletions(-) diff --git a/buildconfig/stubs/pygame/transform.pyi b/buildconfig/stubs/pygame/transform.pyi index 2bb844a48a..5f98baf833 100644 --- a/buildconfig/stubs/pygame/transform.pyi +++ b/buildconfig/stubs/pygame/transform.pyi @@ -17,7 +17,7 @@ def scale_by( dest_surface: Optional[Surface] = None, ) -> Surface: ... def rotate(surface: Surface, angle: float) -> Surface: ... -def skew(surface: Surface, points: Sequence[Coordinate], adjust_size: Optional[bool], dest_surface: Optional[Surface]) -> Surface: ... +def skew(surface: Surface, points: Sequence[Coordinate], bg_color: Optional[Union[ColorValue, None]] = None, adjust_size: Optional[bool] = False, dest_surface: Optional[Surface] = None) -> Surface: ... def rotozoom(surface: Surface, angle: float, scale: float) -> Surface: ... def scale2x(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... def grayscale(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... diff --git a/docs/reST/ref/transform.rst b/docs/reST/ref/transform.rst index 8388a480a7..0a114592fa 100644 --- a/docs/reST/ref/transform.rst +++ b/docs/reST/ref/transform.rst @@ -104,13 +104,16 @@ Instead, always begin with the original image and scale to the desired size.) .. function:: skew | :sl:`skew an image to specified points` - | :sg:`skew(surface, points, adjust_size=False, dest_surface=None)` + | :sg:`skew(surface, points, bg_color=None, adjust_size=False, dest_surface=None)` This maps an image to a new surface warping the image so that its corners match the provided points. When no destination surface is provided, the adjust_size option will change the size of the resulting surface to be the smallest surface the points are capable of fitting in, otherwhise it will - use the original size of the provided surface. + use the original size of the provided surface. If a color for the background + is not provided then it will behave the same as the rotate function. If the + image has pixel alphas, the padded area will be transparent. Otherwise pygame + will pick a color that matches the Surface colorkey or the topleft pixel value. .. versionadded:: 2.3.0 diff --git a/src_c/doc/transform_doc.h b/src_c/doc/transform_doc.h index f1f7d6801b..ee80c952bf 100644 --- a/src_c/doc/transform_doc.h +++ b/src_c/doc/transform_doc.h @@ -5,7 +5,7 @@ #define DOC_TRANSFORM_SCALEBY "scale_by(surface, factor, dest_surface=None) -> Surface\nresize to new resolution, using scalar(s)" #define DOC_TRANSFORM_ROTATE "rotate(surface, angle) -> Surface\nrotate an image" #define DOC_TRANSFORM_ROTOZOOM "rotozoom(surface, angle, scale) -> Surface\nfiltered scale and rotation" -#define DOC_TRANSFORM_SKEW "skew(surface, points, adjust_size=False, dest_surface=None)\nskew an image to specified points" +#define DOC_TRANSFORM_SKEW "skew(surface, points, bg_color=None, adjust_size=False, dest_surface=None)\nskew an image to specified points" #define DOC_TRANSFORM_SCALE2X "scale2x(surface, dest_surface=None) -> Surface\nspecialized image doubler" #define DOC_TRANSFORM_SMOOTHSCALE "smoothscale(surface, size, dest_surface=None) -> Surface\nscale a surface to an arbitrary size smoothly" #define DOC_TRANSFORM_SMOOTHSCALEBY "smoothscale_by(surface, factor, dest_surface=None) -> Surface\nresize to new resolution, using scalar(s)" diff --git a/src_c/transform.c b/src_c/transform.c index c47ca1cab8..a3ebaeb87e 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -1014,39 +1014,39 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) { pgSurfaceObject *surfobj; pgSurfaceObject *dest_surf = NULL; + PyObject *colorobj; SDL_Surface *surf, *newsurf; int adjust_size = 0; int x1, y1, x2, y2, x3, y3, x4, y4; int start = 0, width, top = 0, height; Uint32 bgcolor; - static char *keywords[] = {"surface", "points", "adjust_size", "dest_surf", - NULL}; + static char *keywords[] = {"surface", "points", "bgcolor", + "adjust_size", "dest_surf", NULL}; if (!PyArg_ParseTupleAndKeywords( - args, kwargs, "O!((ii)(ii)(ii)(ii))|pO!", keywords, + args, kwargs, "O!((ii)(ii)(ii)(ii))|OpO!", keywords, &pgSurface_Type, &surfobj, &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4, - &adjust_size, &pgSurface_Type, &dest_surf)) + &colorobj, &adjust_size, &pgSurface_Type, &dest_surf)) return NULL; surf = pgSurface_AsSurface(surfobj); SURF_INIT_CHECK(surf) if (!dest_surf) { if (adjust_size) { start = MIN(MIN(x1, x2), MIN(x3, x4)); - width = MAX(MAX(x1, x2), MAX(x3, x4)) - start; + width = MAX(MAX(x1, x2), MAX(x3, x4)) - start + 1; top = MIN(MIN(y1, y2), MIN(y3, y4)); - height = MAX(MAX(y1, y2), MAX(y3, y4)) - top; - newsurf = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, - surf->format->format); + height = MAX(MAX(y1, y2), MAX(y3, y4)) - top + 1; + newsurf = newsurf_fromsurf(surf, width, height); } else { - newsurf = SDL_CreateRGBSurfaceWithFormat(0, surf->w, surf->h, 32, - surf->format->format); + newsurf = newsurf_fromsurf(surf, surf->w, surf->h); } } else { newsurf = pgSurface_AsSurface(dest_surf); - SURF_INIT_CHECK(newsurf) } + if (!newsurf) + return NULL; if (surf->w < 1 || surf->h < 1) { Py_INCREF(surfobj); @@ -1075,31 +1075,36 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) SDL_LockSurface(newsurf); SDL_LockSurface(surf); pgSurface_Lock(surfobj); - - /* get the background color */ - if (SDL_GetColorKey(surf, &bgcolor) != 0) { - switch (surf->format->BytesPerPixel) { - case 1: - bgcolor = *(Uint8 *)surf->pixels; - break; - case 2: - bgcolor = *(Uint16 *)surf->pixels; - break; - case 4: - bgcolor = *(Uint32 *)surf->pixels; - break; - default: /*case 3:*/ + if (colorobj != Py_None) { + if (_color_from_obj(colorobj, surf->format, NULL, &bgcolor)) + return RAISE(PyExc_TypeError, "invalid bg_color argument"); + } + else { + /* get the background color */ + if (SDL_GetColorKey(surf, &bgcolor) != 0) { + switch (surf->format->BytesPerPixel) { + case 1: + bgcolor = *(Uint8 *)surf->pixels; + break; + case 2: + bgcolor = *(Uint16 *)surf->pixels; + break; + case 4: + bgcolor = *(Uint32 *)surf->pixels; + break; + default: /*case 3:*/ #if SDL_BYTEORDER == SDL_LIL_ENDIAN - bgcolor = (((Uint8 *)surf->pixels)[0]) + - (((Uint8 *)surf->pixels)[1] << 8) + - (((Uint8 *)surf->pixels)[2] << 16); + bgcolor = (((Uint8 *)surf->pixels)[0]) + + (((Uint8 *)surf->pixels)[1] << 8) + + (((Uint8 *)surf->pixels)[2] << 16); #else - bgcolor = (((Uint8 *)surf->pixels)[2]) + - (((Uint8 *)surf->pixels)[1] << 8) + - (((Uint8 *)surf->pixels)[0] << 16); + bgcolor = (((Uint8 *)surf->pixels)[2]) + + (((Uint8 *)surf->pixels)[1] << 8) + + (((Uint8 *)surf->pixels)[0] << 16); #endif + } + bgcolor &= ~surf->format->Amask; } - bgcolor &= ~surf->format->Amask; } SDL_FillRect(newsurf, NULL, bgcolor); @@ -1110,8 +1115,12 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) pgSurface_Unlock(surfobj); SDL_UnlockSurface(newsurf); SDL_UnlockSurface(surf); - - return (PyObject *)pgSurface_New(newsurf); + if (dest_surf) { + Py_INCREF(dest_surf); + return dest_surf; + } + else + return (PyObject *)pgSurface_New(newsurf); } static PyObject * From 3616cd57ed625b58e9fdbf8f42bbcd41030b98d5 Mon Sep 17 00:00:00 2001 From: TemmieGamerGuy <76136819+Temmie3754@users.noreply.github.com> Date: Fri, 12 May 2023 12:15:05 +0100 Subject: [PATCH 10/20] Fix check errors --- src_c/transform.c | 68 +++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src_c/transform.c b/src_c/transform.c index a3ebaeb87e..7215fc7c88 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -1000,6 +1000,39 @@ surf_rotate(PyObject *self, PyObject *args, PyObject *kwargs) return (PyObject *)pgSurface_New(newsurf); } +/* _color_from_obj gets a color from a python object. + +Returns 0 if ok, and sets color to the color. + -1 means error. + If color_obj is NULL, use rgba_default. + If rgba_default is NULL, do not use a default color, return -1. +*/ +int +_color_from_obj(PyObject *color_obj, SDL_PixelFormat *format, + Uint8 rgba_default[4], Uint32 *color) +{ + if (color_obj) { + Uint8 rgba_color[4]; + + if (PyLong_Check(color_obj)) + *color = (Uint32)PyLong_AsLong(color_obj); + else if (PyLong_Check(color_obj)) + *color = (Uint32)PyLong_AsUnsignedLong(color_obj); + else if (pg_RGBAFromColorObj(color_obj, rgba_color)) + *color = SDL_MapRGBA(format, rgba_color[0], rgba_color[1], + rgba_color[2], rgba_color[3]); + else + return -1; + } + else { + if (!rgba_default) + return -1; + *color = SDL_MapRGBA(format, rgba_default[0], rgba_default[1], + rgba_default[2], rgba_default[3]); + } + return 0; +} + static int check_inside(SDL_Surface *surf, SDL_Point p) { @@ -1117,7 +1150,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) SDL_UnlockSurface(surf); if (dest_surf) { Py_INCREF(dest_surf); - return dest_surf; + return (PyObject *)dest_surf; } else return (PyObject *)pgSurface_New(newsurf); @@ -2170,39 +2203,6 @@ get_threshold(SDL_Surface *dest_surf, SDL_Surface *surf, return similar; } -/* _color_from_obj gets a color from a python object. - -Returns 0 if ok, and sets color to the color. - -1 means error. - If color_obj is NULL, use rgba_default. - If rgba_default is NULL, do not use a default color, return -1. -*/ -int -_color_from_obj(PyObject *color_obj, SDL_PixelFormat *format, - Uint8 rgba_default[4], Uint32 *color) -{ - if (color_obj) { - Uint8 rgba_color[4]; - - if (PyLong_Check(color_obj)) - *color = (Uint32)PyLong_AsLong(color_obj); - else if (PyLong_Check(color_obj)) - *color = (Uint32)PyLong_AsUnsignedLong(color_obj); - else if (pg_RGBAFromColorObj(color_obj, rgba_color)) - *color = SDL_MapRGBA(format, rgba_color[0], rgba_color[1], - rgba_color[2], rgba_color[3]); - else - return -1; - } - else { - if (!rgba_default) - return -1; - *color = SDL_MapRGBA(format, rgba_default[0], rgba_default[1], - rgba_default[2], rgba_default[3]); - } - return 0; -} - static PyObject * surf_threshold(PyObject *self, PyObject *args, PyObject *kwds) { From f8c2a688ffb49d9ba5677062d14e83c6115fa1ca Mon Sep 17 00:00:00 2001 From: Temmie <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 3 Oct 2023 23:54:23 +0100 Subject: [PATCH 11/20] Update version number Co-authored-by: Dan Lawrence --- docs/reST/ref/transform.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reST/ref/transform.rst b/docs/reST/ref/transform.rst index 0a114592fa..b3d77de516 100644 --- a/docs/reST/ref/transform.rst +++ b/docs/reST/ref/transform.rst @@ -115,7 +115,7 @@ Instead, always begin with the original image and scale to the desired size.) image has pixel alphas, the padded area will be transparent. Otherwise pygame will pick a color that matches the Surface colorkey or the topleft pixel value. - .. versionadded:: 2.3.0 + .. versionadded:: 2.4.0 .. ## pygame.transform.skew ## From d8e88cc63cef8c4333377d1a4002d4780d082531 Mon Sep 17 00:00:00 2001 From: Temmie <76136819+Temmie3754@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:54:52 +0000 Subject: [PATCH 12/20] Re-add new color_from_obj method --- src_c/transform.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src_c/transform.c b/src_c/transform.c index 350ecaffe8..879d555d71 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -1026,7 +1026,6 @@ surf_rotate(PyObject *self, PyObject *args, PyObject *kwargs) } /* _color_from_obj gets a color from a python object. - Returns 0 if ok, and sets color to the color. -1 means error. If color_obj is NULL, use rgba_default. @@ -1037,17 +1036,10 @@ _color_from_obj(PyObject *color_obj, SDL_PixelFormat *format, Uint8 rgba_default[4], Uint32 *color) { if (color_obj) { - Uint8 rgba_color[4]; - - if (PyLong_Check(color_obj)) - *color = (Uint32)PyLong_AsLong(color_obj); - else if (PyLong_Check(color_obj)) - *color = (Uint32)PyLong_AsUnsignedLong(color_obj); - else if (pg_RGBAFromColorObj(color_obj, rgba_color)) - *color = SDL_MapRGBA(format, rgba_color[0], rgba_color[1], - rgba_color[2], rgba_color[3]); - else + if (!pg_MappedColorFromObj(color_obj, format, color, + PG_COLOR_HANDLE_INT)) { return -1; + } } else { if (!rgba_default) From b36454f9aec088b4d242ae34a74c78e8c294b76a Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Sat, 5 Oct 2024 17:07:32 +0100 Subject: [PATCH 13/20] fix type hints --- buildconfig/stubs/pygame/transform.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/buildconfig/stubs/pygame/transform.pyi b/buildconfig/stubs/pygame/transform.pyi index 318c440dc9..a912ca9963 100644 --- a/buildconfig/stubs/pygame/transform.pyi +++ b/buildconfig/stubs/pygame/transform.pyi @@ -16,7 +16,10 @@ def scale_by( dest_surface: Optional[Surface] = None, ) -> Surface: ... def rotate(surface: Surface, angle: float) -> Surface: ... -def skew(surface: Surface, points: Sequence[Coordinate], bg_color: Optional[Union[ColorValue, None]] = None, adjust_size: Optional[bool] = False, dest_surface: Optional[Surface] = None) -> Surface: ... +def skew(surface: Surface, points: SequenceLike[Point], + bg_color: Optional[Union[ColorLike, None]] = None, + adjust_size: Optional[bool] = False, + dest_surface: Optional[Surface] = None) -> Surface: ... def rotozoom(surface: Surface, angle: float, scale: float) -> Surface: ... def scale2x(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... def grayscale(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... From 245cf01500c032135a7b77e4118d9711e98d68bc Mon Sep 17 00:00:00 2001 From: Temmie <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:29:15 +0100 Subject: [PATCH 14/20] Fix segfault and improve docs --- buildconfig/stubs/pygame/transform.pyi | 17 ++++---- docs/reST/ref/transform.rst | 27 ++++++++----- src_c/doc/transform_doc.h | 2 +- src_c/transform.c | 56 ++++++++++++++------------ 4 files changed, 58 insertions(+), 44 deletions(-) diff --git a/buildconfig/stubs/pygame/transform.pyi b/buildconfig/stubs/pygame/transform.pyi index a912ca9963..3efa806fa2 100644 --- a/buildconfig/stubs/pygame/transform.pyi +++ b/buildconfig/stubs/pygame/transform.pyi @@ -16,10 +16,13 @@ def scale_by( dest_surface: Optional[Surface] = None, ) -> Surface: ... def rotate(surface: Surface, angle: float) -> Surface: ... -def skew(surface: Surface, points: SequenceLike[Point], - bg_color: Optional[Union[ColorLike, None]] = None, - adjust_size: Optional[bool] = False, - dest_surface: Optional[Surface] = None) -> Surface: ... +def skew( + surface: Surface, + points: SequenceLike[Point], + bg_color: Optional[ColorLike] = None, + adjust_size: bool = True, + dest_surface: Optional[Surface] = None, +) -> Surface: ... def rotozoom(surface: Surface, angle: float, scale: float) -> Surface: ... def scale2x(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... def grayscale(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... @@ -40,7 +43,7 @@ def smoothscale_by( dest_surface: Optional[Surface] = None, ) -> Surface: ... def get_smoothscale_backend() -> Literal["GENERIC", "SSE2", "NEON"]: ... -def set_smoothscale_backend(backend: Literal["GENERIC", "SSE2", "NEON"]) -> None: ... +def set_smoothscaprele_backend(backend: Literal["GENERIC", "SSE2", "NEON"]) -> None: ... def chop(surface: Surface, rect: RectLike) -> Surface: ... def laplacian(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... def invert(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... @@ -66,13 +69,13 @@ def box_blur( surface: Surface, radius: int, repeat_edge_pixels: bool = True, - dest_surface: Optional[Surface] = None + dest_surface: Optional[Surface] = None, ) -> Surface: ... def gaussian_blur( surface: Surface, radius: int, repeat_edge_pixels: bool = True, - dest_surface: Optional[Surface] = None + dest_surface: Optional[Surface] = None, ) -> Surface: ... def hsl( surface: Surface, diff --git a/docs/reST/ref/transform.rst b/docs/reST/ref/transform.rst index b7e122835b..33531c3c54 100644 --- a/docs/reST/ref/transform.rst +++ b/docs/reST/ref/transform.rst @@ -104,18 +104,25 @@ Instead, always begin with the original image and scale to the desired size.) .. function:: skew | :sl:`skew an image to specified points` - | :sg:`skew(surface, points, bg_color=None, adjust_size=False, dest_surface=None)` + | :sg:`skew(surface, points, bg_color=None, adjust_size=True, dest_surface=None)` This maps an image to a new surface warping the image so that its corners - match the provided points. When no destination surface is provided, the - adjust_size option will change the size of the resulting surface to be the - smallest surface the points are capable of fitting in, otherwhise it will - use the original size of the provided surface. If a color for the background - is not provided then it will behave the same as the rotate function. If the - image has pixel alphas, the padded area will be transparent. Otherwise pygame - will pick a color that matches the Surface colorkey or the topleft pixel value. - - .. versionadded:: 2.4.0 + match the provided points in a clockwise order: top left, top right, bottom + right, bottom left. Provided points represent the pixel coordinates of the + new corners of the image and can be positive or negative provided they fit + in the new surface. + + When no 'dest_surface' is provided, the 'adjust_size' option will set the + size of the resulting surface to be the smallest surface the points are + capable of fitting in, if false it will use the original size of the + provided surface. + + If 'bg_color' is not provided then it will select a color to use based on + the surface. If the image has pixel alphas, the padded area will be + transparent. Otherwise pygame will pick a color that matches the Surface + colorkey or the top left pixel value. + + .. versionadded:: 2.5.2 .. ## pygame.transform.skew ## diff --git a/src_c/doc/transform_doc.h b/src_c/doc/transform_doc.h index 7628516ca0..95857ab5df 100644 --- a/src_c/doc/transform_doc.h +++ b/src_c/doc/transform_doc.h @@ -5,7 +5,7 @@ #define DOC_TRANSFORM_SCALEBY "scale_by(surface, factor, dest_surface=None) -> Surface\nresize to new resolution, using scalar(s)" #define DOC_TRANSFORM_ROTATE "rotate(surface, angle) -> Surface\nrotate an image" #define DOC_TRANSFORM_ROTOZOOM "rotozoom(surface, angle, scale) -> Surface\nfiltered scale and rotation" -#define DOC_TRANSFORM_SKEW "skew(surface, points, bg_color=None, adjust_size=False, dest_surface=None)\nskew an image to specified points" +#define DOC_TRANSFORM_SKEW "skew(surface, points, bg_color=None, adjust_size=True, dest_surface=None)\nskew an image to specified points" #define DOC_TRANSFORM_SCALE2X "scale2x(surface, dest_surface=None) -> Surface\nspecialized image doubler" #define DOC_TRANSFORM_SMOOTHSCALE "smoothscale(surface, size, dest_surface=None) -> Surface\nscale a surface to an arbitrary size smoothly" #define DOC_TRANSFORM_SMOOTHSCALEBY "smoothscale_by(surface, factor, dest_surface=None) -> Surface\nresize to new resolution, using scalar(s)" diff --git a/src_c/transform.c b/src_c/transform.c index 324a297fbf..e9752718c4 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -1059,8 +1059,8 @@ _color_from_obj(PyObject *color_obj, SDL_PixelFormat *format, return 0; } -static int -check_inside(SDL_Surface *surf, SDL_Point p) +static PG_INLINE int +_check_inside(SDL_Surface *surf, SDL_Point p) { if (p.x >= 0 && p.x <= surf->w && p.y >= 0 && p.y <= surf->h) return 1; @@ -1072,37 +1072,39 @@ static PyObject * surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) { pgSurfaceObject *surfobj; - pgSurfaceObject *dest_surf = NULL; - PyObject *colorobj; + pgSurfaceObject *dest_surface = NULL; + PyObject *colorobj = NULL; SDL_Surface *surf, *newsurf; - int adjust_size = 0; + int adjust_size = 1; int x1, y1, x2, y2, x3, y3, x4, y4; int start = 0, width, top = 0, height; + int bounds_check = 1; Uint32 bgcolor; - static char *keywords[] = {"surface", "points", "bgcolor", - "adjust_size", "dest_surf", NULL}; + static char *keywords[] = {"surface", "points", "bg_color", + "adjust_size", "dest_surface", NULL}; if (!PyArg_ParseTupleAndKeywords( args, kwargs, "O!((ii)(ii)(ii)(ii))|OpO!", keywords, &pgSurface_Type, &surfobj, &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4, - &colorobj, &adjust_size, &pgSurface_Type, &dest_surf)) + &colorobj, &adjust_size, &pgSurface_Type, &dest_surface)) return NULL; surf = pgSurface_AsSurface(surfobj); SURF_INIT_CHECK(surf) - if (!dest_surf) { + if (dest_surface == NULL || dest_surface == Py_None) { if (adjust_size) { start = MIN(MIN(x1, x2), MIN(x3, x4)); width = MAX(MAX(x1, x2), MAX(x3, x4)) - start + 1; top = MIN(MIN(y1, y2), MIN(y3, y4)); height = MAX(MAX(y1, y2), MAX(y3, y4)) - top + 1; newsurf = newsurf_fromsurf(surf, width, height); + bounds_check = 0; } else { newsurf = newsurf_fromsurf(surf, surf->w, surf->h); } } else { - newsurf = pgSurface_AsSurface(dest_surf); + newsurf = pgSurface_AsSurface(dest_surface); } if (!newsurf) return NULL; @@ -1111,11 +1113,13 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) Py_INCREF(surfobj); return (PyObject *)surfobj; } - if (surf->format->format != newsurf->format->format) { - return RAISE(PyExc_ValueError, "surface formats do not match"); + + if (PG_SURF_BytesPerPixel(surf) != PG_SURF_BytesPerPixel(newsurf)) { + return RAISE(PyExc_ValueError, + "source and destination formats need to be the same"); } - if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) + if (PG_SURF_BytesPerPixel(surf) == 0 || PG_SURF_BytesPerPixel(surf) > 4) return RAISE(PyExc_ValueError, "unsupported Surface bit depth for transform"); @@ -1123,10 +1127,10 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) {x2 - start, y2 - top}, {x3 - start, y3 - top}, {x4 - start, y4 - top}}; - if (!(check_inside(newsurf, points[0]) && - check_inside(newsurf, points[1]) && - check_inside(newsurf, points[2]) && - check_inside(newsurf, points[3]))) { + if (bounds_check && !(_check_inside(newsurf, points[0]) && + _check_inside(newsurf, points[1]) && + _check_inside(newsurf, points[2]) && + _check_inside(newsurf, points[3]))) { return RAISE(PyExc_ValueError, "points are not within destination surface"); } @@ -1134,14 +1138,10 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) SDL_LockSurface(newsurf); SDL_LockSurface(surf); pgSurface_Lock(surfobj); - if (colorobj != Py_None) { - if (_color_from_obj(colorobj, surf->format, NULL, &bgcolor)) - return RAISE(PyExc_TypeError, "invalid bg_color argument"); - } - else { + if (colorobj == NULL || colorobj == Py_None) { /* get the background color */ if (SDL_GetColorKey(surf, &bgcolor) != 0) { - switch (surf->format->BytesPerPixel) { + switch (PG_SURF_BytesPerPixel(surf)) { case 1: bgcolor = *(Uint8 *)surf->pixels; break; @@ -1165,6 +1165,10 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) bgcolor &= ~surf->format->Amask; } } + else { + if (_color_from_obj(colorobj, surf->format, NULL, &bgcolor)) + return RAISE(PyExc_TypeError, "invalid bg_color argument"); + } SDL_FillRect(newsurf, NULL, bgcolor); @@ -1174,9 +1178,9 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) pgSurface_Unlock(surfobj); SDL_UnlockSurface(newsurf); SDL_UnlockSurface(surf); - if (dest_surf) { - Py_INCREF(dest_surf); - return (PyObject *)dest_surf; + if (dest_surface) { + Py_INCREF(dest_surface); + return (PyObject *)dest_surface; } else return (PyObject *)pgSurface_New(newsurf); From 4c8a45e65b4cee1cee3f5cab2e5fa1ad20bc465e Mon Sep 17 00:00:00 2001 From: Temmie <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:46:28 +0100 Subject: [PATCH 15/20] Fix compilation issue --- src_c/transform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_c/transform.c b/src_c/transform.c index e9752718c4..02515f5594 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -1090,7 +1090,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; surf = pgSurface_AsSurface(surfobj); SURF_INIT_CHECK(surf) - if (dest_surface == NULL || dest_surface == Py_None) { + if (!dest_surface) { if (adjust_size) { start = MIN(MIN(x1, x2), MIN(x3, x4)); width = MAX(MAX(x1, x2), MAX(x3, x4)) - start + 1; From 41f375e5cf39fb93d234b1aad1e3c97e5e05c691 Mon Sep 17 00:00:00 2001 From: Temmie <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:50:17 +0100 Subject: [PATCH 16/20] Remove unintentional edit --- buildconfig/stubs/pygame/transform.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildconfig/stubs/pygame/transform.pyi b/buildconfig/stubs/pygame/transform.pyi index 3efa806fa2..070861082c 100644 --- a/buildconfig/stubs/pygame/transform.pyi +++ b/buildconfig/stubs/pygame/transform.pyi @@ -43,7 +43,7 @@ def smoothscale_by( dest_surface: Optional[Surface] = None, ) -> Surface: ... def get_smoothscale_backend() -> Literal["GENERIC", "SSE2", "NEON"]: ... -def set_smoothscaprele_backend(backend: Literal["GENERIC", "SSE2", "NEON"]) -> None: ... +def set_smoothscale_backend(backend: Literal["GENERIC", "SSE2", "NEON"]) -> None: ... def chop(surface: Surface, rect: RectLike) -> Surface: ... def laplacian(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... def invert(surface: Surface, dest_surface: Optional[Surface] = None) -> Surface: ... From 970d881220b8b0c24b146933b39696f097b432aa Mon Sep 17 00:00:00 2001 From: Temmie <76136819+Temmie3754@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:42:32 +0100 Subject: [PATCH 17/20] Change color handler to allow for strings Co-authored-by: Damiano <97639432+damusss@users.noreply.github.com> --- src_c/transform.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src_c/transform.c b/src_c/transform.c index 02515f5594..0a68dd58d2 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -1166,7 +1166,8 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) } } else { - if (_color_from_obj(colorobj, surf->format, NULL, &bgcolor)) + if (!pg_MappedColorFromObj(colorobj, surf->format, &bgcolor, + PG_COLOR_HANDLE_ALL)) return RAISE(PyExc_TypeError, "invalid bg_color argument"); } From 1f758db2135efbf67a3e408a484173d66534ee2c Mon Sep 17 00:00:00 2001 From: Temmie <76136819+Temmie3754@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:31:32 +0100 Subject: [PATCH 18/20] Exception wording change --- src_c/transform.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src_c/transform.c b/src_c/transform.c index 0a68dd58d2..087997e750 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -1121,7 +1121,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) if (PG_SURF_BytesPerPixel(surf) == 0 || PG_SURF_BytesPerPixel(surf) > 4) return RAISE(PyExc_ValueError, - "unsupported Surface bit depth for transform"); + "unsupported surface bit depth for transform"); SDL_Point points[4] = {{x1 - start, y1 - top}, {x2 - start, y2 - top}, @@ -1132,7 +1132,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) _check_inside(newsurf, points[2]) && _check_inside(newsurf, points[3]))) { return RAISE(PyExc_ValueError, - "points are not within destination surface"); + "points are not within specified surface"); } SDL_LockSurface(newsurf); @@ -1167,7 +1167,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) } else { if (!pg_MappedColorFromObj(colorobj, surf->format, &bgcolor, - PG_COLOR_HANDLE_ALL)) + PG_COLOR_HANDLE_ALL)) return RAISE(PyExc_TypeError, "invalid bg_color argument"); } From 0eae2285eab2ca71d9420c8c2af9828eaf5e64fc Mon Sep 17 00:00:00 2001 From: Temmie <76136819+Temmie3754@users.noreply.github.com> Date: Fri, 25 Oct 2024 12:18:59 +0100 Subject: [PATCH 19/20] Add tests, update docs and add unique check --- docs/reST/ref/transform.rst | 4 ++-- src_c/transform.c | 14 ++++++++---- test/transform_test.py | 44 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/docs/reST/ref/transform.rst b/docs/reST/ref/transform.rst index fd7f6663f1..58b986967a 100644 --- a/docs/reST/ref/transform.rst +++ b/docs/reST/ref/transform.rst @@ -109,8 +109,8 @@ Instead, always begin with the original image and scale to the desired size.) This maps an image to a new surface warping the image so that its corners match the provided points in a clockwise order: top left, top right, bottom right, bottom left. Provided points represent the pixel coordinates of the - new corners of the image and can be positive or negative provided they fit - in the new surface. + new corners of the image, they must be unique and can be positive or negative + provided they fit in the new surface. When no 'dest_surface' is provided, the 'adjust_size' option will set the size of the resulting surface to be the smallest surface the points are diff --git a/src_c/transform.c b/src_c/transform.c index d62cab3c2c..02eb85ee4f 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -1065,6 +1065,13 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; surf = pgSurface_AsSurface(surfobj); SURF_INIT_CHECK(surf) + + if ((x1 == x2 && y1 == y2) || (x1 == x3 && y1 == y3) || + (x1 == x4 && y1 == y4) || (x2 == x3 && y2 == y3) || + (x2 == x4 && y2 == y4) || (x3 == x4 && y3 == y4)) { + return RAISE(PyExc_ValueError, "all four points must be unique"); + } + if (!dest_surface) { if (adjust_size) { start = MIN(MIN(x1, x2), MIN(x3, x4)); @@ -1096,7 +1103,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) if (PG_SURF_BytesPerPixel(surf) == 0 || PG_SURF_BytesPerPixel(surf) > 4) return RAISE(PyExc_ValueError, - "unsupported surface bit depth for transform"); + "unsupported Surface bit depth for transform"); SDL_Point points[4] = {{x1 - start, y1 - top}, {x2 - start, y2 - top}, @@ -1107,7 +1114,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) _check_inside(newsurf, points[2]) && _check_inside(newsurf, points[3]))) { return RAISE(PyExc_ValueError, - "points are not within specified surface"); + "points are not within specified Surface"); } SDL_LockSurface(newsurf); @@ -1141,8 +1148,7 @@ surf_skew(PyObject *self, PyObject *args, PyObject *kwargs) } } else { - if (!pg_MappedColorFromObj(colorobj, surf->format, &bgcolor, - PG_COLOR_HANDLE_ALL)) + if (_color_from_obj(colorobj, surf, NULL, &bgcolor)) return RAISE(PyExc_TypeError, "invalid bg_color argument"); } diff --git a/test/transform_test.py b/test/transform_test.py index 3e5ad06b68..15d27bc819 100644 --- a/test/transform_test.py +++ b/test/transform_test.py @@ -1450,6 +1450,50 @@ def test_rotate__lossless_at_90_degrees(self): for pt, color in gradient: self.assertTrue(s.get_at(pt) == color) + def test_skew(self): + blue = (0, 0, 255, 255) + red = (255, 0, 0, 255) + black = (0, 0, 0) + w, h = 32, 32 + s = pygame.Surface((w, h), pygame.SRCALPHA, 32) + s.fill(red) + s.fill(black, pygame.rect.Rect(0, 0, 16, 16)) + corner_points = [ + [(1, 1), (19, 1), (19, 19), (1, 19)], + [(0, 10), (31, 0), (3, 31), (0, 13)], + [(5, 16), (17, 2), (19, 13), (2, 18)], + [(5, 4), (28, 2), (8, 25), (27, 20)], + [(20, 20), (15, 5), (30, 30), (5, 15)], + ] + test_points = [ + [((0, 31), blue), ((5, 16), red), ((4, 4), black)], + [((7, 7), black), ((6, 7), blue), ((16, 16), red)], + [((19, 13), red), ((10, 9), black), ((11, 9), red)], + [((10, 8), black), ((18, 14), red), ((20, 14), blue)], + [((17, 14), black), ((17, 13), red), ((16, 14), blue)], + ] + + # check specified test points are correct + for i in range(len(corner_points)): + s2 = pygame.transform.skew(s, corner_points[i], blue, False) + for test in test_points[i]: + self.assertEqual( + s2.get_at(test[0]), + test[1], + "Failed for {0} at {1}".format(corner_points[i], test[0]), + ) + + def test_skew_adjust_size(self): + w, h = 32, 32 + s = pygame.Surface((w, h), pygame.SRCALPHA, 32) + size_values = [-100, -72, -23, -1, 1, 15, 104, 1009] + for x in size_values: + for y in size_values: + s2 = pygame.transform.skew( + s, [(x, 0), (0, 0), (x, y), (0, y)], adjust_size=True + ) + self.assertEqual(s2.size, (abs(x) + 1, abs(y) + 1)) + def test_scale2x(self): # __doc__ (as of 2008-06-25) for pygame.transform.scale2x: From 9e9aaaa2681ceade8f478881403fff433a3c42fd Mon Sep 17 00:00:00 2001 From: Temmie <76136819+Temmie3754@users.noreply.github.com> Date: Fri, 25 Oct 2024 12:26:02 +0100 Subject: [PATCH 20/20] Move _color_from_obj definition --- src_c/transform.c | 52 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src_c/transform.c b/src_c/transform.c index 02eb85ee4f..7cacb251d8 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -1034,6 +1034,32 @@ surf_rotate(PyObject *self, PyObject *args, PyObject *kwargs) return (PyObject *)pgSurface_New(newsurf); } +/* _color_from_obj gets a color from a python object. + +Returns 0 if ok, and sets color to the color. + -1 means error. + If color_obj is NULL, use rgba_default. + If rgba_default is NULL, do not use a default color, return -1. +*/ +int +_color_from_obj(PyObject *color_obj, SDL_Surface *surf, Uint8 rgba_default[4], + Uint32 *color) +{ + if (color_obj) { + if (!pg_MappedColorFromObj(color_obj, surf, color, + PG_COLOR_HANDLE_ALL)) { + return -1; + } + } + else { + if (!rgba_default) + return -1; + *color = SDL_MapRGBA(surf->format, rgba_default[0], rgba_default[1], + rgba_default[2], rgba_default[3]); + } + return 0; +} + static PG_INLINE int _check_inside(SDL_Surface *surf, SDL_Point p) { @@ -2269,32 +2295,6 @@ get_threshold(SDL_Surface *dest_surf, SDL_Surface *surf, return similar; } -/* _color_from_obj gets a color from a python object. - -Returns 0 if ok, and sets color to the color. - -1 means error. - If color_obj is NULL, use rgba_default. - If rgba_default is NULL, do not use a default color, return -1. -*/ -int -_color_from_obj(PyObject *color_obj, SDL_Surface *surf, Uint8 rgba_default[4], - Uint32 *color) -{ - if (color_obj) { - if (!pg_MappedColorFromObj(color_obj, surf, color, - PG_COLOR_HANDLE_ALL)) { - return -1; - } - } - else { - if (!rgba_default) - return -1; - *color = SDL_MapRGBA(surf->format, rgba_default[0], rgba_default[1], - rgba_default[2], rgba_default[3]); - } - return 0; -} - static PyObject * surf_threshold(PyObject *self, PyObject *args, PyObject *kwds) {