Plan 9 from Bell Labs’s /usr/web/sources/contrib/axel/rushhour/src/mkmask.c

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


#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>

Memimage *
eloadfile(char *path)
{
	Memimage *img;
	int fd;

	if (path != nil)
		fd = open(path, OREAD);
	else
		fd = 0;
	if(fd < 0) {
		fprint(2, "cannot open image file %s: %r\n", path);
		exits("image");
	}
	img = readmemimage(fd);
	if(img == nil)
		sysfatal("cannot load image: %r");
	close(fd);
	
	return img;
}

void
main(int argc, char **argv)
{
	char *f;
	Memimage *img, *msk, *black;

	switch(argc) {
	case 2: 
		f = argv[0];
		break;
	case 1:
		f = nil;
		break;
	default:
		fprint(2, "Usage: %s [image]\n", argv0);
		exits("usage");
	}

	memimageinit ();

	img = eloadfile(f);

	black = allocmemimage(img->r, GREY8); //GREY1
	if(black == nil)
		sysfatal("cannot allocate black image: %r");
	memfillcolor(black, DBlack);

	msk = allocmemimage(img->r, GREY8);
	if(msk == nil)
		sysfatal("cannot allocate msk image: %r");
	memfillcolor(msk, DWhite);

	memimagedraw(msk, img->r, black, ZP, img, ZP, SoverD);


	writememimage(1, msk);
}

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.