Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl =head1 NAME pnt2bmp - Converts "Tandy Personal Deskmate P(ai)NT files" to BMP =head1 SYNOPSIS B<pnt2bmp.pl> I<file.pnt> =head1 DESCRIPTION Converts "Tandy 1000 Personal Deskmate P(ai)NT files" to BMP. AFAIK, t +hey are always 312x176. Did this without docs, so may not work on all +. Pixel data is stored in byte pairs, the first byte, two 4-bit pixels, +and the second, a repeat count of the two pixel values http://www.leeland.net/pnt2bmp.html =head1 AUTHOR Lee Pumphret =cut use strict; use warnings; my @tga_palette = map { pack( "CCC", reverse @$_ ) } ( [ 0x00, 0x00, 0x00 ], # Black [ 0x00, 0x00, 0x99 ], # Dark Blue [ 0x00, 0x99, 0x00 ], # Dark Green [ 0x33, 0x99, 0x99 ], # Dark Cyan [ 0x99, 0x00, 0x00 ], # Dark Red [ 0xCC, 0x33, 0xCC ], # Dark Magenta [ 0xCC, 0x66, 0x00 ], # Orange [ 0x99, 0x99, 0x99 ], # Light Gray [ 0x99, 0x66, 0x33 ], # Dark Gray [ 0x66, 0x33, 0xFF ], # Light Blue [ 0x33, 0xCC, 0x00 ], # Light Green [ 0x66, 0xCC, 0xCC ], # Light Cyan [ 0xFF, 0xCC, 0xCC ], # Light Red [ 0xFF, 0x99, 0xFF ], # Light Magenta [ 0xFF, 0xFF, 0x00 ], # Yellow [ 0xFF, 0xFF, 0xFF ], #White ); my @files = glob( shift @ARGV ); foreach my $file (@files) { next and warn "Mismatched extension in filename [$file]... skippin +g\n" unless $file =~ /\.pnt$/i; print "processing $file...\n"; open( IN, "<$file" ) or die "Couldn't open $file :$!"; binmode(IN); my @imdata; my $buffer; my $PNT_HEADER_SIZE = 22; # .pnt file header size (I think) # Read the header ( read( IN, $buffer, $PNT_HEADER_SIZE ) == $PNT_HEADER_SIZE ) or die "Error reading header data!"; warn unpack( "h*", $buffer ) . " $file\n"; my ( $ident, $other ) = unpack( "A4", $buffer ); unless ( $ident =~ m/PNT$/ ) { die "Doesn't look like an PNT file! [$ident]"; } my $count; while ( read( IN, $buffer, 2 ) ) { my ( $pindex, $run ) = unpack( "CC", $buffer ); my $p1 = ( $pindex >> 4 ) & 0x0f; my $p2 = $pindex & 0x0f; push @imdata, ( ( $tga_palette[$p1], $tga_palette[$p2] ) x ($r +un) ); } my $width = 312; unless ( @imdata % $width == 0 ) { # If short, pad it out, but probably damaged. warn "Padding $file, may be damaged\n"; push @imdata, ( $tga_palette[0] ) x ( $width - ( @imdata % $width ) ); } my ( $x, $y ) = ( $width, @imdata / $width ); # Write out the bmp file ( my $outfile = $file ) =~ s/pnt$/bmp/i; my $written = $#imdata; open( OUT, ">$outfile" ) or die "Couldn't open output!"; binmode(OUT); # BMP 3.1 Header print OUT pack "C C l a a a a l l l l s s l l l l l l", 0x42, 0x4D +, 54 + ( $x * 3 ) * $y, 'l', 'e', 'e', 'p', 54, 0x28, $x, $y, 1, 2 +4, 0, 0, 0, 0, 0, 0; # Write out the image data, bottom to top while ( $written > 0 ) { print OUT @imdata[ $written - ( $x - 1 ) .. $written ]; $written -= $x; } close OUT; }

In reply to pnt2bmp by shotgunefx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (4)
    As of 2014-04-21 03:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (490 votes), past polls