Plan 9 from Bell Labs’s /usr/web/sources/contrib/quanstro/drawfunny/p9psrc/compose/compose.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "compose.h"

static	Rectangle	ulrange;	/* the upper left corner of the image must be in this rectangle */
static	Point		ul;	/* the upper left corner of the image is at this point on the screen */

static Point
pclip(Point p, Rectangle r)
{
	if(p.x < r.min.x)
		p.x = r.min.x;
	else if(p.x >= r.max.x)
		p.x = r.max.x-1;

	if(p.y < r.min.y)
		p.y = r.min.y;
	else if(p.y >= r.max.y)
		p.y = r.max.y-1;

	return p;
}

static void
compose(Memimage *screen, Memimage *im, ulong op)
{
	static Memimage *gray;

	if(im == nil)
		return;
	ul = pclip(ul, ulrange);
	memdraw(screen, screen->r, im, ZP, nil, ZP, op);

	/* gray for the rest */
	if(gray == nil && op == S) {
		gray = allocmemimage(screen->r, screen->chan);
		gray->flags |= Frepl;
		gray->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF);
		*wordaddr(gray, ZP) = 0x888888FF;
		if(gray == nil) {
			fprint(2, "g out of memory: %r\n");
			sysfatal("malloc: %r");
		}
	}
}

void
composer(C *c, int n, ulong chan)
{
	int i;
	ulong op;
	Memimage *im;

	memimageinit();
	im = pageimg(c + 0, chan);
	ulrange = im->r;
	op = SoverD;
	for(i = 1; i < n; i++)
		compose(im, pageimg(c + i, 0), op);
	writememimage(1, im);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.