@@ -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 ;
@@ -3567,6 +3575,12 @@ _get_buffer_3D(PyObject *obj, Py_buffer *view_p, int flags)
3567
3575
"A 3D surface view is not contiguous" );
3568
3576
return -1 ;
3569
3577
}
3578
+ PG_PixelFormat * surface_format = PG_GetSurfaceFormat (surface );
3579
+ if (surface_format == NULL ) {
3580
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3581
+ return -1 ;
3582
+ }
3583
+
3570
3584
if (_init_buffer (obj , view_p , flags )) {
3571
3585
return -1 ;
3572
3586
}
@@ -3582,7 +3596,7 @@ _get_buffer_3D(PyObject *obj, Py_buffer *view_p, int flags)
3582
3596
view_p -> shape [2 ] = 3 ;
3583
3597
view_p -> strides [0 ] = pixelsize ;
3584
3598
view_p -> strides [1 ] = surface -> pitch ;
3585
- switch (surface -> format -> Rmask ) {
3599
+ switch (surface_format -> Rmask ) {
3586
3600
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
3587
3601
case 0xffU :
3588
3602
view_p -> strides [2 ] = 1 ;
@@ -3628,29 +3642,57 @@ _get_buffer_3D(PyObject *obj, Py_buffer *view_p, int flags)
3628
3642
static int
3629
3643
_get_buffer_red (PyObject * obj , Py_buffer * view_p , int flags )
3630
3644
{
3645
+ PG_PixelFormat * surface_format =
3646
+ PG_GetSurfaceFormat (pgSurface_AsSurface (obj ));
3647
+ if (surface_format == NULL ) {
3648
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3649
+ return -1 ;
3650
+ }
3651
+
3631
3652
return _get_buffer_colorplane (obj , view_p , flags , "red" ,
3632
- pgSurface_AsSurface ( obj ) -> format -> Rmask );
3653
+ surface_format -> Rmask );
3633
3654
}
3634
3655
3635
3656
static int
3636
3657
_get_buffer_green (PyObject * obj , Py_buffer * view_p , int flags )
3637
3658
{
3659
+ PG_PixelFormat * surface_format =
3660
+ PG_GetSurfaceFormat (pgSurface_AsSurface (obj ));
3661
+ if (surface_format == NULL ) {
3662
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3663
+ return -1 ;
3664
+ }
3665
+
3638
3666
return _get_buffer_colorplane (obj , view_p , flags , "green" ,
3639
- pgSurface_AsSurface ( obj ) -> format -> Gmask );
3667
+ surface_format -> Gmask );
3640
3668
}
3641
3669
3642
3670
static int
3643
3671
_get_buffer_blue (PyObject * obj , Py_buffer * view_p , int flags )
3644
3672
{
3673
+ PG_PixelFormat * surface_format =
3674
+ PG_GetSurfaceFormat (pgSurface_AsSurface (obj ));
3675
+ if (surface_format == NULL ) {
3676
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3677
+ return -1 ;
3678
+ }
3679
+
3645
3680
return _get_buffer_colorplane (obj , view_p , flags , "blue" ,
3646
- pgSurface_AsSurface ( obj ) -> format -> Bmask );
3681
+ surface_format -> Bmask );
3647
3682
}
3648
3683
3649
3684
static int
3650
3685
_get_buffer_alpha (PyObject * obj , Py_buffer * view_p , int flags )
3651
3686
{
3687
+ PG_PixelFormat * surface_format =
3688
+ PG_GetSurfaceFormat (pgSurface_AsSurface (obj ));
3689
+ if (surface_format == NULL ) {
3690
+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
3691
+ return -1 ;
3692
+ }
3693
+
3652
3694
return _get_buffer_colorplane (obj , view_p , flags , "alpha" ,
3653
- pgSurface_AsSurface ( obj ) -> format -> Amask );
3695
+ surface_format -> Amask );
3654
3696
}
3655
3697
3656
3698
static int
0 commit comments