#/usr/bin/perl $infile = $ARGV[0]; $baseout = $ARGV[1]; $swidth = $ARGV[2]; $sheight = $ARGV[3]; for( $x=0 ; $x < 4 ; $x++ ) { if( $ARGV[$x] eq "" ) { $badline = 1; } } if( $badline ) { printf "usage: pgm2fbf \n"; exit; } #first, read in the PGM file enough to: # make sure it's a P5 # read in the width, height # validate those settings open IF, "$infile"; $type = ""; $width = -1; $height = -1; $depth = -1; $done = 0; while( $done != 1 ) { $l = (); chomp $l; $l =~ s/#.*$//g; $l =~ s/\s+/ /g; @bits = split " ", $l; foreach $bit (@bits) { if( $height != -1 && $depth == -1 ) { $depth = int $bit; } if( $width != -1 && $height == -1 ) { $height = int $bit; } if( $type ne "" && $width == -1 ) { $width = int $bit; } if( $type eq "" ) { $type = $bit; } } if( $depth != -1 ) { $done = 1; } } printf "type: %s\n", $type; printf " w: %d\n", $width; printf " h: %d\n", $height; printf " d: %d\n", $depth; if( $type ne "P5" ) { printf "Invalid file format. P5 (BINARY PGM) expected, got %s\n", $type; exit; } if( $width == 0 || $height == 0 ) { printf "Invalid file size. >0,>0 expected, got %d,%d\n", $width, $height; exit; } $fbffile = $baseout . ".fbf"; $rawfile = $baseout . ".raw"; open OFRAW, ">$rawfile"; foreach $l () { print OFRAW $l; } close OFRAW; close IF; $col = $width/$swidth; $row = $height/$sheight; open OFFBF, ">$fbffile"; print OFFBF<