From 71dbddef166f855e28dfae1989ddbd663d38176a Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 9 Dec 2013 03:35:01 +0100 Subject: draw: fix drawing of replicated source image on memlayer with a clip rectangle when a replicated source image with a clipr with clipr.min > Pt(0, 0), drawclip() would properly translate the src->clipr on the dstr but then clamp the source rectangle back on src->r. while traversing down multiple layers, this would cause the translation to be applied multiple times to the dst rectangle giving the wrong image result. this change adds a new drawclipnorepl() function that avoids the clamping of source and mask rectangles to src->r and mask->r. this is then used in libmemlayer. the final memimagedraw() call will call drawclip() which will do the final claming. a testcase is provided: #include #include #include Image *blue; Image *red; void main(int, char *argv[]) { Image *i; if(initdraw(nil, nil, argv[0]) < 0) sysfatal("initdraw: %r"); i = allocimage(display, screen->r, screen->chan, 1, DWhite); red = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DRed); blue = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPaleblue); replclipr(red, 1, Rect(10, 10, 110, 110)); replclipr(blue, 1, Rect(11, 11, 111, 111)); /* draw on non-layer, works correctly */ draw(i, i->r, red, nil, ZP); draw(i, i->r, blue, nil, ZP); draw(screen, screen->r, i, nil, i->r.min); flushimage(display, 1); /* draw on (screen) layer is too far to the right */ draw(screen, screen->r, red, nil, ZP); draw(screen, screen->r, blue, nil, ZP); flushimage(display, 1); for(;;){ sleep(1000); } } --- sys/src/libmemlayer/draw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sys/src/libmemlayer/draw.c') diff --git a/sys/src/libmemlayer/draw.c b/sys/src/libmemlayer/draw.c index c352a0b2c..a9c546bd9 100644 --- a/sys/src/libmemlayer/draw.c +++ b/sys/src/libmemlayer/draw.c @@ -42,7 +42,7 @@ ldrawop(Memimage *dst, Rectangle screenr, Rectangle clipr, void *etc, int insave if(!rectinrect(r, clipr)){ oclipr = dst->clipr; dst->clipr = clipr; - ok = drawclip(dst, &r, d->src, &p0, d->mask, &p1, &srcr, &mr); + ok = drawclipnorepl(dst, &r, d->src, &p0, d->mask, &p1, &srcr, &mr); dst->clipr = oclipr; if(!ok) return; @@ -74,7 +74,7 @@ if(drawdebug) iprint("mask->layer != nil\n"); return; } - if(drawclip(dst, &r, src, &p0, mask, &p1, &srcr, &mr) == 0){ + if(drawclipnorepl(dst, &r, src, &p0, mask, &p1, &srcr, &mr) == 0){ if(drawdebug) iprint("drawclip dstcr %R srccr %R maskcr %R\n", dst->clipr, src->clipr, mask->clipr); return; } -- cgit v1.2.3