#!/usr/bin/perl -w # convert a VM icon from a pbm ascii file into assembler source for aslc68k # prints source to stdout # image size 32 x 32 pixel, colordepth 24bpp, no more than 16 colors used # written by Soeren Gust, sgust@ithh.informationstheater.de # not very good commented, sorry. use strict; open(FILE, $ARGV[0]) or die "Can't open file"; my ($filetype, $size, $color) = ("#", "#", "#"); while($filetype =~ /^#/) { chomp($filetype = ); } if ($filetype ne "P3") { die "Wrong filetype"; } while($size =~ /^#/) { chomp($size = ); } if ($size ne "32 32") { die "Wrong size"; } while($color =~ /^#/) { chomp($color = ); } if ($color ne "255") { die "Wrong colordepth"; } my ($red, $green, $blue, $vmscolor, $indexcolor, @palette, @bitmap); my $maxcolor = 0; for my $y (0..31) { for my $x (0..31) { chomp($red = ); chomp($green = ); chomp($blue = ); $red = $red >> 4; $green = $green >> 4; $blue = $blue >> 4; $vmscolor = 0xf000 + 256 * $red + 16 * $green + $blue; $indexcolor = -1; for my $i (0..$maxcolor-1) { if ($palette[$i] == $vmscolor) { $indexcolor = $i; last; } } if ($indexcolor == -1) { $indexcolor = $maxcolor; $palette[$maxcolor++] = $vmscolor; if ($maxcolor > 16) { die "Too many colors"; } } $bitmap[$y*32+$x] = $indexcolor; } } # fill up palette with white for my $i ($maxcolor..15) { $palette[$i] = 0xffff; } # print palette print "; Icon palette generated by ppmtovmicon.pl\n\011.word "; for my $i (1..16) { printf "\$%04x", $palette[$i-1]; print ',' unless ($i % 8 == 0); print "\n\011.word " if ($i == 8); } print "\n"; # print icon bitmap print "; Icon generated by ppmtovmicon.pl\n"; my $p = 0; for my $y (0..31) { print "\011.word "; for my $x (0..7) { printf "\$%04x", ($bitmap[$p] << 4) + $bitmap[$p+1] + ($bitmap[$p+2] << 12) + ($bitmap[$p+3] << 8); $p += 4; print ',' unless ($x == 7); } print "\n"; }