From: Dobrica Pavlinusic Date: Wed, 4 Jan 2012 15:38:30 +0000 (+0100) Subject: convert ZPL DG into pbm image X-Git-Url: http://git.rot13.org/?p=Printer-Zebra.git;a=commitdiff_plain;h=9a7993f335b5c85141d36611e4726fcf1fc163c5;ds=sidebyside convert ZPL DG into pbm image --- 9a7993f335b5c85141d36611e4726fcf1fc163c5 diff --git a/ZPL2pbm.pl b/ZPL2pbm.pl new file mode 100755 index 0000000..89eead4 --- /dev/null +++ b/ZPL2pbm.pl @@ -0,0 +1,66 @@ +#!/usr/bin/perl +use warnings; +use strict; +use autodie; + +my $file = shift @ARGV || die "usage: $0 dump.zpl"; + +open(my $in, '<', $file); + +while(<$in>) { + chomp; + if ( /~DG(\w):(.+)/ ) { + my ( $name, $t,$w ) = split(/,/,$2,4); + + warn "# $_ => [$name] t=$t w=$w\n"; + + my $data; + read $in, $data, $t; + + my $out; + # ZPL decompress + my $repeat = 1; + foreach my $p ( 0 .. length($data) ) { + my $c = substr($data,$p,1); + if ( $c eq ',' ) { + my $l = ( $w * 2 ) - length($out) % ( $w * 2 ); + $l = $w * 2 if $l == 0; + warn "# $p ZERO-to-EOL $c [$l]\n"; + $out .= "0" x $l; + } elsif ( $c eq ':' ) { + $out .= length($out) > $w ? substr($out,-$w*2) : "00" x $w; + warn "# $p :\n"; + } elsif ( $c eq 'z' ) { + $repeat += 400; + } elsif ( $c ge 'g' && $c le 'y' ) { + $repeat += 20 * ( ord($c) - ord('f') ); + } elsif ( $c ge 'G' && $c le 'Y' ) { + $repeat += ord($c) - ord('F'); + } elsif ( $c =~ m/[0-9A-F]/ ) { + if ( $repeat ) { + warn "# $p $repeat $c\n"; + $out .= $c x $repeat; + $repeat = 0; + } else { + warn "# $p hex $c\n"; + $out .= $c; + } + } else { + warn "ABORT: offset $p data [$c]"; + last; + } + + warn "## $repeat [$c] out = ",length($out); + } + + + my $bitmap = pack('H*', $out); + warn "# graphics of ",length($data)," bytes ZPL decompressed to ",length($out)," hex and ", length($bitmap), " bytes bitmap\n"; + my $pw = $w * 8; + my $ph = int(length($bitmap) / $w); + print "P4\n$pw $ph\n", substr($bitmap,0,$ph*$w); + + } else { + warn "IGNORED: $_\n"; + } +}