rgb2bin.pl
659 Bytes
#!/usr/bin/perl -w
die "Usage: rgb2bin.pl <sgi image file> <output binary file>\n" unless $#ARGV==1;
$root = $ENV{ROOT};
`$root/usr/sbin/rgb2c -F -f RGBA -s 16 -m tex $ARGV[0] > tmp_img.h`;
sub write_short {
my $f = shift;
my $val = shift;
printf $f "%c", (hex($val)&0xFF00) >> 8;
printf $f "%c", (hex($val)&0x00FF);
}
open(OUT_DATA,">$ARGV[1]");
binmode(OUT_DATA);
open(IN_FILE, "<tmp_img.h");
while (<IN_FILE>) {
if (/^\s+0x/) {
@pixel = split /,\s*/;
foreach $rgba (@pixel) {
$rgba =~ s/^\s*//;
write_short(OUT_DATA, $rgba);
}
}
}
close IN_FILE;
close OUT_DATA;
#`rm tmp_img.h`;