my $page = 1;
+my $name = $ARGV[0] || 'page';
+
+sub save_pbm;
+
while(<>) {
- die "no escape at beginning" unless s/^\x1B//;
+ die "no escape at beginning",dump($_) unless s/^(\x00*)\x1B//;
+ warn "WARNING: ", length($1), " extra nulls before ESC\n" if $1;
chomp;
my @a = split(/;/,$_);
my $c = shift @a;
} elsif ( $c eq 'Pr' ) {
print "improve $a[0]\n";
# FIXME windows sends it, cups doesn't
- } elsif ( $c eq 'Dbc' ) {
- my ( $color, $line, $len, $data ) = @a;
- while ( $len > length($data) ) {
- warn "# slurp more ",length($data), " < $len\n";
- $data .= <>;
+ } elsif ( $c eq 'Sv' ) {
+ print "even page on duplex printing\n";
+ } elsif ( $c eq 'Db' ) { # XXX not in cups
+ my ( $color, $two, $data ) = @a;
+ $two eq '2' or die '2';
+ my $path = "$name-Db-$color-$page.pbm";
+ $page++;
+ save_pbm $path, 648, 1015, $data; # FIXME 1016?
+ } elsif ( $c eq 'Dbc' ) { # XXX not in cups
+ my ( $color, $line, $len, $comp ) = @a;
+ while ( $len > length($comp) ) {
+ warn "# slurp more ",length($comp), " < $len\n";
+ $comp .= <>;
+ }
+ $len == length $comp or warn "wrong length $len != ", length $comp;
+
+ my $w = 648 / 2;
+
+=for non-working
+
+ my $data;
+
+ my $i = 0;
+ while ( $i < length $comp ) {
+ my $len = ord(substr($comp,$i,4));
+ $i += 1;
+ warn "$i comp $len\n";
+ $data .= substr($comp,$i,$len);
+ $data .= "\x00" x ( $w - $len );
+ $i += $len;
}
- $len == length $data or die "wrong length $len != ", length $data;
- my $path = "page-$page-$color.pbm";
- open(my $pbm, '>', $path);
+=cut
+
+ my $data = $comp;
- my $w = 1016;
- my $h = 648;
+ my $path = "$name-Dbc-$color-$page.pbm";
+ $page++;
- $h = int( $len * 8 / $w );
+ my $h = int( $len / 128 );
+ save_pbm $path, $w, $h, $data;
- print $pbm "P4\n$w $h\n", $data;
- close($pbm);
- print "printed $path $w * $h size ", -s $path, "\n";
+ } elsif ( $c eq 'Se' ) {
+ my $zero = <>;
+ print "Se - slurping zero bytes at end ",dump($zero);
+ exit 0;
} else {
warn "UNKNOWN: $c ", dump(@a);
}
}
+
+sub save_pbm {
+ my ( $path, $w, $h, $data ) = @_;
+ open(my $pbm, '>', $path);
+ print $pbm "P4\n$w $h\n", $data;
+ close($pbm);
+ print "saved $path $w * $h size ", -s $path, "\n";
+}