Skip to content

Commit 5cc4899

Browse files
committed
function now respects the destination's clip rect
1 parent 8fc4c06 commit 5cc4899

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

src_c/surface.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,6 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
22502250
/* manage destinations memory */
22512251
Py_ssize_t new_size = PyList_GET_SIZE(pos_list);
22522252
if (new_size > destinations->alloc_size) {
2253-
/* no realloc as we don't care about the previous destinations */
22542253
destinations->sequence = (CachedBlitDest *)realloc(
22552254
destinations->sequence, new_size * sizeof(CachedBlitDest));
22562255

@@ -2284,31 +2283,20 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
22842283
return FBLITS_ERR_INVALID_DESTINATION;
22852284
}
22862285

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))
22882290
continue; /* Skip out of bounds destinations */
22892291

22902292
CachedBlitDest *blit_struct = &destinations->sequence[current_size++];
2291-
blit_struct->pixels = (Uint32 *)dst->pixels;
22922293

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;
23122300
}
23132301

23142302
if (!(destinations->size = current_size))

0 commit comments

Comments
 (0)