X-Git-Url: http://git.rot13.org/?p=Printer-Zebra.git;a=blobdiff_plain;f=pbm2ZPL.pl;h=2556f26758e3d6200f918a9dbc3c4c56b5d487a2;hp=72237426beda62b81c3562b930ce661444a1f1af;hb=b3eca0900a7d24282a709acbeab5c53ba66e0e97;hpb=a21934cf314976ab6a6474587508c2ba6e3fa508 diff --git a/pbm2ZPL.pl b/pbm2ZPL.pl index 7223742..2556f26 100755 --- a/pbm2ZPL.pl +++ b/pbm2ZPL.pl @@ -6,20 +6,53 @@ use Data::Dump qw(dump); # DG compression is documented in ZPL II Programming Guide Volume Two, page 71-72 +my $darkness = $ENV{DARKNESS} || 0; my $compress = $ENV{COMPRESS} || 1; -my $pnm_file = shift @ARGV || die "usage: $0 print.pnm"; +my $pnm_file = shift @ARGV || die "usage: $0 print.pnm > print.zpl\n"; open(my $fh, '<', $pnm_file); -my $p4 = <$fh>; chomp $p4; -die "no P4 header in [$p4] from $pnm_file" unless $p4 eq 'P4'; +my $magic = <$fh>; chomp $magic; my $size = <$fh>; while ( $size =~ m/^#/ ) { $size = <$fh> }; # skip comments chomp $size; -my ( $w, $h ) = split(/ /,$size,$2); +my ( $w, $h ) = split(/ /,$size,2); warn "WARNING: width of $pnm_file not 832 but $w !\n" if $w != 832; -local $/ = undef; -my $bitmap = <$fh>; + +my $bitmap; + +if ( $magic eq 'P4' ) { + local $/ = undef; + $bitmap = <$fh>; +} elsif ( $magic eq 'P6' ) { + my $max_color = <$fh>; chomp $max_color; + + my $trashold = $max_color / 2; + + local $/ = undef; + my $rgb = <$fh>; + + my $mask = 0x80; + my $byte = 0; + + my $o = 0; + while ( $o < length($rgb) ) { + my $px = ord(substr($rgb,$o,1)); $o += 3; + $byte ^= $mask if $px < $trashold; + $mask >>= 1; + if ( ! $mask ) { + $bitmap .= chr($byte); + $byte = 0; + $mask = 0x80; + } + } + + warn dump $bitmap; + +} else { + die "$pnm_file magick $magic not supported\n"; +} + print '^XA'; @@ -33,7 +66,7 @@ print '^PMN'; # print mirror Y/N print '^LH0,0'; # label home x,y print '^JMA'; # dots/mm A = 24/12/8/6 B = 12/6/4/3 print '^PR4,4'; # print,slew,backfeed speed in inch/s 2 .. 12 [default: 2,6,2] -print '^MD13'; # media darkness -30 .. 30 / XiIIIPlus 0..30/0.1 increments +printf '^MD%d', $darkness ; # media darkness -30 .. 30 / XiIIIPlus 0..30/0.1 increments print '^JUS'; # configuration update F = factory default R = recall S = save print '^LRN'; # label reverse Y/N print '^CI0'; # change international font 0..255