summaryrefslogtreecommitdiff
path: root/appl/cmd/bit2gif.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/bit2gif.b
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'appl/cmd/bit2gif.b')
-rw-r--r--appl/cmd/bit2gif.b86
1 files changed, 86 insertions, 0 deletions
diff --git a/appl/cmd/bit2gif.b b/appl/cmd/bit2gif.b
new file mode 100644
index 00000000..52788e76
--- /dev/null
+++ b/appl/cmd/bit2gif.b
@@ -0,0 +1,86 @@
+#
+# bit2gif -
+#
+# A simple command line utility for converting inferno bitmaps
+# to gif images.
+#
+# Craig Newell, Jan. 1999 CraigN@cheque.uq.edu.au
+#
+implement bit2gif;
+
+include "sys.m";
+ sys: Sys;
+include "draw.m";
+ draw: Draw;
+ Display: import draw;
+include "string.m";
+include "bufio.m";
+ bufio: Bufio;
+ Iobuf: import bufio;
+include "imagefile.m";
+
+bit2gif : module
+{
+ init: fn(ctx: ref Draw->Context, argv: list of string);
+};
+
+usage()
+{
+ sys->print("usage: bit2gif <inferno bitmap>\n");
+ exit;
+}
+
+init(ctx: ref Draw->Context, argv: list of string)
+{
+ sys = load Sys Sys->PATH;
+
+ # check arguments
+ if (argv == nil)
+ usage();
+ argv = tl argv;
+ if (argv == nil)
+ usage();
+ s := hd argv;
+ if (len s && s[0] == '-')
+ usage();
+
+ # load the modules
+ str := load String String->PATH;
+ draw = load Draw Draw->PATH;
+ bufio = load Bufio Bufio->PATH;
+ imgfile := load WImagefile WImagefile->WRITEGIFPATH;
+ imgfile->init(bufio);
+
+ # open the display
+ display: ref Draw->Display;
+ if (ctx == nil) {
+ display = Display.allocate(nil);
+ } else {
+ display = ctx.display;
+ }
+
+ # process all the files
+ while (argv != nil) {
+
+ # get the filenames
+ bit_name := hd argv;
+ (gif_name, nil) := str->splitstrl(bit_name, ".bit");
+ gif_name = gif_name + ".gif";
+
+ # load inferno bitmap
+ img := display.open(bit_name);
+ if (img == nil) {
+ sys->print("bit2gif: unable to read <%s>\n", bit_name);
+ } else {
+ # save as gif
+ o := bufio->create(gif_name, Bufio->OWRITE, 8r644);
+ if (o != nil) {
+ imgfile->writeimage(o, img);
+ o.close();
+ }
+ }
+
+ # next argument
+ argv = tl argv;
+ }
+}