@@ -2250,7 +2250,6 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
2250
2250
/* manage destinations memory */
2251
2251
Py_ssize_t new_size = PyList_GET_SIZE (pos_list );
2252
2252
if (new_size > destinations -> alloc_size ) {
2253
- /* no realloc as we don't care about the previous destinations */
2254
2253
destinations -> sequence = (CachedBlitDest * )realloc (
2255
2254
destinations -> sequence , new_size * sizeof (CachedBlitDest ));
2256
2255
@@ -2284,31 +2283,20 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
2284
2283
return FBLITS_ERR_INVALID_DESTINATION ;
2285
2284
}
2286
2285
2287
- if (x < - src -> w || x > dst -> w || y < - src -> h || y > dst -> h )
2286
+ SDL_Rect * clip_rect = & dst -> clip_rect ;
2287
+ SDL_Rect clipped ;
2288
+ if (!SDL_IntersectRect (clip_rect , & (SDL_Rect ){x , y , src -> w , src -> h },
2289
+ & clipped ))
2288
2290
continue ; /* Skip out of bounds destinations */
2289
2291
2290
2292
CachedBlitDest * blit_struct = & destinations -> sequence [current_size ++ ];
2291
- blit_struct -> pixels = (Uint32 * )dst -> pixels ;
2292
2293
2293
- if (x < 0 ) {
2294
- blit_struct -> w = src -> w + x ;
2295
- blit_struct -> x = - x ;
2296
- }
2297
- else {
2298
- blit_struct -> pixels += x ;
2299
- blit_struct -> w = x > dst -> w - src -> w ? dst -> w - x : src -> w ;
2300
- blit_struct -> x = 0 ;
2301
- }
2302
-
2303
- if (y < 0 ) {
2304
- blit_struct -> h = src -> h + y ;
2305
- blit_struct -> y = - y ;
2306
- }
2307
- else {
2308
- blit_struct -> pixels += y * dst -> pitch / 4 ;
2309
- blit_struct -> h = y > dst -> h - src -> h ? dst -> h - y : src -> h ;
2310
- blit_struct -> y = 0 ;
2311
- }
2294
+ blit_struct -> pixels =
2295
+ (Uint32 * )dst -> pixels + clipped .y * dst -> pitch / 4 + clipped .x ;
2296
+ blit_struct -> w = clipped .w ;
2297
+ blit_struct -> h = clipped .h ;
2298
+ blit_struct -> x = x < clip_rect -> x ? clip_rect -> x - x : 0 ;
2299
+ blit_struct -> y = y < clip_rect -> y ? clip_rect -> y - y : 0 ;
2312
2300
}
2313
2301
2314
2302
if (!(destinations -> size = current_size ))
0 commit comments