5 component_encode
= function(str
)
13 if string.sub(str
, i
, i
) == "1" then
20 value
= (value
- c2
) / 93;
22 return string.char(34 + c1
, 34 + c2
);
25 value
= (value
- c3
) / 93;
27 value
= (value
- c2
) / 93;
29 return string.char(37 + c1
, 34 + c2
, 34 + c3
);
32 value
= (value
- c4
) / 93;
34 value
= (value
- c3
) / 93;
36 value
= (value
- c2
) / 93;
38 return string.char(45 + c1
, 34 + c2
, 34 + c3
, 34 + c4
);
41 value
= (value
- c5
) / 93;
43 value
= (value
- c4
) / 93;
45 value
= (value
- c3
) / 93;
47 value
= (value
- c2
) / 93;
49 return string.char(66 + c1
, 34 + c2
, 34 + c3
, 34 + c4
, 34 + c5
);
53 encode_letter
= function(x
, y
, name
)
55 for i
= 1,cellheight
do
56 letter
= letter
.. component_encode(string.sub(lines
[y
+ i
- 1], x
, x
+ cellwidth
));
58 print("!BEGIN " .. name
);
62 for line
in io
.stdin
:lines() do
63 table.insert(lines
, line
);
64 if linelen
and #line
~= linelen
then
65 error("Inconsistent line length");
68 linecount
= linecount
+ 1;
71 if linecount
== 0 or linecount
% 6 ~= 0 then
72 error("Line count must be positive and divisible by 6");
75 if (linelen
or 0) % 16 ~= 0 then
76 error("Line length must be positive and divisible by 16");
79 cellwidth
= linelen
/ 16;
80 cellheight
= linecount
/ 6;
82 if cellwidth
> 31 then
83 error("Font too wide (max 31 pels)");
86 prefix
= string.char(34, 34 + cellwidth
);
92 encode_letter(cellwidth
* x
+ 1, cellheight
* y
+ 1, j
+ 32);