#!/usr/bin/perl -w # # Converts a 128x14 2-color XPM to a C file containing an array # of 32-bit values. use strict; my $blackColorCode; my $whiteColorCode; my $numPixelRows = 0; print "#include \n"; print "const uint32_t titleBitmap[14][8] =\n{\n"; while (<>) { if (/"(.)\s+c\s+#000000"/i) # if black color code line { $blackColorCode = $1; } elsif (/"(.)\s+c\s+#FFFFFF"/i) # if white color code line { $whiteColorCode = $1; } elsif (defined $blackColorCode && defined $whiteColorCode && /"(.*?)"/) # if pixel row { # Only keep the pixels. $_ = $1; die unless length($_) == 128; ++$numPixelRows; # Change the two codes to 0 and 1. s/\Q$blackColorCode\E/0/g; s/\Q$whiteColorCode\E/1/g; # Double each pixel horizontally. s/([01])/$1$1/g; # Group strings of 32 bits into a hex value. s/([01]{32})/ sprintf("0x%08x, ", eval "0b$1") /ge; print " { $_},\n"; } } print "};\n"; die unless $numPixelRows == 14;