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;
29 my $l = $len - length $data;
31 warn "# slurp $l got ",length($rest);
36 die "no escape at beginning",dump($_) unless s/^(\x00*)\x1B//;
37 warn "WARNING: ", length($1), " extra nulls before ESC\n" if $1;
38 my @a = split(/;/,$_);
42 print "$_ mode insertion @a\n";
43 } elsif ( $c eq 'Pc' ) {
44 print "$_ contrast @a\n";
45 } elsif ( $c eq 'Pl' ) {
46 print "$_ luminosity @a\n";
47 } elsif ( $c eq 'Ps' ) {
48 print "$_ speed @a\n";
49 } elsif ( $c eq 'Pr' ) {
50 print "$_ ribbon $a[0]\n";
51 } elsif ( $c eq 'Ss' ) {
52 print "$_ sequence start\n";
53 } elsif ( $c eq 'Se' ) {
54 print "$_ sequence end\n";
55 } elsif ( $c eq 'Sr' ) {
56 print "$_ sequence recto - card side\n";
57 } elsif ( $c eq 'Sv' ) {
58 print "$_ sequence verso - back side\n";
59 } elsif ( $c eq 'Db' ) {
60 my ( $color, $two ) = @a;
61 print "$c;$color;$two;... bitmap ",length($_), " bytes\n";
62 $two eq '2' or die 'only 2 colors supported';
63 my $path = "$name-Db-$color-$page.pbm"; $page++;
64 save_pbm $path, 648, 1016, bitmap( $_, 648 * 1016 / 8 );
65 } elsif ( $c eq 'Dbc' ) { # XXX not in cups
66 my ( $color, $line, $len ) = @a;
67 print "$c;$color;$line;$len;... download bitmap compressed\n";
68 my $comp = bitmap( $_, $len );
70 die "compression not supported" unless $color =~ m/[ko]/;
74 while ( $i < length $comp ) {
75 my $first = substr($comp,$i++,1);
76 if ( $first eq "\x00" ) {
78 } elsif ( $first eq "\xFF" ) {
82 $data .= substr($comp,$i,$len);
83 my $padding = 81 - $len;
84 #warn "# $len + $padding\n";
85 $data .= "\x00" x $padding;
90 my $path = "$name-Dbc-$color-$page.pbm"; $page++;
91 save_pbm $path, 648, 1016, $data;
93 } elsif ( $c eq 'Mr' ) {
94 print "$_ motor ribbon @a\n";
101 my ( $path, $w, $h, $data ) = @_;
102 open(my $pbm, '>', $path);
103 print $pbm "P4\n$w $h\n", $data;
105 print "saved $path $w * $h size ", -s $path, "\n";