Skip to content

Commit f40f479

Browse files
committed
function now respects the destination's clip rect
1 parent 8deb2b6 commit f40f479

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
@@ -2260,7 +2260,6 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
22602260
/* manage destinations memory */
22612261
Py_ssize_t new_size = PyList_GET_SIZE(pos_list);
22622262
if (new_size > destinations->alloc_size) {
2263-
/* no realloc as we don't care about the previous destinations */
22642263
destinations->sequence = (CachedBlitDest *)realloc(
22652264
destinations->sequence, new_size * sizeof(CachedBlitDest));
22662265

@@ -2294,31 +2293,20 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
22942293
return FBLITS_ERR_INVALID_DESTINATION;
22952294
}
22962295

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

23002302
CachedBlitDest *blit_struct = &destinations->sequence[current_size++];
2301-
blit_struct->pixels = (Uint32 *)dst->pixels;
23022303

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;
23222310
}
23232311

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

0 commit comments

Comments
 (0)