3 ## -----------------------------------------------------------------------
5 ## Copyright 2001 H. Peter Anvin - All Rights Reserved
7 ## This program is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
10 ## USA; either version 2 of the License, or (at your option) any later
11 ## version; incorporated herein by reference.
13 ## -----------------------------------------------------------------------
17 ## Convert an LSS-16 image to PPM
21 ## lss16toppm [-map] < file.lss > file.ppm
23 ## The -map causes the color map to be output on stderr.
27 foreach $arg ( @ARGV ) {
28 if ( $arg eq '-map' ) {
31 print STDERR "$0: Unknown option: $arg\n";
36 if ( read(STDIN, $header, 56) != 56 ) {
37 print STDERR "$0: Short file\n";
41 ($magic, $xsize, $ysize, @colorset) = unpack("Vvvc48", $header);
43 if ( $magic != 0x1413f33d ) {
44 print STDERR "$0: Invalid file format\n";
49 for ( $i = 0 ; $i < 16 ; $i++ ) {
50 $r = int((shift @colorset) * 255 / 63 + 0.5);
51 $g = int((shift @colorset) * 255 / 63 + 0.5);
52 $b = int((shift @colorset) * 255 / 63 + 0.5);
54 $color{$i} = pack("ccc", $r, $g, $b);
57 printf STDERR "#%02x%02x%02x=%d\n", $r, $g, $b, $i;
63 if ( defined($nybble_buf) ) {
67 if ( read(STDIN, $ch, 1) != 1 ) {
68 print STDERR "$0: Short read on input (file corrupt)\n";
72 $nybble_buf = $ch >> 4;
79 print "$xsize $ysize\n";
82 for ( $y = 0 ; $y < $ysize ; $y++ ) {
85 undef $nybble_buf; # Nybble buffer starts clear on each line
86 while ( $x < $xsize ) {
98 $c += get_nybble() << 4;
101 # Truncate overlong runs
102 $c = $xsize-$x if ( $c > $xsize-$x );