Skip to content

Commit e6163c4

Browse files
committed
Refine source clipping coordinate adjustment
The original code was functionally correct but semantically confusing. The delta (sdx, sdy) was calculated relative to dst_x/dst_y but applied to left/top in the rendering loop, which obscured the intent.
1 parent 5bb1c96 commit e6163c4

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/draw-builtin.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ static const twin_src_msk_op comp3[2][4][4][3] = {
557557
#define operand_index(o) \
558558
((o)->source_kind == TWIN_SOLID ? 3 : o->u.pixmap->format)
559559

560-
/* FIXME: source clipping is busted */
561560
static void _twin_composite_simple(twin_pixmap_t *dst,
562561
twin_coord_t dst_x,
563562
twin_coord_t dst_y,
@@ -596,29 +595,40 @@ static void _twin_composite_simple(twin_pixmap_t *dst,
596595
if (left >= right || top >= bottom)
597596
return;
598597

598+
/* Adjust source coordinates after clipping
599+
* When destination is clipped, source coordinates must be adjusted
600+
* to maintain correct 1:1 mapping between dst and src pixels.
601+
*/
602+
src_x += (left - dst_x);
603+
src_y += (top - dst_y);
604+
599605
if (src->source_kind == TWIN_PIXMAP) {
600606
src_x += src->u.pixmap->origin_x;
601607
src_y += src->u.pixmap->origin_y;
602608
} else {
603609
s.c = src->u.argb;
604610
}
605611

606-
sdx = src_x - dst_x;
607-
sdy = src_y - dst_y;
612+
sdx = src_x - left;
613+
sdy = src_y - top;
608614

609615
if (msk) {
610616
twin_source_u m;
611617
twin_coord_t mdx, mdy;
612618

619+
/* Adjust mask coordinates after clipping (same as source) */
620+
msk_x += (left - dst_x);
621+
msk_y += (top - dst_y);
622+
613623
if (msk->source_kind == TWIN_PIXMAP) {
614624
msk_x += msk->u.pixmap->origin_x;
615625
msk_y += msk->u.pixmap->origin_y;
616626
} else {
617627
m.c = msk->u.argb;
618628
}
619629

620-
mdx = msk_x - dst_x;
621-
mdy = msk_y - dst_y;
630+
mdx = msk_x - left;
631+
mdy = msk_y - top;
622632

623633
twin_src_msk_op op = comp3[operator][operand_index(src)][operand_index(msk)][dst->format];
624634
for (iy = top; iy < bottom; iy++) {

0 commit comments

Comments
 (0)