plan9fox/sys/src/libmemdraw
cinap_lenrek 71dbddef16 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);
	}
}
2013-12-09 03:35:01 +01:00
..
alloc.c libmemdraw: change memimageinit() to return integer error (for kernel), minor cleanups 2013-11-12 21:42:05 +01:00
alpha.hoc Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
arc.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
arctest.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
cload.c draw: add badrect() function to reject zero, negative size or orverly huge rectangles 2013-06-16 19:01:46 +02:00
cmap.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
cread.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
defont.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
draw.c draw: fix drawing of replicated source image on memlayer with a clip rectangle 2013-12-09 03:35:01 +01:00
drawtest.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
ellipse.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
fillpoly.c libmemdraw: change memimageinit() to return integer error (for kernel), minor cleanups 2013-11-12 21:42:05 +01:00
hwdraw.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
iprint.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
line.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
load.c draw: add badrect() function to reject zero, negative size or orverly huge rectangles 2013-06-16 19:01:46 +02:00
mkcmap.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
mkfile Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
openmemsubfont.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
poly.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
read.c libdraw: fix unloadimage() for wide images, libmemdraw: work arround width limit by outputting uncompressed image in writememimage() if compressed blocksize exceeds chunk limit 2011-09-04 23:51:14 +02:00
string.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
subfont.c Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
times Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
unload.c draw: add badrect() function to reject zero, negative size or orverly huge rectangles 2013-06-16 19:01:46 +02:00
write.c libdraw: reduce memory for writeimage/writememimage 2011-09-04 04:38:08 +02:00