Skip to content

Commit 37cef59

Browse files
committed
Fix to respect clip rect. Removed unused includes from pygame.h.
1 parent 7361e7e commit 37cef59

File tree

5 files changed

+16
-26
lines changed

5 files changed

+16
-26
lines changed

src/data_block.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ calculate_fragmentation_map(pgSurfaceObject *dest, DataBlock *block)
190190
destination->pixels = dest_pixels + clipped.y * dest_skip + clipped.x;
191191
destination->width = clipped.w;
192192
destination->rows = clipped.h;
193+
destination->src_offset =
194+
(src_rect.x < dest_clip->x ? dest_clip->x - src_rect.x : 0) +
195+
(src_rect.y < dest_clip->y ? dest_clip->y - src_rect.y : 0) *
196+
src_surf->pitch / 4;
193197
}
194198

195199
positions_x += length;
@@ -234,7 +238,7 @@ blit_fragments_blitcopy(FragmentationMap *frag_map, pgSurfaceObject *dest,
234238
for (int j = 0; j < fragment->length; j++) {
235239
BlitDestination *item = &destinations[j];
236240

237-
uint32_t *srcp32 = src_start;
241+
uint32_t *srcp32 = src_start + item->src_offset;
238242
uint32_t *dstp32 = item->pixels;
239243

240244
if (item->width == 1 && item->rows == 1) {
@@ -367,17 +371,17 @@ blit_fragments_add_scalar(FragmentationMap *frag_map, PyObject **animation,
367371
Fragment *fragment = &fragments[i];
368372
SDL_Surface *src_surf =
369373
((pgSurfaceObject *)animation[fragment->animation_index])->surf;
370-
const int src_skip = src_surf->pitch - src_surf->w * 4;
371374
uint8_t *const src_start = (uint8_t *)src_surf->pixels;
372375

373376
for (int j = 0; j < fragment->length; j++) {
374377
BlitDestination *item = &destinations[j];
375378

376-
uint8_t *srcp8 = src_start;
379+
uint8_t *srcp8 = src_start + item->src_offset * 4;
377380
uint8_t *dstp8 = (uint8_t *)item->pixels;
381+
const int actual_dst_skip = 4 * (dst_skip - item->width);
382+
const int src_skip = src_surf->pitch - item->width * 4;
378383

379384
int h = item->rows;
380-
const int actual_dst_skip = 4 * (dst_skip - item->width);
381385

382386
while (h--) {
383387
for (int k = 0; k < item->width; k++) {

src/include/data_block.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef struct {
2626

2727
typedef struct {
2828
uint32_t *pixels;
29-
int width, rows;
29+
int width, rows, src_offset;
3030
} BlitDestination;
3131

3232
typedef struct {

src/include/pygame.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,8 @@ typedef struct {
5858
#define pgSurface_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(surface, 0))
5959

6060
#define pgSurface_Check(x) (PyObject_IsInstance((x), (PyObject *)&pgSurface_Type))
61-
#define pgSurface_New2 \
62-
(*(pgSurfaceObject * (*)(SDL_Surface *, int)) PYGAMEAPI_GET_SLOT(surface, 1))
63-
64-
#define pgSurface_SetSurface \
65-
(*(int (*)(pgSurfaceObject *, SDL_Surface *, int))PYGAMEAPI_GET_SLOT(surface, 3))
66-
67-
#define pgSurface_Blit \
68-
(*(int (*)(pgSurfaceObject *, pgSurfaceObject *, SDL_Rect *, SDL_Rect *, \
69-
int))PYGAMEAPI_GET_SLOT(surface, 2))
70-
7161
#define import_pygame_surface() _LOAD_SLOTS_FROM_PYGAME(surface)
7262

73-
#define pgSurface_New(surface) pgSurface_New2((surface), 1)
74-
#define pgSurface_NewNoOwn(surface) pgSurface_New2((surface), 0)
75-
#define pgSurface_AsSurface(x) (((pgSurfaceObject *)(x))->surf)
76-
7763
#define SURF_INIT_CHECK(surf) \
7864
if (!surf) { \
7965
PyErr_SetString(PyExc_RuntimeError, "Surface is not initialized"); \

src/updaters_simd_avx2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,14 @@ blit_fragments_add_avx2(FragmentationMap *frag_map, PyObject **animation,
547547
Fragment *fragment = &fragments[i];
548548
SDL_Surface *src_surf =
549549
((pgSurfaceObject *)animation[fragment->animation_index])->surf;
550-
const int src_skip = src_surf->pitch / 4 - src_surf->w;
551-
const int actual_dst_skip = dst_skip - src_surf->w;
552550
uint32_t *const src_start = (uint32_t *)src_surf->pixels;
553551

554552
for (int j = 0; j < fragment->length; j++) {
555553
BlitDestination *item = &destinations[j];
556-
uint32_t *srcp32 = src_start;
554+
uint32_t *srcp32 = src_start + item->src_offset;
557555
uint32_t *dstp32 = item->pixels;
556+
const int src_skip = src_surf->pitch / 4 - item->width;
557+
const int actual_dst_skip = dst_skip - item->width;
558558

559559
if (item->width == 1 && item->rows == 1) {
560560
blit_add_avx2_1x1(srcp32, dstp32);

src/updaters_simd_sse2.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,15 @@ blit_fragments_add_sse2(FragmentationMap *frag_map, PyObject **animation,
460460
Fragment *fragment = &fragments[i];
461461
SDL_Surface *src_surf =
462462
((pgSurfaceObject *)animation[fragment->animation_index])->surf;
463-
const int src_skip = src_surf->pitch / 4 - src_surf->w;
464-
const int actual_dst_skip = dst_skip - src_surf->w;
465463
uint32_t *const src_start = (uint32_t *)src_surf->pixels;
466464

467465
for (int j = 0; j < fragment->length; j++) {
468466
BlitDestination *item = &destinations[j];
469467

470-
uint32_t *srcp32 = src_start;
468+
uint32_t *srcp32 = src_start + item->src_offset;
471469
uint32_t *dstp32 = item->pixels;
470+
const int src_skip = src_surf->pitch / 4 - item->width;
471+
const int actual_dst_skip = dst_skip - item->width;
472472

473473
if (item->width == 1 && item->rows == 1) {
474474
blit_add_sse2_1x1(srcp32, dstp32);
@@ -534,6 +534,6 @@ void
534534
blit_fragments_add_sse2(FragmentationMap *frag_map, PyObject **animation,
535535
int dst_skip)
536536
{
537-
BAD_sse2_FUNCTION_CALL
537+
BAD_SSE2_FUNCTION_CALL
538538
}
539539
#endif /* __SSE2__ || ENABLE_ARM_NEON */

0 commit comments

Comments
 (0)