#!/usr/bin/perl -w 

# Takes an RGBA file, throws away the GB and outputs only the R and A.
# All in raw format. 

die "Usage: raw2BWAlpha.pl <input RGBA RAW> <output 1color RAW>\n" unless $#ARGV==1;

$in = shift;
$out = shift;
#$idx=0;

open(INFILE, "<$in") or die "Can't open $in: $!";
open(OUTFILE, ">$out") or die "Can't open $out: $!";

while( read( INFILE, $byte, 1) != 0 ) {
    $red = 16 * vec($byte,0,4 );
    $alpha = 255;

    syswrite OUTFILE, (pack("C", $red)), 1;
    syswrite OUTFILE, (pack("C", $red)), 1;
    syswrite OUTFILE, (pack("C", $red)), 1;
    syswrite OUTFILE, (pack("C", $alpha)), 1;


}
close INFILE;
close OUTFILE;

