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