@@ -290,8 +290,13 @@ static struct PyMethodDef surface_methods[] = {
290
290
291
291
{"set_colorkey" , (PyCFunction )surf_set_colorkey , METH_VARARGS ,
292
292
DOC_SURFACE_SETCOLORKEY },
293
+ {"set_colorkey_raw" , (PyCFunction )surf_set_colorkey_raw , METH_VARARGS ,
294
+ "TODO" },
293
295
{"get_colorkey" , (PyCFunction )surf_get_colorkey , METH_NOARGS ,
294
296
DOC_SURFACE_GETCOLORKEY },
297
+ {"get_colorkey_raw" , (PyCFunction )surf_get_colorkey_raw , METH_NOARGS ,
298
+ "TODO" },
299
+ {"has_colorkey" , (PyCFunction )surf_has_colorkey , METH_NOARGS , "TODO" },
295
300
{"set_alpha" , (PyCFunction )surf_set_alpha , METH_VARARGS ,
296
301
DOC_SURFACE_SETALPHA },
297
302
{"get_alpha" , (PyCFunction )surf_get_alpha , METH_NOARGS ,
@@ -1062,7 +1067,8 @@ surf_get_palette(PyObject *self, PyObject *_null)
1062
1067
rgba [0 ] = c -> r ;
1063
1068
rgba [1 ] = c -> g ;
1064
1069
rgba [2 ] = c -> b ;
1065
- color = pgColor_NewLength (rgba , 3 );
1070
+ rgba [3 ] = c -> a ;
1071
+ color = pgColor_New (rgba );
1066
1072
1067
1073
if (!color ) {
1068
1074
Py_DECREF (list );
@@ -1252,6 +1258,29 @@ surf_set_colorkey(pgSurfaceObject *self, PyObject *args)
1252
1258
Py_RETURN_NONE ;
1253
1259
}
1254
1260
1261
+ static PyObject *
1262
+ surf_set_colorkey_raw (pgSurfaceObject * self , PyObject * args )
1263
+ {
1264
+ SDL_Surface * surf = pgSurface_AsSurface (self );
1265
+ Uint32 flags = 0 , color = 0 ;
1266
+ int result ;
1267
+ int hascolor = SDL_FALSE ;
1268
+
1269
+ if (!PyArg_ParseTuple (args , "I" , & color ))
1270
+ return NULL ;
1271
+
1272
+ SURF_INIT_CHECK (surf )
1273
+
1274
+ pgSurface_Prep (self );
1275
+ result = SDL_SetColorKey (surf , SDL_TRUE , color );
1276
+ pgSurface_Unprep (self );
1277
+
1278
+ if (result == -1 )
1279
+ return RAISE (pgExc_SDLError , SDL_GetError ());
1280
+
1281
+ Py_RETURN_NONE ;
1282
+ }
1283
+
1255
1284
static PyObject *
1256
1285
surf_get_colorkey (pgSurfaceObject * self , PyObject * _null )
1257
1286
{
@@ -1261,11 +1290,12 @@ surf_get_colorkey(pgSurfaceObject *self, PyObject *_null)
1261
1290
1262
1291
SURF_INIT_CHECK (surf )
1263
1292
1264
- if (SDL_GetColorKey (surf , & mapped_color ) != 0 ) {
1265
- SDL_ClearError ();
1293
+ if (!SDL_HasColorKey (surf )) {
1266
1294
Py_RETURN_NONE ;
1267
1295
}
1268
1296
1297
+ SDL_GetColorKey (surf , & mapped_color );
1298
+
1269
1299
if (SDL_ISPIXELFORMAT_ALPHA (surf -> format -> format ))
1270
1300
SDL_GetRGBA (mapped_color , surf -> format , & r , & g , & b , & a );
1271
1301
else
@@ -1274,6 +1304,39 @@ surf_get_colorkey(pgSurfaceObject *self, PyObject *_null)
1274
1304
return Py_BuildValue ("(bbbb)" , r , g , b , a );
1275
1305
}
1276
1306
1307
+ static PyObject *
1308
+ surf_get_colorkey_raw (pgSurfaceObject * self , PyObject * _null )
1309
+ {
1310
+ SDL_Surface * surf = pgSurface_AsSurface (self );
1311
+ Uint32 mapped_color ;
1312
+ Uint8 r , g , b , a = 255 ;
1313
+
1314
+ SURF_INIT_CHECK (surf )
1315
+
1316
+ if (SDL_GetColorKey (surf , & mapped_color ) != 0 ) {
1317
+ return RAISE (pgExc_SDLError , SDL_GetError ());
1318
+ }
1319
+
1320
+ return PyLong_FromLong (mapped_color );
1321
+ }
1322
+
1323
+ static PyObject *
1324
+ surf_has_colorkey (pgSurfaceObject * self , PyObject * _null )
1325
+ {
1326
+ SDL_Surface * surf = pgSurface_AsSurface (self );
1327
+ Uint32 mapped_color ;
1328
+ Uint8 r , g , b , a = 255 ;
1329
+
1330
+ SURF_INIT_CHECK (surf )
1331
+
1332
+ if (SDL_HasColorKey (surf )) {
1333
+ Py_RETURN_TRUE ;
1334
+ }
1335
+ else {
1336
+ Py_RETURN_FALSE ;
1337
+ }
1338
+ }
1339
+
1277
1340
static PyObject *
1278
1341
surf_set_alpha (pgSurfaceObject * self , PyObject * args )
1279
1342
{
@@ -2425,7 +2488,7 @@ surf_get_flags(PyObject *self, PyObject *_null)
2425
2488
if (is_alpha ) {
2426
2489
flags |= PGS_SRCALPHA ;
2427
2490
}
2428
- if (SDL_GetColorKey (surf , NULL ) == 0 )
2491
+ if (SDL_HasColorKey (surf , NULL ))
2429
2492
flags |= PGS_SRCCOLORKEY ;
2430
2493
if (sdl_flags & SDL_PREALLOC )
2431
2494
flags |= PGS_PREALLOC ;
@@ -2831,7 +2894,7 @@ surf_get_bounding_rect(PyObject *self, PyObject *args, PyObject *kwargs)
2831
2894
2832
2895
format = surf -> format ;
2833
2896
2834
- if (SDL_GetColorKey (surf , & colorkey ) == 0 ) {
2897
+ if (SDL_HasColorKey (surf , & colorkey )) {
2835
2898
has_colorkey = 1 ;
2836
2899
SDL_GetRGBA (colorkey , surf -> format , & keyr , & keyg , & keyb , & a );
2837
2900
}
@@ -3860,7 +3923,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
3860
3923
pgSurface_Prep (srcobj );
3861
3924
3862
3925
if ((blend_flags != 0 && blend_flags != PYGAME_BLEND_ALPHA_SDL2 ) ||
3863
- ((SDL_GetColorKey (src , & key ) == 0 || _PgSurface_SrcAlpha (src ) == 1 ) &&
3926
+ ((SDL_HasColorKey (src ) || _PgSurface_SrcAlpha (src ) == 1 ) &&
3864
3927
/* This simplification is possible because a source subsurface
3865
3928
is converted to its owner with a clip rect and a dst
3866
3929
subsurface cannot be blitted to its owner because the
0 commit comments