implement Drawmask; include "sys.m"; sys: Sys; include "draw.m"; draw: Draw; Display, Image, Rect, Point: import draw; stderr: ref Sys->FD; # usage: draw xpos ypos img.bit [xpos ypos img.bit]... Drawmask: module { init: fn(ctxt: ref Draw->Context, argv: list of string); }; init(ctxt: ref Draw->Context, argv: list of string) { sys = load Sys Sys->PATH; stderr = sys->fildes(2); draw = load Draw Draw->PATH; argv = tl argv; if (argv == nil || len argv % 4 != 0) { sys->fprint(stderr, "usage: draw xpos ypos img.bit mask.bit [xpos ypos img.bit mask.bit]...\n"); raise "fail:usage"; } displ := ctxt.display; base := displ.readimage(sys->fildes(0)); if (base == nil) { sys->fprint(stderr, "draw: cannot read base image: %r\n"); raise "fail:error"; } for (; argv != nil; argv = tl tl tl tl argv) { (xpos, ypos, imgfile, maskfile) := (int hd argv, int hd tl argv, hd tl tl argv, hd tl tl tl argv); img := displ.open(imgfile); if (img == nil) { sys->fprint(stderr, "draw: cannot open %s: %r\n", imgfile); raise "fail:error"; } mask := displ.open(maskfile); if (mask == nil) { sys->fprint(stderr, "draw: cannot open %s: %r\n", maskfile); raise "fail:error"; } r := Rect((xpos, ypos), (xpos + img.r.dx(), ypos + img.r.dy())); base.draw(r, img, mask, img.r.min); } displ.writeimage(sys->fildes(1), base); }