implement k and o compression
[Printer-EVOLIS.git] / evolis-printer.pl
index d6e2763..11bd8b7 100755 (executable)
@@ -7,62 +7,76 @@ use strict;
 
 use Data::Dump qw(dump);
 
-my $feeder = {qw(
-F Feeder
-M Manual
-B Auto
-)};
-
 local $/ = "\r";
 
 my $page = 1;
 
+my $name = $ARGV[0] || 'page';
+
 sub save_pbm;
 
 while(<>) {
-       s/\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0// && warn "FIXME: string 15 null bytes";
-
-       die "no escape at beginning",dump($_) 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;
-       warn "# $c @a\n";
        if ( $c eq 'Pmi' ) {
-               my $f = $a[0] || die 'missing feeder';
-               print "feeder $f | $feeder->{$f}\n";
-               $a[1] eq 's' or die;
+               print "$_ mode insertion @a\n";
        } elsif ( $c eq 'Pc' ) {
-               my $color = $a[0];
-               $a[1] eq '=' or die;
-               my $temperature = $a[2];
-               print "temperature $color = $temperature\n";
+               print "$_ contrast @a\n";
+       } elsif ( $c eq 'Pl' ) {
+               print "$_ luminosity @a\n";
+       } elsif ( $c eq 'Ps' ) {
+               print "$_ speed @a\n";
        } elsif ( $c eq 'Pr' ) {
-               print "improve $a[0]\n";
-               # FIXME windows sends it, cups doesn't
-       } elsif ( $c eq 'Db' ) { # XXX not in cups
+               print "$_ ribbon $a[0]\n";
+       } elsif ( $c eq 'Ss' ) {
+               print "$_ sequence start\n";
+       } elsif ( $c eq 'Se' ) {
+               print "$_ sequence end\n";
+       } elsif ( $c eq 'Sr' ) {
+               print "$_ sequence recto - card side\n";
+       } elsif ( $c eq 'Sv' ) {
+               print "$_ sequence verso - back side\n";
+       } elsif ( $c eq 'Db' ) {
                my ( $color, $two, $data ) = @a;
+               print "$c;$color;$two;... bitmap\n";
                $two eq '2' or die '2';
-               my $path = "page-Db-$color-$page.pbm";
-               $page++;
+               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, $data ) = @a;
-               while ( $len > length($data) ) {
-                       warn "# slurp more ",length($data), " < $len\n";
-                       $data .= <>;
+               my ( $color, $line, $len, $comp ) = @a;
+               print "$c;$color;$line;$len;... download bitmap compressed\n";
+               while ( $len > length($comp) ) {
+                       warn "# slurp more ",length($comp), " < $len\n";
+                       $comp .= <>;
                }
-               $len == length $data or warn "wrong length $len != ", length $data;
+               $len == length $comp or warn "wrong length $len != ", length $comp;
 
-               my $path = "page-Dbc-$color-$page.pbm";
-               $page++;
+               my $data;
+               my $i = 0;
+               while ( $i < length $comp ) {
+                       my $first = substr($comp,$i++,1);
+                       if ( $first eq "\x00" ) {
+                               $data .= "\x00" x 81;
+                       } elsif ( $first eq "\xFF" ) {
+                               $data .= "\xFF" x 81;
+                       } else {
+                               my $len = ord $first;
+                               $data .= substr($comp,$i,$len);
+                               my $padding = 81 - $len;
+warn "# $len $padding\n";
+                               $data .= "\x00" x $padding;
+                               $i += $len;
+                       }
+               }
 
-               my ( $w, $h ) = ( 646, 1081 );  # from driver
-#              ( $w, $h ) = ( 636, 994 );              # from test card
-               $h = int( length($data) * 8 / $w );
-               save_pbm $path, $w, $h, $data;
+               my $path = "$name-Dbc-$color-$page.pbm"; $page++;
+               save_pbm $path, 648, 1015, $data;
 
        } else {
-               warn "UNKNOWN: $c ", dump(@a);
+               print "FIXME: $_\n";
        }
 }