6 my $file = shift @ARGV || die "usage: $0 dump.zpl";
8 open(my $in, '<', $file);
12 if ( /~DG(\w):(.+)/ ) {
13 my ( $name, $t,$w ) = split(/,/,$2,4);
15 warn "# $_ => [$name] t=$t w=$w\n";
23 foreach my $p ( 0 .. length($data) ) {
24 my $c = substr($data,$p,1);
26 my $l = ( $w * 2 ) - length($out) % ( $w * 2 );
27 $l = $w * 2 if $l == 0;
28 warn "# $p ZERO-to-EOL $c [$l]\n";
30 } elsif ( $c eq ':' ) {
31 $out .= length($out) > $w ? substr($out,-$w*2) : "00" x $w;
33 } elsif ( $c eq 'z' ) {
35 } elsif ( $c ge 'g' && $c le 'y' ) {
36 $repeat += 20 * ( ord($c) - ord('f') );
37 } elsif ( $c ge 'G' && $c le 'Y' ) {
38 $repeat += ord($c) - ord('F');
39 } elsif ( $c =~ m/[0-9A-F]/ ) {
41 warn "# $p $repeat $c\n";
49 warn "ABORT: offset $p data [$c]";
53 warn "## $repeat [$c] out = ",length($out);
57 my $bitmap = pack('H*', $out);
58 warn "# graphics of ",length($data)," bytes ZPL decompressed to ",length($out)," hex and ", length($bitmap), " bytes bitmap\n";
60 my $ph = int(length($bitmap) / $w);
61 print "P4\n$pw $ph\n", substr($bitmap,0,$ph*$w);