#!/usr/bin/perl $bpp=6; $width=80*4; $height=60*4; $bits = (2**$bpp)-1; $invert=(2**$bpp); print "BPP: $bpp; Width: $width; Height: $height; bits: $bits; invert: $invert\n"; open(FILE, "minicom.cap") || die "Unable to open capture file: $!"; binmode FILE; open(OUT, ">qcam.ppm") || die "Unable to open output file: $!"; binmode OUT; print OUT "P5\n$width $height\n$bits\n"; $state=0; # for 6bpp. do { $c = ord(getc(FILE)); $b1 = ($c & 0xf0)>>4; $b2 = $c & 0xf; if ($bpp==4) { print "Alert: corrupt data.\n" if ($b1>16); $b1=16 if ($b1==0); print OUT chr($invert-$b1); print "Alert: corrupt data.\n" if ($b2>16); $b2=16 if ($b2==0); print OUT chr($invert-$b2); } else { $bytesthisline++; if ($state==0) { $t1 = ($b1<<2) | (($b2&0x0c)>>2); $save = ($b2 & 0x3) << 4; # replaced the next line, but haven't tested it yet. -- 2/11/2000 $t1++ if ($t1 == 0); print OUT chr($invert-$t1); $state = 1; } elsif ($state==1) { $t1 = ($save | $b1); # replaced the next line, but haven't tested it yet. -- 2/11/2000 $t1++ if ($t1 == 0); print OUT chr($invert-$t1); $save = $b2 << 2; $state = 2; } else { $t1 = $save | ($b1 >> 2); print OUT chr($invert-$t1); $t2 = (($b1 & 0x3) << 4) | $b2; # replaced the next two lines, but haven't tested yet. -- 2/11/2000 $t1++ if ($t1 == 0); $t2++ if ($t2 == 0); print OUT chr($invert-$t2); $state = 0; } # According to the code I've read, the line should prematurely end and the # state should return to 0 if there are fewer bits on the line than the read- # length lets us get (the remaining bits, and possibly extra bytes, don't # exist). This code doesn't exactly work, and if my math is correct, really # isn't necessary anyway. All scan widths are divisible by 3 and 4, so we # should be good. # if (($bytesthisline * 12) >= $width) { # $bytesthisline=0; # $state=0; # } } } while (!eof(FILE)); close FILE; close OUT;