#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);
}
|