3 # Simulate EVOLIS Dualys printer
8 use Data::Dump qw(dump);
10 die "usage: $0 evolis.commands\n" unless @ARGV;
11 my $name = shift @ARGV;
19 open(my $e, '<', $name) || die "$name: $!";
22 warn "# tell ",tell($e),"\n";
23 $data =~ s/D.+;\d+;//;
26 warn "# bitmap $l $len\n";
27 return $data if length $data == $len;
30 my $l = $len - length $data;
32 warn "# slurp $l got ",length($rest);
37 die "no escape at beginning",dump($_) unless s/^(\x00*)\x1B//;
38 warn "WARNING: ", length($1), " extra nulls before ESC\n" if $1;
39 my @a = split(/;/,$_);
43 print "$_ mode insertion @a\n";
44 } elsif ( $c eq 'Pc' ) {
45 print "$_ contrast @a\n";
46 } elsif ( $c eq 'Pl' ) {
47 print "$_ luminosity @a\n";
48 } elsif ( $c eq 'Ps' ) {
49 print "$_ speed @a\n";
50 } elsif ( $c eq 'Pr' ) {
51 print "$_ ribbon $a[0]\n";
52 } elsif ( $c eq 'Ss' ) {
53 print "$_ sequence start\n";
54 } elsif ( $c eq 'Se' ) {
55 print "$_ sequence end\n";
56 } elsif ( $c eq 'Sr' ) {
57 print "$_ sequence recto - card side\n";
58 } elsif ( $c eq 'Sv' ) {
59 print "$_ sequence verso - back side\n";
60 } elsif ( $c eq 'Db' ) {
61 my ( $color, $two ) = @a;
62 print "$c;$color;$two;... bitmap ",length($_), " bytes\n";
63 $two eq '2' or die 'only 2 colors supported';
64 my $path = "$name-Db-$color-$page.pbm"; $page++;
65 save_pbm $path, 648, 1016, bitmap( $_, 648 * 1016 / 8 );
66 } elsif ( $c eq 'Dbc' ) { # XXX not in cups
67 my ( $color, $line, $len ) = @a;
68 print "$c;$color;$line;$len;... download bitmap compressed\n";
69 my $comp = bitmap( $_, $len );
71 die "compression not supported" unless $color =~ m/[ko]/;
75 while ( $i < length $comp ) {
76 my $first = substr($comp,$i++,1);
77 if ( $first eq "\x00" ) {
79 } elsif ( $first eq "\xFF" ) {
83 $data .= substr($comp,$i,$len);
84 my $padding = 81 - $len;
85 #warn "# $len + $padding\n";
86 $data .= "\x00" x $padding;
91 my $path = "$name-Dbc-$color-$page.pbm"; $page++;
92 save_pbm $path, 648, 1016, $data;
94 } elsif ( $c eq 'Mr' ) {
95 print "$_ motor ribbon @a\n";
102 my ( $path, $w, $h, $data ) = @_;
103 open(my $pbm, '>', $path);
104 print $pbm "P4\n$w $h\n", $data;
106 print "saved $path $w * $h size ", -s $path, "\n";