@@ -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 ++ ) {
0 commit comments