Bryan,

I've updated the netpbm Palm image handling to cover the 16-bit direct
color image format introduced with PalmOS 4.0 (and also in the
Handspring Visor and Sony Clie' devices).

I've attached a context diff to the 9.14 sources in the pnm/pnmtopalm/
directory.  I'd be happy to provide a full tar file of that directory,
instead, if that would be of more assistance.  Please let me know.

Bill
-----------------
 Bill Janssen  <[EMAIL PROTECTED]> (650) 812-4763  FAX: (650) 812-4777
 Xerox Palo Alto Research Center, 3333 Coyote Hill Rd, Palo Alto, CA  94304



*** 1.1 2001/06/07 03:25:10
--- pnm/pnmtopalm/palm.h        2001/06/07 03:51:06
***************
*** 1,9 ****
--- 1,12 ----
  #define PALM_IS_COMPRESSED_FLAG               0x8000
  #define PALM_HAS_COLORMAP_FLAG                0x4000
  #define PALM_HAS_TRANSPARENCY_FLAG    0x2000
+ #define PALM_DIRECT_COLOR             0x0400
+ #define PALM_4_BYTE_FIELD             0x0200
  
  #define PALM_COMPRESSION_SCANLINE     0x00
  #define PALM_COMPRESSION_RLE          0x01
+ #define PALM_COMPRESSION_PACKBITS     0x02
  #define PALM_COMPRESSION_NONE         0xFF
  
  typedef unsigned long Color_s, *Color;
*** 1.1 2001/06/07 03:25:10
--- pnm/pnmtopalm/palmtopnm.1   2001/06/09 02:24:07
***************
*** 30,36 ****
  .SH "SEE ALSO"
  pnmtopalm(1), pnm(5)
  .SH BUGS
! There is currently no support for 16-bit colors used in the Handspring Visor series. 
 This should be added after Palm OS 4.0 is released.
  
  There is currently no support for direct generation of an alpha-mask if the Palm 
pixmap has a transparent color.  However, this can still be achieved with 
\fBppmcolormask\fR by a netpbm pipe similar to:
  
--- 30,36 ----
  .SH "SEE ALSO"
  pnmtopalm(1), pnm(5)
  .SH BUGS
! An additional compression format, \fIpackbits\fR, has been added with PalmOS 4.0.  
This package should be updated to support it.
  
  There is currently no support for direct generation of an alpha-mask if the Palm 
pixmap has a transparent color.  However, this can still be achieved with 
\fBppmcolormask\fR by a netpbm pipe similar to:
  
***************
*** 40,46 ****
  It was heavily modified by Bill Janssen to
  add support for color, compression, and transparency.
  .br
! Copyright 1995-2000 by Ian Goldberg and Bill Janssen.
  .\" Permission to use, copy, modify, and distribute this software and its
  .\" documentation for any purpose and without fee is hereby granted, provided
  .\" that the above copyright notice appear in all copies and that both that
--- 40,46 ----
  It was heavily modified by Bill Janssen to
  add support for color, compression, and transparency.
  .br
! Copyright 1995-2001 by Ian Goldberg and Bill Janssen.
  .\" Permission to use, copy, modify, and distribute this software and its
  .\" documentation for any purpose and without fee is hereby granted, provided
  .\" that the above copyright notice appear in all copies and that both that
*** 1.1 2001/06/07 03:25:10
--- pnm/pnmtopalm/palmtopnm.c   2001/06/09 02:12:58
***************
*** 47,57 ****
      xel *xelrow;
      unsigned char *Tbmprow, *lastrow;
      int argsGood = 1, verbose = 0, transparent = 0, forceplain = 0, showhist = 0;
!     int rle_compression = 0, scanline_compression = 0;
      xelval *graymap;
      xelval mapped_color;
      int cc;
!     unsigned int mask, ncolors, maxval, incount, inval;
      unsigned int *seen = 0;
      unsigned int rendition = 1, rendition_counter, unread_header;
      Colormap colormap = 0;
--- 47,57 ----
      xel *xelrow;
      unsigned char *Tbmprow, *lastrow;
      int argsGood = 1, verbose = 0, transparent = 0, forceplain = 0, showhist = 0;
!     int rle_compression = 0, scanline_compression = 0, packbits_compression = 0;
      xelval *graymap;
      xelval mapped_color;
      int cc;
!     unsigned int mask, ncolors, maxval, incount, inval, redbits, greenbits, bluebits;
      unsigned int *seen = 0;
      unsigned int rendition = 1, rendition_counter, unread_header;
      Colormap colormap = 0;
***************
*** 119,124 ****
--- 119,126 ----
        ctype = "rle (Palm OS 3.5)";
        else if (compressionType == PALM_COMPRESSION_SCANLINE)
        ctype = "scanline (Palm OS 2.0)";
+       else if (compressionType == PALM_COMPRESSION_PACKBITS)
+       ctype = "packbits (Palm OS 4.0)";
        else if (compressionType == PALM_COMPRESSION_NONE)
        ctype = "none";
        else
***************
*** 135,140 ****
--- 137,147 ----
        rle_compression = 1;
        else if (compressionType == PALM_COMPRESSION_SCANLINE)
        scanline_compression = 1;
+       else if (compressionType == PALM_COMPRESSION_PACKBITS) {
+       packbits_compression = 1;
+       pm_message ("Decompression of 'packbits' compressed Palm bitmaps is not yet 
+supported.");
+       return 1;
+       }
        else {
        pm_message ("The input is compressed with an unknown compression type %d", 
compressionType);
        return 1;
***************
*** 144,150 ****
      }
  
      /* figure the maxval, colormap, and pnm format */
!     if (flags & PALM_HAS_COLORMAP_FLAG) {
        colormap = palmcolor_read_colormap (ifp);
        format = PPM_TYPE;
        maxval = 255;
--- 151,161 ----
      }
  
      /* figure the maxval, colormap, and pnm format */
!     if (flags & PALM_DIRECT_COLOR) {
!       colormap = 0;
!       format = PPM_TYPE;
!       maxval = 255;
!     } else if (flags & PALM_HAS_COLORMAP_FLAG) {
        colormap = palmcolor_read_colormap (ifp);
        format = PPM_TYPE;
        maxval = 255;
***************
*** 163,168 ****
--- 174,188 ----
        maxval = (1 << pixelSize) - 1;
      }
  
+     if (flags & PALM_DIRECT_COLOR) {
+       redbits = fgetc(ifp);
+       greenbits = fgetc(ifp);
+       bluebits = fgetc(ifp);
+       pad = fgetc(ifp);
+       pad = fgetc(ifp);
+       temp_color = (fgetc(ifp) << 16) | (fgetc(ifp) << 8) | fgetc(ifp);
+     }
+ 
      if (transparent) {
        if (flags & PALM_HAS_TRANSPARENCY_FLAG) {
        if (colormap != 0) {
***************
*** 172,177 ****
--- 192,199 ----
                            sizeof(Color_s), palmcolor_compare_indices));
          printf("#%02x%02x%02x\n", (unsigned int) ((*actual_color >> 16) & 0xFF),
                 (unsigned int) ((*actual_color >> 8) & 0xFF), (unsigned int) 
(*actual_color & 0xFF));
+       } else if (flags & PALM_DIRECT_COLOR) {
+         printf("#%02x%02x%02x\n", ((temp_color >> 16) & 0xFF), ((temp_color >> 8) & 
+0xFF), (temp_color & 0xFF));
        } else {
          unsigned int grayval = ((maxval - transparentIndex) * 256) / maxval;
          printf("#%02x%02x%02x\n", grayval, grayval, grayval);
***************
*** 235,261 ****
          pm_error("Error reading Tbmp file");
        }
        }
!       inbit = 8 - pixelSize;
!       inbyte = Tbmprow;
!       for (j=0; j<cols; ++j) {
!       color = ((*inbyte) & (mask << inbit)) >> inbit;
!       if (showhist)
!         seen[color] += 1;
!       if (colormap) {
!         temp_color = (color << 24);
!         actual_color = (bsearch (&temp_color,
!                                  colormap->color_entries, colormap->ncolors,
!                                  sizeof(Color_s), palmcolor_compare_indices));
!         PPM_ASSIGN(xelrow[j], (*actual_color >> 16) & 0xFF, (*actual_color >> 8) & 
0xFF, (*actual_color & 0xFF));
        } else {
!         mapped_color = graymap[color];
!         PNM_ASSIGN1(xelrow[j], mapped_color);
        }
!       if (!inbit) {
!         ++inbyte;
!         inbit = 8 - pixelSize;
!       } else {
!         inbit -= pixelSize;
        }
        }
        pnm_writepnmrow(stdout, xelrow, cols, maxval, format, forceplain);
--- 257,318 ----
          pm_error("Error reading Tbmp file");
        }
        }
!       if (flags & PALM_DIRECT_COLOR) {
! 
!       /* There's a problem with this.  Take the Palm 16-bit direct color.  That's
!          5 bits for the red, 6 for the green, and 5 for the blue.  So what should
!          the MAXVAL be?  I decided to use 255 (8 bits) for everything, since that's
!          the theoretical max of the number of bits in any one color, according to 
Palm.
!          So the Palm color 0xFFFF (white) would be red=0x1F, green=0x3F, and 
blue=0x1F.
!          How do we promote those colors?  Simple shift would give us 
R=248,G=252,B=248;
!          which is slightly green.  Hardly seems right.
! 
!          So I've perverted the math a bit.  Each color value is multiplied by 255,
!          then divided by either 31 (red or blue) or 63 (green).  That's the right way
!          to do it anyway.
!          */
! 
!       if (pixelSize == 16) {
!         for (inbyte = Tbmprow, j = 0;  j < cols;  ++j) {
!           inval = *inbyte++ << 8;
!           inval |= *inbyte++;
!           if (showhist)
!             seen[inval] += 1;
! 
!           /*
!           if (verbose)
!             pm_message("%d,%d:  color 0x%04x => %d/%d/%d", i, j, inval, (((inval >> 
11) & 0x1F) * maxval) / 31 , (((inval >> 5) & 0x3F) * maxval) / 63, ((inval & 0x1F) * 
maxval) / 31);
!             */
! 
!           PPM_ASSIGN(xelrow[j], (((inval >> 11) & 0x1F) * maxval) / 31 , (((inval >> 
5) & 0x3F) * maxval) / 63, ((inval & 0x1F) * maxval) / 31);
!         }
        } else {
!         pm_error ("Can only convert 16-bit direct color Palm bitmaps.");
!         return 1;
        }
!       } else {
!       inbit = 8 - pixelSize;
!       inbyte = Tbmprow;
!       for (j=0; j<cols; ++j) {
!         color = ((*inbyte) & (mask << inbit)) >> inbit;
!         if (showhist)
!           seen[color] += 1;
!         if (colormap) {
!           temp_color = (color << 24);
!           actual_color = (bsearch (&temp_color,
!                                    colormap->color_entries, colormap->ncolors,
!                                    sizeof(Color_s), palmcolor_compare_indices));
!           PPM_ASSIGN(xelrow[j], (*actual_color >> 16) & 0xFF, (*actual_color >> 8) & 
0xFF, (*actual_color & 0xFF));
!         } else {
!           mapped_color = graymap[color];
!           PNM_ASSIGN1(xelrow[j], mapped_color);
!         }
!         if (!inbit) {
!           ++inbyte;
!           inbit = 8 - pixelSize;
!         } else {
!           inbit -= pixelSize;
!         }
        }
        }
        pnm_writepnmrow(stdout, xelrow, cols, maxval, format, forceplain);
*** 1.1 2001/06/07 03:25:10
--- pnm/pnmtopalm/pnmtopalm.1   2001/06/09 02:22:50
***************
*** 29,38 ****
  Display the format of the output file.
  .TP
  .B -depth N
! Produce a file of depth N, where N must be either 1, 2, 4, or 8.  Any depth greater 
than 1 will produce a version 1 or 2 bitmap.  Because the default Palm 8-bit colormap 
is not grayscale, if the input is a grayscale or monochrome pixmap, the output will 
never be more than 4 bits deep, regardless of the specified depth.
  .TP
  .B -maxdepth N
! Produce a file of minimal depth, but in any case less than N bits wide.
  .TP
  .B -offset
  Fill in the \fInextDepthOffset\fR field in the file header, to provide for multiple 
renditions of the pixmap in the same file.
--- 29,38 ----
  Display the format of the output file.
  .TP
  .B -depth N
! Produce a file of depth N, where N must be either 1, 2, 4, 8, or 16.  Any depth 
greater than 1 will produce a version 1 or 2 bitmap.  Because the default Palm 8-bit 
colormap is not grayscale, if the input is a grayscale or monochrome pixmap, the 
output will never be more than 4 bits deep, regardless of the specified depth.  Note 
that 8-bit color is only supported in PalmOS 3.5 (and higher), and 16-bit direct color 
is only supported in PalmOS 4.0 (and higher).  However, the 16-bit direct color format 
is also compatible with the various PalmOS 3.x versions used in the Handspring Visor, 
so these images may also work in that device.
  .TP
  .B -maxdepth N
! Produce a file of minimal depth, but in any case less than N bits wide.  If 16-bit 
is specified, the output will always be 16-bit direct color.
  .TP
  .B -offset
  Fill in the \fInextDepthOffset\fR field in the file header, to provide for multiple 
renditions of the pixmap in the same file.
***************
*** 56,62 ****
  .SH "SEE ALSO"
  palmtopnm(1), ppmquant(1), pnm(5)
  .SH NOTES
! There is currently no support for 16-bit colors used in the Handspring Visor series. 
 This should be added after Palm OS 4.0 is released.
  
  Palm pixmaps may contains multiple renditions of the same pixmap, in different 
depths.  To construct an N-multiple-rendition Palm pixmap with pnmtopalm, first 
construct renditions 1 through N-1 using the \fI-offset\fR switch, then construct the 
Nth pixmap without the -offset switch.  Then concatenate the individual renditions 
together in a single file using \fBcat\fR command.
  .SH AUTHORS
--- 56,62 ----
  .SH "SEE ALSO"
  palmtopnm(1), ppmquant(1), pnm(5)
  .SH NOTES
! An additional compression format, \fIpackbits\fR, has been added with PalmOS 4.0.  
This package should be updated to support it.
  
  Palm pixmaps may contains multiple renditions of the same pixmap, in different 
depths.  To construct an N-multiple-rendition Palm pixmap with pnmtopalm, first 
construct renditions 1 through N-1 using the \fI-offset\fR switch, then construct the 
Nth pixmap without the -offset switch.  Then concatenate the individual renditions 
together in a single file using \fBcat\fR command.
  .SH AUTHORS
***************
*** 64,70 ****
  and George Caswell.  It was completely re-written by Bill Janssen to
  add support for color, compression, and transparency.
  .br
! Copyright 1995-2000 by Ian Goldberg, George Caswell, and Bill Janssen.
  .\" Permission to use, copy, modify, and distribute this software and its
  .\" documentation for any purpose and without fee is hereby granted, provided
  .\" that the above copyright notice appear in all copies and that both that
--- 64,70 ----
  and George Caswell.  It was completely re-written by Bill Janssen to
  add support for color, compression, and transparency.
  .br
! Copyright 1995-2001 by Ian Goldberg, George Caswell, and Bill Janssen.
  .\" Permission to use, copy, modify, and distribute this software and its
  .\" documentation for any purpose and without fee is hereby granted, provided
  .\" that the above copyright notice appear in all copies and that both that
*** 1.1 2001/06/07 03:25:10
--- pnm/pnmtopalm/pnmtopalm.c   2001/06/09 02:14:01
***************
*** 29,35 ****
      int setOffset = 0;
      int cc, max_bpp = 0, custom_colormap = 0, flags = 0, specified_bpp = 0, bpp;
      int scanline_compression = 0, rle_compression = 0;
!     int argsGood = 1, verbose = 0, version, maxmaxval;
      unsigned int newMaxVal, color, last_color, repeatcount, limit;
      Color_s temp_color;
      register Color found;
--- 29,35 ----
      int setOffset = 0;
      int cc, max_bpp = 0, custom_colormap = 0, flags = 0, specified_bpp = 0, bpp;
      int scanline_compression = 0, rle_compression = 0;
!     int argsGood = 1, verbose = 0, version, maxmaxval, directColor = 0;
      unsigned int newMaxVal, color, last_color, repeatcount, limit;
      Color_s temp_color;
      register Color found;
***************
*** 42,54 ****
         if ((strcmp(argv[cc], "-depth") == 0) && ((cc + 1) < argc)) {
         cc++;
         specified_bpp = atoi(argv[cc]);
!        if ((specified_bpp != 1) && (specified_bpp != 2) && (specified_bpp != 4) && 
(specified_bpp != 8))
!          pm_error("bad value for -depth flag; valid values are 1, 2, 4, or 8");
         } else if ((strcmp(argv[cc], "-maxdepth") == 0) && ((cc + 1) < argc)) {
         cc++;
         max_bpp = atoi(argv[cc]);
!        if ((max_bpp != 1) && (max_bpp != 2) && (max_bpp != 4) && (max_bpp != 8))
!          pm_error("bad value for -maxdepth flag; valid values are 1, 2, 4, or 8");
         } else if ((strcmp(argv[cc], "-transparent") == 0) && ((cc + 1) < argc)) {
         cc++;
         transparentValue = argv[cc];
--- 42,54 ----
         if ((strcmp(argv[cc], "-depth") == 0) && ((cc + 1) < argc)) {
         cc++;
         specified_bpp = atoi(argv[cc]);
!        if ((specified_bpp != 1) && (specified_bpp != 2) && (specified_bpp != 4) && 
(specified_bpp != 8) && (specified_bpp != 16))
!          pm_error("bad value for -depth flag; valid values are 1, 2, 4, 8, or 16");
         } else if ((strcmp(argv[cc], "-maxdepth") == 0) && ((cc + 1) < argc)) {
         cc++;
         max_bpp = atoi(argv[cc]);
!        if ((max_bpp != 1) && (max_bpp != 2) && (max_bpp != 4) && (max_bpp != 8) && 
(max_bpp != 16))
!          pm_error("bad value for -maxdepth flag; valid values are 1, 2, 4, 8, or 
16");
         } else if ((strcmp(argv[cc], "-transparent") == 0) && ((cc + 1) < argc)) {
         cc++;
         transparentValue = argv[cc];
***************
*** 111,122 ****
        maxmaxval = PGM_OVERALLMAXVAL;
  
      } else if ((format == PPM_FORMAT) || (format == RPPM_FORMAT)) {
!       /* We assume that we only get a PPM if the image cannot be represented
!        as PBM or PGM.  So we're going to have to support 8-bit colors.
!        if "custom_colormap" is specified (not recommended by Palm) we will put
!        in our own colormap; otherwise we will assume that the colors have been
!        mapped to the default Palm colormap by appropriate use of ppmquant. */
!       if (!custom_colormap) {
        colormap = palmcolor_build_default_8bit_colormap();
        bpp = 8;
        if (((specified_bpp != 0) && (specified_bpp != 8)) ||
--- 111,134 ----
        maxmaxval = PGM_OVERALLMAXVAL;
  
      } else if ((format == PPM_FORMAT) || (format == RPPM_FORMAT)) {
! 
!       /* We assume that we only get a PPM if the image cannot be
!       represented as PBM or PGM.  There are two options here: either
!       8-bit with a colormap, either the standard one or a custom one,
!       or 16-bit direct color.  In the 8-bit case, if "custom_colormap"
!       is specified (not recommended by Palm) we will put in our own
!       colormap; otherwise we will assume that the colors have been
!       mapped to the default Palm colormap by appropriate use of
!       ppmquant.  We try for 8-bit color first, since it's supported by
!       more PalmOS devices. */
! 
!       if ((specified_bpp == 16) || 
!         (specified_bpp == 0 && max_bpp == 16)) {
!       /* we do the 16-bit direct color */
!       directColor = 1;
!       bpp = 16;
!       } else if (!custom_colormap) {
!       /* standard indexed 8-bit color */
        colormap = palmcolor_build_default_8bit_colormap();
        bpp = 8;
        if (((specified_bpp != 0) && (specified_bpp != 8)) ||
***************
*** 125,130 ****
--- 137,143 ----
        if (verbose)
          pm_message("input is color %dx%d, using default colormap at 8 bpp", cols, 
rows);
        } else {
+       /* indexed 8-bit color with a custom colormap */
        colormap = palmcolor_build_custom_8bit_colormap (rows, cols, pixels);
        for (bpp = 1;  (1 << bpp) < colormap->ncolors;  bpp *= 2)
          ;
***************
*** 148,163 ****
  
      if (transparentValue != 0) {
        transcolor = ppm_parsecolor (transparentValue, maxmaxval);
!       temp_color = ((((PPM_GETR(transcolor) * newMaxVal) / maxval) << 16) |
!                   (((PPM_GETG(transcolor) * newMaxVal) / maxval) << 8) |
!                   ((PPM_GETB(transcolor) * newMaxVal) / maxval));
!       found = (bsearch (&temp_color,
!                       colormap->color_entries, colormap->ncolors,
!                       sizeof(Color_s), palmcolor_compare_colors));
!       if (!found) {
!       pm_error("Specified transparent color %s not found in colormap.", 
transparentValue);
!       } else
!       transindex = (*found >> 24) & 0xFF;
      }
  
      flags = 0;
--- 161,178 ----
  
      if (transparentValue != 0) {
        transcolor = ppm_parsecolor (transparentValue, maxmaxval);
!       if (!directColor) {
!       temp_color = ((((PPM_GETR(transcolor) * newMaxVal) / maxval) << 16) |
!                     (((PPM_GETG(transcolor) * newMaxVal) / maxval) << 8) |
!                     ((PPM_GETB(transcolor) * newMaxVal) / maxval));
!       found = (bsearch (&temp_color,
!                         colormap->color_entries, colormap->ncolors,
!                         sizeof(Color_s), palmcolor_compare_colors));
!       if (!found) {
!         pm_error("Specified transparent color %s not found in colormap.", 
transparentValue);
!       } else
!         transindex = (*found >> 24) & 0xFF;
!       }
      }
  
      flags = 0;
***************
*** 167,172 ****
--- 182,189 ----
        flags |= PALM_HAS_COLORMAP_FLAG;
      if (rle_compression || scanline_compression)
        flags |= PALM_IS_COMPRESSED_FLAG;
+     if (directColor)
+       flags |= PALM_DIRECT_COLOR;
  
      /* Write Tbmp header. */
      (void) pm_writebigshort( stdout, cols );  /* width */
***************
*** 211,216 ****
--- 228,252 ----
             sizeof(Color_s), palmcolor_compare_colors);
      }
  
+     if (directColor) {
+       if (bpp == 16) {
+       fputc(5, stdout);       /* # of bits of red */
+       fputc(6, stdout);       /* # of bits of green */        
+       fputc(5, stdout);       /* # of bits of blue */
+       fputc(0, stdout);       /* reserved by Palm */
+       } else {
+       pm_error("Don't know how to support %d bit DirectColor bitmaps.", bpp);
+       }
+       if (transparentValue != 0) {
+       fputc(0, stdout);
+       fputc((PPM_GETR(transcolor) * 255) / maxval, stdout);
+       fputc((PPM_GETG(transcolor) * 255) / maxval, stdout);
+       fputc((PPM_GETB(transcolor) * 255) / maxval, stdout);
+       } else {
+       pm_writebiglong(stdout, 0);             /* no transparent color */
+       }
+     }
+ 
      last_color = 0xFFFFFFFF;
      rowdata = malloc(rowbytes);
      if (scanline_compression)
***************
*** 219,234 ****
      for ( row = 0; row < rows; ++row ) {
          memset(rowdata, 0, rowbytes);
        outbyte = 0x00;
!       /* outbit is the lowest bit number we want to access for this pixel */
!       outbit = 8 - bpp;
!       for ( col = 0, pP = pixels[row], outptr = rowdata; col < cols; ++col, ++pP ) {
  
            if (colormap == 0) {
              /* we assume grayscale, and use simple scaling */
              color = (PNM_GET1(*pP) * newMaxVal)/maxval;
              if (color > newMaxVal)
                pm_error("oops.  Bug in color re-calculation code.  color of %u.", 
color);
!             color = (newMaxVal - color);      /* note greyscale maps are inverted */
            } else {
              temp_color = ((((PPM_GETR(*pP) * newMaxVal)/maxval) << 16) |
                            (((PPM_GETG(*pP) * newMaxVal)/maxval) << 8) |
--- 255,285 ----
      for ( row = 0; row < rows; ++row ) {
          memset(rowdata, 0, rowbytes);
        outbyte = 0x00;
! 
!       if (directColor) {
!         for (col = 0, pP = pixels[row], outptr = rowdata; col < cols; ++col, ++pP ) {
!           if (bpp == 16) {
!             color = ((((PPM_GETR(*pP) * 31)/maxval) << 11) |
!                      (((PPM_GETG(*pP) * 63)/maxval) << 5) |
!                      ((PPM_GETB(*pP) * 31)/maxval));
!             /*
!             if (verbose)
!               pm_message("Color %d/%d/%d => 0x%04x", PPM_GETR(*pP), PPM_GETG(*pP), 
PPM_GETB(*pP), color);
!               */
!             *outptr++ = (color >> 8) & 0xFF;
!             *outptr++ = color & 0xFF;
!           }
!         }
!       } else {
!         /* outbit is the lowest bit number we want to access for this pixel */
!         for ( outbit = 8 - bpp, col = 0, pP = pixels[row], outptr = rowdata; col < 
cols; ++col, ++pP ) {
  
            if (colormap == 0) {
              /* we assume grayscale, and use simple scaling */
              color = (PNM_GET1(*pP) * newMaxVal)/maxval;
              if (color > newMaxVal)
                pm_error("oops.  Bug in color re-calculation code.  color of %u.", 
color);
!             color = (newMaxVal - color); /* note greyscale maps are inverted */
            } else {
              temp_color = ((((PPM_GETR(*pP) * newMaxVal)/maxval) << 16) |
                            (((PPM_GETG(*pP) * newMaxVal)/maxval) << 8) |
***************
*** 267,278 ****
            } else {
              outbit -= bpp;
            }
!       }
!       if ((cols % (8 / bpp)) != 0) {
!         /* Handle case of partial byte */
!         *outptr++ = outbyte;
        }
- 
        /* now output the row of pixels, compressed appropriately */
  
        if (scanline_compression) {
--- 318,329 ----
            } else {
              outbit -= bpp;
            }
!         }
!         if ((cols % (8 / bpp)) != 0) {
!           /* Handle case of partial byte */
!           *outptr++ = outbyte;
!         }
        }
        /* now output the row of pixels, compressed appropriately */
  
        if (scanline_compression) {

Reply via email to