@@ -1332,9 +1332,17 @@ flood_fill(PyObject *self, PyObject *arg, PyObject *kwargs)
13321332 }
13331333
13341334 if (pgSurface_Check (colorobj )) {
1335- pat_surfobj = (pgSurfaceObject * )colorobj ;
1336- pattern = pat_surfobj -> surf ; /* No conversion: we will map per-pixel */
1337- color = 0 ; /* new_color unused for pattern path */
1335+ pat_surfobj = ((pgSurfaceObject * )colorobj );
1336+
1337+ pattern = PG_ConvertSurface (pat_surfobj -> surf , surf -> format );
1338+
1339+ if (pattern == NULL ) {
1340+ return RAISE (PyExc_RuntimeError , "error converting pattern surf" );
1341+ }
1342+
1343+ SDL_SetSurfaceRLE (pattern , SDL_FALSE );
1344+
1345+ color = 0 ;
13381346 }
13391347 else {
13401348 CHECK_LOAD_COLOR (colorobj );
@@ -1381,7 +1389,7 @@ flood_fill(PyObject *self, PyObject *arg, PyObject *kwargs)
13811389 }
13821390
13831391 if (flood_fill_result == -1 ) {
1384- return PyErr_NoMemory ();
1392+ return NULL ; /* error already set by flood_fill_inner */
13851393 }
13861394
13871395 /* Compute return rect. */
@@ -2484,9 +2492,9 @@ draw_line(SDL_Surface *surf, SDL_Rect surf_clip_rect, int x1, int y1, int x2,
24842492 }
24852493 set_and_check_rect (surf , surf_clip_rect , x2 , y2 , color , drawn_area );
24862494}
2487- #ifndef SURF_GET_AT
2488- #define SURF_GET_AT (p_color , p_surf , p_x , p_y , p_pixels , p_format , p_pix ) \
2489- switch (PG_FORMAT_BytesPerPixel(p_format )) { \
2495+
2496+ #define SURF_GET_AT_FORMAT (p_color , p_surf , p_x , p_y , p_pixels , p_pix ) \
2497+ switch (PG_SURF_BytesPerPixel(p_surf )) { \
24902498 case 1: \
24912499 p_color = (Uint32) * \
24922500 ((Uint8 *)(p_pixels) + (p_y) * p_surf->pitch + (p_x)); \
@@ -2508,7 +2516,6 @@ draw_line(SDL_Surface *surf, SDL_Rect surf_clip_rect, int x1, int y1, int x2,
25082516 * ((Uint32 * )(p_pixels + (p_y ) * p_surf -> pitch ) + (p_x )); \
25092517 break ; \
25102518 }
2511- #endif // SURF_GET_AT
25122519
25132520static int
25142521flood_fill_inner (SDL_Surface * surf , int x1 , int y1 , Uint32 new_color ,
@@ -2517,11 +2524,8 @@ flood_fill_inner(SDL_Surface *surf, int x1, int y1, Uint32 new_color,
25172524 // breadth first flood fill, like graph search
25182525 SDL_Rect cliprect ;
25192526 size_t mask_idx ;
2520- PG_PixelFormat * format = PG_GetSurfaceFormat (surf );
2521- if (!format ) {
2522- return -1 ;
2523- }
25242527 if (!PG_GetSurfaceClipRect (surf , & cliprect )) {
2528+ PyErr_SetString (pgExc_SDLError , SDL_GetError ());
25252529 return -1 ;
25262530 }
25272531 size_t frontier_bufsize = 8 , frontier_size = 1 , next_frontier_size = 0 ;
@@ -2531,6 +2535,7 @@ flood_fill_inner(SDL_Surface *surf, int x1, int y1, Uint32 new_color,
25312535 struct point2d * frontier =
25322536 malloc (frontier_bufsize * sizeof (struct point2d ));
25332537 if (frontier == NULL ) {
2538+ PyErr_NoMemory ();
25342539 return -1 ;
25352540 }
25362541
@@ -2539,6 +2544,7 @@ flood_fill_inner(SDL_Surface *surf, int x1, int y1, Uint32 new_color,
25392544
25402545 if (frontier_next == NULL ) {
25412546 free (frontier );
2547+ PyErr_NoMemory ();
25422548 return -1 ;
25432549 }
25442550
@@ -2551,6 +2557,7 @@ flood_fill_inner(SDL_Surface *surf, int x1, int y1, Uint32 new_color,
25512557 if (mask == NULL ) {
25522558 free (frontier );
25532559 free (frontier_next );
2560+ PyErr_NoMemory ();
25542561 return -1 ;
25552562 }
25562563 Uint32 old_color = 0 ;
@@ -2566,7 +2573,7 @@ flood_fill_inner(SDL_Surface *surf, int x1, int y1, Uint32 new_color,
25662573 goto flood_fill_finished ;
25672574 }
25682575
2569- SURF_GET_AT (old_color , surf , x1 , y1 , (Uint8 * )surf -> pixels , format , pix );
2576+ SURF_GET_AT_FORMAT (old_color , surf , x1 , y1 , (Uint8 * )surf -> pixels , pix );
25702577
25712578 if (pattern == NULL && old_color == new_color ) {
25722579 // not an error, but nothing to do here
@@ -2589,16 +2596,17 @@ flood_fill_inner(SDL_Surface *surf, int x1, int y1, Uint32 new_color,
25892596
25902597 Uint32 current_color = 0 ;
25912598
2592- SURF_GET_AT (current_color , surf , x , y , ( Uint8 * ) surf -> pixels ,
2593- format , pix );
2599+ SURF_GET_AT_FORMAT (current_color , surf , x , y ,
2600+ ( Uint8 * ) surf -> pixels , pix );
25942601
25952602 if (current_color != old_color ) {
25962603 continue ;
25972604 }
25982605
25992606 if (pattern != NULL ) {
2600- SURF_GET_AT (new_color , pattern , x % pattern -> w , y % pattern -> h ,
2601- (Uint8 * )pattern -> pixels , format , pix );
2607+ SURF_GET_AT_FORMAT (new_color , pattern , x % pattern -> w ,
2608+ y % pattern -> h , (Uint8 * )pattern -> pixels ,
2609+ pix );
26022610 }
26032611
26042612 // clipping and color mapping have already happened here
@@ -2635,6 +2643,7 @@ flood_fill_inner(SDL_Surface *surf, int x1, int y1, Uint32 new_color,
26352643 free (mask );
26362644 free (frontier );
26372645 free (old_buf );
2646+ PyErr_NoMemory ();
26382647 return -1 ;
26392648 }
26402649
@@ -2645,6 +2654,7 @@ flood_fill_inner(SDL_Surface *surf, int x1, int y1, Uint32 new_color,
26452654 free (old_buf );
26462655 free (mask );
26472656 free (frontier_next );
2657+ PyErr_NoMemory ();
26482658 return -1 ;
26492659 }
26502660 }
0 commit comments