@@ -1054,7 +1054,7 @@ surf_get_palette(PyObject *self, PyObject *_null)
1054
1054
1055
1055
SURF_INIT_CHECK (surf )
1056
1056
1057
- pal = surf -> format -> palette ;
1057
+ pal = PG_GetSurfacePalette ( surf ) ;
1058
1058
1059
1059
if (!pal )
1060
1060
return RAISE (pgExc_SDLError , "Surface has no palette to get\n" );
@@ -1093,7 +1093,7 @@ surf_get_palette_at(PyObject *self, PyObject *args)
1093
1093
return NULL ;
1094
1094
SURF_INIT_CHECK (surf )
1095
1095
1096
- pal = surf -> format -> palette ;
1096
+ pal = PG_GetSurfacePalette ( surf ) ;
1097
1097
1098
1098
if (!pal )
1099
1099
return RAISE (pgExc_SDLError , "Surface has no palette to set\n" );
@@ -1132,7 +1132,7 @@ surf_set_palette(PyObject *self, PyObject *seq)
1132
1132
if (!PySequence_Check (seq ))
1133
1133
return RAISE (PyExc_ValueError , "Argument must be a sequence type" );
1134
1134
1135
- pal = surf -> format -> palette ;
1135
+ pal = PG_GetSurfacePalette ( surf ) ;
1136
1136
1137
1137
if (!SDL_ISPIXELFORMAT_INDEXED (PG_SURF_FORMATENUM (surf )))
1138
1138
return RAISE (pgExc_SDLError , "Surface colors are not indexed\n" );
@@ -1192,7 +1192,7 @@ surf_set_palette_at(PyObject *self, PyObject *args)
1192
1192
if (!SDL_ISPIXELFORMAT_INDEXED (PG_SURF_FORMATENUM (surf )))
1193
1193
return RAISE (pgExc_SDLError , "Surface colors are not indexed\n" );
1194
1194
1195
- pal = surf -> format -> palette ;
1195
+ pal = PG_GetSurfacePalette ( surf ) ;
1196
1196
1197
1197
if (!pal ) {
1198
1198
return RAISE (pgExc_SDLError , "Surface is not palettized\n" );
@@ -2485,7 +2485,7 @@ surf_scroll(PyObject *self, PyObject *args, PyObject *keywds)
2485
2485
int dx = 0 , dy = 0 , scroll_flag = PGS_SCROLL_DEFAULT ;
2486
2486
int erase = 0 , repeat = 0 ;
2487
2487
SDL_Surface * surf ;
2488
- SDL_Rect * clip_rect , work_rect ;
2488
+ SDL_Rect work_rect ;
2489
2489
int w = 0 , h = 0 , x = 0 , y = 0 ;
2490
2490
2491
2491
static char * kwids [] = {"dx" , "dy" , "scroll_flag" , NULL };
@@ -2517,11 +2517,15 @@ surf_scroll(PyObject *self, PyObject *args, PyObject *keywds)
2517
2517
}
2518
2518
}
2519
2519
2520
- clip_rect = & surf -> clip_rect ;
2520
+ SDL_Rect clip_rect ;
2521
+ if (!PG_GetSurfaceClipRect (surf , & clip_rect )) {
2522
+ return RAISE (pgExc_SDLError , SDL_GetError ());
2523
+ }
2524
+
2521
2525
SDL_Rect surf_rect = {0 , 0 , surf -> w , surf -> h };
2522
2526
2523
2527
// In SDL3, SDL_IntersectRect is renamed to SDL_GetRectIntersection
2524
- if (!SDL_IntersectRect (clip_rect , & surf_rect , & work_rect )) {
2528
+ if (!SDL_IntersectRect (& clip_rect , & surf_rect , & work_rect )) {
2525
2529
Py_RETURN_NONE ;
2526
2530
}
2527
2531
@@ -2578,7 +2582,11 @@ static PyObject *
2578
2582
surf_get_flags (PyObject * self , PyObject * _null )
2579
2583
{
2580
2584
Uint32 sdl_flags = 0 ;
2585
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
2586
+ SDL_WindowFlags window_flags = 0 ;
2587
+ #else
2581
2588
Uint32 window_flags = 0 ;
2589
+ #endif
2582
2590
Uint32 flags = 0 ;
2583
2591
int is_alpha ;
2584
2592
int is_window_surf = 0 ;
@@ -3575,6 +3583,12 @@ _get_buffer_3D(PyObject *obj, Py_buffer *view_p, int flags)
3575
3583
"A 3D surface view is not contiguous" );
3576
3584
return -1 ;
3577
3585
}
3586
+ PG_PixelFormat * surface_format = PG_GetSurfaceFormat (surface );
3587
+ if (surface_format == NULL ) {
3588
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3589
+ return -1 ;
3590
+ }
3591
+
3578
3592
if (_init_buffer (obj , view_p , flags )) {
3579
3593
return -1 ;
3580
3594
}
@@ -3590,7 +3604,7 @@ _get_buffer_3D(PyObject *obj, Py_buffer *view_p, int flags)
3590
3604
view_p -> shape [2 ] = 3 ;
3591
3605
view_p -> strides [0 ] = pixelsize ;
3592
3606
view_p -> strides [1 ] = surface -> pitch ;
3593
- switch (surface -> format -> Rmask ) {
3607
+ switch (surface_format -> Rmask ) {
3594
3608
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
3595
3609
case 0xffU :
3596
3610
view_p -> strides [2 ] = 1 ;
@@ -3636,29 +3650,57 @@ _get_buffer_3D(PyObject *obj, Py_buffer *view_p, int flags)
3636
3650
static int
3637
3651
_get_buffer_red (PyObject * obj , Py_buffer * view_p , int flags )
3638
3652
{
3653
+ PG_PixelFormat * surface_format =
3654
+ PG_GetSurfaceFormat (pgSurface_AsSurface (obj ));
3655
+ if (surface_format == NULL ) {
3656
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3657
+ return -1 ;
3658
+ }
3659
+
3639
3660
return _get_buffer_colorplane (obj , view_p , flags , "red" ,
3640
- pgSurface_AsSurface ( obj ) -> format -> Rmask );
3661
+ surface_format -> Rmask );
3641
3662
}
3642
3663
3643
3664
static int
3644
3665
_get_buffer_green (PyObject * obj , Py_buffer * view_p , int flags )
3645
3666
{
3667
+ PG_PixelFormat * surface_format =
3668
+ PG_GetSurfaceFormat (pgSurface_AsSurface (obj ));
3669
+ if (surface_format == NULL ) {
3670
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3671
+ return -1 ;
3672
+ }
3673
+
3646
3674
return _get_buffer_colorplane (obj , view_p , flags , "green" ,
3647
- pgSurface_AsSurface ( obj ) -> format -> Gmask );
3675
+ surface_format -> Gmask );
3648
3676
}
3649
3677
3650
3678
static int
3651
3679
_get_buffer_blue (PyObject * obj , Py_buffer * view_p , int flags )
3652
3680
{
3681
+ PG_PixelFormat * surface_format =
3682
+ PG_GetSurfaceFormat (pgSurface_AsSurface (obj ));
3683
+ if (surface_format == NULL ) {
3684
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3685
+ return -1 ;
3686
+ }
3687
+
3653
3688
return _get_buffer_colorplane (obj , view_p , flags , "blue" ,
3654
- pgSurface_AsSurface ( obj ) -> format -> Bmask );
3689
+ surface_format -> Bmask );
3655
3690
}
3656
3691
3657
3692
static int
3658
3693
_get_buffer_alpha (PyObject * obj , Py_buffer * view_p , int flags )
3659
3694
{
3695
+ PG_PixelFormat * surface_format =
3696
+ PG_GetSurfaceFormat (pgSurface_AsSurface (obj ));
3697
+ if (surface_format == NULL ) {
3698
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3699
+ return -1 ;
3700
+ }
3701
+
3660
3702
return _get_buffer_colorplane (obj , view_p , flags , "alpha" ,
3661
- pgSurface_AsSurface ( obj ) -> format -> Amask );
3703
+ surface_format -> Amask );
3662
3704
}
3663
3705
3664
3706
static int
0 commit comments