gzraw.pl
805 Bytes
#!/usr/bin/perl -w
die "Usage: gzraw input_file output_file <image var name> <gz size var name>\n" unless $#ARGV==3;
$in = shift;
$out = shift;
$gzimg_var = shift;
$gzsize_var = shift;
`gzip -c -9 -n $in | dd bs=10 skip=1 of=img.gz`;
$idx=0;
open(INFILE, "<img.gz") or die "Can't open $in: $!";
binmode(INFILE);
open(OUTFILE, ">$out") or die "Can't open $out: $!";
$size = `stat img.gz`;
$size =~ /(.*Size: )(\d+)/;
$gz_size = $2;
printf OUTFILE "int %s = %s;\n", $gzsize_var, $gz_size;
printf OUTFILE "unsigned char %s[] __attribute__((aligned (16))) = { \n", $gzimg_var;
while( read(INFILE, $byte, 1) != 0 ) {
printf OUTFILE "0x%02x, ", vec($byte, 0, 8);
$idx++;
if ($idx%80==0) {
printf OUTFILE "\n";
}
}
printf OUTFILE "};\n";
close INFILE;
close OUTFILE;
`rm img.gz`;