1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-12-23 04:56:52 +02:00
antorcha/tools/xbm2ant
2012-06-28 16:36:14 -03:00

48 lines
902 B
Perl
Executable File

#!/usr/bin/perl
#
# tools/xbm2ant - Convert X bitmap file to Antorcha image binary
#
# Written 2012 by Werner Almesberger
# Copyright 2012 Werner Almesberger
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
sub add
{
local $v = $_[0];
for (my $i = 0; $i != 8; $i++) {
push(@v, ($v >> $i) & 1);
}
}
while (<>) {
if (/width (\d+)/) {
$xm = $1;
next;
}
if (/height (\d+)/) {
$ym = $1;
die "no more than 16 rows" if $ym > 16;
next;
}
next unless /^\s*(0x.*[0-9abcdef])/;
for (split(/,\s*/, $1)) {
&add(hex($_));
}
}
$span = ($xm+7) & ~7;
for ($x = 0; $x != $xm; $x++) {
$v = 0;
for ($y = 0; $y != 16; $y++) {
$v |= 1 << $y if $v[$x+$y*$span];
}
print pack("v", $v);
}