1# 2# bit2gif - 3# 4# A simple command line utility for converting inferno bitmaps 5# to gif images. 6# 7# Craig Newell, Jan. 1999 CraigN@cheque.uq.edu.au 8# 9implement bit2gif; 10 11include "sys.m"; 12 sys: Sys; 13include "draw.m"; 14 draw: Draw; 15 Display: import draw; 16include "string.m"; 17include "bufio.m"; 18 bufio: Bufio; 19 Iobuf: import bufio; 20include "imagefile.m"; 21 22bit2gif : module 23{ 24 init: fn(ctx: ref Draw->Context, argv: list of string); 25}; 26 27usage() 28{ 29 sys->print("usage: bit2gif <inferno bitmap>\n"); 30 exit; 31} 32 33init(ctx: ref Draw->Context, argv: list of string) 34{ 35 sys = load Sys Sys->PATH; 36 37 # check arguments 38 if (argv == nil) 39 usage(); 40 argv = tl argv; 41 if (argv == nil) 42 usage(); 43 s := hd argv; 44 if (len s && s[0] == '-') 45 usage(); 46 47 # load the modules 48 str := load String String->PATH; 49 draw = load Draw Draw->PATH; 50 bufio = load Bufio Bufio->PATH; 51 imgfile := load WImagefile WImagefile->WRITEGIFPATH; 52 imgfile->init(bufio); 53 54 # open the display 55 display: ref Draw->Display; 56 if (ctx == nil) { 57 display = Display.allocate(nil); 58 } else { 59 display = ctx.display; 60 } 61 62 # process all the files 63 while (argv != nil) { 64 65 # get the filenames 66 bit_name := hd argv; 67 (gif_name, nil) := str->splitstrl(bit_name, ".bit"); 68 gif_name = gif_name + ".gif"; 69 70 # load inferno bitmap 71 img := display.open(bit_name); 72 if (img == nil) { 73 sys->print("bit2gif: unable to read <%s>\n", bit_name); 74 } else { 75 # save as gif 76 o := bufio->create(gif_name, Bufio->OWRITE, 8r644); 77 if (o != nil) { 78 imgfile->writeimage(o, img); 79 o.close(); 80 } 81 } 82 83 # next argument 84 argv = tl argv; 85 } 86} 87