6 # convert Zebra label printer ZPL to pbm image
8 my $file = shift @ARGV || die "usage: $0 dump.zpl > dump.pbm";
10 open(my $in, '<', $file);
14 if ( /~DG(\w+:)?(.+)/ ) {
15 my ( $name, $t,$w ) = split(/,/,$2,4);
17 warn "# $_ => [$name] t=$t w=$w\n";
25 foreach my $p ( 0 .. length($data) ) {
26 my $c = substr($data,$p,1);
28 my $l = ( $w * 2 ) - length($out) % ( $w * 2 );
29 $l = $w * 2 if $l == 0;
30 warn "# $p ZERO-to-EOL $c [$l]\n";
32 } elsif ( $c eq ':' ) {
33 $out .= length($out) > $w ? substr($out,-$w*2) : "00" x $w;
35 } elsif ( $c eq 'z' ) {
37 } elsif ( $c ge 'g' && $c le 'y' ) {
38 $repeat += 20 * ( ord($c) - ord('f') );
39 } elsif ( $c ge 'G' && $c le 'Y' ) {
40 $repeat += ord($c) - ord('F');
41 } elsif ( $c =~ m/[0-9A-F]/ ) {
43 warn "# $p $repeat $c\n";
51 warn "ABORT: offset $p data [$c]";
55 warn "## $repeat [$c] out = ",length($out);
59 my $bitmap = pack('H*', $out);
60 warn "# graphics of ",length($data)," bytes ZPL decompressed to ",length($out)," hex and ", length($bitmap), " bytes bitmap\n";
62 my $ph = int(length($bitmap) / $w);
63 print "P4\n$pw $ph\n", substr($bitmap,0,$ph*$w);