@@ -2260,7 +2260,6 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
2260
2260
/* manage destinations memory */
2261
2261
Py_ssize_t new_size = PyList_GET_SIZE (pos_list );
2262
2262
if (new_size > destinations -> alloc_size ) {
2263
- /* no realloc as we don't care about the previous destinations */
2264
2263
destinations -> sequence = (CachedBlitDest * )realloc (
2265
2264
destinations -> sequence , new_size * sizeof (CachedBlitDest ));
2266
2265
@@ -2294,31 +2293,20 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
2294
2293
return FBLITS_ERR_INVALID_DESTINATION ;
2295
2294
}
2296
2295
2297
- if (x < - src -> w || x > dst -> w || y < - src -> h || y > dst -> h )
2296
+ SDL_Rect * clip_rect = & dst -> clip_rect ;
2297
+ SDL_Rect clipped ;
2298
+ if (!SDL_IntersectRect (clip_rect , & (SDL_Rect ){x , y , src -> w , src -> h },
2299
+ & clipped ))
2298
2300
continue ; /* Skip out of bounds destinations */
2299
2301
2300
2302
CachedBlitDest * blit_struct = & destinations -> sequence [current_size ++ ];
2301
- blit_struct -> pixels = (Uint32 * )dst -> pixels ;
2302
2303
2303
- if (x < 0 ) {
2304
- blit_struct -> w = src -> w + x ;
2305
- blit_struct -> x = - x ;
2306
- }
2307
- else {
2308
- blit_struct -> pixels += x ;
2309
- blit_struct -> w = x > dst -> w - src -> w ? dst -> w - x : src -> w ;
2310
- blit_struct -> x = 0 ;
2311
- }
2312
-
2313
- if (y < 0 ) {
2314
- blit_struct -> h = src -> h + y ;
2315
- blit_struct -> y = - y ;
2316
- }
2317
- else {
2318
- blit_struct -> pixels += y * dst -> pitch / 4 ;
2319
- blit_struct -> h = y > dst -> h - src -> h ? dst -> h - y : src -> h ;
2320
- blit_struct -> y = 0 ;
2321
- }
2304
+ blit_struct -> pixels =
2305
+ (Uint32 * )dst -> pixels + clipped .y * dst -> pitch / 4 + clipped .x ;
2306
+ blit_struct -> w = clipped .w ;
2307
+ blit_struct -> h = clipped .h ;
2308
+ blit_struct -> x = x < clip_rect -> x ? clip_rect -> x - x : 0 ;
2309
+ blit_struct -> y = y < clip_rect -> y ? clip_rect -> y - y : 0 ;
2322
2310
}
2323
2311
2324
2312
if (!(destinations -> size = current_size ))
0 commit comments