From 647f029775233ba08cea419b856688e17db71a03 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 20 Jun 2012 18:27:41 -0300 Subject: [PATCH] tools/bit2ant: X bitmap to Antorcha image converter --- tools/bit2ant | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 tools/bit2ant diff --git a/tools/bit2ant b/tools/bit2ant new file mode 100755 index 0000000..37aa0a8 --- /dev/null +++ b/tools/bit2ant @@ -0,0 +1,47 @@ +#!/usr/bin/perl +# +# tools/bit2ant - 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); +}