Hi all. Well, I fell off the planet again for awhile -- very distracted with another mission at the moment. Catching up a little here.
First order of business is to post the completed CG42 maker script that I wrote (and mentioned) awhile back, but just finally got tested and finalized. This is an expansion and improvement of the more basic script I originally posted in the middle of this post.
Rather than attaching as a file I'll just make a CODE block and paste it. It's only like 121 lines. Copy this text to a text editor on your machine (notepad, gedit, etc.) and save as "MakeCG42FromBMP2.pl" (at least that is the name that the syntax screen will reference).
This script will take a normal, unmodified 480 x 182, 24 bit BMP file, remove the first 54 bytes (clip), mirror it left to right (mirror), flip it top to bottom (flip), and pad 64 bytes of 0xFF to the end (pad). These are the things that you normally have to do to the file manually to make it show correctly on the phone.
The script does some basic checking to make sure the input file is the right size based on the switches you use.
I tested and validated it and it works well for me. If you find any bugs, please let me know and I'll correct this post.
To use:
On Windows (at a command prompt, with Perl installed, with the script and the .bmp in the same directory you are presently "in"):perl MakeCG42FromBMP.pl yourfile.bmpOn Linux (in a terminal window - be sure to adjust the shebang in the first line to point to your copy of Perl):
./MakeCG42FromBMP.pl yourfile.bmpThe Code
Code:#!/usr/local/bin/perl # MotoCache1 - take 480 x 182, 24 bit BMP file and make it into a CG42 code group # # Syntax: # MakeCG42FromBMP.pl filename.bmp [/noclip] [/nomirror] [/noflip] # # Ordinarily the BMP file needs to have the first 54 bytes removed (clip), # the image needs to be mirrored (mirror), the image needs to be flipped (flip), # and 64 bytes of 0xFF needs to be padded to the end (pad). If any of these # steps have already been done to the supplied file, use the appropriate # switch to tell script not to do it again. # use strict; my $file = shift(@ARGV); my %switches = map {lc($_)=>1} @ARGV; print "\nMakeCG42FromBMP v.2.0 - MotoCache1\n\n"; if (not -e $file) { print "Make Droid1 CG42 from a 480 x 182, 24 bit BMP file.\n\n"; print "Syntax: MakeCG42FromBMP.pl filename.bmp [/noclip] [/nomirror] [/noflip]\n\n"; print " /noclip - first 54 bytes of BMP already removed, don't do it\n"; print " /nomirror - image already mirrored (or you want it to appear backwards)\n"; print " /noflip - image already flipped (or you want it to appear upside down)\n\n"; exit; } print "Processing $file...\n\n"; # The most likely source of trouble would be if the input file isn't right, so we're going # to spend some code to make sure it is, and try to give useful messages if it is not. # Fle size check if ($switches{'/noclip'}) { # File should be 262080 bytes if (-s $file == 262134) { print "You specified the /noclip switch, but your file is 262134 bytes which means\n"; print "it needs to be clipped. Cannot continue.\n\n"; exit; } elsif (-s $file != 262080) { print "You specified the /noclip switch. A file that has already been clipped should\n"; print "be 262080 bytes, but the your file is " . (-s $file) . " Cannot continue.\n\n"; exit; } else { # File is good for /noclip - nothing special to do } } else { # File should be 262134 bytes if (-s $file == 262080) { print "You did not specify the /noclip switch, but your file is 262080 bytes which means\n"; print "it should not be clipped. Cannot continue.\n\n"; exit; } elsif (-s $file != 262134) { print "An appropriate 480 x 182, 24 bit BMP should be 262134 bytes. Your file is \n"; print (-s $file) . " bytes. Cannot continue.\n\n"; exit; } else { # File is good } } print " File $file is correct size (262134 bytes).\n"; # Open source file and read in binary mode open (IN,$file) or die ("Can't open $file for input. Error: $!"); binmode IN; # Open target file and write in binary mode open (OUT,">$file.CG42.smg") or die ("Can't open $file.CG42.smg for output. Error: $!"); binmode OUT; my ($imageData,$bytesRead); if (not $switches{'/noclip'}) { print " Clipping...\n"; $bytesRead = read(IN,$imageData,54); # clip } # Read image data $bytesRead = read(IN,$imageData,262080); close IN; if ($bytesRead == 262080) { print " Read 262080 image bytes.\n"; } else { die ("\nFailed to read 262080 image bytes. Cannot continue."); } unless ($switches{'/nomirror'}) { print " Mirroring...\n"; $imageData = mirrorImage(3,480,182,\$imageData); } unless ($switches{'/noflip'}) { print " Flipping...\n"; $imageData = reverse(split(//,$imageData)); } print " Padding...\n"; $imageData .= "\xFF" x 64; print " Writing output file $file.CG42.smg...\n"; print OUT $imageData; close OUT; print "\nDone!\n\n"; sub mirrorImage { my $bytesPerPx = shift; my $widthPx = shift; my $heightPx = shift; my $imageRef = shift; # Reference to scalar holding image my $lineBytes = $bytesPerPx * $widthPx; my @array = unpack("(a$lineBytes)$heightPx", $$imageRef); for (my $row=0; $row <= ($heightPx-1); $row++) { $array[$row] = pack("(a$bytesPerPx)$widthPx",reverse(unpack("(a$bytesPerPx)$widthPx", $array[$row]))); } $$imageRef = pack("(a$lineBytes)$heightPx",@array); }
New script works like a champ! Now if we could only figure out how to generate correct checksums...