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 <u.h> #include <libc.h> #include <draw.h> 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); } }
This commit is contained in:
parent
193e55b88c
commit
71dbddef16
4 changed files with 46 additions and 13 deletions
|
@ -127,6 +127,7 @@ extern int cloadmemimage(Memimage*, Rectangle, uchar*, int);
|
|||
extern int unloadmemimage(Memimage*, Rectangle, uchar*, int);
|
||||
extern ulong* wordaddr(Memimage*, Point);
|
||||
extern uchar* byteaddr(Memimage*, Point);
|
||||
extern int drawclipnorepl(Memimage*, Rectangle*, Memimage*, Point*, Memimage*, Point*, Rectangle*, Rectangle*);
|
||||
extern int drawclip(Memimage*, Rectangle*, Memimage*, Point*, Memimage*, Point*, Rectangle*, Rectangle*);
|
||||
extern void memfillcolor(Memimage*, ulong);
|
||||
extern int memsetchan(Memimage*, ulong);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue