Skip to content

Commit 5aec242

Browse files
authored
Merge branch 'pygame-community:main' into transform.pixelate
2 parents d2ca0b5 + c951503 commit 5aec242

File tree

5 files changed

+41
-54
lines changed

5 files changed

+41
-54
lines changed

src_c/_pygame.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ typedef enum {
670670
#define PYGAMEAPI_RWOBJECT_NUMSLOTS 5
671671
#define PYGAMEAPI_PIXELARRAY_NUMSLOTS 2
672672
#define PYGAMEAPI_COLOR_NUMSLOTS 5
673-
#define PYGAMEAPI_MATH_NUMSLOTS 2
674673
#define PYGAMEAPI_BASE_NUMSLOTS 30
675674
#define PYGAMEAPI_EVENT_NUMSLOTS 10
676675
#define PYGAMEAPI_WINDOW_NUMSLOTS 1

src_c/include/_pygame.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -509,26 +509,10 @@ typedef struct pgColorObject pgColorObject;
509509
#endif /* PYGAMEAPI_COLOR_INTERNAL */
510510

511511
/*
512-
* Math module
512+
* Geometry module
513513
*/
514-
#ifndef PYGAMEAPI_MATH_INTERNAL
515-
#define pgVector2_Check(x) \
516-
((x)->ob_type == (PyTypeObject *)PYGAMEAPI_GET_SLOT(math, 0))
517-
518-
#define pgVector3_Check(x) \
519-
((x)->ob_type == (PyTypeObject *)PYGAMEAPI_GET_SLOT(math, 1))
520-
/*
521-
#define pgVector2_New \
522-
(*(PyObject*(*)) \
523-
PYGAMEAPI_GET_SLOT(PyGAME_C_API, 1))
524-
*/
525-
#define import_pygame_math() IMPORT_PYGAME_MODULE(math)
526-
#endif /* PYGAMEAPI_MATH_INTERNAL */
527-
528514
#ifndef PYGAMEAPI_GEOMETRY_INTERNAL
529-
530515
#define import_pygame_geometry() IMPORT_PYGAME_MODULE(geometry)
531-
532516
#endif /* ~PYGAMEAPI_GEOMETRY_INTERNAL */
533517

534518
/*

src_c/math.c

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4625,9 +4625,7 @@ MODINIT_DEFINE(pg_math)
46254625
MODINIT_DEFINE(math)
46264626
#endif
46274627
{
4628-
PyObject *module, *apiobj;
4629-
static void *c_api[PYGAMEAPI_MATH_NUMSLOTS];
4630-
4628+
PyObject *module;
46314629
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
46324630
"math",
46334631
DOC_MATH,
@@ -4638,14 +4636,6 @@ MODINIT_DEFINE(math)
46384636
NULL,
46394637
NULL};
46404638

4641-
/* initialize the extension types */
4642-
if ((PyType_Ready(&pgVector2_Type) < 0) ||
4643-
(PyType_Ready(&pgVector3_Type) < 0) ||
4644-
(PyType_Ready(&pgVectorIter_Type) < 0) ||
4645-
(PyType_Ready(&pgVectorElementwiseProxy_Type) < 0)) {
4646-
return NULL;
4647-
}
4648-
46494639
/* initialize the module */
46504640
module = PyModule_Create(&_module);
46514641

@@ -4654,29 +4644,10 @@ MODINIT_DEFINE(math)
46544644
}
46554645

46564646
/* add extension types to module */
4657-
if ((PyModule_AddObjectRef(module, "Vector2",
4658-
(PyObject *)&pgVector2_Type) < 0) ||
4659-
(PyModule_AddObjectRef(module, "Vector3",
4660-
(PyObject *)&pgVector3_Type) < 0) ||
4661-
(PyModule_AddObjectRef(module, "VectorElementwiseProxy",
4662-
(PyObject *)&pgVectorElementwiseProxy_Type) <
4663-
0) ||
4664-
(PyModule_AddObjectRef(module, "VectorIterator",
4665-
(PyObject *)&pgVectorIter_Type) < 0)) {
4666-
Py_DECREF(module);
4667-
return NULL;
4668-
}
4669-
4670-
/* export the C api */
4671-
c_api[0] = &pgVector2_Type;
4672-
c_api[1] = &pgVector3_Type;
4673-
/*
4674-
c_api[2] = pgVector_NEW;
4675-
c_api[3] = pgVectorCompatible_Check;
4676-
*/
4677-
apiobj = encapsulate_api(c_api, "math");
4678-
if (PyModule_AddObject(module, PYGAMEAPI_LOCAL_ENTRY, apiobj)) {
4679-
Py_XDECREF(apiobj);
4647+
if ((PyModule_AddType(module, &pgVector2_Type) < 0) ||
4648+
(PyModule_AddType(module, &pgVector3_Type) < 0) ||
4649+
(PyModule_AddType(module, &pgVectorElementwiseProxy_Type) < 0) ||
4650+
(PyModule_AddType(module, &pgVectorIter_Type) < 0)) {
46804651
Py_DECREF(module);
46814652
return NULL;
46824653
}

src_c/transform.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height)
137137
/* Copy palette, colorkey, etc info */
138138
if (SDL_ISPIXELFORMAT_INDEXED(PG_SURF_FORMATENUM(surf))) {
139139
SDL_Palette *newsurf_palette = PG_GetSurfacePalette(newsurf);
140-
SDL_Palette *surf_palette = PG_GetSurfacePalette(newsurf);
140+
SDL_Palette *surf_palette = PG_GetSurfacePalette(surf);
141141

142142
if (newsurf_palette == NULL) {
143143
PyErr_SetString(
@@ -2704,7 +2704,7 @@ modify_hsl(SDL_Surface *surf, PG_PixelFormat *fmt, SDL_Surface *dst,
27042704
Uint8 *srcp8 = (Uint8 *)surf->pixels;
27052705
Uint8 *dstp8 = (Uint8 *)dst->pixels;
27062706
SDL_Palette *surf_palette = PG_GetSurfacePalette(surf);
2707-
SDL_Palette *dst_palette = PG_GetSurfacePalette(surf);
2707+
SDL_Palette *dst_palette = PG_GetSurfacePalette(dst);
27082708

27092709
if (PG_FORMAT_BytesPerPixel(fmt) == 4 ||
27102710
PG_FORMAT_BytesPerPixel(fmt) == 3) {

test/transform_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,39 @@ def test_rotate__lossless_at_90_degrees(self):
14611461
for pt, color in gradient:
14621462
self.assertTrue(s.get_at(pt) == color)
14631463

1464+
def test_rotate_after_convert_regression(self):
1465+
# Tests a regression found from https://github.com/pygame-community/pygame-ce/pull/3314
1466+
# Reported in https://github.com/pygame-community/pygame-ce/issues/3463
1467+
1468+
pygame.display.set_mode((1, 1))
1469+
1470+
output1 = pygame.transform.rotate(
1471+
pygame.image.load(
1472+
os.path.join(
1473+
os.path.abspath(os.path.dirname(__file__)),
1474+
"../examples/data/alien1.png",
1475+
)
1476+
).convert_alpha(),
1477+
180,
1478+
)
1479+
output2 = pygame.transform.rotate(
1480+
pygame.image.load(
1481+
os.path.join(
1482+
os.path.abspath(os.path.dirname(__file__)),
1483+
"../examples/data/alien1.png",
1484+
)
1485+
),
1486+
180,
1487+
).convert_alpha()
1488+
1489+
for x in range(50):
1490+
for y in range(50):
1491+
color1 = pygame.Color(output1.get_at((x, y)))
1492+
color2 = pygame.Color(output2.get_at((x, y)))
1493+
self.assertEqual(color1, color2)
1494+
1495+
pygame.quit()
1496+
14641497
def test_scale2x(self):
14651498
# __doc__ (as of 2008-06-25) for pygame.transform.scale2x:
14661499

0 commit comments

Comments
 (0)