blob: 52788e76a79627cde8767bb74f9dd26719604ee4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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;
}
}
|