@@ -335,8 +335,10 @@ pg_vidinfo_getattr(PyObject *self, char *name)
335335 info -> vfmt -> Bshift , info -> vfmt -> Ashift );
336336 }
337337 else if (!strcmp (name , "losses" )) {
338- return Py_BuildValue ("(iiii)" , info -> vfmt -> Rloss , info -> vfmt -> Gloss ,
339- info -> vfmt -> Bloss , info -> vfmt -> Aloss );
338+ return Py_BuildValue ("(iiii)" , PG_FORMAT_R_LOSS (info -> vfmt ),
339+ PG_FORMAT_G_LOSS (info -> vfmt ),
340+ PG_FORMAT_B_LOSS (info -> vfmt ),
341+ PG_FORMAT_A_LOSS (info -> vfmt ));
340342 }
341343 else if (!strcmp (name , "current_h" )) {
342344 return PyLong_FromLong (info -> current_h );
@@ -382,8 +384,9 @@ pg_vidinfo_str(PyObject *self)
382384 PG_FORMAT_BytesPerPixel (info -> vfmt ), info -> vfmt -> Rmask ,
383385 info -> vfmt -> Gmask , info -> vfmt -> Bmask , info -> vfmt -> Amask ,
384386 info -> vfmt -> Rshift , info -> vfmt -> Gshift , info -> vfmt -> Bshift ,
385- info -> vfmt -> Ashift , info -> vfmt -> Rloss , info -> vfmt -> Gloss ,
386- info -> vfmt -> Bloss , info -> vfmt -> Aloss , info -> current_w , info -> current_h ,
387+ info -> vfmt -> Ashift , PG_FORMAT_R_LOSS (info -> vfmt ),
388+ PG_FORMAT_G_LOSS (info -> vfmt ), PG_FORMAT_B_LOSS (info -> vfmt ),
389+ PG_FORMAT_A_LOSS (info -> vfmt ), info -> current_w , info -> current_h ,
387390 pixel_format_name );
388391}
389392
@@ -415,7 +418,7 @@ static pg_VideoInfo *
415418pg_GetVideoInfo (pg_VideoInfo * info )
416419{
417420 SDL_DisplayMode mode ;
418- SDL_PixelFormat * tempformat ;
421+ PG_PixelFormat * tempformat ;
419422 Uint32 formatenum ;
420423 pgSurfaceObject * winsurfobj ;
421424 SDL_Surface * winsurf ;
@@ -431,7 +434,12 @@ pg_GetVideoInfo(pg_VideoInfo *info)
431434 winsurf = pgSurface_AsSurface (winsurfobj );
432435 info -> current_w = winsurf -> w ;
433436 info -> current_h = winsurf -> h ;
434- info -> vfmt_data = * (winsurf -> format );
437+ PG_PixelFormat * fmt = PG_GetSurfaceFormat (winsurf );
438+ if (!fmt ) {
439+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
440+ return (pg_VideoInfo * )NULL ;
441+ }
442+ info -> vfmt_data = * fmt ;
435443 info -> vfmt = & info -> vfmt_data ;
436444 }
437445 else {
@@ -449,7 +457,9 @@ pg_GetVideoInfo(pg_VideoInfo *info)
449457 if ((tempformat = SDL_AllocFormat (formatenum ))) {
450458 info -> vfmt_data = * tempformat ;
451459 info -> vfmt = & info -> vfmt_data ;
460+ #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
452461 SDL_FreeFormat (tempformat );
462+ #endif
453463 }
454464 else {
455465 PyErr_SetString (pgExc_SDLError , SDL_GetError ());
@@ -1423,7 +1433,11 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
14231433 Py_DECREF (surface );
14241434
14251435 /* ensure window is always black after a set_mode call */
1436+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
1437+ SDL_FillRect (surf , NULL , SDL_MapSurfaceRGB (surf , 0 , 0 , 0 ));
1438+ #else
14261439 SDL_FillRect (surf , NULL , SDL_MapRGB (surf -> format , 0 , 0 , 0 ));
1440+ #endif
14271441 }
14281442
14291443 /*set the window icon*/
@@ -1968,7 +1982,7 @@ pg_set_palette(PyObject *self, PyObject *args)
19681982
19691983 Py_INCREF (surface );
19701984 surf = pgSurface_AsSurface (surface );
1971- pal = surf -> format -> palette ;
1985+ pal = PG_GetSurfacePalette ( surf ) ;
19721986 if (PG_SURF_BytesPerPixel (surf ) != 1 || !pal ) {
19731987 Py_DECREF (surface );
19741988 return RAISE (pgExc_SDLError , "Display mode is not colormapped" );
0 commit comments