1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/firmware/contrib/conv_bmp2_chararray.pl Tue Jan 29 22:31:52 2008 +0100
1.3 @@ -0,0 +1,86 @@
1.4 +#!/usr/bin/perl -w
1.5 +
1.6 +use strict;
1.7 +
1.8 +my $input_file = $ARGV[0] || "text.bmp";
1.9 +
1.10 +###################################################
1.11 +
1.12 +my $buffer = '';
1.13 +
1.14 +open(F, $input_file) or die $!;
1.15 +binmode(F);
1.16 +while(my $temp = <F>){$buffer .= $temp;}
1.17 +close(F);
1.18 +
1.19 +# read header
1.20 +# 0 2 UINT bfType;
1.21 +# 2 4 DWORD bfSize;
1.22 +# 6 2 UINT bfReserved1;
1.23 +# 8 2 UINT bfReserved2;
1.24 +# 10 4 DWORD bfOffBits;
1.25 +
1.26 +my $header = substr($buffer, 0, 14);
1.27 +$buffer = substr($buffer, 14);
1.28 +
1.29 +# read info
1.30 +# 0 4 DWORD biSize;
1.31 +# 4 4 LONG biWidth;
1.32 +# 8 4 LONG biHeight;
1.33 +# 12 2 WORD biPlanes;
1.34 +# 14 2 WORD biBitCount;
1.35 +# 16 4 DWORD biCompression;
1.36 +# 20 4 DWORD biSizeImage;
1.37 +# 24 4 LONG biXPelsPerMeter;
1.38 +# 28 4 LONG biYPelsPerMeter;
1.39 +# 32 4 DWORD biClrUsed;
1.40 +# 36 4 DWORD biClrImportant;
1.41 +
1.42 +my $info = substr($buffer, 0, 40);
1.43 +my $bits = substr($buffer, 40);
1.44 +
1.45 +my ($bitcount) = unpack('v', substr($info, 14, 2));
1.46 +my ($compress) = unpack('i', substr($info, 16, 4));
1.47 +my ($size_x) = unpack('i', substr($info, 4, 4));
1.48 +my ($size_y) = unpack('i', substr($info, 8, 4));
1.49 +
1.50 +unless ($bitcount == 24){
1.51 + die "can only operate on 24 bit bitmaps (this is $bitcount bit)";
1.52 +}
1.53 +unless ($compress == 0){
1.54 + die "can only operate on uncompressed bitmaps";
1.55 +}
1.56 +
1.57 +####################################################
1.58 +
1.59 +
1.60 +my $line_shift = $size_x * 3;
1.61 +$line_shift += ($size_x % 4);
1.62 +
1.63 +
1.64 +print "/*Bitmap-Size: $size_x x $size_y */\n";
1.65 +print "/* | 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || : || (undef) | */\n";
1.66 +
1.67 +my $x;
1.68 +my $y;
1.69 +
1.70 +for ($y=$size_y-1; $y >= 0; $y--) {
1.71 + printf ("/* Row %2d */ \"",($size_y - $y - 1));
1.72 + for ($x=0; $x <=$size_x-1; $x=$x+8){
1.73 + my $_8pix = 0;
1.74 + for my $subx(0..7) {
1.75 + my $offset = (($x+$subx) * 3) + ($y * $line_shift);
1.76 + my $b = ord(substr($bits, $offset+0, 1));
1.77 + my $g = ord(substr($bits, $offset+1, 1));
1.78 + my $r = ord(substr($bits, $offset+2, 1));
1.79 + unless (($r == 255) && ($g == 255) && ($b == 255)){
1.80 + $_8pix += 2 ** (7 - $subx);
1.81 + }
1.82 +
1.83 + }
1.84 + print "\\x";
1.85 + print "0" if ($_8pix < 16);
1.86 + printf ("%x",$_8pix);
1.87 + }
1.88 + print "\"\n";
1.89 +}