summaryrefslogtreecommitdiff
path: root/appl/cmd/metamorph.b
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /appl/cmd/metamorph.b
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'appl/cmd/metamorph.b')
-rw-r--r--appl/cmd/metamorph.b94
1 files changed, 94 insertions, 0 deletions
diff --git a/appl/cmd/metamorph.b b/appl/cmd/metamorph.b
new file mode 100644
index 00000000..9b693c85
--- /dev/null
+++ b/appl/cmd/metamorph.b
@@ -0,0 +1,94 @@
+implement metamorph;
+
+include "sys.m";
+include "draw.m";
+include "bufio.m";
+include "string.m";
+include "imagefile.m";
+
+sys: Sys;
+bufio: Bufio;
+str: String;
+draw: Draw;
+
+FD: import sys;
+Display: import draw;
+
+stderr: ref FD;
+
+metamorph: module
+{
+ init: fn(ctxt: ref Draw->Context, argv: list of string);
+};
+
+init(ctxt: ref Draw->Context, args: list of string)
+{
+ sys = load Sys Sys->PATH;
+ stderr = sys->fildes(2);
+ bufio = load Bufio Bufio->PATH;
+ str = load String String->PATH;
+ if (bufio == nil) {
+ sys->fprint(stderr, "could not load %s: %r\n", Bufio->PATH);
+ exit;
+ }
+ draw = load Draw Draw->PATH;
+ if (draw == nil) {
+ sys->fprint(stderr, "could not load %s: %r\n", Draw->PATH);
+ exit;
+ }
+ ri := load RImagefile RImagefile->READGIFPATH;
+ if (ri == nil) {
+ sys->fprint(stderr, "could not load %s: %r\n", RImagefile->READGIFPATH);
+ exit;
+ }
+ ir := load Imageremap Imageremap->PATH;
+ if (ir == nil) {
+ sys->fprint(stderr, "could not load %s: %r\n", Imageremap->PATH);
+ exit;
+ }
+
+ if (len args < 2) {
+ sys->fprint(stderr, "Metamorph Usage:\n metamorph <# of slides>\n\n");
+ return;
+ }
+
+ infile :string;
+
+
+ (numslides, nil) := str->toint((hd (tl args)), 10);
+
+ for (count := 1;count <=numslides; count++) {
+
+ ri->init(bufio);
+
+ if ( count < 10 )
+ infile= sys->sprint("img00%d.GIF",count);
+ if (( count >= 10 ) && ( count < 100))
+ infile= sys->sprint("img0%d.GIF",count);
+ if (count >= 100)
+ infile= sys->sprint("img%d.GIF",count);
+
+ outfile := sys->sprint("img%d.bit",count);
+
+ inf := bufio->open(infile, Bufio->OREAD);
+ sys->print ("Reading %s\n",infile);
+ if (inf == nil) {
+ sys->fprint(stderr, "could not fopen(0): %r\n");
+ exit;
+ }
+ (gif, s) := ri->read(inf);
+ if (gif == nil) {
+ sys->fprint(stderr, "bad GIF: %s\n", s);
+ exit;
+ }
+ (im, e) := ir->remap(gif, ctxt.display, 1);
+ if (im == nil) {
+ sys->fprint(stderr, "bad remap: %s\n", e);
+ exit;
+ }
+ sys->print("Writing %s\n",outfile);
+ outf := sys->create(outfile, sys->OWRITE,438);
+ ctxt.display.writeimage(outf, im);
+ outf = nil;
+ }
+}