about summary refs log tree commit diff
path: root/converter/ppm
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-12-28 19:53:34 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-12-28 19:53:34 +0000
commit5d16663331afd0bc2edaeb2e49042dc219ce9c2f (patch)
tree476fbb2ab4311d4bb6d65b250825e254a7a2c1ef /converter/ppm
parent42f0bf8e7f1ff88000a3584c265e6f1631662ec4 (diff)
downloadnetpbm-mirror-5d16663331afd0bc2edaeb2e49042dc219ce9c2f.tar.gz
netpbm-mirror-5d16663331afd0bc2edaeb2e49042dc219ce9c2f.tar.xz
netpbm-mirror-5d16663331afd0bc2edaeb2e49042dc219ce9c2f.zip
promote Development to Advanced
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@4827 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/ppm')
-rw-r--r--converter/ppm/411toppm.c6
-rw-r--r--converter/ppm/autocad.h2
-rw-r--r--converter/ppm/eyuvtoppm.c41
-rw-r--r--converter/ppm/gouldtoppm.c149
-rw-r--r--converter/ppm/ilbmtoppm.c11
-rw-r--r--converter/ppm/leaftoppm.c53
-rw-r--r--converter/ppm/mitsu.h27
-rw-r--r--converter/ppm/mtvtoppm.c33
-rw-r--r--converter/ppm/neotoppm.c5
-rw-r--r--converter/ppm/pc1toppm.c23
-rw-r--r--converter/ppm/pi1toppm.c3
-rw-r--r--converter/ppm/picttoppm.c7
-rw-r--r--converter/ppm/ppmtoacad.c23
-rw-r--r--converter/ppm/ppmtoapplevol.c3
-rw-r--r--converter/ppm/ppmtoarbtxt.c59
-rw-r--r--converter/ppm/ppmtoascii.c9
-rw-r--r--converter/ppm/ppmtobmp.c1
-rw-r--r--converter/ppm/ppmtoeyuv.c16
-rw-r--r--converter/ppm/ppmtoicr.c2
-rw-r--r--converter/ppm/ppmtoilbm.c3
-rw-r--r--converter/ppm/ppmtoleaf.c70
-rw-r--r--converter/ppm/ppmtomitsu.c175
-rw-r--r--converter/ppm/ppmtompeg/bframe.c6
-rw-r--r--converter/ppm/ppmtompeg/bitio.c7
-rw-r--r--converter/ppm/ppmtompeg/block.c9
-rw-r--r--converter/ppm/ppmtompeg/bsearch.c7
-rw-r--r--converter/ppm/ppmtompeg/file.c3
-rw-r--r--converter/ppm/ppmtompeg/frame.c3
-rw-r--r--converter/ppm/ppmtompeg/frametype.c1
-rw-r--r--converter/ppm/ppmtompeg/fsize.c4
-rw-r--r--converter/ppm/ppmtompeg/gethostname.c3
-rw-r--r--converter/ppm/ppmtompeg/gethostname_win32.c6
-rw-r--r--converter/ppm/ppmtompeg/headers/frames.h3
-rw-r--r--converter/ppm/ppmtompeg/iframe.c3
-rw-r--r--converter/ppm/ppmtompeg/input.c1
-rw-r--r--converter/ppm/ppmtompeg/jpeg.c1
-rw-r--r--converter/ppm/ppmtompeg/jrevdct.c6
-rw-r--r--converter/ppm/ppmtompeg/memory.c7
-rw-r--r--converter/ppm/ppmtompeg/mfwddct.c3
-rw-r--r--converter/ppm/ppmtompeg/mheaders.c15
-rw-r--r--converter/ppm/ppmtompeg/moutput.c5
-rw-r--r--converter/ppm/ppmtompeg/mpeg.c5
-rw-r--r--converter/ppm/ppmtompeg/mquant.c3
-rw-r--r--converter/ppm/ppmtompeg/nojpeg.c4
-rw-r--r--converter/ppm/ppmtompeg/noparallel.c4
-rw-r--r--converter/ppm/ppmtompeg/opts.c14
-rw-r--r--converter/ppm/ppmtompeg/parallel.c12
-rw-r--r--converter/ppm/ppmtompeg/param.c2
-rw-r--r--converter/ppm/ppmtompeg/pframe.c9
-rw-r--r--converter/ppm/ppmtompeg/postdct.c6
-rw-r--r--converter/ppm/ppmtompeg/ppmtompeg.c5
-rw-r--r--converter/ppm/ppmtompeg/psearch.c9
-rw-r--r--converter/ppm/ppmtompeg/qtest.c3
-rw-r--r--converter/ppm/ppmtompeg/rate.c12
-rw-r--r--converter/ppm/ppmtompeg/readframe.c10
-rw-r--r--converter/ppm/ppmtompeg/rgbtoycc.c4
-rw-r--r--converter/ppm/ppmtompeg/specifics.c14
-rw-r--r--converter/ppm/ppmtompeg/subsample.c5
-rw-r--r--converter/ppm/ppmtoneo.c3
-rw-r--r--converter/ppm/ppmtopi1.c3
-rw-r--r--converter/ppm/ppmtopict.c220
-rw-r--r--converter/ppm/ppmtopj.c480
-rw-r--r--converter/ppm/ppmtopjxl.c552
-rw-r--r--converter/ppm/ppmtoppm.c5
-rw-r--r--converter/ppm/ppmtopuzz.c67
-rw-r--r--converter/ppm/ppmtospu.c22
-rw-r--r--converter/ppm/ppmtoterm.c19
-rw-r--r--converter/ppm/ppmtowinicon.c1076
-rw-r--r--converter/ppm/ppmtoxpm.c340
-rw-r--r--converter/ppm/ppmtoyuv.c9
-rw-r--r--converter/ppm/ppmtoyuvsplit.c3
-rw-r--r--converter/ppm/qrttoppm.c104
-rw-r--r--converter/ppm/rawtoppm.c5
-rw-r--r--converter/ppm/rgb3toppm.c41
-rw-r--r--converter/ppm/sldtoppm.c289
-rw-r--r--converter/ppm/spctoppm.c155
-rw-r--r--converter/ppm/tgatoppm.c1
-rw-r--r--converter/ppm/vidtoppm.c65
-rw-r--r--converter/ppm/winico.h20
-rw-r--r--converter/ppm/winicontoppm.c98
-rw-r--r--converter/ppm/ximtoppm.c400
-rw-r--r--converter/ppm/yuvsplittoppm.c31
-rw-r--r--converter/ppm/yuvtoppm.c9
83 files changed, 2816 insertions, 2136 deletions
diff --git a/converter/ppm/411toppm.c b/converter/ppm/411toppm.c
index eb2372a5..a50e5145 100644
--- a/converter/ppm/411toppm.c
+++ b/converter/ppm/411toppm.c
@@ -105,7 +105,7 @@ parseCommandLine(int argc, const char ** argv,
     opt.opt_table = option_def;
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
     opt.allowNegNum = FALSE;  /* We have no parms that are negative numbers */
-    
+
     pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0);
         /* Uses and sets argc, argv, and some of *cmdlineP and others. */
 
@@ -182,7 +182,7 @@ YUVtoPPM(FILE  * const ifP,
         r = CHOP((int)(tempR >> 16));
         g = CHOP((int)(tempG >> 16));
         b = CHOP((int)(tempB >> 16));
-        
+
         PPM_ASSIGN(pixrow[col], r, g, b);
     }
 }
@@ -225,6 +225,8 @@ main(int argc, const char **argv) {
     return 0;
 }
 
+
+
 /*
    By default a .411 file is width=64, height=48, 4608 bytes.
    There is no header.
diff --git a/converter/ppm/autocad.h b/converter/ppm/autocad.h
index 3005782b..ef82cf6f 100644
--- a/converter/ppm/autocad.h
+++ b/converter/ppm/autocad.h
@@ -56,7 +56,7 @@ static unsigned char acadcol[256][3] = {
     {76, 38, 66}, {38, 0, 28}, {38, 19, 33}, {255, 0, 127}, {255, 127, 191},
     {165, 0, 82}, {165, 82, 124}, {127, 0, 63}, {127, 63, 95}, {76, 0, 38},
     {76, 38, 57}, {38, 0, 19}, {38, 19, 28}, {255, 0, 63}, {255, 127, 159},
-    {165, 0, 41}, {165, 82, 103}, {127, 0, 31}, {127, 63, 79},	{76, 0, 19},
+    {165, 0, 41}, {165, 82, 103}, {127, 0, 31}, {127, 63, 79},  {76, 0, 19},
     {76, 38, 47}, {38, 0, 9}, {38, 19, 23}, {84, 84, 84}, {118, 118, 118},
     {152, 152, 152}, {186, 186, 186}, {220, 220, 220}, {255, 255, 255}
 };
diff --git a/converter/ppm/eyuvtoppm.c b/converter/ppm/eyuvtoppm.c
index 910a125b..3ec29268 100644
--- a/converter/ppm/eyuvtoppm.c
+++ b/converter/ppm/eyuvtoppm.c
@@ -1,6 +1,6 @@
 /* Bryan got this from mm.ftp-cs.berkeley.edu from the package
-   mpeg-encode-1.5b-src under the name eyuvtoppm.c on March 30, 2000.  
-   The file was dated April 14, 1995.  
+   mpeg-encode-1.5b-src under the name eyuvtoppm.c on March 30, 2000.
+   The file was dated April 14, 1995.
 
    Bryan rewrote the program entirely to match Netpbm coding style,
    use the Netpbm libraries and also to output to stdout and ignore
@@ -70,7 +70,7 @@ parseCommandLine(int argc, char ** argv,
     option_def_index = 0;   /* incremented by OPTENT3 */
     OPTENT3('w', "width",     OPT_UINT,  &cmdlineP->width,   NULL,         0);
     OPTENT3('h', "height",    OPT_UINT,  &cmdlineP->height,  NULL,         0);
-    
+
     /* DEFAULTS */
     cmdlineP->width = 352;
     cmdlineP->height = 240;
@@ -93,7 +93,7 @@ parseCommandLine(int argc, char ** argv,
                  "You specified %u.", cmdlineP->height);
 
 
-    if (argc-1 == 0) 
+    if (argc-1 == 0)
         cmdlineP->inputFileName = "-";
     else if (argc-1 != 1)
         pm_error("Program takes zero or one argument (filename).  You "
@@ -106,7 +106,7 @@ parseCommandLine(int argc, char ** argv,
 
 
 
-static uint8 ** 
+static uint8 **
 allocUint8Array(unsigned int const cols,
                 unsigned int const rows) {
 
@@ -129,7 +129,7 @@ allocUint8Array(unsigned int const cols,
 
 
 
-static void 
+static void
 freeUint8Array(uint8 **     const array,
                unsigned int const rows) {
 
@@ -162,28 +162,28 @@ freeStorage(unsigned int const rows,
             uint8 **     const orig_y,
             uint8 **     const orig_cb,
             uint8 **     const orig_cr) {
-    
-    freeUint8Array(orig_y,  rows); 
-    freeUint8Array(orig_cb, rows); 
+
+    freeUint8Array(orig_y,  rows);
+    freeUint8Array(orig_cb, rows);
     freeUint8Array(orig_cr, rows);
 
 }
 
 
 
-static void 
+static void
 YUVtoPPM(FILE *       const ofP,
          unsigned int const cols,
          unsigned int const rows,
          uint8 **     const orig_y,
          uint8 **     const orig_cb,
-         uint8 **     const orig_cr) { 
+         uint8 **     const orig_cr) {
 /*----------------------------------------------------------------------------
    Convert the YUV image in arrays orig_y[][], orig_cb[][], and orig_cr[][]
    to a PPM image and write it to file *ofP.
 -----------------------------------------------------------------------------*/
     pixel * const pixrow = ppm_allocrow(cols);
-    
+
     unsigned int row;
 
     ppm_writeppminit(ofP, cols, rows, 255, FALSE);
@@ -202,11 +202,11 @@ YUVtoPPM(FILE *       const ofP,
             tempR = 104635*v + 76310*y;
             tempG = -25690*u + -53294*v + 76310*y;
             tempB = 132278*u + 76310*y;
-            
+
             r = CHOP((int)(tempR >> 16));
             g = CHOP((int)(tempG >> 16));
             b = CHOP((int)(tempB >> 16));
-            
+
             PPM_ASSIGN(pixrow[col], r, g, b);
         }
         ppm_writeppmrow(stdout, pixrow, cols, 255, FALSE);
@@ -216,12 +216,12 @@ YUVtoPPM(FILE *       const ofP,
 
 
 
-static void 
+static void
 ReadYUV(FILE *       const ifP,
         unsigned int const cols,
         unsigned int const rows,
-        uint8 **     const orig_y, 
-        uint8 **     const orig_cb, 
+        uint8 **     const orig_y,
+        uint8 **     const orig_cb,
         uint8 **     const orig_cr,
         bool *       const eofP) {
 
@@ -240,7 +240,7 @@ ReadYUV(FILE *       const ifP,
         if (bytesRead != cols)
             eof = true;
     }
-        
+
     for (row = 0; row < rows / 2 && !eof; ++row) {  /* U */
         size_t bytesRead;
 
@@ -249,7 +249,7 @@ ReadYUV(FILE *       const ifP,
         if (bytesRead != cols / 2)
             eof = true;
     }
-        
+
     for (row = 0; row < rows / 2 && !eof; ++row) { /* V */
         size_t bytesRead;
 
@@ -297,7 +297,7 @@ main(int argc, const char **argv) {
 
     for (frameSeq = 0, eof = false; !eof; ++frameSeq) {
 
-        ReadYUV(ifP, cmdline.width, cmdline.height, 
+        ReadYUV(ifP, cmdline.width, cmdline.height,
                 orig_y, orig_cb, orig_cr, &eof);
 
         if (!eof) {
@@ -317,3 +317,4 @@ main(int argc, const char **argv) {
 }
 
 
+
diff --git a/converter/ppm/gouldtoppm.c b/converter/ppm/gouldtoppm.c
index 5db7c51a..6cc7726c 100644
--- a/converter/ppm/gouldtoppm.c
+++ b/converter/ppm/gouldtoppm.c
@@ -22,101 +22,106 @@ main( argc, argv )
 int argc;
 char *argv[];
 {
-	FILE *ifp;
-	pixel *pixrow;
+        FILE *ifp;
+        pixel *pixrow;
 
-	unsigned long cols, nlines, bytesperline, bitsperpixel, NB, x, y;
-	unsigned char pbuffer[4];
+        unsigned long cols, nlines, bytesperline, bitsperpixel, NB, x, y;
+        unsigned char pbuffer[4];
 
-	int color_type;
+        int color_type;
 
 
-	ppm_init( &argc, argv );
+        ppm_init( &argc, argv );
 
-	if ( argc > 2 )
-		pm_usage( "[gouldfile]" );
+        if ( argc > 2 )
+                pm_usage( "[gouldfile]" );
 
-	if ( argc == 2 )
-		ifp = pm_openr( argv[1] );
-	else
-		ifp = stdin;
+        if ( argc == 2 )
+                ifp = pm_openr( argv[1] );
+        else
+                ifp = stdin;
 
-	getgouldheader( ifp, &cols, &nlines, &bytesperline, &bitsperpixel, &NB);
+        getgouldheader( ifp, &cols, &nlines, &bytesperline, &bitsperpixel, &NB);
 
-	ppm_writeppminit(stdout, cols, nlines, MAXVAL, 0);
+        ppm_writeppminit(stdout, cols, nlines, MAXVAL, 0);
 
-	color_type = bitsperpixel/8;
-	if (color_type == 0) color_type = NB;
+        color_type = bitsperpixel/8;
+        if (color_type == 0) color_type = NB;
 
-	pixrow = ppm_allocrow(cols);
+        pixrow = ppm_allocrow(cols);
 
-	for (y = 0; y < nlines; ++y)
-	{
-		for (x = 0; x < cols; ++x)
-		{
-			switch (color_type)
-			{
-			case 0:
-				pm_error("incorrect color type" );
+        for (y = 0; y < nlines; ++y)
+        {
+                for (x = 0; x < cols; ++x)
+                {
+                        switch (color_type)
+                        {
+                        case 0:
+                                pm_error("incorrect color type" );
 
-			case 1:
-				fread(pbuffer, 1, 1, ifp);
-				PPM_ASSIGN( pixrow[x], pbuffer[0], pbuffer[0], pbuffer[0]);
-				break;
+                        case 1:
+                                fread(pbuffer, 1, 1, ifp);
+                                PPM_ASSIGN( pixrow[x], pbuffer[0], pbuffer[0], pbuffer[0]);
+                                break;
 
-			case 2:
-				fread(pbuffer, 2, 1, ifp);
-				PPM_ASSIGN( pixrow[x], pbuffer[0], pbuffer[1], pbuffer[1]);
-				break;
+                        case 2:
+                                fread(pbuffer, 2, 1, ifp);
+                                PPM_ASSIGN( pixrow[x], pbuffer[0], pbuffer[1], pbuffer[1]);
+                                break;
 
-			case 3:
-				fread(pbuffer, 3, 1, ifp);
-				PPM_ASSIGN( pixrow[x], pbuffer[0], pbuffer[1], pbuffer[2]);
-				break;
+                        case 3:
+                                fread(pbuffer, 3, 1, ifp);
+                                PPM_ASSIGN( pixrow[x], pbuffer[0], pbuffer[1], pbuffer[2]);
+                                break;
 
-			default :
-				fread(pbuffer, 3, 1, ifp);
-				PPM_ASSIGN( pixrow[x], pbuffer[0], pbuffer[1], pbuffer[2]);
-				break;
+                        default :
+                                fread(pbuffer, 3, 1, ifp);
+                                PPM_ASSIGN( pixrow[x], pbuffer[0], pbuffer[1], pbuffer[2]);
+                                break;
 
-			} /* switch */
-		}
-		ppm_writeppmrow(stdout, pixrow, cols, MAXVAL, 0);
-	}
+                        } /* switch */
+                }
+                ppm_writeppmrow(stdout, pixrow, cols, MAXVAL, 0);
+        }
 
-	pm_close(ifp);
-	pm_close(stdout);
+        pm_close(ifp);
+        pm_close(stdout);
 
-	exit(0);
+        exit(0);
 }
 
+
+
 static void
 getgouldheader( infile, cols, nlines, bytesperline, bitsperpixel, NB)
 FILE *infile;
 unsigned long *cols, *nlines, *bytesperline, *bitsperpixel, *NB;
 {
-	unsigned long nlines_new, bytesperline_new, numheaderrec;
-	unsigned char headerblk[512];
-	int i;
-
-	if (fread(headerblk, 512, 1, infile) == 0)
-		pm_error("cannot read gould header" );
-
-	*nlines       = (headerblk[3]<<8) | headerblk[2];
-	*bytesperline = (headerblk[5]<<8) | headerblk[4];
-	*bitsperpixel = (headerblk[7]<<8) | headerblk[6];
-	numheaderrec  = (headerblk[9]<<8) | headerblk[8];
-	nlines_new    = (headerblk[15]<<24)| (headerblk[14]<<16) | (headerblk[13]<<8) | (headerblk[12]);
-	bytesperline_new = (headerblk[19]<<24)| (headerblk[18]<<16) | (headerblk[17]<<8) | (headerblk[16]);
-	*NB           = (headerblk[23]<<24)| (headerblk[22]<<16) | (headerblk[21]<<8) | (headerblk[20]);
-
-	if (numheaderrec > 1)
-		for (i = 1 ; i <numheaderrec; ++i)
-			if (fread(headerblk, 512, 1, infile) == 0)
-				pm_error("cannot read gould header(2nd)" );
-
-	if (*nlines==0) *nlines=nlines_new;
-	if (*bytesperline==0) *bytesperline=bytesperline_new;
-
-	*cols = (*bytesperline)*8 / (*bitsperpixel);
+        unsigned long nlines_new, bytesperline_new, numheaderrec;
+        unsigned char headerblk[512];
+        int i;
+
+        if (fread(headerblk, 512, 1, infile) == 0)
+                pm_error("cannot read gould header" );
+
+        *nlines       = (headerblk[3]<<8) | headerblk[2];
+        *bytesperline = (headerblk[5]<<8) | headerblk[4];
+        *bitsperpixel = (headerblk[7]<<8) | headerblk[6];
+        numheaderrec  = (headerblk[9]<<8) | headerblk[8];
+        nlines_new    = (headerblk[15]<<24)| (headerblk[14]<<16) | (headerblk[13]<<8) | (headerblk[12]);
+        bytesperline_new = (headerblk[19]<<24)| (headerblk[18]<<16) | (headerblk[17]<<8) | (headerblk[16]);
+        *NB           = (headerblk[23]<<24)| (headerblk[22]<<16) | (headerblk[21]<<8) | (headerblk[20]);
+
+        if (numheaderrec > 1)
+                for (i = 1 ; i <numheaderrec; ++i)
+                        if (fread(headerblk, 512, 1, infile) == 0)
+                                pm_error("cannot read gould header(2nd)" );
+
+        if (*nlines==0) *nlines=nlines_new;
+        if (*bytesperline==0) *bytesperline=bytesperline_new;
+
+        *cols = (*bytesperline)*8 / (*bitsperpixel);
 }
+
+
+
diff --git a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c
index 1b66c0b3..8a8cf9f3 100644
--- a/converter/ppm/ilbmtoppm.c
+++ b/converter/ppm/ilbmtoppm.c
@@ -112,6 +112,7 @@ ID2string(IFF_ID const id) {
 }
 
 
+
 /****************************************************************************
  Memory allocation
  ****************************************************************************/
@@ -154,6 +155,7 @@ alloc_rawrow(unsigned int const cols) {
 }
 
 
+
 /****************************************************************************
  Basic I/O functions
  ****************************************************************************/
@@ -207,6 +209,8 @@ get_byte(FILE *          const ifP,
     return (unsigned char) i;
 }
 
+
+
 static long
 get_big_long(FILE *          const ifP,
              IFF_ID          const iffid,
@@ -540,6 +544,7 @@ read_bmhd(FILE *        const ifP,
 }
 
 
+
 /****************************************************************************
  ILBM functions
  ****************************************************************************/
@@ -594,6 +599,7 @@ read_ilbm_plane(FILE *          const ifP,
 }
 
 
+
 static const unsigned char bit_mask[] = {1, 2, 4, 8, 16, 32, 64, 128};
 
 static void
@@ -637,6 +643,7 @@ decodeRow(FILE *          const ifP,
 }
 
 
+
 static void
 decodeMask(FILE *          const ifP,
            unsigned long * const remainingChunksizeP,
@@ -699,6 +706,7 @@ decodeMask(FILE *          const ifP,
 }
 
 
+
 /****************************************************************************
  Multipalette handling
  ****************************************************************************/
@@ -1609,6 +1617,8 @@ rgbn_to_ppm(FILE *         const ifP,
     chunk_end(ifP, ID_BODY, remainingChunksize);
 }
 
+
+
 /****************************************************************************
  Multipalette chunk reader
 
@@ -1782,6 +1792,7 @@ PCHG_Decompress(PCHGHeader *     const PCHG,
 }
 
 
+
 static void
 PCHG_ConvertSmall(PCHGHeader *    const pchgP,
                   ColorMap *      const cmapP,
diff --git a/converter/ppm/leaftoppm.c b/converter/ppm/leaftoppm.c
index 61c19c1e..0dcc1255 100644
--- a/converter/ppm/leaftoppm.c
+++ b/converter/ppm/leaftoppm.c
@@ -10,7 +10,7 @@
  * implied warranty.
  *
  * known problems: doesn't do compressed ileaf images.
- * 
+ *
  */
 
 #include <stdio.h>
@@ -20,11 +20,11 @@
 #define LEAF_MAXVAL 255
 
 static void
-leaf_init(FILE *  const fp, 
+leaf_init(FILE *  const fp,
           int *   const colsP,
-          int *   const rowsP, 
-          int *   const depthP, 
-          int *   const ncolorsP, 
+          int *   const rowsP,
+          int *   const depthP,
+          int *   const ncolorsP,
           pixel * const colors) {
 
     unsigned char buf[256];
@@ -34,41 +34,41 @@ leaf_init(FILE *  const fp,
     short rows;
     short depth;
     long magic;
-    
+
     pm_readbiglong(fp, &magic);
     if ((uint32_t)magic != 0x894f5053)
         pm_error("Bad magic number.  First 4 bytes should be "
                  "0x894f5053 but are instead 0x%08x", (unsigned)magic);
-    
+
     /* version =   2 bytes
-       hres =      2 
+       hres =      2
        vres =      2
        unique id = 4
        offset x =  2
        offset y =  2
-       TOTAL    =  14 bytes 
+       TOTAL    =  14 bytes
     */
-    
+
     pm_readbigshort(fp, &version);
 
     if (fread(buf, 1, 12, fp) != 12)
         pm_error("bad header, short file?");
-    
+
     pm_readbigshort(fp, &cols);
     *colsP = cols;
     pm_readbigshort(fp, &rows);
     *rowsP = rows;
     pm_readbigshort(fp, &depth);
     *depthP = depth;
-    
+
     if ((compressed = fgetc(fp)) != 0)
         pm_error("Can't do compressed images.");
 
     if ((*depthP == 1) && (version < 4)) {
-        fgetc(fp); 
+        fgetc(fp);
         *ncolorsP = 0;
     } else if ((*depthP == 8) && (version < 4)) {
-        fgetc(fp); 
+        fgetc(fp);
         *ncolorsP = 0;
     } else {
         long format;
@@ -121,19 +121,19 @@ main(int argc, char * argv[]) {
     pixel colormap[MAXCOLORS];
     int rows, cols, row, col, depth, ncolors;
 
-    
+
     ppm_init(&argc, argv);
-    
+
     if (argc-1 > 1)
         pm_error("Too many arguments.  Only argument is ileaf file name");
-    
+
     if (argc-1 == 1)
         ifd = pm_openr(argv[1]);
     else
         ifd = stdin;
-    
+
     leaf_init(ifd, &cols, &rows, &depth, &ncolors, colormap);
-    
+
     if ((depth == 8) && (ncolors == 0)) {
         /* gray image */
         gray * grayrow;
@@ -177,7 +177,7 @@ main(int argc, char * argv[]) {
 
         ppm_writeppminit(stdout, cols, rows, (pixval) maxval, 0);
         pixrow = ppm_allocrow( cols );
-    
+
         for (row = 0; row < rows; ++row) {
             for (col = 0; col < cols; ++col)
                 pixrow[col] = colormap[fgetc(ifd)];
@@ -190,18 +190,18 @@ main(int argc, char * argv[]) {
         /* mono image */
         bit *bitrow;
         unsigned int row;
-        
+
         pbm_writepbminit(stdout, cols, rows, 0);
         bitrow = pbm_allocrow(cols);
-    
+
         for (row = 0; row < rows; ++row) {
             unsigned char bits;
             bits = 0x00;  /* initial value */
             for (col = 0; col < cols; ++col) {
                 int const shift = col % 8;
-                if (shift == 0) 
+                if (shift == 0)
                     bits = (unsigned char) fgetc(ifd);
-                bitrow[col] = (bits & (unsigned char)(0x01 << (7 - shift))) ? 
+                bitrow[col] = (bits & (unsigned char)(0x01 << (7 - shift))) ?
                     PBM_WHITE : PBM_BLACK;
             }
             if ((cols % 16) && (cols % 16) <= 8)
@@ -211,6 +211,9 @@ main(int argc, char * argv[]) {
         pbm_freerow(bitrow);
     }
     pm_close(ifd);
-    
+
     return 0;
 }
+
+
+
diff --git a/converter/ppm/mitsu.h b/converter/ppm/mitsu.h
index bca4fbdf..b0ae9aa5 100644
--- a/converter/ppm/mitsu.h
+++ b/converter/ppm/mitsu.h
@@ -10,19 +10,30 @@
 #define A_MAXROWS   1350
 #define AS_MAXROWS  1650
 
+/* To use the macros in this file that generate Mitsu output, define a
+   function named 'cmd' that outputs a character.  Like this:
+
+    static void
+    cmd(char const arg) {
+
+        fputc(arg, stdout);
+    }
+*/
+
 #define ONLINE         cmd('\021')
 #define CLRMEM         cmd('\033'), cmd('Z')
 
-struct mediasize {
-        char size;
-        int  maxcols, maxrows;
+struct Mediasize {
+    char         size;
+    unsigned int maxcols;
+    unsigned int maxrows;
 };
 
-const struct mediasize MSize_User={' ',1184,1350};
-const struct mediasize MSize_A4  ={'0',1184,1452};
-const struct mediasize MSize_A   ={'1',1216,1350};
-const struct mediasize MSize_A4S ={'2',1184,1754};
-const struct mediasize MSize_AS  ={'3',1216,1650};
+static struct Mediasize const MSize_User={' ',1184,1350};
+static struct Mediasize const MSize_A4  ={'0',1184,1452};
+static struct Mediasize const MSize_A   ={'1',1216,1350};
+static struct Mediasize const MSize_A4S ={'2',1184,1754};
+static struct Mediasize const MSize_AS  ={'3',1216,1650};
 #define MEDIASIZE(chr) cmd('\033'), cmd('#'), cmd('P'), cmd((chr).size)
 
 #define HENLARGE(enl)  cmd('\033'), cmd('&'), cmd('P'), cmd(enl), cmd('\001')
diff --git a/converter/ppm/mtvtoppm.c b/converter/ppm/mtvtoppm.c
index e8558632..42f99428 100644
--- a/converter/ppm/mtvtoppm.c
+++ b/converter/ppm/mtvtoppm.c
@@ -30,39 +30,42 @@ main( argc, argv )
     ppm_init( &argc, argv );
 
     if ( argc > 2 )
-	pm_usage( "[mtvfile]" );
+        pm_usage( "[mtvfile]" );
 
     if ( argc == 2 )
-	ifp = pm_openr( argv[1] );
+        ifp = pm_openr( argv[1] );
     else
-	ifp = stdin;
+        ifp = stdin;
 
     /* Read in the MTV file.  First the header. */
     if ( fgets( line, MAXLINE, ifp ) == NULL )
-	pm_error( "unable to read MTV file header" );
+        pm_error( "unable to read MTV file header" );
     if ( sscanf( line, "%d%d", &cols, &rows ) != 2 )
-	pm_error( "unable to parse MTV file header" );
+        pm_error( "unable to parse MTV file header" );
 
     if ( cols <= 0 || rows <= 0 )
-	pm_error( "invalid size: %d %d", cols, rows );
+        pm_error( "invalid size: %d %d", cols, rows );
     maxval = 255;
 
     ppm_writeppminit( stdout, cols, rows, maxval, 0 );
     pixelrow = ppm_allocrow( cols );
 
     for ( row = 0; row < rows; row++ )
-	{
-	for ( col = 0, pP = pixelrow; col < cols; col++, pP++ )
-	    {
-	    if ( fread( buf, sizeof(buf), 1, ifp ) != 1 )
-		pm_error( "EOF / read error" );
-	    PPM_ASSIGN( *pP, buf[0], buf[1], buf[2] );
-	    }
-	ppm_writeppmrow( stdout, pixelrow, cols, maxval, 0 );
-	}
+        {
+        for ( col = 0, pP = pixelrow; col < cols; col++, pP++ )
+            {
+            if ( fread( buf, sizeof(buf), 1, ifp ) != 1 )
+                pm_error( "EOF / read error" );
+            PPM_ASSIGN( *pP, buf[0], buf[1], buf[2] );
+            }
+        ppm_writeppmrow( stdout, pixelrow, cols, maxval, 0 );
+        }
 
     pm_close( ifp );
     pm_close( stdout );
 
     exit( 0 );
     }
+
+
+
diff --git a/converter/ppm/neotoppm.c b/converter/ppm/neotoppm.c
index d8cf2918..6ce5ef43 100644
--- a/converter/ppm/neotoppm.c
+++ b/converter/ppm/neotoppm.c
@@ -57,7 +57,7 @@ main( int argc, char * argv[] ) {
         /* Read the palette. */
         for ( i = 0; i < 16; ++i ) {
             short j;
-            
+
             pm_readbigshort (ifp, &j);
             PPM_ASSIGN( pal[i],
                         ( j & 0x700 ) >> 8,
@@ -102,3 +102,6 @@ main( int argc, char * argv[] ) {
 
     exit( 0 );
 }
+
+
+
diff --git a/converter/ppm/pc1toppm.c b/converter/ppm/pc1toppm.c
index ec6678a4..45d09faa 100644
--- a/converter/ppm/pc1toppm.c
+++ b/converter/ppm/pc1toppm.c
@@ -13,7 +13,7 @@
  documentation.  This software is provided "as is" without express or
  implied warranty.
 
- Algorithm for PC1 compression from "gimp-degas" GIMP plugin 
+ Algorithm for PC1 compression from "gimp-degas" GIMP plugin
  by Markus F.X.J. Oberhumer
 
 */
@@ -39,7 +39,7 @@ unsigned int const colsPerBlock = 16;
 
 
 static void
-readPalette(FILE *   const ifP, 
+readPalette(FILE *   const ifP,
             pixel (* const palP)[]) {
 
     /* Read the palette. */
@@ -78,7 +78,7 @@ processStretch(unsigned int     const countbyte,
         }
     } else {
         /* next byte repeated 257-countbyte times */
-                
+
         unsigned char const duplicated_color = getc(ifP);
         unsigned int  const count = 257 - countbyte;
         unsigned int i;
@@ -121,8 +121,8 @@ readPc1(FILE * const ifP,
             unsigned int const countbyte = getc(ifP);
 
             processStretch(countbyte, ifP, &col, &bufferCursor);
-	    }
-	}
+            }
+        }
 }
 
 
@@ -130,7 +130,7 @@ readPc1(FILE * const ifP,
 static void
 reInterleave(unsigned char     const buffer[],
              unsigned short (* const screenP)[]) {
-    
+
     /* The buffer is in one plane for each line, to optimize packing */
     /* Re-interleave to match the Atari screen layout                */
 
@@ -142,10 +142,10 @@ reInterleave(unsigned char     const buffer[],
         for (block = 0; block < BLOCKS; ++block) {
             unsigned int plane;
             for (plane = 0; plane < planes; ++plane) {
-                unsigned int const blockIndex = 
+                unsigned int const blockIndex =
                     row*ROWBYTES + plane*PLANEBYTES + block*BLOCKBYTES;
 
-                screen[row*ROWSHORTS + block*BLOCKSHORTS + plane] = 
+                screen[row*ROWSHORTS + block*BLOCKSHORTS + plane] =
                     (buffer[blockIndex+0] << 8) + (buffer[blockIndex+1]);
             }
         }
@@ -202,9 +202,9 @@ main(int argc, char ** argv) {
     const char * inputFilename;
     FILE* ifP;
     pixel palette[16];  /* Degas palette */
-    static unsigned short screen[32000/2];   
+    static unsigned short screen[32000/2];
         /* simulates the Atari's video RAM */
-    static unsigned char buffer[32000];   
+    static unsigned char buffer[32000];
         /* simulates the Atari's video RAM */
 
     ppm_init(&argc, argv);
@@ -231,3 +231,6 @@ main(int argc, char ** argv) {
 
     return 0;
 }
+
+
+
diff --git a/converter/ppm/pi1toppm.c b/converter/ppm/pi1toppm.c
index 69b99863..9a07f535 100644
--- a/converter/ppm/pi1toppm.c
+++ b/converter/ppm/pi1toppm.c
@@ -90,3 +90,6 @@ main( argc, argv )
 
     exit( 0 );
     }
+
+
+
diff --git a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c
index ec701cfc..8ca553bd 100644
--- a/converter/ppm/picttoppm.c
+++ b/converter/ppm/picttoppm.c
@@ -339,6 +339,7 @@ allocateRaster(struct Raster * const rasterP,
 }
 
 
+
 static void
 freeRaster(struct Raster const raster) {
 
@@ -346,6 +347,7 @@ freeRaster(struct Raster const raster) {
 }
 
 
+
 struct BlitInfo {
     struct Rect       srcRect;
     struct Rect       srcBounds;
@@ -763,6 +765,7 @@ skipPolyOrRegion(FILE *          const ifP,
 }
 
 
+
 #define NA (0)
 
 #define FNT_BOLD    (1)
@@ -969,6 +972,7 @@ rectequal(const struct Rect * const comparand,
 }
 
 
+
 static int
 rectheight(const struct Rect * const r) {
 
@@ -2719,6 +2723,7 @@ interpretCompressedLine(unsigned char * const linebuf,
 }
 
 
+
 /* There is some confusion about when, in PICT, a line length is one byte and
   when it is two.  An Apple document says it is two bytes when the number of
   pixels in the row, padded, is > 250.  Ppmtopict generated PICTs that way
@@ -3194,6 +3199,8 @@ drawPen(struct Canvas * const canvasP,
     drawPenRect(canvasP, &clippedPenrect);
 }
 
+
+
 /*
  * Digital Line Drawing
  * by Paul Heckbert
diff --git a/converter/ppm/ppmtoacad.c b/converter/ppm/ppmtoacad.c
index b5ee4d65..4f4dc5dd 100644
--- a/converter/ppm/ppmtoacad.c
+++ b/converter/ppm/ppmtoacad.c
@@ -108,33 +108,33 @@ static void outrun(color, ysize, y, xstart, xend)
                 stdout, (int) ((xend + 1) * aspect + 0.4999));
             (void) pm_writelittleshort(stdout, yb - yspan);
         } else {
-            (void) pm_writelittleshort(stdout, (short) 0xFD00); 
+            (void) pm_writelittleshort(stdout, (short) 0xFD00);
               /* Solid fill header */
-            (void) pm_writelittleshort(stdout, 4);      
+            (void) pm_writelittleshort(stdout, 4);
               /* Vertices to follow */
             (void) pm_writelittleshort(stdout, -2);     /* Fill type */
 
-            (void) pm_writelittleshort(stdout, (short)0xFD00); 
+            (void) pm_writelittleshort(stdout, (short)0xFD00);
               /* Solid fill vertex */
             (void) pm_writelittleshort(stdout, xstart);
             (void) pm_writelittleshort(stdout, yb);
 
-            (void) pm_writelittleshort(stdout, (short) 0xFD00); 
+            (void) pm_writelittleshort(stdout, (short) 0xFD00);
               /* Solid fill vertex */
             (void) pm_writelittleshort(stdout, xend + 1);
             (void) pm_writelittleshort(stdout, yb);
 
-            (void) pm_writelittleshort(stdout, (short) 0xFD00); 
+            (void) pm_writelittleshort(stdout, (short) 0xFD00);
               /* Solid fill vertex */
             (void) pm_writelittleshort(stdout, xend + 1);
             (void) pm_writelittleshort(stdout, yb - yspan);
 
-            (void) pm_writelittleshort(stdout, (short) 0xFD00); 
+            (void) pm_writelittleshort(stdout, (short) 0xFD00);
               /* Solid fill vertex */
             (void) pm_writelittleshort(stdout, xstart);
             (void) pm_writelittleshort(stdout, yb - yspan);
 
-            (void) pm_writelittleshort(stdout, (short) 0xFD00); 
+            (void) pm_writelittleshort(stdout, (short) 0xFD00);
               /* Solid fill trailer */
             (void) pm_writelittleshort(stdout, 4); /* Vertices that precede */
             (void) pm_writelittleshort(stdout, -2);     /* Fill type */
@@ -147,6 +147,8 @@ static void outrun(color, ysize, y, xstart, xend)
     }
 }
 
+
+
 /*  SLIDEOUT  --  Write an AutoCAD slide.  */
 
 static void slideout(xdots, ydots, ncolors, red, green, blue)
@@ -253,12 +255,14 @@ static void slideout(xdots, ydots, ncolors, red, green, blue)
     if (dxbmode) {
         putchar(0);                   /* DXB end sentinel */
     } else {
-        (void) pm_writelittleshort(stdout, (short) 0xFC00); 
+        (void) pm_writelittleshort(stdout, (short) 0xFC00);
           /* End of file marker */
     }
     pm_freerow((char *) acadmap);
 }
 
+
+
 /*  Main program.  */
 
 int main(argc, argv)
@@ -391,3 +395,6 @@ int main(argc, argv)
     pm_freerow((char *) Blue);
     exit(0);
 }
+
+
+
diff --git a/converter/ppm/ppmtoapplevol.c b/converter/ppm/ppmtoapplevol.c
index 1e979de9..50c85dc6 100644
--- a/converter/ppm/ppmtoapplevol.c
+++ b/converter/ppm/ppmtoapplevol.c
@@ -97,3 +97,6 @@ main (int argc, const char * argv[]) {
 
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ppmtoarbtxt.c b/converter/ppm/ppmtoarbtxt.c
index 6d4c6eac..cb2c388b 100644
--- a/converter/ppm/ppmtoarbtxt.c
+++ b/converter/ppm/ppmtoarbtxt.c
@@ -69,11 +69,11 @@ parseCommandLine(int argc, const char ** argv,
     unsigned int hdSpec, tlSpec;
 
     unsigned int option_def_index;
-    
+
     MALLOCARRAY(option_def, 100);
 
     option_def_index = 0;   /* incremented by OPTENTRY */
-    OPTENT3(0,   "hd",   OPT_STRING, &cmdlineP->hd, 
+    OPTENT3(0,   "hd",   OPT_STRING, &cmdlineP->hd,
             &hdSpec,             0);
     OPTENT3(0,   "tl",   OPT_STRING, &cmdlineP->tl,
             &tlSpec,             0);
@@ -113,7 +113,6 @@ parseCommandLine(int argc, const char ** argv,
 
 
 
-
 typedef enum {
 /* The types of object we handle */
     BDATA, IRED, IGREEN, IBLUE, ILUM, FRED, FGREEN, FBLUE, FLUM,
@@ -134,7 +133,7 @@ typedef union {
         char * bdat;   /* Binary data (text with newlines etc.) */
         unsigned int ndat;
     } binData;
-    
+
     struct Icdat {
         char icformat[MAXFORMAT+1];  /* Integer colors */
         unsigned int icolmin, icolmax;
@@ -144,7 +143,7 @@ typedef union {
         char fcformat[MAXFORMAT+1];  /* Float colors */
         double fcolmin, fcolmax;
     } fcolData;
-    
+
     struct Idat {
         char iformat[MAXFORMAT+1];   /* Integer data */
     } iData;
@@ -152,7 +151,7 @@ typedef union {
 
 
 /* Each object has a type and some data */
-typedef struct { 
+typedef struct {
     SkeletonObjectType objType;
     SkeletonObjectData odata;
 } SkeletonObject;
@@ -187,11 +186,11 @@ dumpSkeleton(SkeletonObject ** const skeletonPList,
 static void
 dumpAllSkeleton(SkeletonObject ** const bodySkeletonPList,
                 unsigned int      const bodyNskl,
-                SkeletonObject ** const headSkeletonPList, 
+                SkeletonObject ** const headSkeletonPList,
                 unsigned int      const headNskl,
                 SkeletonObject ** const tailSkeletonPList,
                 unsigned int      const tailNskl) {
-    
+
     pm_message("Body skeleton:");
     dumpSkeleton(bodySkeletonPList, bodyNskl);
 
@@ -240,7 +239,7 @@ writeFcol(FILE *           const ofP,
           double           const value) {
 
     struct Fcdat * const fcdataP = &objectP->odata.fcolData;
-    
+
     fprintf(ofP, fcdataP->fcformat,
             (double)
             (fcdataP->fcolmin
@@ -255,7 +254,7 @@ writeIdat(FILE *           const ofP,
           unsigned int     const value) {
 
     struct Idat * const idataP = &objectP->odata.iData;
-    
+
     fprintf(ofP, idataP->iformat, value);
 }
 
@@ -272,7 +271,7 @@ writeText(FILE *            const ofP,
           double            const red,
           double            const green,
           double            const blue) {
-    
+
     unsigned int i;
 
     for (i = 0; i < nObj; ++i) {
@@ -352,6 +351,7 @@ objClass(SkeletonObjectType const objType) {
 }
 
 
+
 /*----------------------------------------------------------------------------
   Format string validation
 
@@ -366,7 +366,7 @@ objClass(SkeletonObjectType const objType) {
 
   Documentation for parse_printf_format() is usually available in texinfo
   format on GNU/Linux systems.  As of Dec. 2014 there is no official man page.
-  
+
   Online documentation is available from:
   https://
   www.gnu.org/software/libc/manual/html_node/Parsing-a-Template-String.html
@@ -379,7 +379,7 @@ validateParsePrintfFlag(int                const printfConversion,
                         const char **      const errorP) {
 /*----------------------------------------------------------------------------
   Assuming 'printfConversion' is the value reported by parse_printf_format()
-  as the type of argument a format string requires, 
+  as the type of argument a format string requires,
   return an explanation of how it is incompatible with 'ctyp' as
   *errorP -- return null string if it is compatible.
 -----------------------------------------------------------------------------*/
@@ -403,7 +403,7 @@ validateParsePrintfFlag(int                const printfConversion,
     default:
         switch (printfConversion & ~PA_FLAG_MASK) {
         case PA_CHAR:
-            pm_message("Warning: char type conversion."); 
+            pm_message("Warning: char type conversion.");
         case PA_INT:
             if(objClass(ctyp) == OBJTYP_ICOLOR ||
                objClass(ctyp) == OBJTYP_INT )
@@ -496,7 +496,7 @@ validateFormatOne(char               const typeSpecifier,
     case '0': case '1': case '2': case '3': case '4': case '5':
     case '6': case '7': case '8': case '9':
         break;
-        
+
     case 'c': case 'C':
         pm_message("Warning: char type conversion: %%%c.", typeSpecifier);
     case 'i': case 'd': case 'u': case 'o': case 'x': case 'X':
@@ -599,12 +599,12 @@ validateFormat(const char *       const format,
 
     if (error)
         pm_error("Invalid format string '%s'.  %s", format, error);
-}              
-               
+}
+
 
 
 static SkeletonObject *
-newBinDataObj(unsigned int const nDat, 
+newBinDataObj(unsigned int const nDat,
               const char * const bdat) {
 /*----------------------------------------------------------------------------
   Create a binary data object.
@@ -787,7 +787,7 @@ newFcSkelFromReplString(const char *       const fcolorObjstr,
         retval = NULL;
 
     return retval;
-} 
+}
 
 
 
@@ -805,7 +805,7 @@ newISkelFromReplString(const char *       const intObjstr,
     int nOdata;
 
     nOdata = sscanf(intObjstr, "%s", formstr);
-    
+
     if (nOdata == 1)
         retval = newIdataObj(objType, formstr);
     else if (nOdata == EOF) {
@@ -815,7 +815,7 @@ newISkelFromReplString(const char *       const intObjstr,
         retval = NULL;
 
     return retval;
-} 
+}
 
 
 
@@ -842,7 +842,7 @@ newSkeletonFromReplString(const char * const objstr) {
     int conversionCt;
     char s1[MAX_OBJ_BUF];    /* Dry read. */
     char s2[MAX_OBJ_BUF];    /* Extra tailing characters. */
-    float f1, f2;            /* Dry read. */ 
+    float f1, f2;            /* Dry read. */
 
     typstr[0] = '\0';  /* initial value */
 
@@ -905,7 +905,7 @@ readThroughCloseParen(FILE * const ifP,
             if (chr == ')') {
                 gotEscSeq = true;
                 objstr[i] = '\0';
-	        } else
+                } else
                 objstr[i] = chr;
         }
     }
@@ -942,7 +942,7 @@ SkeletonBuffer_add(SkeletonBuffer * const bufferP,
         pm_error("Too many skeletons.  Max = %u", bufferP->capacity);
 
     bufferP->skeletonPList[bufferP->nSkeleton++] = skeletonP;
-}                   
+}
 
 
 
@@ -1050,7 +1050,7 @@ readSkeletonFile(const char *      const filename,
         /* A buffer for accumulating skeleton objects */
     Buffer buffer;
         /* A buffer for accumulating binary (literal; unsubstituted) data, on
-           its way to becoming a binary skeleton object. 
+           its way to becoming a binary skeleton object.
         */
     bool eof;
     const char * error;
@@ -1135,7 +1135,7 @@ convertIt(FILE *            const ifP,
           FILE *            const ofP,
           SkeletonObject ** const bodySkeletonPList,
           unsigned int      const bodyNskl,
-          SkeletonObject ** const headSkeletonPList, 
+          SkeletonObject ** const headSkeletonPList,
           unsigned int      const headNskl,
           SkeletonObject ** const tailSkeletonPList,
           unsigned int      const tailNskl) {
@@ -1154,7 +1154,7 @@ convertIt(FILE *            const ifP,
     dmaxval = (double)maxval;
 
     /* Write header */
-    writeText(ofP, headNskl, headSkeletonPList, 
+    writeText(ofP, headNskl, headSkeletonPList,
               cols, rows , 0, 0, 0.0, 0.0, 0.0);
 
     /* Write raster */
@@ -1175,7 +1175,7 @@ convertIt(FILE *            const ifP,
     }
 
     /* Write trailer */
-    writeText(ofP, tailNskl, tailSkeletonPList, 
+    writeText(ofP, tailNskl, tailSkeletonPList,
               cols, rows, 0, 0, 0.0, 0.0, 0.0);
 }
 
@@ -1184,7 +1184,7 @@ convertIt(FILE *            const ifP,
 int
 main(int           argc,
      const char ** argv) {
-    
+
     struct CmdlineInfo cmdline;
 
     unsigned int headNskl, bodyNskl, tailNskl;
@@ -1240,3 +1240,4 @@ main(int           argc,
 }
 
 
+
diff --git a/converter/ppm/ppmtoascii.c b/converter/ppm/ppmtoascii.c
index 6b0b04d7..524bcd2c 100644
--- a/converter/ppm/ppmtoascii.c
+++ b/converter/ppm/ppmtoascii.c
@@ -164,7 +164,7 @@ ppmtoascii(pixel * const *    const pixels,
 
     for (row = 0; row < rows; row += cellHeight) {
         unsigned int col;
-        for (col = 0; col < cols; col += cellWidth)	{
+        for (col = 0; col < cols; col += cellWidth)     {
             unsigned int const sumthresh = cellWidth * cellHeight * 1.0 / 2;
 
             float sumr, sumg, sumb;
@@ -181,7 +181,7 @@ ppmtoascii(pixel * const *    const pixels,
                 for (subcol = 0; subcol < cellWidth; ++subcol) {
                     pixel color;
                     pixval value;
-                
+
                     if (row + subrow < rows && col + subcol < cols)
                         color = pixels[row + subrow][col + subcol];
                     else
@@ -225,7 +225,7 @@ main(int argc, const char ** argv) {
     parseCommandLine(argc, argv, &cmdline);
 
     ifP = pm_openr(cmdline.inputFileName);
-    
+
     pixels = ppm_readppm(ifP, &cols, &rows, &maxval);
 
     pm_close(ifP);
@@ -234,3 +234,6 @@ main(int argc, const char ** argv) {
 
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ppmtobmp.c b/converter/ppm/ppmtobmp.c
index 41cee482..8590c5ef 100644
--- a/converter/ppm/ppmtobmp.c
+++ b/converter/ppm/ppmtobmp.c
@@ -183,6 +183,7 @@ putLong(FILE * const fp, long const v) {
 }
 
 
+
 /*----------------------------------------------------------------------------
    BMP writing
 -----------------------------------------------------------------------------*/
diff --git a/converter/ppm/ppmtoeyuv.c b/converter/ppm/ppmtoeyuv.c
index c4cedcdf..0cfe9b13 100644
--- a/converter/ppm/ppmtoeyuv.c
+++ b/converter/ppm/ppmtoeyuv.c
@@ -66,7 +66,7 @@
 #include "ppm.h"
 #include "mallocvar.h"
 
-typedef	unsigned char uint8;
+typedef unsigned char uint8;
 
 /* Multiplication tables */
 
@@ -92,6 +92,8 @@ luminance(pixel const p) {
         ;
 }
 
+
+
 static __inline__ float
 chrominanceRed(pixel const p) {
     return mult5[PPM_GETR(p)]
@@ -100,6 +102,8 @@ chrominanceRed(pixel const p) {
         ;
 }
 
+
+
 static __inline__ float
 chrominanceBlue(pixel const p) {
     return mult16874[PPM_GETR(p)]
@@ -171,10 +175,10 @@ freeMultiplicationTables(void) {
  *
  * PPMtoYUV
  *
- *	convert PPM data into YUV data
- *	assumes that ydivisor = 1
+ *      convert PPM data into YUV data
+ *      assumes that ydivisor = 1
  *
- * RETURNS:	nothing
+ * RETURNS:     nothing
  *
  * SIDE EFFECTS:    none
  *
@@ -362,8 +366,8 @@ main(int argc, const char **argv) {
 
     eof = false;  /* EOF not yet encountered */
     lastMaxval = 0;  /* No previous maxval */
-    lastWidth = 0;	/* No previous width */
-    lastHeight = 0;	/* No previous height */
+    lastWidth = 0;      /* No previous width */
+    lastHeight = 0;     /* No previous height */
     orig_y = orig_cr = orig_cb = 0;
 
     while (!eof) {
diff --git a/converter/ppm/ppmtoicr.c b/converter/ppm/ppmtoicr.c
index 74ed4308..de21fc68 100644
--- a/converter/ppm/ppmtoicr.c
+++ b/converter/ppm/ppmtoicr.c
@@ -149,7 +149,6 @@ validateComputableSize(unsigned int const cols,
 
 
 
-
 static void
 makeIcrColormap(colorhist_vector const chv,
                 unsigned int     const colorCt,
@@ -290,6 +289,7 @@ windowNameFmFileName(const char * const fileName) {
 }
 
 
+
             int
 main(int argc, const char ** const argv) {
 
diff --git a/converter/ppm/ppmtoilbm.c b/converter/ppm/ppmtoilbm.c
index f9672733..c91315c3 100644
--- a/converter/ppm/ppmtoilbm.c
+++ b/converter/ppm/ppmtoilbm.c
@@ -344,6 +344,7 @@ writeTextChunks(void) {
 }
 
 
+
 static void
 writeCmap(pixel * const colormap,
           int     const colors,
@@ -2138,7 +2139,7 @@ main(int argc, char ** argv) {
         else
         if( pm_keymatch(argv[argn], "-nofloyd", 5) ||
             pm_keymatch(argv[argn], "-nofs", 5) )
-	    defunctArgs++;
+            defunctArgs++;
         else
         if( pm_keymatch(argv[argn], "-annotation", 3) ) {
             if( ++argn >= argc )
diff --git a/converter/ppm/ppmtoleaf.c b/converter/ppm/ppmtoleaf.c
index dcff0985..dc73dc48 100644
--- a/converter/ppm/ppmtoleaf.c
+++ b/converter/ppm/ppmtoleaf.c
@@ -11,7 +11,7 @@
  *
  * Known problems: pgms are not converted to leaf grayscales; they are
  * converted to 8-bit color images with all gray for colors.
- * 
+ *
  */
 
 #include <stdio.h>
@@ -31,7 +31,7 @@ static int
 colorstobpp(unsigned int const colors) {
 
     int bpp;
-    
+
     if (colors <= 2)
         bpp = 1;
     else if (colors <= 256)
@@ -49,15 +49,14 @@ GetPixel(int const x,
          int const y) {
 
     int color;
-    
+
     color = ppm_lookupcolor(cht, &pixels[y][x]);
-    
+
     return color;
 }
 
 
 
-
 static void
 leaf_writeimg(unsigned int const width,
               unsigned int const height,
@@ -70,52 +69,52 @@ leaf_writeimg(unsigned int const width,
     */
 
     /* NOTE: byte order in ileaf img file fmt is big-endian, always! */
-    
+
     /* magic */
     fputc(0x89, stdout);
     fputc(0x4f, stdout);
     fputc(0x50, stdout);
     fputc(0x53, stdout);
-    
+
     /* version 4 */
     fputc(0x00, stdout);
     fputc(0x04, stdout);
-    
+
     /* h resolution: pixels/inch: say 75=screen resolution */
     fputc(0x00, stdout);
     fputc(75, stdout);
-    
+
     /* v resolution: pixels/inch: say 75=screen resolution */
     fputc(0x00, stdout);
     fputc(75, stdout);
-    
+
     /* unique id, could be anything */
     fputc(0x01, stdout);
     fputc(0x02, stdout);
     fputc(0x03, stdout);
     fputc(0x04, stdout);
-    
+
     /* x offset, always zero */
     fputc(0x00, stdout);
     fputc(0x00, stdout);
-    
+
     /* y offset, always zero */
     fputc(0x00, stdout);
     fputc(0x00, stdout);
-    
+
     /* dimensions 64k x 64k max */
     fputc((unsigned char)((width >> 8) & 0x00ff), stdout);
     fputc((unsigned char)(width  & 0x00ff), stdout);
     fputc((unsigned char)((height >> 8) & 0x00ff), stdout);
     fputc((unsigned char)(height  & 0x00ff), stdout);
-    
+
     /* depth */
     fputc(0x00, stdout);
     fputc((unsigned char)depth, stdout);
-    
+
     /* compressed, 0=uncompressed, 1=compressed */
     fputc(0x00, stdout);
-    
+
     /* format, mono/gray = 0x20000000, RGB=0x29000000 */
     if (depth == 1)
         fputc(0x20, stdout);
@@ -125,7 +124,7 @@ leaf_writeimg(unsigned int const width,
     fputc(0x00, stdout);
     fputc(0x00, stdout);
     fputc(0x00, stdout);
-    
+
     /* colormap size */
     if (depth == 8) {
         unsigned int i;
@@ -139,10 +138,10 @@ leaf_writeimg(unsigned int const width,
             fputc((unsigned char) Green[i]*255/maxval, stdout);
         for (i = 0; i < 256; ++i)
             fputc((unsigned char) Blue[i]*255/maxval, stdout);
-    
+
         for (row=0; row < height; ++row) {
             unsigned int col;
-            for (col = 0; col < width; ++col) 
+            for (col = 0; col < width; ++col)
                 fputc(GetPixel(col, row), stdout);
             if ((width % 2) != 0)
                 fputc(0x00, stdout); /* pad to 2-bytes */
@@ -180,18 +179,18 @@ leaf_writeimg(unsigned int const width,
 
         fputc(0x00, stdout);
         fputc(0x00, stdout);
-        
+
         for (row = 0; row < height; ++row) {
             unsigned int col;
-            for (col = 0; col < width; ++col) 
+            for (col = 0; col < width; ++col)
                 fputc(pixels[row][col].r * 255 / maxval, stdout);
             if (width % 2 != 0)
                 fputc(0x00, stdout); /* pad to 2-bytes */
-            for (col = 0; col < width; ++col) 
+            for (col = 0; col < width; ++col)
                 fputc(pixels[row][col].g * 255 / maxval, stdout);
             if (width % 2 != 0)
                 fputc(0x00, stdout); /* pad to 2-bytes */
-            for (col = 0; col < width; ++col) 
+            for (col = 0; col < width; ++col)
                 fputc(pixels[row][col].b * 255 / maxval, stdout);
             if (width % 2 != 0)
                 fputc(0x00, stdout); /* pad to 2-bytes */
@@ -212,24 +211,24 @@ main(int argc, const char * argv[]) {
     pixval maxval;
     colorhist_vector chv;
     const char * const usage = "[ppmfile]";
-    
+
     pm_proginit(&argc, argv);
-    
+
     argn = 1;
-    
+
     if (argn < argc) {
         ifP = pm_openr(argv[argn]);
         argn++;
     } else
         ifP = stdin;
-    
+
     if (argn != argc)
         pm_usage(usage);
-    
+
     pixels = ppm_readppm(ifP, &cols, &rows, &maxval);
-    
+
     pm_close(ifP);
-    
+
     /* Figure out the colormap. */
     pm_message("Computing colormap...");
     chv = ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &colors);
@@ -237,14 +236,14 @@ main(int argc, const char * argv[]) {
         unsigned int i;
 
         pm_message("... Done.  %u colors found.", colors);
-    
+
         for (i = 0; i < colors; ++i) {
             Red[i]   = (int) PPM_GETR( chv[i].color);
             Green[i] = (int) PPM_GETG( chv[i].color);
             Blue[i]  = (int) PPM_GETB( chv[i].color);
         }
         BitsPerPixel = colorstobpp(colors);
-    
+
         /* And make a hash table for fast lookup. */
         cht = ppm_colorhisttocolorhash(chv, colors);
         ppm_freecolorhist(chv);
@@ -252,8 +251,11 @@ main(int argc, const char * argv[]) {
         BitsPerPixel = 24;
         pm_message("  ... Done.  24-bit true color %u color image.", colors);
     }
-    
+
     leaf_writeimg(cols, rows, BitsPerPixel, colors, maxval);
-    
+
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ppmtomitsu.c b/converter/ppm/ppmtomitsu.c
index 50b790d6..8fb7cddd 100644
--- a/converter/ppm/ppmtomitsu.c
+++ b/converter/ppm/ppmtomitsu.c
@@ -20,6 +20,7 @@
 ** implied warranty.
 */
 
+#include <stdbool.h>
 #include <assert.h>
 #include <string.h>
 #include <stdio.h>
@@ -35,28 +36,84 @@
 #define HASHSIZE 2048
 #define myhash(x) ((PPM_GETR(x)*3 + PPM_GETG(x)*5 + PPM_GETB(x)*7) % HASHSIZE)
 
-typedef struct hashinfo {
+typedef struct Hashinfo {
         pixel     color;
         long      flag;
-        struct hashinfo * next;
-} hashinfo;
+        struct Hashinfo * next;
+} Hashinfo;
 
-#define cmd(arg)           fputc((arg), stdout)
-#define datum(arg)         fputc((char)(arg), stdout)
-#define data(arg,num)      fwrite((arg), sizeof(char), (num), stdout)
+
+
+static struct Mediasize
+mediaSize(const char * const media,
+          bool         const dpi300) {
+
+    struct Mediasize medias;
+
+    if (TOUPPER(media[0]) == 'A') {
+        switch (TOUPPER(media[1])) {
+        case 'S':
+            medias = MSize_AS;
+            break;
+        case '4':
+            if (TOUPPER(media[2]) == 'S')
+                medias = MSize_A4S;
+            else
+                medias = MSize_A4;
+            break;
+        default:
+            medias = MSize_A;
+        }
+    } else
+        medias = MSize_User;
+
+    if (dpi300) {
+        medias.maxcols *= 2;
+        medias.maxrows *= 2;
+    }
+
+    return medias;
+}
 
 
 
 static void
-check_and_rotate(int              const cols,
-                 int              const rows,
-                 int              const enlarge,
-                 struct mediasize const medias) {
+cmd(char const arg) {
+
+    fputc(arg, stdout);
+}
+
+
+
+static void
+datum(unsigned char const arg) {
+
+    fputc(arg, stdout);
+}
+
+
+
+static void
+data(unsigned char * const arg,
+     size_t          const len) {
+
+    fwrite((unsigned char *)arg, 1, len, stdout);
+}
+
+
+
+static void
+checkAndRotate(int              const cols,
+               int              const rows,
+               int              const enlarge,
+               struct Mediasize const medias) {
 
     if (cols > rows) {
         ROTATEIMG(DOROTATE);                        /* rotate image */
         if (enlarge * rows > medias.maxcols || enlarge * cols > medias.maxrows)
-            pm_error("Image too large, MaxPixels = %u x %u",
+            pm_error("Image too large (%u x %u).  "
+                     "Size of output media: %u x %u",
+                     enlarge*rows, enlarge*cols,
                      medias.maxrows, medias.maxcols);
         HPIXELS(cols);
         VPIXELS(rows);
@@ -66,7 +123,9 @@ check_and_rotate(int              const cols,
     } else {
         ROTATEIMG(DONTROTATE);
         if (enlarge * rows > medias.maxrows || enlarge * cols > medias.maxcols)
-            pm_error("Image too large, MaxPixels = %u x %u",
+            pm_error("Image too large (%u x %u).  "
+                     "Size of output media: %u x %u",
+                     enlarge*rows, enlarge*cols,
                      medias.maxrows, medias.maxcols);
         HPIXELS(cols);
         VPIXELS(rows);
@@ -83,7 +142,7 @@ lineputinit(int              const cols,
             int              const sharpness,
             int              const enlarge,
             int              const copy,
-            struct mediasize const medias) {
+            struct Mediasize const medias) {
     ONLINE;
     CLRMEM;
     MEDIASIZE(medias);
@@ -132,7 +191,7 @@ lineputinit(int              const cols,
     default:
         SHARPNESS(SP_USER);
     }
-    check_and_rotate(cols, rows, enlarge, medias);
+    checkAndRotate(cols, rows, enlarge, medias);
     DATASTART;
 }
 
@@ -142,7 +201,7 @@ static void
 lookuptableinit(int              const sharpness,
                 int              const enlarge,
                 int              const copy,
-                struct mediasize const medias) {
+                struct Mediasize const medias) {
 
     ONLINE;
     CLRMEM;
@@ -200,10 +259,10 @@ static void
 lookuptabledata(int              const cols,
                 int              const rows,
                 int              const enlarge,
-                struct mediasize const medias) {
+                struct Mediasize const medias) {
 
     DONELOOKUPTABLE;
-    check_and_rotate(cols, rows, enlarge, medias);
+    checkAndRotate(cols, rows, enlarge, medias);
     DATASTART;
 }
 
@@ -215,7 +274,7 @@ frametransferinit(int              const cols,
                   int              const sharpness,
                   int              const enlarge,
                   int              const copy,
-                  struct mediasize const medias) {
+                  struct Mediasize const medias) {
 
     ONLINE;
     CLRMEM;
@@ -265,7 +324,7 @@ frametransferinit(int              const cols,
     default:
         SHARPNESS(SP_USER);
     }
-    check_and_rotate(cols, rows, enlarge, medias);
+    checkAndRotate(cols, rows, enlarge, medias);
 }
 
 
@@ -273,14 +332,14 @@ frametransferinit(int              const cols,
 static void
 doLookupTableColors(colorhist_vector const table,
                     unsigned int     const nColor,
-                    hashinfo *       const colorhashtable) {
+                    Hashinfo *       const colorhashtable) {
 
     unsigned int colval;
     for (colval = 0; colval < nColor; ++colval) {
-        struct hashinfo * const hashchain =
+        struct Hashinfo * const hashchain =
             &colorhashtable[myhash((table[colval]).color)];
 
-        struct hashinfo * hashrun;
+        struct Hashinfo * hashrun;
 
         cmd('$');
         datum(colval);
@@ -310,13 +369,13 @@ doLookupTableColors(colorhist_vector const table,
 static void
 doLookupTableGrays(colorhist_vector const table,
                    unsigned int     const nColor,
-                   hashinfo *       const colorhashtable) {
+                   Hashinfo *       const colorhashtable) {
 
     unsigned int colval;
     for (colval = 0; colval < nColor; ++colval) {
-        struct hashinfo * const hashchain =
+        struct Hashinfo * const hashchain =
             &colorhashtable[myhash((table[colval]).color)];
-        struct hashinfo * hashrun;
+        struct Hashinfo * hashrun;
 
         cmd('$');
         datum(colval);
@@ -352,8 +411,8 @@ generateLookupTable(colorhist_vector const table,
                     int              const sharpness,
                     int              const enlarge,
                     int              const copy,
-                    struct mediasize const medias,
-                    hashinfo **      const colorhashtableP) {
+                    struct Mediasize const medias,
+                    Hashinfo **      const colorhashtableP) {
 /*----------------------------------------------------------------------------
    Write to the output file the palette (color lookup table) indicated by
    'table' and generate a hash table to use with it: *colorhashtableP.
@@ -361,7 +420,7 @@ generateLookupTable(colorhist_vector const table,
    Also write the various properties 'sharpness', 'enlarge', 'copy', and
    'medias' to the output file.
 -----------------------------------------------------------------------------*/
-    hashinfo * colorhashtable;
+    Hashinfo * colorhashtable;
 
     lookuptableinit(sharpness, enlarge, copy, medias);
 
@@ -394,7 +453,7 @@ static void
 writeColormapRaster(pixel **         const pixels,
                     unsigned int     const cols,
                     unsigned int     const rows,
-                    hashinfo *       const colorhashtable) {
+                    Hashinfo *       const colorhashtable) {
 /*----------------------------------------------------------------------------
    Write a colormapped raster: write the pixels pixels[][] (dimensions cols x
    rows) as indices into the colormap (palette; lookup table) indicated by
@@ -407,9 +466,9 @@ writeColormapRaster(pixel **         const pixels,
 
         for (col = 0; col < cols; ++col) {
             pixel * const pixrow = pixels[row];
-            struct hashinfo * const hashchain =
+            struct Hashinfo * const hashchain =
                 &colorhashtable[myhash(pixrow[col])];
-            struct hashinfo * p;
+            struct Hashinfo * p;
 
             p = hashchain;
             while (!PPM_EQUAL((p->color), pixrow[col])) {
@@ -429,13 +488,13 @@ useLookupTable(pixel **         const pixels,
                int              const sharpness,
                int              const enlarge,
                int              const copy,
-               struct mediasize const medias,
+               struct Mediasize const medias,
                unsigned int     const cols,
                unsigned int     const rows,
                int              const format,
                unsigned int     const nColor) {
 
-    hashinfo * colorhashtable;
+    Hashinfo * colorhashtable;
 
     pm_message("found %u colors - using the lookuptable-method", nColor);
 
@@ -523,7 +582,7 @@ useNoLookupTable(pixel **         const pixels,
                  int              const sharpness,
                  int              const enlarge,
                  int              const copy,
-                 struct mediasize const medias,
+                 struct Mediasize const medias,
                  unsigned int     const cols,
                  unsigned int     const rows,
                  int              const format) {
@@ -553,7 +612,7 @@ doTiny(FILE *           const ifP,
        int              const sharpness,
        int              const enlarge,
        int              const copy,
-       struct mediasize const medias) {
+       struct Mediasize const medias) {
 
     pixel * pixelrow;
     unsigned char * redrow;
@@ -596,26 +655,28 @@ doTiny(FILE *           const ifP,
 
 
 int
-main(int argc, char * argv[]) {
-    FILE * ifP;
+main(int argc, const char ** argv) {
+
+    FILE *           ifP;
     int              argn;
     bool             dpi300;
+    bool             tiny;
     int              cols, rows, format;
     pixval           maxval;
-    int              sharpness, enlarge, copy, tiny;
-    struct mediasize medias;
+    int              sharpness, enlarge, copy;
+    struct Mediasize medias;
     char             media[16];
     const char * const usage = "[-sharpness <1-4>] [-enlarge <1-3>] [-media <a,a4,as,a4s>] [-copy <1-9>] [-tiny] [-dpi300] [ppmfile]";
 
-    ppm_init(&argc, argv);
+    pm_proginit(&argc, argv);
 
-    dpi300 = FALSE;
+    dpi300 = false;
     argn = 1;
     sharpness = 32;
     enlarge   = 1;
     copy      = 1;
     memset(media, '\0', 16);
-    tiny      = FALSE;
+    tiny      = false;
 
     /* check for flags */
     while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') {
@@ -648,9 +709,9 @@ main(int argc, char * argv[]) {
             pm_usage(usage);
         }
     else if (pm_keymatch(argv[argn], "-dpi300", 2))
-        dpi300 = TRUE;
+        dpi300 = true;
     else if (pm_keymatch(argv[argn], "-tiny", 2))
-        tiny = TRUE;
+        tiny = true;
     else
         pm_usage(usage);
     ++argn;
@@ -666,28 +727,7 @@ main(int argc, char * argv[]) {
     if (argn != argc)
         pm_usage(usage);
 
-    if (TOUPPER(media[0]) == 'A')
-        switch (TOUPPER(media[1])) {
-        case 'S':
-            medias = MSize_AS;
-            break;
-        case '4':
-            if(TOUPPER(media[2]) == 'S')
-                medias = MSize_A4S;
-            else {
-                medias = MSize_A4;
-            }
-            break;
-        default:
-            medias = MSize_A;
-        }
-    else
-        medias = MSize_User;
-
-    if (dpi300) {
-        medias.maxcols *= 2;
-        medias.maxrows *= 2;
-    }
+    medias = mediaSize(media, dpi300);
 
     ppm_readppminit(ifP, &cols, &rows, &maxval, &format);
 
@@ -721,3 +761,6 @@ main(int argc, char * argv[]) {
     pm_close(ifP);
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/bframe.c b/converter/ppm/ppmtompeg/bframe.c
index fb546cc0..8bce3e14 100644
--- a/converter/ppm/ppmtompeg/bframe.c
+++ b/converter/ppm/ppmtompeg/bframe.c
@@ -114,7 +114,6 @@ halfMotion(motion const motion) {
 
 
 
-
 /*===========================================================================*
  *
  *  compute the block resulting from motion compensation
@@ -439,7 +438,6 @@ MotionSufficient(MpegFrame *      const curr,
 
 
 
-
 struct stats {
     int IBlocks;
     int BBlocks;
@@ -1156,6 +1154,7 @@ SetBQScale(qB)
 }
 
 
+
 /*===========================================================================*
  *
  * GetBQScale
@@ -1174,6 +1173,7 @@ GetBQScale()
 }
 
 
+
 /*===========================================================================*
  *
  * ResetBFrameStats
@@ -1326,6 +1326,7 @@ ComputeBMotionLumBlock(MpegFrame * const prev,
 }
 
 
+
 /*===========================================================================*
  *
  *  estimate the seconds to compute a B-frame
@@ -1344,3 +1345,4 @@ EstimateSecondsPerBFrame() {
 }
 
 
+
diff --git a/converter/ppm/ppmtompeg/bitio.c b/converter/ppm/ppmtompeg/bitio.c
index 79c9f36f..b95f1ce1 100644
--- a/converter/ppm/ppmtompeg/bitio.c
+++ b/converter/ppm/ppmtompeg/bitio.c
@@ -133,6 +133,7 @@ Dump(BitBucket * const bbPtr) {
 }
 
 
+
 /*=====================*
  * EXPORTED PROCEDURES *
  *=====================*/
@@ -217,6 +218,7 @@ Bitio_Free(BitBucket * const bbPtr) {
 }
 
 
+
 /*===========================================================================*
  *
  * Bitio_Write
@@ -318,6 +320,7 @@ Bitio_Write(BitBucket * const bbPtr,
 }
 
 
+
 /*===========================================================================*
  *
  * Bitio_Flush
@@ -516,6 +519,7 @@ Bitio_WriteToSocket(BitBucket * const bbPtr,
 }
 
 
+
 /*===========================================================================*
  *
  * Bitio_BytePad
@@ -534,3 +538,6 @@ Bitio_BytePad(BitBucket * const bbPtr) {
         Bitio_Write(bbPtr, 0, lastPtrPtr->bitsleftcur % 8);
     }
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/block.c b/converter/ppm/ppmtompeg/block.c
index 23396b4c..db8dc277 100644
--- a/converter/ppm/ppmtompeg/block.c
+++ b/converter/ppm/ppmtompeg/block.c
@@ -42,6 +42,8 @@ halfVector(vector const v) {
     return half;
 }
 
+
+
 /*===========================*
  * COMPUTE DCT OF DIFFERENCE *
  *===========================*/
@@ -361,6 +363,7 @@ ComputeMotionLumBlock(MpegFrame * const prevFrame,
 }
 
 
+
 /*=======================*
  * BASIC ERROR FUNCTIONS *
  *=======================*/
@@ -691,6 +694,7 @@ AddMotionBlock(Block          block,
 }
 
 
+
 /*===========================================================================*
  *
  *  adds the motion-compensated B-frame block to the given block
@@ -734,6 +738,7 @@ AddBMotionBlock(Block          block,
 }
 
 
+
 /*===========================================================================*
  *
  *  copies the given block into the appropriate data area
@@ -764,6 +769,7 @@ BlockToData(uint8 ** const data,
 }
 
 
+
 /*===========================================================================*
  *
  *  copies data into appropriate blocks
@@ -834,6 +840,7 @@ BlockifyFrame(MpegFrame * const frameP) {
 }
 
 
+
 /*===========================================================================*
  *                                       *
  * UNUSED PROCEDURES                                 *
@@ -925,6 +932,7 @@ ComputeSubSampledMotionLumBlock(MpegFrame * const prevFrame,
 }
 
 
+
 /*===========================================================================*
  *
  *  return the MAD of the currentBlock and the motion-compensated block,
@@ -1021,6 +1029,7 @@ LumMotionErrorSubSampled(LumBlock    const currentBlock,
 }
 
 
+
 #endif /* UNUSED_PROCEDURES */
 /*
  * Copyright (c) 1995 The Regents of the University of California.
diff --git a/converter/ppm/ppmtompeg/bsearch.c b/converter/ppm/ppmtompeg/bsearch.c
index b825ef72..6d13ab34 100644
--- a/converter/ppm/ppmtompeg/bsearch.c
+++ b/converter/ppm/ppmtompeg/bsearch.c
@@ -116,6 +116,7 @@ SetBSearchAlg(const char * const alg) {
 }
 
 
+
 /*===========================================================================*
  *
  * BSearchName
@@ -256,6 +257,7 @@ FindBestMatchExhaust(const LumBlock * const blockP,
 }
 
 
+
 /*===========================================================================*
  *
  * FindBestMatchTwoLevel
@@ -587,6 +589,7 @@ FindBestMatchSubSample(const LumBlock * const blockP,
 }
 
 
+
 /*===========================================================================*
  *
  * FindBestMatch
@@ -775,6 +778,7 @@ BMotionSearchSimple(const LumBlock * const currentBlockP,
 }
 
 
+
 /*===========================================================================*
  *
  * BMotionSearchCross2
@@ -863,6 +867,7 @@ BMotionSearchCross2(const LumBlock * const currentBlockP,
 }
 
 
+
 /*===========================================================================*
  *
  * BMotionSearchExhaust
@@ -1027,6 +1032,7 @@ BMotionSearch(const LumBlock * const currentBlockP,
 }
 
 
+
 /*===========================================================================*
  *                                       *
  * UNUSED PROCEDURES                                 *
@@ -1085,4 +1091,5 @@ ValidBMotion(by, bx, mode, fmy, fmx, bmy, bmx)
 }
 
 
+
 #endif /* UNUSED_PROCEDURES */
diff --git a/converter/ppm/ppmtompeg/file.c b/converter/ppm/ppmtompeg/file.c
index b81e8077..bc097452 100644
--- a/converter/ppm/ppmtompeg/file.c
+++ b/converter/ppm/ppmtompeg/file.c
@@ -301,3 +301,6 @@ MatchesGlob(char *string, char *glob) {
 
     return TRUE;
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/frame.c b/converter/ppm/ppmtompeg/frame.c
index 09e35410..81c1ff9f 100644
--- a/converter/ppm/ppmtompeg/frame.c
+++ b/converter/ppm/ppmtompeg/frame.c
@@ -395,6 +395,7 @@ Frame_Init(unsigned int const numOfFramesRequested) {
 }
 
 
+
 /*===========================================================================*
  *
  * FreeFrame
@@ -495,6 +496,7 @@ Frame_Exit(void) {
 }
 
 
+
 /*===========================================================================*
  *
  * Frame_Free
@@ -845,3 +847,4 @@ Frame_Resize(MpegFrame * const omf,
 }
 
 
+
diff --git a/converter/ppm/ppmtompeg/frametype.c b/converter/ppm/ppmtompeg/frametype.c
index 78e324d0..ff45564b 100644
--- a/converter/ppm/ppmtompeg/frametype.c
+++ b/converter/ppm/ppmtompeg/frametype.c
@@ -187,6 +187,7 @@ FType_PastRef(currFrameNum)
 }
 
 
+
 /*===========================================================================*
  *
  * SetFramePattern
diff --git a/converter/ppm/ppmtompeg/fsize.c b/converter/ppm/ppmtompeg/fsize.c
index 84772719..83b383e4 100644
--- a/converter/ppm/ppmtompeg/fsize.c
+++ b/converter/ppm/ppmtompeg/fsize.c
@@ -94,6 +94,7 @@ Fsize_Validate(int * const xP,
 }
 
 
+
 /*===========================================================================*
  *
  * Fsize_Note
@@ -132,3 +133,6 @@ Fsize_Note(int          const id,
     }
 #endif
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/gethostname.c b/converter/ppm/ppmtompeg/gethostname.c
index 649fff91..dedb3129 100644
--- a/converter/ppm/ppmtompeg/gethostname.c
+++ b/converter/ppm/ppmtompeg/gethostname.c
@@ -26,3 +26,6 @@ GetHostName(void) {
 
     return strdup(utsname.nodename);
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/gethostname_win32.c b/converter/ppm/ppmtompeg/gethostname_win32.c
index b831e22d..2e03476d 100644
--- a/converter/ppm/ppmtompeg/gethostname_win32.c
+++ b/converter/ppm/ppmtompeg/gethostname_win32.c
@@ -30,6 +30,8 @@ pushString(push_string_t *p, const char *fmt, ...)
     va_end(args);
 }
 
+
+
 #if _WIN32_WINNT < 0x0600
 /*
  * Reference available here:
@@ -371,6 +373,8 @@ get_string_version(push_string_t *str)
     return TRUE;
 }
 
+
+
 const char *
 GetHostName(void)
 {
@@ -389,6 +393,8 @@ GetHostName(void)
     return (const char *)_strdup(str.str);
 }
 
+
+
 #ifdef GETHOSTNAME_LOCAL_DEBUG
 int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst,
                    LPSTR lpsCmdLine, int nCmdShow)
diff --git a/converter/ppm/ppmtompeg/headers/frames.h b/converter/ppm/ppmtompeg/headers/frames.h
index 9108ac21..88638690 100644
--- a/converter/ppm/ppmtompeg/headers/frames.h
+++ b/converter/ppm/ppmtompeg/headers/frames.h
@@ -125,6 +125,8 @@ MotionToFrameCoord(int   const by,
     *xP = bx * DCTSIZE + mx;
 }
 
+
+
 #define COORD_IN_FRAME(fy,fx, type)                 \
     ((type == LUM_BLOCK) ?                      \
      ((fy >= 0) && (fx >= 0) && (fy < Fsize_y) && (fx < Fsize_x)) : \
@@ -175,6 +177,7 @@ encodeMotionVector(int      const x,
 }
 
 
+
 #define DoQuant(bit, src, dest)                                         \
   if (pattern & bit) {                                                  \
     switch (Mpost_QuantZigBlock(src, dest, QScale, FALSE)) {            \
diff --git a/converter/ppm/ppmtompeg/iframe.c b/converter/ppm/ppmtompeg/iframe.c
index 81ff0ec0..2bc50196 100644
--- a/converter/ppm/ppmtompeg/iframe.c
+++ b/converter/ppm/ppmtompeg/iframe.c
@@ -983,3 +983,6 @@ int32 time_elapsed(void) {
     return timeBuffer.tms_utime + timeBuffer.tms_stime;
 #endif
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/input.c b/converter/ppm/ppmtompeg/input.c
index e12b0d4c..83aa387c 100644
--- a/converter/ppm/ppmtompeg/input.c
+++ b/converter/ppm/ppmtompeg/input.c
@@ -415,6 +415,7 @@ processSimpleFileName(const char *            const input,
 }
 
 
+
 #define INPUT_ENTRY_BLOCK_SIZE   128
 
 void
diff --git a/converter/ppm/ppmtompeg/jpeg.c b/converter/ppm/ppmtompeg/jpeg.c
index 4540f6f0..6680404b 100644
--- a/converter/ppm/ppmtompeg/jpeg.c
+++ b/converter/ppm/ppmtompeg/jpeg.c
@@ -339,7 +339,6 @@ JMovie2JPEG(const char * const infilename,
 
 
 
-
 /*===========================================================================*
  *
  * ReadJPEG  contributed by James Arthur Boucher of Boston University's
diff --git a/converter/ppm/ppmtompeg/jrevdct.c b/converter/ppm/ppmtompeg/jrevdct.c
index ebadb997..f46051bc 100644
--- a/converter/ppm/ppmtompeg/jrevdct.c
+++ b/converter/ppm/ppmtompeg/jrevdct.c
@@ -179,6 +179,8 @@ mpeg_jrevdct(data)
   else mpeg_jrevdct_quick(data);
 }
 
+
+
 /*
  * Perform the inverse DCT on one block of coefficients.
  */
@@ -1179,6 +1181,7 @@ mpeg_jrevdct_quick(data)
 }
 
 
+
 /* here is the reference one, in case of problems with the normal one */
 
 /* idctref.c, Inverse Discrete Fourier Transform, double precision          */
@@ -1273,3 +1276,6 @@ int16 *block;
       block[8*i+j] = (v<-256) ? -256 : ((v>255) ? 255 : v);
     }
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/memory.c b/converter/ppm/ppmtompeg/memory.c
index 0ebe4686..8c272707 100644
--- a/converter/ppm/ppmtompeg/memory.c
+++ b/converter/ppm/ppmtompeg/memory.c
@@ -59,13 +59,20 @@ char    *MemAlloc(size_t size)
     return malloc(size);
 }
 
+
+
 void    MemFree(char *ptr, long bytes)
 {
     totalMemory -= bytes;
     free(ptr);
 }
 
+
+
 void    PrintMaxMemory(void)
 {
     fprintf(stdout, "MMMMM-----MAX MEMORY-----MMMMM = %ld\n", maxMemory);
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/mfwddct.c b/converter/ppm/ppmtompeg/mfwddct.c
index 8b379cd8..1355ef91 100644
--- a/converter/ppm/ppmtompeg/mfwddct.c
+++ b/converter/ppm/ppmtompeg/mfwddct.c
@@ -326,6 +326,7 @@ mp_fwd_dct_fast(data2d, dest2d)
 }
 
 
+
 extern boolean pureDCT;
 void
 mp_fwd_dct_block2(data, dest)
@@ -348,6 +349,8 @@ mp_fwd_dct_block2(data, dest)
   else mp_fwd_dct_fast(data, dest);
 }
 
+
+
 /* Modifies from the MPEG2 verification coder */
 /* fdctref.c, forward discrete cosine transform, double precision           */
 
diff --git a/converter/ppm/ppmtompeg/mheaders.c b/converter/ppm/ppmtompeg/mheaders.c
index 7e5db6c1..54dada83 100644
--- a/converter/ppm/ppmtompeg/mheaders.c
+++ b/converter/ppm/ppmtompeg/mheaders.c
@@ -429,6 +429,7 @@ GenMBType(bbPtr, pict_code_type, mb_quant, motion_forw, motion_back,
 }
 
 
+
 /*===========================================================================*
  *
  * GenMotionCode
@@ -459,6 +460,7 @@ GenMotionCode(BitBucket * const bbPtr,
 }
 
 
+
 /*===========================================================================*
  *
  * GenBlockPattern
@@ -485,6 +487,7 @@ GenBlockPattern(bbPtr, mb_pattern)
 }
 
 
+
 /*===========================================================================*
  *
  * GenMBAddrIncr
@@ -512,6 +515,7 @@ GenMBAddrIncr(bbPtr, addr_incr)
 }
 
 
+
 /*===========================================================================*
  *
  * GenPictHead
@@ -624,6 +628,7 @@ GenPictHead(bbPtr, temp_ref, code_type, vbv_delay, full_pel_forw_flag,
 }
 
 
+
 /*=====================*
  * EXPORTED PROCEDURES *
  *=====================*/
@@ -649,6 +654,7 @@ SetGOPStartTime(index)
 }
 
 
+
 /*===========================================================================*
  *
  * Mhead_GenPictureHeader
@@ -688,6 +694,7 @@ Mhead_GenPictureHeader(bbPtr, frameType, pictCount, f_code)
 }
 
 
+
 /*===========================================================================*
  *
  * Mhead_GenSequenceHeader
@@ -849,6 +856,7 @@ Mhead_GenSequenceHeader(BitBucket *   const bbPtr,
 }
 
 
+
 /*===========================================================================*
  *
  * Mhead_GenSequenceEnder
@@ -869,6 +877,7 @@ Mhead_GenSequenceEnder(bbPtr)
 }
 
 
+
 /*===========================================================================*
  *
  * Mhead_GenGOPHeader
@@ -967,6 +976,7 @@ Mhead_GenGOPHeader(bbPtr, drop_frame_flag, tc_hrs, tc_min, tc_sec, tc_pict,
 }
 
 
+
 /*===========================================================================*
  *
  * Mhead_GenSliceHeader
@@ -1010,6 +1020,7 @@ Mhead_GenSliceHeader(bbPtr, verticalPos, qscale, extra_info, extra_info_size)
 }
 
 
+
 /*===========================================================================*
  *
  * Mhead_GenSliceEnder
@@ -1030,6 +1041,7 @@ Mhead_GenSliceEnder(bbPtr)
 }
 
 
+
 /*===========================================================================*
  *
  * Mhead_GenMBHeader
@@ -1158,6 +1170,7 @@ if ( addr_incr != 1 )
 }
 
 
+
 #ifdef UNUSED_PROCEDURES
 
 /* GenMBEnd only used for `D` pictures. Shouldn't really ever be called. */
@@ -1169,4 +1182,6 @@ GenMBEnd(bbPtr)
     Bitio_Write(bbPtr, 0x01, 1);
 }
 
+
+
 #endif /* UNUSED_PROCEDURES */
diff --git a/converter/ppm/ppmtompeg/moutput.c b/converter/ppm/ppmtompeg/moutput.c
index 765a2b6f..bc7fb2b6 100644
--- a/converter/ppm/ppmtompeg/moutput.c
+++ b/converter/ppm/ppmtompeg/moutput.c
@@ -167,6 +167,7 @@ void    UnQuantZig(FlatBlock in, Block out, int qscale, boolean iblock)
 }
 
 
+
 /*
  * --------------------------------------------------------------
  *
@@ -335,6 +336,7 @@ void    mp_rle_huff_block(FlatBlock in, BitBucket *out)
 }
 
 
+
 /*
  * --------------------------------------------------------------
  *
@@ -440,3 +442,6 @@ void    mp_rle_huff_pblock(FlatBlock in, BitBucket *out)
     DBG_PRINT(("End of block\n"));
     Bitio_Write(out, 0x2, 2);   /* end of block marker */
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/mpeg.c b/converter/ppm/ppmtompeg/mpeg.c
index e67eec1e..ff8c6035 100644
--- a/converter/ppm/ppmtompeg/mpeg.c
+++ b/converter/ppm/ppmtompeg/mpeg.c
@@ -285,7 +285,6 @@ SetBitRateFileName(const char * const fileName) {
 
 
 
-
 static void
 finishFrameOutput(MpegFrame * const frameP,
                   BitBucket * const bbP,
@@ -316,7 +315,6 @@ finishFrameOutput(MpegFrame * const frameP,
 
 
 
-
 static void
 outputIFrame(MpegFrame * const frameP,
              BitBucket * const bbP,
@@ -1241,6 +1239,7 @@ SetStatFileName(const char * const fileName) {
 }
 
 
+
 /*===========================================================================*
  *
  * SetGOPSize
@@ -1260,6 +1259,7 @@ SetGOPSize(size)
 }
 
 
+
 /*===========================================================================*
  *
  * PrintStartStats
@@ -1463,6 +1463,7 @@ SetFrameRate()
 }
 
 
+
 /*=====================*
  * INTERNAL PROCEDURES *
  *=====================*/
diff --git a/converter/ppm/ppmtompeg/mquant.c b/converter/ppm/ppmtompeg/mquant.c
index 99b1cb8e..0251a142 100644
--- a/converter/ppm/ppmtompeg/mquant.c
+++ b/converter/ppm/ppmtompeg/mquant.c
@@ -42,3 +42,6 @@ void mp_quant_block(Block in, Block out) {
         out[i][7] = in[i][7] / qtable[i][7];
     }
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/nojpeg.c b/converter/ppm/ppmtompeg/nojpeg.c
index 5b86ab56..dc1b222e 100644
--- a/converter/ppm/ppmtompeg/nojpeg.c
+++ b/converter/ppm/ppmtompeg/nojpeg.c
@@ -52,6 +52,7 @@ JMovie2JPEG(const char * const infilename,
 }
 
 
+
 void
 ReadJPEG(MpegFrame * const mf,
          FILE *      const fp) {
@@ -59,3 +60,6 @@ ReadJPEG(MpegFrame * const mf,
     pm_error("This program has not been built with the "
              "ability to handle JPEG input files");
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/noparallel.c b/converter/ppm/ppmtompeg/noparallel.c
index 02c46a58..d21f3e9a 100644
--- a/converter/ppm/ppmtompeg/noparallel.c
+++ b/converter/ppm/ppmtompeg/noparallel.c
@@ -92,6 +92,7 @@ SetParallelPerfect(boolean const val) {
 }
 
 
+
 void
 SetRemoteShell(const char * const shell) {
     /* do nothing -- this may be called during non-parallel execution */
@@ -228,3 +229,6 @@ GetRemoteDecodedRefFrame(MpegFrame * const frame,
     pm_error("This version of Ppmtompeg cannot run parallel mode because "
              "it does not have socket capability.");
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/opts.c b/converter/ppm/ppmtompeg/opts.c
index 6f5f9816..9d750c54 100644
--- a/converter/ppm/ppmtompeg/opts.c
+++ b/converter/ppm/ppmtompeg/opts.c
@@ -157,7 +157,6 @@ SetupCollectQuantStats(const char * const charPtr)
 
 
 
-
 /*===========================================================================*
  *
  * SetupKillDimAreas
@@ -223,6 +222,7 @@ SetupSquashSmall(const char * const charPtr)
 }
 
 
+
 /*===========================================================================*
  *
  * SetupLocalDCT
@@ -254,6 +254,7 @@ SetupLocalDCT(const char * const charPtr)
 }
 
 
+
 /*===========================================================================*
  *
  * SetupLaplace
@@ -290,6 +291,8 @@ SetupLaplace()
   }
 }
 
+
+
 static void
 SetupWriteDistortions(const char * const charPtr)
 {
@@ -341,6 +344,8 @@ SetupWriteDistortions(const char * const charPtr)
     }}
 }
 
+
+
 /*=====================*
  * EXPORTED PROCEDURES *
  *=====================*/
@@ -361,6 +366,7 @@ CalcLambdas(void) {
 }
 
 
+
 /*===========================================================================*
  *
  * Mpost_UnQuantZigBlockLaplace
@@ -424,6 +430,8 @@ Mpost_UnQuantZigBlockLaplace(in, out, qscale, iblock)
     }
 }
 
+
+
 int
 mse(Block blk1, Block blk2)
 {
@@ -442,7 +450,6 @@ mse(Block blk1, Block blk2)
 
 
 
-
 /*===========================================================================*
  *
  * Tune_Init
@@ -489,6 +496,8 @@ void Tune_Init()
 
 }
 
+
+
 /*===========================================================================*
  *
  * ParseTuneParam
@@ -545,3 +554,4 @@ void ParseTuneParam(const char * const charPtr)
 }
 
 
+
diff --git a/converter/ppm/ppmtompeg/parallel.c b/converter/ppm/ppmtompeg/parallel.c
index b24764d6..fb0f2fe9 100644
--- a/converter/ppm/ppmtompeg/parallel.c
+++ b/converter/ppm/ppmtompeg/parallel.c
@@ -324,6 +324,7 @@ static void
 }
 
 
+
 /*===========================================================================*
  *
  * NotifyDecodeServerReady
@@ -446,6 +447,7 @@ int id;
 }
 
 
+
 /*===========================================================================*
  *
  * SendDecodedFrame
@@ -484,6 +486,7 @@ SendDecodedFrame(MpegFrame * const frameP) {
 }
 
 
+
 /*===========================================================================*
  *
  * GetRemoteDecodedFrame
@@ -524,6 +527,7 @@ GetRemoteDecodedRefFrame(MpegFrame * const frameP,
 }
 
 
+
 /*********
   routines handling forks, execs, PIDs and signals
   save, system-style forks
@@ -559,6 +563,8 @@ static void cleanup_fork( dummy )       /* try to kill all child processes */
   }
 }
 
+
+
 /*===========================================================================*
  *
  * safe_fork
@@ -611,6 +617,7 @@ static int safe_fork(command)       /* fork child process and remember its PID *
 }
 
 
+
 /*=====================*
  * EXPORTED PROCEDURES *
  *=====================*/
@@ -638,6 +645,7 @@ SetIOConvert(boolean const separate) {
 }
 
 
+
 /*===========================================================================*
  *
  * SetParallelPerfect
@@ -657,6 +665,7 @@ SetParallelPerfect(boolean val)
 }
 
 
+
 /*===========================================================================*
  *
  * SetRemoteShell
@@ -675,6 +684,7 @@ SetRemoteShell(const char * const shell) {
 }
 
 
+
 static void
 decodedFrameToDisk(int const otherSock) {
 /*----------------------------------------------------------------------------
@@ -1146,6 +1156,7 @@ GetRemoteFrame(MpegFrame * const frameP,
 }
 
 
+
 struct combineControl {
     unsigned int numFrames;
 };
@@ -1323,6 +1334,7 @@ CombineServer(int          const numFrames,
 }
 
 
+
 /*=====================*
  * MASTER SERVER STUFF *
  *=====================*/
diff --git a/converter/ppm/ppmtompeg/param.c b/converter/ppm/ppmtompeg/param.c
index 9499b4ea..3408c6fc 100644
--- a/converter/ppm/ppmtompeg/param.c
+++ b/converter/ppm/ppmtompeg/param.c
@@ -241,6 +241,7 @@ ReadMachineNames(FILE * const fpointer)
 }
 
 
+
 /*===========================================================================*
  *
  * GetFrameRate
@@ -1044,6 +1045,7 @@ ReadParamFile(const char *         const fileName,
 }
 
 
+
 /*
  * Copyright (c) 1995 The Regents of the University of California.
  * All rights reserved.
diff --git a/converter/ppm/ppmtompeg/pframe.c b/converter/ppm/ppmtompeg/pframe.c
index d61848b1..89aab874 100644
--- a/converter/ppm/ppmtompeg/pframe.c
+++ b/converter/ppm/ppmtompeg/pframe.c
@@ -75,6 +75,8 @@ halfVector(vector const vector) {
     return half;
 }
 
+
+
 /*===========================================================================*
  *
  *  decide if (0,0) motion is better than the given motion vector
@@ -120,6 +122,7 @@ ZeroMotionBetter(const LumBlock * const currentBlockP,
 }
 
 
+
 /*===========================================================================*
  *
  *                USER-MODIFIABLE
@@ -851,6 +854,7 @@ GenPFrame(BitBucket * const bb,
 }
 
 
+
 /*===========================================================================*
  *
  * ResetPFrameStats
@@ -876,6 +880,7 @@ void
 }
 
 
+
 /*===========================================================================*
  *
  * SetPQScale
@@ -895,6 +900,7 @@ int qP;
 }
 
 
+
 /*===========================================================================*
  *
  * GetPQScale
@@ -913,6 +919,7 @@ int
 }
 
 
+
 float
 PFrameTotalTime(void) {
     return (float)totalTime/(float)TIME_RATE;
@@ -992,6 +999,7 @@ float
 }
 
 
+
 /*===========================================================================*
  *
  * ComputeHalfPixelData
@@ -1048,6 +1056,7 @@ MpegFrame *frame;
 }
 
 
+
 /*
  * Copyright (c) 1995 The Regents of the University of California.
  * All rights reserved.
diff --git a/converter/ppm/ppmtompeg/postdct.c b/converter/ppm/ppmtompeg/postdct.c
index 68712963..f3de075a 100644
--- a/converter/ppm/ppmtompeg/postdct.c
+++ b/converter/ppm/ppmtompeg/postdct.c
@@ -261,6 +261,7 @@ Mpost_UnQuantZigBlock(in, out, qscale, iblock)
 }
 
 
+
 /*===========================================================================*
  *
  * Mpost_QuantZigBlock
@@ -460,6 +461,7 @@ Mpost_RLEHuffIBlock(in, out)
 }
 
 
+
 /*===========================================================================*
  *
  * Mpost_RLEHuffPBlock
@@ -565,6 +567,7 @@ Mpost_RLEHuffPBlock(in, out)
 }
 
 
+
 /*===========================================================================*
  *
  * CalcRLEHuffLength
@@ -624,3 +627,6 @@ CalcRLEHuffLength(in)
   countbits += 2; /* end of block marker */
   return countbits;
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/ppmtompeg.c b/converter/ppm/ppmtompeg/ppmtompeg.c
index cc2cb27e..78e33c54 100644
--- a/converter/ppm/ppmtompeg/ppmtompeg.c
+++ b/converter/ppm/ppmtompeg/ppmtompeg.c
@@ -402,7 +402,6 @@ encodeSomeFrames(struct inputSource * const inputSourceP,
 
 
 
-
 static void
 encodeFrames(struct inputSource * const inputSourceP,
              boolean              const childProcess,
@@ -507,7 +506,6 @@ encodeFrames(struct inputSource * const inputSourceP,
 
 
 
-
 static void
 runMaster(struct inputSource * const inputSourceP,
           const char *         const paramFileName,
@@ -708,3 +706,6 @@ main(int argc, char **argv) {
 
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/psearch.c b/converter/ppm/ppmtompeg/psearch.c
index de3d3e26..c82ad4ad 100644
--- a/converter/ppm/ppmtompeg/psearch.c
+++ b/converter/ppm/ppmtompeg/psearch.c
@@ -135,6 +135,7 @@ SetPixelSearch(const char * const searchType) {
 }
 
 
+
 /*===========================================================================*
  *
  * SetPSearchAlg
@@ -164,6 +165,7 @@ SetPSearchAlg(const char * const alg)
 }
 
 
+
 /*===========================================================================*
  *
  * PSearchName
@@ -198,6 +200,7 @@ PSearchName(void)
 }
 
 
+
 /*===========================================================================*
  *
  * SetSearchRange
@@ -232,6 +235,7 @@ SetSearchRange(int const pixelsP, int const pixelsB) {
 }
 
 
+
 /*===========================================================================*
  *
  *              USER-MODIFIABLE
@@ -252,6 +256,7 @@ MotionSearchPreComputation(MpegFrame * const frameP) {
 }
 
 
+
 /*===========================================================================*
  *
  * PSubSampleSearch
@@ -649,6 +654,7 @@ PLocalSearch(const LumBlock * const currentBlockP,
 }
 
 
+
 /*===========================================================================*
  *
  * PTwoLevelSearch
@@ -837,6 +843,7 @@ ShowPMVHistogram(fpointer)
 }
 
 
+
 void
 ShowBBMVHistogram(fpointer)
     FILE *fpointer;
@@ -884,6 +891,7 @@ ShowBBMVHistogram(fpointer)
 }
 
 
+
 void
 ShowBFMVHistogram(fpointer)
     FILE *fpointer;
@@ -931,6 +939,7 @@ ShowBFMVHistogram(fpointer)
 }
 
 
+
 /*
  * Copyright (c) 1995 The Regents of the University of California.
  * All rights reserved.
diff --git a/converter/ppm/ppmtompeg/qtest.c b/converter/ppm/ppmtompeg/qtest.c
index 85eda2c8..15e4e197 100644
--- a/converter/ppm/ppmtompeg/qtest.c
+++ b/converter/ppm/ppmtompeg/qtest.c
@@ -61,3 +61,6 @@ main()
 
     printf("Huffman output is %d bits\n", bb->totalbits);
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/rate.c b/converter/ppm/ppmtompeg/rate.c
index 26c30ffe..4237427e 100644
--- a/converter/ppm/ppmtompeg/rate.c
+++ b/converter/ppm/ppmtompeg/rate.c
@@ -316,6 +316,8 @@ initRateControl(bool const wantUnderflowWarning,
     return result;
 }
 
+
+
 /*===========================================================================*
  *
  * initGOPRateControl
@@ -464,7 +466,6 @@ targetRateControl(MpegFrame * const frame) {
 
 
 
-
 static void
 updateVBVBuffer(int const frameBits) {
 /*----------------------------------------------------------------------------
@@ -580,6 +581,7 @@ updateRateControl(int const type) {
 }
 
 
+
 /*===========================================================================*
  *
  * MB_RateOut
@@ -647,6 +649,7 @@ void incNumBlocks(num)
 }
 
 
+
 /*===========================================================================*
  *
  * incMacroBlockBits()
@@ -670,6 +673,7 @@ void incMacroBlockBits(num)
 }
 
 
+
 /*===========================================================================*
  *
  *      needQScaleChange(current Q scale, 4 luminance blocks)
@@ -707,6 +711,7 @@ int needQScaleChange(oldQScale, blk0, blk1, blk2, blk3)
 }
 
 
+
 /*===========================================================================*
  *
  * determineMBCount()
@@ -761,6 +766,7 @@ void checkBufferFullness (oldQScale)
 }
 
 
+
 /*===========================================================================*
  *
  * void checkSpatialActivity()
@@ -845,7 +851,6 @@ void checkSpatialActivity(blk0, blk1, blk2, blk3)
 
 
 
-
 /*============================================================================*
  *
  * getRateMode ()
@@ -864,6 +869,7 @@ int getRateMode()
 }
 
 
+
 /*===========================================================================*
  *
  * setBitRate ()
@@ -921,7 +927,6 @@ int getBitRate ()
 
 
 
-
 /*===========================================================================*
  *
  * setBufferSize ()
@@ -954,6 +959,7 @@ void setBufferSize (const char * const charPtr)
 }
 
 
+
 /*===========================================================================*
  *
  * getBufferSize ()
diff --git a/converter/ppm/ppmtompeg/readframe.c b/converter/ppm/ppmtompeg/readframe.c
index dcc02052..85f432d8 100644
--- a/converter/ppm/ppmtompeg/readframe.c
+++ b/converter/ppm/ppmtompeg/readframe.c
@@ -386,6 +386,7 @@ SetFileType(const char * const conversion)
 }
 
 
+
 /*===========================================================================*
  *
  * SetFileFormat
@@ -558,6 +559,8 @@ ReadEYUV(mf, fpointer, width, height)
     /* ignore leftover stuff on the bottom */
 }
 
+
+
 /*===========================================================================*
  *
  * ReadAYUV
@@ -616,6 +619,8 @@ ReadAYUV(mf, fpointer, width, height)
 
 }
 
+
+
 /*===========================================================================*
  *
  * SeparateLine
@@ -702,6 +707,7 @@ SeparateLine(fpointer, lineptr, width)
 }
 
 
+
 /*===========================================================================*
  *
  * ReadY
@@ -749,6 +755,7 @@ ReadY(mf, fpointer, width, height)
 }
 
 
+
 /*===========================================================================*
  *
  * ReadSub4
@@ -808,6 +815,7 @@ ReadSub4(mf, fpointer, width, height)
 }
 
 
+
 /*=====================*
  * INTERNAL PROCEDURES *
  *=====================*/
@@ -846,7 +854,6 @@ int w,h;
 
 
 
-
 /*===========================================================================*
  *
  * DoKillDim
@@ -912,6 +919,7 @@ int w,h;
 }
 
 
+
 /*
  * Copyright (c) 1995 The Regents of the University of California.
  * All rights reserved.
diff --git a/converter/ppm/ppmtompeg/rgbtoycc.c b/converter/ppm/ppmtompeg/rgbtoycc.c
index 9357c8d8..189003d7 100644
--- a/converter/ppm/ppmtompeg/rgbtoycc.c
+++ b/converter/ppm/ppmtompeg/rgbtoycc.c
@@ -108,6 +108,7 @@ compute_mult_tables(const pixval maxval) {
 }
 
 
+
 /*=====================*
  * EXPORTED PROCEDURES *
  *=====================*/
@@ -202,3 +203,6 @@ PNMtoYUV(MpegFrame *  const frameP,
         }
     }
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/specifics.c b/converter/ppm/ppmtompeg/specifics.c
index e8597978..acf98116 100644
--- a/converter/ppm/ppmtompeg/specifics.c
+++ b/converter/ppm/ppmtompeg/specifics.c
@@ -247,6 +247,8 @@ FILE *fp;
 
 }
 
+
+
 /* Version 1 */
 void Parse_Specifics_File_v1(fp)
 FILE *fp;
@@ -442,7 +444,6 @@ Parse_Specifics_File_v2(FILE * const fP) {
 
 
 
-
 /*=================================================================
  *
  *     MakeFslEntry
@@ -467,8 +468,6 @@ FrameSpecList *MakeFslEntry()
 
 
 
-
-
 /*================================================================
  *
  *   AddSlc
@@ -503,8 +502,6 @@ int snum,qs;
 
 
 
-
-
 /*================================================================
  *
  *   AddBs
@@ -544,9 +541,6 @@ int bnum,qs;
 
 
 
-
-
-
 /*================================================================
  *
  *  SpecLookup
@@ -685,6 +679,7 @@ int start_qs;
 }
 
 
+
 /*================================================================
  *
  *  SpecTypeLookup
@@ -718,3 +713,6 @@ int fn;
 #endif
   return tmp->frametype;
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/subsample.c b/converter/ppm/ppmtompeg/subsample.c
index 93b76db0..e411feb4 100644
--- a/converter/ppm/ppmtompeg/subsample.c
+++ b/converter/ppm/ppmtompeg/subsample.c
@@ -199,6 +199,7 @@ LumMotionErrorB(const LumBlock * const currentBlockP,
 }
 
 
+
 /*===========================================================================*
  *
  * LumMotionErrorC
@@ -240,6 +241,7 @@ LumMotionErrorC(const LumBlock * const currentBlockP,
 }
 
 
+
 /*===========================================================================*
  *
  * LumMotionErrorD
@@ -279,3 +281,6 @@ LumMotionErrorD(const LumBlock * const currentBlockP,
     }
     return diff;
 }
+
+
+
diff --git a/converter/ppm/ppmtoneo.c b/converter/ppm/ppmtoneo.c
index 5703c12a..d573e9e6 100644
--- a/converter/ppm/ppmtoneo.c
+++ b/converter/ppm/ppmtoneo.c
@@ -121,3 +121,6 @@ main(int argc, char *argv[] ) {
 
     exit( 0 );
 }
+
+
+
diff --git a/converter/ppm/ppmtopi1.c b/converter/ppm/ppmtopi1.c
index 64f836c7..896ec7f7 100644
--- a/converter/ppm/ppmtopi1.c
+++ b/converter/ppm/ppmtopi1.c
@@ -118,3 +118,6 @@ main( argc, argv )
 
     exit( 0 );
     }
+
+
+
diff --git a/converter/ppm/ppmtopict.c b/converter/ppm/ppmtopict.c
index 36464b6c..c7f1d61d 100644
--- a/converter/ppm/ppmtopict.c
+++ b/converter/ppm/ppmtopict.c
@@ -12,8 +12,10 @@
 */
 
 #include <assert.h>
+
 #include "pm_c_util.h"
 #include "pm.h"
+#include "mallocvar.h"
 #include "ppm.h"
 
 #define HEADER_SIZE     512
@@ -130,14 +132,15 @@
 #define PICT_headerOp       0x0C00
 
 #define MAXCOLORS 256
-static colorhash_table cht;
 
 
 
 static void
 putFill(FILE *       const ifP,
         unsigned int const n) {
-
+/*----------------------------------------------------------------------------
+   Write 'n' bytes of zeroes to *ifP.
+-----------------------------------------------------------------------------*/
     unsigned int i;
 
     for (i = 0; i < n; ++i)
@@ -194,19 +197,21 @@ putRect(FILE * const ifP,
 #define     counttochar(c)  ((c)-1)
 
 static void
-putRow(FILE *         const ofP,
-       unsigned int   const row,
-       unsigned int   const cols,
-       pixel *        const rowpixels,
-       char *         const outBuf,
-       unsigned int * const outCountP) {
+putRow(FILE *          const ofP,
+       unsigned int    const row,
+       unsigned int    const cols,
+       pixel *         const rowpixels,
+       colorhash_table const cht,
+       unsigned char * const outBuf,
+       unsigned int *  const outCountP) {
 /*----------------------------------------------------------------------------
    Write the row rowpixels[], which is 'cols' pixels wide and is row 'row' of
    the image, to file *ofP in PICT format.
 
    Return as *outCountP the number of bytes we write to *ofP.
 
-   Use buffer 'outBuf'.
+   Use buffer 'outBuf', which is at least 1.5*cols + 1 bytes -- the worst
+   case compacted size of the row.
 -----------------------------------------------------------------------------*/
     unsigned int i;
     unsigned int count;
@@ -214,13 +219,13 @@ putRow(FILE *         const ofP,
     unsigned int rep;
     unsigned int outCount;
     pixel lastpix;
-    char * p;
+    unsigned int outCursor;
 
-    run = 0;
-    count = 0;
-    lastpix = rowpixels[cols-1];
+    run = 0;  /* initial value */
+    count = 0;  /* initial value */
+    lastpix = rowpixels[cols-1];  /* initial value */
 
-    for (i = 0, p = &outBuf[0]; i < cols; ++i) {
+    for (i = 0, outCursor = 0; i < cols; ++i) {
 
         pixel const pix = rowpixels[cols - 1 - i];
 
@@ -228,23 +233,23 @@ putRow(FILE *         const ofP,
             ++run;
         else if (run < RUN_THRESH) {
             while (run > 0) {
-                *p++ = ppm_lookupcolor(cht, &lastpix);
+                outBuf[outCursor++] = ppm_lookupcolor(cht, &lastpix);
                 --run;
                 ++count;
                 if (count == MAX_COUNT) {
-                    *p++ = counttochar(MAX_COUNT);
+                    outBuf[outCursor++] = counttochar(MAX_COUNT);
                     count -= MAX_COUNT;
                 }
             }
             run = 1;
         } else {
             if (count > 0)
-                *p++ = counttochar(count);
+                outBuf[outCursor++] = counttochar(count);
             count = 0;
             while (run > 0) {
                 rep = MIN(run, MAX_RUN);
-                *p++ = ppm_lookupcolor(cht, &lastpix);
-                *p++ = runtochar(rep);
+                outBuf[outCursor++] = ppm_lookupcolor(cht, &lastpix);
+                outBuf[outCursor++] = runtochar(rep);
                 assert(run >= rep);
                 run -= rep;
             }
@@ -254,46 +259,43 @@ putRow(FILE *         const ofP,
     }
     if (run < RUN_THRESH) {
         while (run > 0) {
-            *p++ = ppm_lookupcolor(cht, &lastpix);
+            outBuf[outCursor++] = ppm_lookupcolor(cht, &lastpix);
             --run;
             ++count;
             if (count == MAX_COUNT) {
-                *p++ = counttochar(MAX_COUNT);
+                outBuf[outCursor++] = counttochar(MAX_COUNT);
                 count -= MAX_COUNT;
             }
         }
     } else {
         if (count > 0)
-            *p++ = counttochar(count);
+            outBuf[outCursor++] = counttochar(count);
         count = 0;
         while (run > 0) {
             rep = MIN(run, MAX_RUN);
-            *p++ = ppm_lookupcolor(cht, &lastpix);
-            *p++ = runtochar(rep);
+            outBuf[outCursor++] = ppm_lookupcolor(cht, &lastpix);
+            outBuf[outCursor++] = runtochar(rep);
             assert(run >= rep);
             run -= rep;
         }
         run = 1;
     }
     if (count > 0)
-        *p++ = counttochar(count);
+        outBuf[outCursor++] = counttochar(count);
 
-    {
-        unsigned int const packcols = p - outBuf;
-            /* How many we wrote */
-        if (cols-1 > 200) {
-            putShort(ofP, packcols);
-            outCount = packcols + 2;
-        } else {
-            putc(packcols, ofP);
-            outCount = packcols + 1;
-        }
-    }
-    /* now write out the packed row */
-    while (p != outBuf) {
-        --p;
-        putc(*p, ofP);
+    /* Write out the packed row */
+
+    if (cols-1 > 200) {
+        putShort(ofP, outCursor);
+        outCount = outCursor + 2;
+    } else {
+        putc(outCursor, ofP);
+        outCount = outCursor + 1;
     }
+
+    for (i = 0; i < outCursor; ++i)
+        putc(outBuf[outCursor-i-1], ofP);
+
     *outCountP = outCount;
 }
 
@@ -303,12 +305,13 @@ putRow(FILE *         const ofP,
 
 /* real dumb putRow with no compression */
 static void
-putRow(FILE *         const ifP,
-       unsigned int   const row,
-       unsigned int   const cols,
-       pixel *        const rowpixels,
-       char *         const outBuf,
-       unsigned int * const outCountP) {
+putRow(FILE *          const ifP,
+       unsigned int    const row,
+       unsigned int    const cols,
+       pixel *         const rowpixels,
+       char *          const outBuf,
+       colorhash_table const cht,
+       unsigned int *  const outCountP) {
 
     unsigned int const bc = cols + (cols + MAX_COUNT - 1) / MAX_COUNT;
 
@@ -345,20 +348,82 @@ putRow(FILE *         const ifP,
 
 
 
+static void
+writeColorMap(FILE *           const ofP,
+              colorhist_vector const chv,
+              unsigned int     const colorCt,
+              long             const lmaxval) {
+
+    unsigned int i;
+
+    for (i = 0; i < colorCt; ++i) {
+        long rval, gval, bval;
+
+        putShort(ofP, i);
+        rval = PPM_GETR(chv[i].color);
+        gval = PPM_GETG(chv[i].color);
+        bval = PPM_GETB(chv[i].color);
+        if (lmaxval != 65535L) {
+            rval = rval * 65535L / lmaxval;
+            gval = gval * 65535L / lmaxval;
+            bval = bval * 65535L / lmaxval;
+        }
+        putShort(ofP, (short)rval);
+        putShort(ofP, (short)gval);
+        putShort(ofP, (short)bval);
+    }
+}
+
+
+
+static void
+writeRaster(FILE *          const ofP,
+            pixel **        const pixels,
+            unsigned int    const rows,
+            unsigned int    const cols,
+            colorhash_table const cht) {
+
+    unsigned char * outBuf;  /* malloc'ed */
+    unsigned int oc;
+    unsigned int row;
+
+    if (cols > UINT_MAX - cols/MAX_COUNT - 1) {
+        /* We can't compute the size of buffer 'putRow' needs for worst-case
+           compaction.
+        */
+        pm_error("Image is too wide (%u columns) for computation", cols);
+    }
+
+    MALLOCARRAY(outBuf, cols + cols/MAX_COUNT + 1);
+    if (!outBuf)
+        pm_error("Unable to allocate %u-byte row buffer",
+                 cols + cols/MAX_COUNT + 1);
+
+    for (row = 0, oc = 0; row < rows; ++row) {
+        unsigned int rowSize;
+        putRow(ofP, row, cols, pixels[row], cht, outBuf, &rowSize);
+        oc += rowSize;
+    }
+    /* Pad to an even number of pixdata bytes */
+    if (oc & 0x1)
+        putc(0, ofP);
+
+    free(outBuf);
+}
+
+
+
 int
 main(int argc, const char ** argv) {
 
     FILE * ifP;
-    int nColors;
-    unsigned int oc;
-    unsigned int i;
+    int colorCt;
     int rows, cols;
-    unsigned int row;
     pixel ** pixels;
-    char * outBuf;
     pixval maxval;
-    long lmaxval, rval, gval, bval;
     colorhist_vector chv;
+    colorhash_table cht;
+    long lmaxval;
 
     pm_proginit(&argc, argv);
 
@@ -367,8 +432,8 @@ main(int argc, const char ** argv) {
     else
         ifP = stdin;
     if (argc-1 > 1)
-        pm_error("Too many arguments.  The only argument is the "
-                 "input file name");
+        pm_error("Too many arguments (%u).  The only argument is the "
+                 "input file name", argc-1);
 
     pixels = ppm_readppm(ifP, &cols, &rows, &maxval);
     if (cols < 8)
@@ -378,19 +443,19 @@ main(int argc, const char ** argv) {
 
     /* Figure out the colormap. */
     pm_message("computing colormap..." );
-    chv = ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &nColors);
+    chv = ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &colorCt);
     if (chv == NULL)
         pm_error("too many colors - try doing a 'pnmquant %u'", MAXCOLORS);
-    pm_message("%u colors found", nColors);
+    pm_message("%u colors found", colorCt);
 
     /* Make a hash table for fast color lookup. */
-    cht = ppm_colorhisttocolorhash(chv, nColors);
+    cht = ppm_colorhisttocolorhash(chv, colorCt);
 
     /* write the header */
     putFill(stdout, HEADER_SIZE);
 
     /* write picSize and picFrame */
-    putShort(stdout, 0);
+    putShort(stdout, 0);  /* We overwrite this later when we know the size */
     putRect(stdout, 0, 0, rows, cols);
 
     /* write version op and version */
@@ -427,43 +492,24 @@ main(int argc, const char ** argv) {
     putLong(stdout, 0L);    /* pmReserved */
     putLong(stdout, 0L);    /* ctSeed */
     putShort(stdout, 0);    /* ctFlags */
-    putShort(stdout, nColors-1); /* ctSize */
+    putShort(stdout, colorCt-1); /* ctSize */
 
-    /* Write out the colormap. */
-    for (i = 0; i < nColors; ++i) {
-        putShort(stdout, i);
-        rval = PPM_GETR(chv[i].color);
-        gval = PPM_GETG(chv[i].color);
-        bval = PPM_GETB(chv[i].color);
-        if (lmaxval != 65535L) {
-            rval = rval * 65535L / lmaxval;
-            gval = gval * 65535L / lmaxval;
-            bval = bval * 65535L / lmaxval;
-        }
-        putShort(stdout, (short)rval);
-        putShort(stdout, (short)gval);
-        putShort(stdout, (short)bval);
-    }
+    writeColorMap(stdout, chv, colorCt, lmaxval);
 
     putRect(stdout, 0, 0, rows, cols);  /* srcRect */
     putRect(stdout, 0, 0, rows, cols);  /* dstRect */
     putShort(stdout, 0);            /* mode */
 
-    /* Finally, write out the data. */
-    outBuf = malloc((unsigned)(cols+cols/MAX_COUNT+1));
-    for (row = 0, oc = 0; row < rows; ++row) {
-        unsigned int rowSize;
-        putRow(stdout, row, cols, pixels[row], outBuf, &rowSize);
-        oc += rowSize;
-    }
-    /* if we wrote an odd number of pixdata bytes, pad */
-    if (oc & 0x1)
-        putc(0, stdout);
+    writeRaster(stdout, pixels, rows, cols, cht);
+
     putShort(stdout, PICT_EndOfPicture);
 
-    lmaxval = ftell(stdout) - HEADER_SIZE;
-    if (fseek(stdout, (long)HEADER_SIZE, 0) >= 0)
-        putShort(stdout, (short)(lmaxval & 0xffff));
+    {
+        /* patch size of pict in */
+        long const picSz = ftell(stdout) - HEADER_SIZE;
+        if (fseek(stdout, (long)HEADER_SIZE, 0) >= 0)
+            putShort(stdout, (short)(picSz & 0xffff));
+    }
 
     return 0;
 }
diff --git a/converter/ppm/ppmtopj.c b/converter/ppm/ppmtopj.c
index d116773f..8fe6c05d 100644
--- a/converter/ppm/ppmtopj.c
+++ b/converter/ppm/ppmtopj.c
@@ -1,4 +1,4 @@
-/* ppmtopj.c - convert a portable pixmap to an HP PainJetXL image
+/* ppmtopj.c - convert a PPM to an HP PainJetXL image
 **
 ** Copyright (C) 1990 by Christos Zoulas (christos@ee.cornell.edu)
 **
@@ -12,245 +12,263 @@
 
 #include <string.h>
 
+#include "mallocvar.h"
 #include "nstring.h"
 #include "ppm.h"
 
-static int compress_row ARGS((unsigned char *op, unsigned char *oe, unsigned char *cp));
 /*
  * XXX: Only 8.5 x 11 paper
  */
-#define WIDTH	  8.5
-#define HEIGHT	  11.0
-#define DPI	  180
-#define XPIX	  ((int) ((DPI * WIDTH + 7) / 8) << 3)
-#define YPIX	  ((int) ((DPI * HEIGHT + 7) / 8) << 3)
-
-#define C_RESET 			"\033E"
-#define C_RENDER 			"\033*t%dJ"
-# define C_RENDER_NONE			0
-# define C_RENDER_SNAP			1
-# define C_RENDER_BW			2
-# define C_RENDER_DITHER		3
-# define C_RENDER_DIFFUSE		4
-# define C_RENDER_MONODITHER		5
-# define C_RENDER_MONODIFFUSE		6
-# define C_RENDER_MONO_CL_DITHER	5
-# define C_RENDER_MONO_CL_DIFFUSE	6
-#define C_BACK_SCALE			"\033*t%dK"
-# define C_BACK_SCALE_LIGHT		0
-# define C_BACK_SCALE_DARK		1
-#define C_GAMMA				"\033*t%dI"
-#define C_IMAGE_WIDTH			"\033*r%dS"
-#define C_IMAGE_HEIGHT			"\033*r%dT"
-#define C_DATA_PLANES			"\033*r%dU"
-#define C_TRANS_MODE			"\033*b%dM"
-# define C_TRANS_MODE_STD		0
-# define C_TRANS_MODE_RLE		1
-# define C_TRANS_MODE_TIFF		2
-#define C_SEND_PLANE			"\033*b%dV"
-#define C_LAST_PLANE			"\033*b%dW"
-#define C_BEGIN_RASTER			"\033*r%dA"
-# define C_BEGIN_RASTER_MARGIN		0
-# define C_BEGIN_RASTER_ACTIVE		1
-# define C_BEGIN_RASTER_NOSCALE		0
-# define C_BEGIN_RASTER_SCALE		2
-#define C_END_RASTER			"\033*r%dC"
-# define C_END_RASTER_UNUSED		0
-#define C_RESOLUTION			"\033*t%dR"
-# define C_RESOLUTION_90DPI		90
-# define C_RESOLUTION_180DPI		180
-#define C_MOVE_X			"\033*p+%dX"
-#define C_MOVE_Y			"\033*p+%dY"
-
-static const char * const rmode[] = { 
-    "none", "snap", "bw", "dither", "diffuse", 
-    "monodither", "monodiffuse", "clusterdither", 
-    "monoclusterdither", NULL 
+#define WIDTH     8.5
+#define HEIGHT    11.0
+#define DPI   180
+#define XPIX      ((int) ((DPI * WIDTH + 7) / 8) << 3)
+#define YPIX      ((int) ((DPI * HEIGHT + 7) / 8) << 3)
+
+#define C_RESET             "\033E"
+#define C_RENDER            "\033*t%dJ"
+# define C_RENDER_NONE          0
+# define C_RENDER_SNAP          1
+# define C_RENDER_BW            2
+# define C_RENDER_DITHER        3
+# define C_RENDER_DIFFUSE       4
+# define C_RENDER_MONODITHER        5
+# define C_RENDER_MONODIFFUSE       6
+# define C_RENDER_MONO_CL_DITHER    5
+# define C_RENDER_MONO_CL_DIFFUSE   6
+#define C_BACK_SCALE            "\033*t%dK"
+# define C_BACK_SCALE_LIGHT     0
+# define C_BACK_SCALE_DARK      1
+#define C_GAMMA             "\033*t%dI"
+#define C_IMAGE_WIDTH           "\033*r%dS"
+#define C_IMAGE_HEIGHT          "\033*r%dT"
+#define C_DATA_PLANES           "\033*r%dU"
+#define C_TRANS_MODE            "\033*b%dM"
+# define C_TRANS_MODE_STD       0
+# define C_TRANS_MODE_RLE       1
+# define C_TRANS_MODE_TIFF      2
+#define C_SEND_PLANE            "\033*b%dV"
+#define C_LAST_PLANE            "\033*b%dW"
+#define C_BEGIN_RASTER          "\033*r%dA"
+# define C_BEGIN_RASTER_MARGIN      0
+# define C_BEGIN_RASTER_ACTIVE      1
+# define C_BEGIN_RASTER_NOSCALE     0
+# define C_BEGIN_RASTER_SCALE       2
+#define C_END_RASTER            "\033*r%dC"
+# define C_END_RASTER_UNUSED        0
+#define C_RESOLUTION            "\033*t%dR"
+# define C_RESOLUTION_90DPI     90
+# define C_RESOLUTION_180DPI        180
+#define C_MOVE_X            "\033*p+%dX"
+#define C_MOVE_Y            "\033*p+%dY"
+
+static const char * const rmode[] = {
+    "none",
+    "snap",
+    "bw",
+    "dither",
+    "diffuse",
+    "monodither",
+    "monodiffuse",
+    "clusterdither",
+    "monoclusterdither",
+    NULL
 };
 
-/*
- * Run-length encoding for the PaintJet. We have pairs of <instances>
- * <value>, where instances goes from 0 (meaning one instance) to 255
- * If we are unlucky we can double the size of the image.
- */
-static int
-compress_row(op, oe, cp)
-unsigned char *op, *oe, *cp;
-{
-    unsigned char *ce = cp;
-    while ( op < oe ) {	
-	unsigned char px = *op++;
-	unsigned char *pr = op;
-	while ( op < oe && *op == px && op - pr < 255) op++;
-	*ce++ = op - pr;
-	*ce++ = px;
+
+
+static void
+compressRow(const unsigned char * const opArg,
+            const unsigned char * const oe,
+            unsigned char *       const cp,
+            int *                 const szP) {
+/*----------------------------------------------------------------------------
+  Run-length encoding for the PaintJet. We have pairs of <instances> <value>,
+  where instances goes from 0 (meaning one instance) to 255 If we are unlucky
+  we can double the size of the image.
+-----------------------------------------------------------------------------*/
+    unsigned char * ce;
+    const unsigned char * op;
+
+    for (op = opArg, ce = cp; op < oe; ) {
+        unsigned char         const px = *op++;
+        const unsigned char * const pr = op;
+
+        while (op < oe && *op == px && op - pr < 255)
+            ++op;
+
+        *ce++ = op - pr;
+        *ce++ = px;
     }
-    return ce - cp;
+    *szP = ce - cp;
 }
 
-int main(argc, argv)
-int argc;
-char *argv[];
-{
-	pixel **pixels;
-	FILE *ifp;
-	int argn, rows, cols, r, c, k, p;
-	pixval maxval;
-	unsigned char *obuf, *op, *cbuf;
-	int render_mode = C_RENDER_NONE;
-	int back_scale = C_BACK_SCALE_DARK;
-	int gamma = 0;
-	int mode = C_TRANS_MODE_STD;
-	int center = 0;
-	int xoff = 0, yoff = 0;
-	/*
-	 * XXX: Someday we could make this command line options.
-	 */
-	int posscale = C_BEGIN_RASTER_MARGIN | C_BEGIN_RASTER_NOSCALE;
-	int resolution = C_RESOLUTION_180DPI;
-
-	const char * const usage = "[-center] [-xpos <pos>] [-ypos <pos>] [-gamma <val>] [-back <dark|lite>] [-rle] [-render <none|snap|bw|dither|diffuse|monodither|monodiffuse|clusterdither|monoclusterdither>] [ppmfile]";
-
-
-	ppm_init( &argc, argv );
-
-	argn = 1;
-	while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
-	    {
-	    if ( pm_keymatch(argv[argn],"-render",2) && argn + 1 < argc )
-		{
-		++argn;
-		for (r = 0; rmode[r] != NULL; r++)
-		     if (streq(rmode[r], argv[argn]))
-			 break;
-		if (rmode[r] != NULL)
-		    render_mode = r;
-		else
-		    pm_usage(usage);
-		}
-	    else if ( pm_keymatch(argv[argn],"-back",2) && argn + 1 < argc )
-		{
-		++argn;
-		if (streq(argv[argn], "dark"))
-		    back_scale = C_BACK_SCALE_DARK;
-		else if (streq(argv[argn], "lite"))
-		    back_scale = C_BACK_SCALE_LIGHT;
-		else
-		    pm_usage(usage);
-		}
-	    else if ( pm_keymatch(argv[argn],"-gamma",2) && argn + 1 < argc )
-		{
-		++argn;
-		if ( sscanf( argv[argn], "%d",&gamma ) != 1 )
-		    pm_usage( usage );
-		}
-	    else if ( pm_keymatch(argv[argn],"-xpos",2) && argn + 1 < argc )
-		{
-		++argn;
-		if ( sscanf( argv[argn], "%d",&xoff ) != 1 )
-		    pm_usage( usage );
-		}
-	    else if ( pm_keymatch(argv[argn],"-ypos",2) && argn + 1 < argc )
-		{
-		++argn;
-		if ( sscanf( argv[argn], "%d",&yoff ) != 1 )
-		    pm_usage( usage );
-		}
-	    else if (pm_keymatch(argv[argn],"-rle",2))
-		mode = C_TRANS_MODE_RLE;
-	    else if (pm_keymatch(argv[argn],"-center",2))
-		center = 1;
-	    else
-		pm_usage( usage );
-	    ++argn;
-	    }
-
-	if ( argn < argc )
-	    {
-	    ifp = pm_openr( argv[argn] );
-	    ++argn;
-	    }
-	else
-	    ifp = stdin;
-
-	if ( argn != argc )
-	    pm_usage( usage );
-
-	pixels = ppm_readppm( ifp, &cols, &rows, &maxval );
-
-	pm_close( ifp );
-	obuf = (unsigned char *) pm_allocrow(cols, sizeof(unsigned char));
-	cbuf = (unsigned char *) pm_allocrow(cols * 2, sizeof(unsigned char));
-
-        if (cols > XPIX || rows > YPIX)
-	    pm_message("image too large for page");
-        if (center) {
-	    if (xoff || yoff)
-		pm_error("cannot specify both center and position");
-	    xoff = (XPIX - cols) / 2;
-	    yoff = (YPIX - rows) / 2;
-	}
-
-	(void) printf(C_RESET);
-	/*
-	 * Set the resolution before begin raster otherwise it
-	 * does not work.
-	 */
-	(void) printf(C_RESOLUTION, resolution);
-	(void) printf(C_BEGIN_RASTER, posscale);
-	if (xoff)
-	    (void) printf(C_MOVE_X, xoff);
-	if (yoff)
-	    (void) printf(C_MOVE_Y, yoff);
-	(void) printf(C_TRANS_MODE, mode);
-	(void) printf(C_RENDER, render_mode);
-	(void) printf(C_BACK_SCALE, back_scale);
-	(void) printf(C_GAMMA,	 gamma);
-	(void) printf(C_IMAGE_WIDTH, cols);
-	(void) printf(C_IMAGE_HEIGHT, rows);
-	(void) printf(C_DATA_PLANES, 3);
-
-        for (r = 0; r < rows; r++)
-	    /* for each primary */
-	    for (p = 0; p < 3; p++) {
-		switch (p) {
-		case 0:
-		    for (c = 0, op = &obuf[-1]; c < cols; c++) {
-			if ((k = (c & 7)) == 0)
-			    *++op = 0;
-			if (PPM_GETR(pixels[r][c]) > maxval / 2)
-			    *op |= 1 << (7 - k);
-		    }
-		    break;
-		case 1:
-		    for (c = 0, op = &obuf[-1]; c < cols; c++) {
-			if ((k = (c & 7)) == 0)
-			    *++op = 0;
-			if (PPM_GETG(pixels[r][c]) > maxval / 2)
-			    *op |= 1 << (7 - k);
-		    }
-		    break;
-		case 2:
-		    for (c = 0, op = &obuf[-1]; c < cols; c++) {
-			if ((k = (c & 7)) == 0)
-			    *++op = 0;
-			if (PPM_GETB(pixels[r][c]) > maxval / 2)
-			    *op |= 1 << (7 - k);
-		    }
-		    break;
-		}
-		++op;
-		if (mode == C_TRANS_MODE_RLE) {
-		    k = compress_row(obuf, op, cbuf);
-		    op = cbuf;
-		}
-		else {
-		    k = op - obuf;
-		    op = obuf;
-		}
-		(void) printf(p == 2 ? C_LAST_PLANE : C_SEND_PLANE, k);
-		(void) fwrite(op, 1, k, stdout);
-	    }
-	(void) printf(C_END_RASTER, C_END_RASTER_UNUSED);
-	exit(0);
+
+
+int
+main(int argc, const char ** argv) {
+
+    pixel ** pixels;
+    FILE * ifP;
+    int argn, rows, cols, k;
+    unsigned int row;
+    pixval maxval;
+    unsigned char *obuf, *op, *cbuf;
+    int render_mode = C_RENDER_NONE;
+    int back_scale = C_BACK_SCALE_DARK;
+    int gamma = 0;
+    int mode = C_TRANS_MODE_STD;
+    int center = 0;
+    int xoff = 0, yoff = 0;
+    /*
+     * XXX: Someday we could make this command line options.
+     */
+    int const posscale = C_BEGIN_RASTER_MARGIN | C_BEGIN_RASTER_NOSCALE;
+    int const resolution = C_RESOLUTION_180DPI;
+
+    const char * const usage = "[-center] [-xpos <pos>] [-ypos <pos>] [-gamma <val>] [-back <dark|lite>] [-rle] [-render <none|snap|bw|dither|diffuse|monodither|monodiffuse|clusterdither|monoclusterdither>] [ppmfile]";
+
+
+    pm_proginit( &argc, argv );
+
+    argn = 1;
+    while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
+        {
+        if ( pm_keymatch(argv[argn],"-render",2) && argn + 1 < argc )
+        {
+        unsigned int r;
+        ++argn;
+        for (r = 0; rmode[r] != NULL; r++)
+             if (streq(rmode[r], argv[argn]))
+             break;
+        if (rmode[r] != NULL)
+            render_mode = r;
+        else
+            pm_usage(usage);
+        }
+        else if ( pm_keymatch(argv[argn],"-back",2) && argn + 1 < argc )
+        {
+        ++argn;
+        if (streq(argv[argn], "dark"))
+            back_scale = C_BACK_SCALE_DARK;
+        else if (streq(argv[argn], "lite"))
+            back_scale = C_BACK_SCALE_LIGHT;
+        else
+            pm_usage(usage);
+        }
+        else if ( pm_keymatch(argv[argn],"-gamma",2) && argn + 1 < argc )
+        {
+        ++argn;
+        if ( sscanf( argv[argn], "%d",&gamma ) != 1 )
+            pm_usage( usage );
+        }
+        else if ( pm_keymatch(argv[argn],"-xpos",2) && argn + 1 < argc )
+        {
+        ++argn;
+        if ( sscanf( argv[argn], "%d",&xoff ) != 1 )
+            pm_usage( usage );
+        }
+        else if ( pm_keymatch(argv[argn],"-ypos",2) && argn + 1 < argc )
+        {
+        ++argn;
+        if ( sscanf( argv[argn], "%d",&yoff ) != 1 )
+            pm_usage( usage );
+        }
+        else if (pm_keymatch(argv[argn],"-rle",2))
+        mode = C_TRANS_MODE_RLE;
+        else if (pm_keymatch(argv[argn],"-center",2))
+        center = 1;
+        else
+        pm_usage( usage );
+        ++argn;
+        }
+
+    if ( argn < argc )
+        {
+        ifP = pm_openr( argv[argn] );
+        ++argn;
+        }
+    else
+        ifP = stdin;
+
+    if ( argn != argc )
+        pm_usage( usage );
+
+    pixels = ppm_readppm(ifP, &cols, &rows, &maxval);
+
+    pm_close(ifP);
+
+    MALLOCARRAY_NOFAIL(obuf, cols);
+
+    if (cols > UINT_MAX / 2)
+        pm_error("Image too wide (%u columns) for computation", cols);
+
+    MALLOCARRAY_NOFAIL(cbuf, cols * 2);
+
+    if (cols > XPIX || rows > YPIX)
+        pm_message("image too large for page");
+
+    if (center) {
+        if (xoff || yoff)
+        pm_error("cannot specify both center and position");
+        xoff = (XPIX - cols) / 2;
+        yoff = (YPIX - rows) / 2;
+    }
+
+    printf(C_RESET);
+    /*
+     * Set the resolution before begin raster otherwise it
+     * does not work.
+     */
+    printf(C_RESOLUTION, resolution);
+    printf(C_BEGIN_RASTER, posscale);
+    if (xoff)
+        printf(C_MOVE_X, xoff);
+    if (yoff)
+        printf(C_MOVE_Y, yoff);
+    printf(C_TRANS_MODE, mode);
+    printf(C_RENDER, render_mode);
+    printf(C_BACK_SCALE, back_scale);
+    printf(C_GAMMA,   gamma);
+    printf(C_IMAGE_WIDTH, cols);
+    printf(C_IMAGE_HEIGHT, rows);
+    printf(C_DATA_PLANES, 3);
+
+    for (row = 0; row < rows; ++row) {
+        /* for each primary */
+        unsigned int plane;
+        for (plane = 0; plane < 3; ++plane) {
+            unsigned int col;
+
+            for (col = 0, op = &obuf[-1]; col < cols; ++col) {
+                pixel  const p = pixels[row][col];
+                pixval const comp =
+                    plane == 0 ? PPM_GETR(p) :
+                    plane == 1 ? PPM_GETG(p) :
+                    plane == 2 ? PPM_GETB(p) :
+                    0; /* can't happen */
+
+                if ((k = (col & 0x7)) == 0)
+                    *++op = 0;
+                if (comp > maxval / 2)
+                        *op |= 1 << (7 - k);
+            }
+            ++op;
+            if (mode == C_TRANS_MODE_RLE) {
+                compressRow(obuf, op, cbuf, &k);
+                op = cbuf;
+            } else {
+                k = op - obuf;
+                op = obuf;
+            }
+            printf(plane == 2 ? C_LAST_PLANE : C_SEND_PLANE, k);
+            fwrite(op, 1, k, stdout);
+        }
+    }
+    printf(C_END_RASTER, C_END_RASTER_UNUSED);
+
+    exit(0);
 }
+
+
+
diff --git a/converter/ppm/ppmtopjxl.c b/converter/ppm/ppmtopjxl.c
index 90bcef0f..daaf7d59 100644
--- a/converter/ppm/ppmtopjxl.c
+++ b/converter/ppm/ppmtopjxl.c
@@ -1,7 +1,7 @@
 /* ppmtopcl.c - convert PPM into PCL language for HP PaintJet and
  *              PaintJet XL color printers
  * AJCD 12/3/91
- * 
+ *
  * usage:
  *       ppmtopcl [-nopack] [-gamma <n>] [-presentation] [-dark]
  *          [-diffuse] [-cluster] [-dither]
@@ -18,6 +18,7 @@
 #include <string.h>
 
 #include "pm_c_util.h"
+#include "mallocvar.h"
 #include "nstring.h"
 #include "ppm.h"
 #include "runlength.h"
@@ -47,7 +48,7 @@ static int yshift = 0;
 static int quality = 0;
 static double xscale = 0.0;
 static double yscale = 0.0;
-static double gamma_val = 0.0;
+static double gammaVal = 0.0;
 
 /* argument types */
 #define DIM 0
@@ -58,7 +59,7 @@ static const struct options {
     int type;
     void *value;
 } options[] = {
-   {"-gamma",        REAL, &gamma_val },
+   {"-gamma",        REAL, &gammaVal },
    {"-presentation", BOOL, &quality },
    {"-width",        DIM,  &xsize },
    {"-xsize",        DIM,  &xsize },
@@ -86,12 +87,12 @@ putword(unsigned short const w) {
 
 
 static unsigned int
-bitsperpixel(unsigned int v) {
+bitwidth(unsigned int v) {
 
     unsigned int bpp;
 
     /* calculate # bits for value */
-    
+
     for (bpp = 0; v > 0; ) {
         ++bpp;
         v >>= 1;
@@ -101,83 +102,350 @@ bitsperpixel(unsigned int v) {
 
 
 
-static char *inrow = NULL;
-static char *outrow = NULL;
-/* "signed" was commented out below, but it caused warnings on an SGI 
+/* The following belong to the bit putter.  They really should be in a
+   struct passed to the methods of the bit putter instead.
+*/
+
+static char *inrow;
+static char *outrow;
+/* "signed" was commented out below, but it caused warnings on an SGI
    compiler, which defaulted to unsigned character.  2001.03.30 BJH */
-static signed char *runcnt = NULL;
+static signed char * runcnt;
+static int out = 0;
+static int cnt = 0;
+static int num = 0;
+static bool pack = false;
+
+static void
+initbits(unsigned int const bytesPerRow) {
+
+    MALLOCARRAY(inrow,  bytesPerRow);
+    MALLOCARRAY(outrow, bytesPerRow * 2);
+    MALLOCARRAY(runcnt, bytesPerRow);
+
+    if (!inrow || !outrow || !runcnt)
+        pm_error("can't allocate space for row");
+}
+
+
+
+static void
+termbits() {
+
+    free(runcnt);
+    free(outrow);
+    free(inrow);
+}
 
-static void 
-putbits(int const bArg,
-        int const nArg) {
+
+
+static void
+putbits(unsigned int const bArg,
+        unsigned int const nArg) {
 /*----------------------------------------------------------------------------
-  Put 'n' bits in 'b' out, packing into bytes; n=0 flushes bits.
+  Add 'bArg' to byte-packing output buffer as 'n' bits.
 
-  n should never be > 8 
+  n should never be > 8
 -----------------------------------------------------------------------------*/
-    static int out = 0;
-    static int cnt = 0;
-    static int num = 0;
-    static bool pack = false;
-
     int b;
     int n;
+    int xo;
+    int xc;
 
     b = bArg;
     n = nArg;
 
-    if (n) {
-        int xo = 0;
-        int xc = 0;
+    assert(n <= 8);
+
+    if (cnt + n > 8) {  /* overflowing current byte? */
+        xc = cnt + n - 8;
+        xo = (b & ~(-1 << xc)) << (8-xc);
+        n -= xc;
+        b >>= xc;
+    } else {
+        xo = 0;
+        xc = 0;
+    }
+
+    cnt += n;
 
-        assert(n <= 8);
+    out |= (b & ~(-1 << n)) << (8-cnt);
 
-        if (cnt + n > 8) {  /* overflowing current byte? */
-            xc = cnt + n - 8;
-            xo = (b & ~(-1 << xc)) << (8-xc);
-            n -= xc;
-            b >>= xc;
-        }
-        cnt += n;
-        out |= (b & ~(-1 << n)) << (8-cnt);
-        if (cnt >= 8) {
-            inrow[num++] = out;
-            out = xo;
-            cnt = xc;
+    if (cnt >= 8) {
+        inrow[num++] = out;
+        out = xo;
+        cnt = xc;
+    }
+}
+
+
+
+static void
+flushbits() {
+/*----------------------------------------------------------------------------
+   flush a row of buffered bits.
+-----------------------------------------------------------------------------*/
+    if (cnt) {
+        inrow[num++] = out;
+        out = cnt = 0;
+    }
+    for (; num > 0 && inrow[num-1] == 0; --num);
+    /* remove trailing zeros */
+    printf("\033*b");
+    if (num && !nopack) {            /* TIFF 4.0 packbits encoding */
+        size_t outSize;
+        pm_rlenc_compressbyte(
+            (unsigned char *)inrow, (unsigned char *)outrow,
+            PM_RLE_PACKBITS, num, &outSize);
+        if (outSize < num) {
+            num = outSize;
+            if (!pack) {
+                printf("2m");
+                pack = true;
+            }
+        } else {
+            if (pack) {
+                printf("0m");
+                pack = false;
+            }
         }
-    } else { /* flush row */
-        if (cnt) {
-            inrow[num++] = out;
-            out = cnt = 0;
+    }
+    printf("%dW", num);
+    {
+        unsigned int i;
+        for (i = 0; i < num; ++i)
+            putchar(pack ? outrow[i] : inrow[i]);
+    }
+    num = 0; /* new row */
+}
+
+
+
+static void
+computeColormap(pixel **           const pixels,
+                unsigned int       const cols,
+                unsigned int       const rows,
+                unsigned int       const maxColors,
+                colorhist_vector * const chvP,
+                colorhash_table *  const chtP,
+                unsigned int *     const colorCtP) {
+
+    colorhist_vector chv;
+    colorhash_table cht;
+    int colorCt;
+
+    pm_message("Computing colormap...");
+
+    chv = ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &colorCt);
+    if (!chv)
+        pm_error("too many colors; reduce to %u or fewer with 'pnmquant'",
+                 MAXCOLORS);
+
+    pm_message("... Done.  %u colors found.", colorCt);
+
+    /* And make a hash table for fast lookup. */
+    cht = ppm_colorhisttocolorhash(chv, colorCt);
+
+    *chvP     = chv;
+    *chtP     = cht;
+    *colorCtP = colorCt;
+}
+
+
+
+static unsigned int
+nextPowerOf2(unsigned int const arg) {
+/*----------------------------------------------------------------------------
+   Works only on 0-7
+-----------------------------------------------------------------------------*/
+        switch (arg) { /* round up to 1,2,4,8 */
+        case 0:                         return 0; break;
+        case 1:                         return 1; break;
+        case 2:                         return 2; break;
+        case 3: case 4:                 return 4; break;
+        case 5: case 6: case 7: case 8: return 8; break;
+        default:
+            assert(false);
         }
-        for (; num > 0 && inrow[num-1] == 0; --num);
-            /* remove trailing zeros */
-        printf("\033*b"); 
-        if (num && !nopack) {            /* TIFF 4.0 packbits encoding */
-            size_t outSize;
-            pm_rlenc_compressbyte(
-                (unsigned char *)inrow, (unsigned char *)outrow,
-                PM_RLE_PACKBITS, num, &outSize); 
-            if (outSize < num) {
-                num = outSize;
-                if (!pack) {
-                    printf("2m");
-                    pack = true;
-                }
-            } else {
-                if (pack) {
-                    printf("0m");
-                    pack = false;
-                }
+}
+
+
+
+static void
+computeColorDownloadingMode(unsigned int   const colorCt,
+                            unsigned int   const cols,
+                            pixval         const maxval,
+                            unsigned int * const bytesPerRowP,
+                            bool *         const colorMappedP,
+                            unsigned int * const bitsPerPixelRedP,
+                            unsigned int * const bitsPerPixelGrnP,
+                            unsigned int * const bitsPerPixelBluP,
+                            unsigned int * const bitsPerIndexP) {
+/*----------------------------------------------------------------------------
+-----------------------------------------------------------------------------*/
+    unsigned int const indexBitCt = bitwidth(colorCt);
+
+    assert(colorCt > 0);
+    assert(indexBitCt > 0);
+
+    if (indexBitCt > 8) {
+        /* Can't use indexed mode */
+        /* We will instead write 1-3 full bytes per pixel, with those
+           bytes divided into red bits, green bits, and blue bits.  We
+           pad the red bits as needed to fill out whole bytes.  We
+           stick to 1, 2, 4, or 8 bits per pixel only because this program's
+           bit writer can't handle more than 8, which would happen with those
+           padded red fields if we allowed e.g. 7 bits for green and blue
+           (ergo 10 bits for red).
+        */
+        unsigned int const bitsPerSample = nextPowerOf2(bitwidth(maxval));
+        unsigned int const bitsPerPixel  = ROUNDUP(3 * bitsPerSample, 8);
+        unsigned int const bytesPerPixel = bitsPerPixel / 8;
+
+        *colorMappedP     = false;
+        *bitsPerPixelGrnP = bitsPerSample;
+        *bitsPerPixelBluP = bitsPerSample;
+        *bitsPerPixelRedP =
+            bitsPerPixel - *bitsPerPixelGrnP - *bitsPerPixelBluP;
+        *bytesPerRowP = bytesPerPixel * cols;
+    } else {
+        unsigned int const bitsPerPixel = nextPowerOf2(indexBitCt);
+
+        unsigned int pixelsPerByte;
+
+        *colorMappedP = true;
+
+        *bitsPerIndexP = bitsPerPixel;
+        pixelsPerByte = 8 / bitsPerPixel;
+        *bytesPerRowP = (cols + pixelsPerByte - 1) / pixelsPerByte;
+    }
+    if (*colorMappedP)
+        pm_message("Writing %u bit color indices", *bitsPerIndexP);
+    else
+        pm_message("Writing direct color, %u red bits, %u green, %u blue",
+                   *bitsPerPixelRedP, *bitsPerPixelGrnP, *bitsPerPixelBluP);
+}
+
+
+
+static void
+writePclHeader(unsigned int const cols,
+               unsigned int const rows,
+               pixval       const maxval,
+               int          const xshift,
+               int          const yshift,
+               unsigned int const quality,
+               unsigned int const xsize,
+               unsigned int const ysize,
+               double       const gammaVal,
+               unsigned int const dark,
+               unsigned int const render,
+               bool         const colorMapped,
+               unsigned int const bitsPerPixelRed,
+               unsigned int const bitsPerPixelGrn,
+               unsigned int const bitsPerPixelBlu,
+               unsigned int const bitsPerIndex) {
+
+#if 0
+    printf("\033&l26A");                         /* paper size */
+#endif
+    printf("\033*r%us%uT", cols, rows);          /* source width, height */
+    if (xshift != 0 || yshift != 0)
+        printf("\033&a%+dh%+dV", xshift, yshift); /* xshift, yshift */
+    if (quality)
+        printf("\033*o%uQ", quality);             /* print quality */
+    printf("\033*t");
+    if (xsize == 0 && ysize == 0)
+        printf("180r");                   /* resolution */
+    else {                               /* destination width, height */
+        if (xsize != 0)
+            printf("%uh", xsize);
+        if (ysize != 0)
+            printf("%uv", ysize);
+    }
+    if (gammaVal != 0)
+        printf("%.3fi", gammaVal);                    /* gamma correction */
+    if (dark)
+        printf("%uk", dark);              /* scaling algorithms */
+    printf("%uJ", render);               /* rendering algorithm */
+    printf("\033*v18W");                           /* configure image data */
+    putchar(0); /* relative colors */
+    putchar(colorMapped ? 1 : 3); /* index/direct pixel mode */
+    putchar(bitsPerIndex); /* ignored in direct pixel mode */
+    putchar(colorMapped ? 0 : bitsPerPixelRed);
+    putchar(colorMapped ? 0 : bitsPerPixelGrn);
+    putchar(colorMapped ? 0 : bitsPerPixelBlu);
+    putword(maxval); /* max red reference */
+    putword(maxval); /* max green reference */
+    putword(maxval); /* max blue reference */
+    putword(0); /* min red reference */
+    putword(0); /* min green reference */
+    putword(0); /* min blue reference */
+}
+
+
+
+static void
+writePalette(colorhist_vector const chv,
+             unsigned int     const colorCt) {
+
+    unsigned int i;
+
+    for (i = 0; i < colorCt; ++i) {
+        unsigned int const r = PPM_GETR( chv[i].color);
+        unsigned int const g = PPM_GETG( chv[i].color);
+        unsigned int const b = PPM_GETB( chv[i].color);
+
+        if (i == 0)
+            printf("\033*v");
+        if (r)
+            printf("%ua", r);
+        if (g)
+            printf("%ub", g);
+        if (b)
+            printf("%uc", b);
+        if (i == colorCt - 1)
+            printf("%uI", i);    /* assign color index */
+        else
+            printf("%ui", i);    /* assign color index */
+    }
+}
+
+
+
+static void
+writeRaster(pixel **        const pixels,
+            unsigned int    const rows,
+            unsigned int    const cols,
+            colorhash_table const cht,
+            bool            const colorMapped,
+            unsigned int    const bitsPerIndex,
+            unsigned int    const bitsPerPixelRed,
+            unsigned int    const bitsPerPixelGrn,
+            unsigned int    const bitsPerPixelBlu) {
+
+    unsigned int row;
+
+    for (row = 0; row < rows; ++row) {
+        pixel * const pixrow = pixels[row];
+
+        if (colorMapped) {
+            unsigned int col;
+
+            for (col = 0; col < cols; ++col)
+                putbits(ppm_lookupcolor(cht, &pixrow[col]), bitsPerIndex);
+            flushbits();
+        } else {
+            unsigned int col;
+
+            for (col = 0; col < cols; ++col) {
+                putbits(PPM_GETR(pixrow[col]), bitsPerPixelRed);
+                putbits(PPM_GETG(pixrow[col]), bitsPerPixelGrn);
+                putbits(PPM_GETB(pixrow[col]), bitsPerPixelBlu);
+                /* don't need to flush */
             }
+            flushbits();
         }
-        printf("%dW", num);
-        {
-            unsigned int i;
-            for (i = 0; i < num; ++i)
-                putchar(pack ? outrow[i] : inrow[i]);
-        }
-        num = 0; /* new row */
     }
 }
 
@@ -188,16 +456,17 @@ main(int argc, const char * argv[]) {
 
     FILE * ifP;
     pixel ** pixels;
-    unsigned int row;
-    unsigned int bpp;
     int rows, cols;
     pixval maxval;
-    int bpr, bpg, bpb;
+    bool colorMapped;
+    unsigned int bytesPerRow;
+    unsigned int bitsPerPixelRed, bitsPerPixelGrn, bitsPerPixelBlu;
+    unsigned int bitsPerIndex;
     int render;
-    int colors, pclindex;
+    unsigned int colorCt;
     colorhist_vector chv;
     colorhash_table cht;
-   
+
     pm_proginit(&argc, argv);
 
     while (argc > 1 && argv[1][0] == '-') {
@@ -267,42 +536,14 @@ main(int argc, const char * argv[]) {
     if (maxval > PCL_MAXVAL)
         pm_error("color range too large; reduce with ppmcscale");
 
-    /* Figure out the colormap. */
-    pm_message("Computing colormap...");
-    chv = ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &colors);
-    if (!chv)
-        pm_error("too many colors; reduce with pnmquant");
-    pm_message("... Done.  %u colors found.", colors);
+    computeColormap(pixels, cols, rows, MAXCOLORS, &chv, &cht, &colorCt);
 
-    /* And make a hash table for fast lookup. */
-    cht = ppm_colorhisttocolorhash(chv, colors);
-
-    /* work out color downloading mode */
-    pclindex = bitsperpixel(colors);
-    if (pclindex > 8) /* can't use indexed mode */
-        pclindex = 0;
-    else {
-        switch (pclindex) { /* round up to 1,2,4,8 */
-        case 0: /* direct mode (no palette) */
-            bpp = bitsperpixel(maxval); /* bits per pixel */
-            bpg = bpp; bpb = bpp;
-            bpp = (bpp*3+7)>>3;     /* bytes per pixel now */
-            bpr = (bpp<<3)-bpg-bpb; 
-            bpp *= cols;            /* bytes per row now */
-            break;
-        case 5:         pclindex++;
-        case 6:         pclindex++;
-        case 3: case 7: pclindex++;
-        default:
-            bpp = 8/pclindex;
-            bpp = (cols+bpp-1)/bpp;      /* bytes per row */
-        }
-    }
-    inrow = (char *)malloc((unsigned)bpp);
-    outrow = (char *)malloc((unsigned)bpp*2);
-    runcnt = (signed char *)malloc((unsigned)bpp);
-    if (inrow == NULL || outrow == NULL || runcnt == NULL)
-        pm_error("can't allocate space for row");
+    computeColorDownloadingMode(
+        colorCt, cols, maxval,
+        &bytesPerRow, &colorMapped,
+        &bitsPerPixelRed, &bitsPerPixelGrn, &bitsPerPixelBlu, &bitsPerIndex);
+
+    initbits(bytesPerRow);
 
     /* set up image details */
     if (xscale != 0.0)
@@ -310,92 +551,31 @@ main(int argc, const char * argv[]) {
     if (yscale != 0.0)
         ysize = rows * yscale * 4;
 
-    /* write PCL header */
-#if 0
-    printf("\033&l26A");                         /* paper size */
-#endif
-    printf("\033*r%ds%dT", cols, rows);          /* source width, height */
-    if (xshift != 0 || yshift != 0)
-        printf("\033&a%+dh%+dV", xshift, yshift); /* xshift, yshift */
-    if (quality)
-        printf("\033*o%dQ", quality);             /* print quality */
-    printf("\033*t");
-    if (xsize == 0 && ysize == 0)
-        printf("180r");                   /* resolution */
-    else {                               /* destination width, height */
-        if (xsize != 0)
-            printf("%dh", xsize);
-        if (ysize != 0)
-            printf("%dv", ysize);
-    }
-    if (gamma_val != 0)
-        printf("%.3fi", gamma_val);                    /* gamma correction */
-    if (dark)
-        printf("%dk", dark);              /* scaling algorithms */
-    printf("%dJ", render);               /* rendering algorithm */
-    printf("\033*v18W");                           /* configure image data */
-    putchar(0); /* relative colors */
-    putchar(pclindex ? 1 : 3); /* index/direct pixel mode */
-    putchar(pclindex); /* ignored in direct pixel mode */
-    if (pclindex) {
-        putchar(0);
-        putchar(0);
-        putchar(0);
-    } else {
-        putchar(bpr); /* bits per red */
-        putchar(bpg); /* bits per green */
-        putchar(bpb); /* bits per blue */
-    }
-    putword(maxval); /* max red reference */
-    putword(maxval); /* max green reference */
-    putword(maxval); /* max blue reference */
-    putword(0); /* min red reference */
-    putword(0); /* min green reference */
-    putword(0); /* min blue reference */
-    if (pclindex) {                        /* set palette */
-        unsigned int i;
-        for (i = 0; i < colors; ++i) {
-            int const r = PPM_GETR( chv[i].color);
-            int const g = PPM_GETG( chv[i].color);
-            int const b = PPM_GETB( chv[i].color);
-            if (i == 0)
-                printf("\033*v");
-            if (r)
-                printf("%da", r);
-            if (g)
-                printf("%db", g);
-            if (b)
-                printf("%dc", b);
-            if (i == colors-1)
-                printf("%dI", i);    /* assign color index */
-            else
-                printf("%di", i);    /* assign color index */
-        }
-    }
-    ppm_freecolorhist(chv);
+    writePclHeader(cols, rows, maxval, xshift, yshift, quality, xsize, ysize,
+                   gammaVal, dark, render,
+                   colorMapped,
+                   bitsPerPixelRed, bitsPerPixelGrn, bitsPerPixelBlu,
+                   bitsPerIndex);
+
+    if (colorMapped)
+        writePalette(chv, colorCt);
 
     /* start raster graphics at CAP */
     printf("\033*r%dA", (xsize != 0 || ysize != 0) ? 3 : 1);
 
-    for (row = 0; row < rows; row++) {
-        pixel * const pixrow = pixels[row];
-        if (pclindex) { /* indexed color mode */
-            unsigned int col;
-            for (col = 0; col < cols; ++col)
-                putbits(ppm_lookupcolor(cht, &pixrow[col]), pclindex);
-            putbits(0, 0); /* flush row */
-        } else { /* direct color mode */
-            unsigned int col;
-            for (col = 0; col < cols; ++col) {
-                putbits(PPM_GETR(pixrow[col]), bpr);
-                putbits(PPM_GETG(pixrow[col]), bpg);
-                putbits(PPM_GETB(pixrow[col]), bpb);
-                /* don't need to flush */
-            }
-            putbits(0, 0); /* flush row */
-        }
-    }
+    writeRaster(pixels, rows, cols, cht, colorMapped,
+                bitsPerIndex,
+                bitsPerPixelRed, bitsPerPixelGrn, bitsPerPixelBlu);
+
     printf("\033*rC"); /* end raster graphics */
 
+    ppm_freecolorhash(cht);
+    ppm_freecolorhist(chv);
+
+    termbits();
+
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ppmtoppm.c b/converter/ppm/ppmtoppm.c
index 500c9856..3a48eacc 100644
--- a/converter/ppm/ppmtoppm.c
+++ b/converter/ppm/ppmtoppm.c
@@ -20,7 +20,7 @@ main(int argc, char *argv[]) {
     pixval maxval;
     int row;
     pixel* pixelrow;
-    
+
     ppm_init(&argc, argv);
 
     if (argc-1 != 0)
@@ -42,3 +42,6 @@ main(int argc, char *argv[]) {
 
     exit(0);
 }
+
+
+
diff --git a/converter/ppm/ppmtopuzz.c b/converter/ppm/ppmtopuzz.c
index 1277cc20..08b852b0 100644
--- a/converter/ppm/ppmtopuzz.c
+++ b/converter/ppm/ppmtopuzz.c
@@ -33,12 +33,12 @@ main( argc, argv )
     ppm_init( &argc, argv );
 
     if ( argc > 2 )
-	pm_usage( "[ppmfile]" );
+        pm_usage( "[ppmfile]" );
 
     if ( argc == 2 )
-	ifp = pm_openr( argv[1] );
+        ifp = pm_openr( argv[1] );
     else
-	ifp = stdin;
+        ifp = stdin;
 
     pixels = ppm_readppm( ifp, &cols, &rows, &maxval );
     pm_close( ifp );
@@ -46,11 +46,11 @@ main( argc, argv )
     pm_message( "computing colormap..." );
     chv = ppm_computecolorhist( pixels, cols, rows, MAXCOLORS, &colors );
     if ( chv == (colorhist_vector) 0 )
-	{
-	pm_message(
-	    "too many colors - try doing a 'pnmquant %d'", MAXCOLORS );
-	exit( 1 );
-	}
+        {
+        pm_message(
+            "too many colors - try doing a 'pnmquant %d'", MAXCOLORS );
+        exit( 1 );
+        }
     pm_message( "%d colors found", colors );
 
     /* Write puzzle header. */
@@ -58,19 +58,19 @@ main( argc, argv )
     (void) pm_writebiglong( stdout, rows );
     (void) putchar( (unsigned char) colors );
     if ( maxval > MAXVAL )
-	pm_message(
-	    "maxval is not %d - automatically rescaling colors", MAXVAL );
+        pm_message(
+            "maxval is not %d - automatically rescaling colors", MAXVAL );
     for ( i = 0; i < colors; ++i )
-	{
-	pixel p;
+        {
+        pixel p;
 
-	p = chv[i].color;
-	if ( maxval != MAXVAL )
-	    PPM_DEPTH( p, p, maxval, MAXVAL );
-	(void) putchar( (unsigned char) PPM_GETR( p ) );
-	(void) putchar( (unsigned char) PPM_GETG( p ) );
-	(void) putchar( (unsigned char) PPM_GETB( p ) );
-	}
+        p = chv[i].color;
+        if ( maxval != MAXVAL )
+            PPM_DEPTH( p, p, maxval, MAXVAL );
+        (void) putchar( (unsigned char) PPM_GETR( p ) );
+        (void) putchar( (unsigned char) PPM_GETG( p ) );
+        (void) putchar( (unsigned char) PPM_GETB( p ) );
+        }
 
     /* Convert color vector to color hash table, for fast lookup. */
     cht = ppm_colorhisttocolorhash( chv, colors );
@@ -78,19 +78,22 @@ main( argc, argv )
 
     /* And write out the data. */
     for ( row = 0; row < rows; ++row )
-	{
-	for ( col = 0, pP = pixels[row]; col < cols; ++col, ++pP )
-	    {
-	    register int color;
-
-	    color = ppm_lookupcolor( cht, pP );
-	    if ( color == -1 )
-		pm_error(
-		    "color not found?!?  row=%d col=%d  r=%d g=%d b=%d",
-		    row, col, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP) );
-	    (void) putchar( (unsigned char) color );
-	    }
-	}
+        {
+        for ( col = 0, pP = pixels[row]; col < cols; ++col, ++pP )
+            {
+            register int color;
+
+            color = ppm_lookupcolor( cht, pP );
+            if ( color == -1 )
+                pm_error(
+                    "color not found?!?  row=%d col=%d  r=%d g=%d b=%d",
+                    row, col, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP) );
+            (void) putchar( (unsigned char) color );
+            }
+        }
 
     exit( 0 );
     }
+
+
+
diff --git a/converter/ppm/ppmtospu.c b/converter/ppm/ppmtospu.c
index a6acbaa0..df0fb970 100644
--- a/converter/ppm/ppmtospu.c
+++ b/converter/ppm/ppmtospu.c
@@ -48,11 +48,11 @@ parseCommandLine(int argc, const char ** argv,
     MALLOCARRAY_NOFAIL(option_def, 100);
 
     option_def_index = 0;   /* incremented by OPTENT3 */
-    OPTENT3(0,   "d0",       OPT_FLAG,   
+    OPTENT3(0,   "d0",       OPT_FLAG,
             NULL,                       &d0Spec, 0);
-    OPTENT3(0,   "d2",       OPT_FLAG,   
+    OPTENT3(0,   "d2",       OPT_FLAG,
             NULL,                       &d2Spec, 0);
-    OPTENT3(0,   "d4",       OPT_FLAG,   
+    OPTENT3(0,   "d4",       OPT_FLAG,
             NULL,                       &d4Spec, 0);
 
     opt.opt_table = option_def;
@@ -72,7 +72,7 @@ parseCommandLine(int argc, const char ** argv,
     else
         cmdlineP->dithflag = 2;
 
-    if (argc-1 < 1) 
+    if (argc-1 < 1)
         cmdlineP->inputFileName = "-";
     else {
         cmdlineP->inputFileName = argv[1];
@@ -129,7 +129,7 @@ findIndex(unsigned int const col,
    Spectrum palette index.
 -----------------------------------------------------------------------------*/
     int r, x1;
-    
+
     x1 = 10 * index;  /* initial value */
     if (index & 0x1)
         x1 -= 5;
@@ -143,7 +143,7 @@ findIndex(unsigned int const col,
 
     if (col >= (x1+160))
         r += 32;
-    
+
     return r;
 }
 
@@ -183,7 +183,7 @@ dither(unsigned int       const row,
         { 0, 2 },
         { 3, 1 }
     };
-    
+
     unsigned int c[3];  /* An element for each plane */
     unsigned int col;
 
@@ -262,7 +262,7 @@ sort(struct PixelType * const pixelType,
             ++i;
         while (pixelType[j-1].popularity > pivot)
             --j;
-        
+
         if (i < j) {
             /* An element not less popular than pivot is to the left of a
                pixel not more popular than pivot, so swap them.  Note that we
@@ -274,7 +274,7 @@ sort(struct PixelType * const pixelType,
             --j;
         }
     }
-    
+
     if (j - left > 1)
         sort(pixelType, left, j);
     if (right - i > 1)
@@ -445,7 +445,7 @@ convertRow(unsigned int       const row,
     /* Mark palette entries as all free */
     for (i = 0; i < 48; ++i)
         palP->pal[row][i] = -1;
-    
+
     /* Mark reserved palette entries */
     palP->pal[row][0]  = palP->pal[row][15] = palP->pal[row][16] = 0;
     palP->pal[row][31] = palP->pal[row][32] = palP->pal[row][47] = 0;
@@ -494,7 +494,7 @@ writeScreen(const short * const screen) {
     /* Write the bitmap */
 
     unsigned int i;
-    
+
     for (i = 0; i < 16000; ++i) {
         char const c0 = 0xff & (screen[i] >> 8);
         char const c1 = 0xff & screen[i];
diff --git a/converter/ppm/ppmtoterm.c b/converter/ppm/ppmtoterm.c
index d388f77d..6e41a8cb 100644
--- a/converter/ppm/ppmtoterm.c
+++ b/converter/ppm/ppmtoterm.c
@@ -86,7 +86,7 @@ parseCommandLine(int argc, const char ** argv,
 
 
 static void
-generatePalette(unsigned char        rgb[NUM_COLORS][3], 
+generatePalette(unsigned char        rgb[NUM_COLORS][3],
                 char                 ansiCode[NUM_COLORS][MAX_ANSI_STR_LEN],
                 unsigned int * const paletteSizeP) {
 /*----------------------------------------------------------------------------
@@ -150,7 +150,7 @@ generatePalette(unsigned char        rgb[NUM_COLORS][3],
 static void
 lookupInPalette(pixel          const pixel,
                 pixval         const maxval,
-                unsigned char        rgb[NUM_COLORS][3], 
+                unsigned char        rgb[NUM_COLORS][3],
                 unsigned int   const palLen,
                 unsigned int * const paletteIdxP) {
 /*----------------------------------------------------------------------------
@@ -166,7 +166,7 @@ lookupInPalette(pixel          const pixel,
     unsigned int paletteIdxSoFar;
     unsigned int dist;
     unsigned int i;
-            
+
     /* The following loop calculates the index that corresponds to the
        minimum color distance between the given RGB values and the
        values available in the palette.
@@ -200,18 +200,18 @@ main(int argc, const char ** argv) {
     unsigned char   rgb[NUM_COLORS][3];
     char            ansiCode[NUM_COLORS][MAX_ANSI_STR_LEN];
 
-    pm_proginit(&argc, argv);    
+    pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
 
     ifP = pm_openr(cmdline.inputFileName);
-    
+
     pixels = ppm_readppm(ifP, &cols, &rows, &maxval);
 
     pm_close(ifP);
-        
+
     generatePalette(rgb, ansiCode, &palLen);
-    
+
     for (row = 0; row < rows; ++row) {
         unsigned int col;
         for (col = 0; col < cols; ++col) {
@@ -227,6 +227,9 @@ main(int argc, const char ** argv) {
     printf(ESC "\x30m");
 
     ppm_freearray(pixels, rows);
-    
+
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c
index c673798f..0e2751f3 100644
--- a/converter/ppm/ppmtowinicon.c
+++ b/converter/ppm/ppmtowinicon.c
@@ -1,4 +1,4 @@
-/* ppmtowinicon.c - read portable pixmap file(s) and write a MS Windows .ico
+/* ppmtowinicon.c - read PPM images and write a MS Windows .ico
 **
 ** Copyright (C) 2000 by Lee Benfield - lee@benf.org
 **
@@ -10,6 +10,7 @@
 ** implied warranty.
 */
 
+#include <assert.h>
 #include <math.h>
 #include <string.h>
 
@@ -25,31 +26,30 @@
 
 #define MAXCOLORS 256
 
-struct cmdlineInfo {
+struct CmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
-    unsigned int iconCount;
-    const char **inputFilespec;  /* '-' if stdin; malloc'ed array */
-    const char **andpgmFilespec;    /* NULL if unspecified; malloc'ed array */
-    const char *output;     /* '-' if unspecified */
-    unsigned int truetransparent;
-    unsigned int verbose;
+    unsigned int  iconCount;
+    const char ** inputFileNm;  /* '-' if stdin; malloc'ed array */
+    const char ** andpgmFileNm;    /* NULL if unspecified; malloc'ed array */
+    const char *  output;     /* '-' if unspecified */
+    unsigned int  truetransparent;
+    unsigned int  verbose;
 };
 
 
 static bool verbose;
 
-static int      file_offset = 0; /* not actually used, but useful for debug. */
-static FILE *   ofp;
+static int      fileOffset = 0; /* not actually used, but useful for debug. */
 
 static void
-parseCommandLine(int                 argc, 
-                 char **             argv,
-                 struct cmdlineInfo *cmdlineP ) {
+parseCommandLine(int                  argc,
+                 const char **        argv,
+                 struct CmdlineInfo * cmdlineP) {
 /*----------------------------------------------------------------------------
    Parse program command line described in Unix standard form by argc
-   and argv.  Return the information in the options as *cmdlineP.  
+   and argv.  Return the information in the options as *cmdlineP.
 
    If command line is internally inconsistent (invalid options, etc.),
    issue error message to stderr and abort program.
@@ -82,31 +82,30 @@ parseCommandLine(int                 argc,
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
     opt.allowNegNum = FALSE;  /* We have no parms that are negative numbers */
 
-    pm_optParseOptions3( &argc, argv, opt, sizeof(opt), 0);
+    pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0);
         /* Uses and sets argc, argv, and some of *cmdlineP and others. */
 
     if (!outputSpec)
         cmdlineP->output = "-";
 
-
     if (!andpgms) {
         if (argc-1 == 0) {
             cmdlineP->iconCount = 1;
-            MALLOCARRAY_NOFAIL(cmdlineP->inputFilespec, cmdlineP->iconCount);
-            cmdlineP->inputFilespec[0] = "-";
+            MALLOCARRAY_NOFAIL(cmdlineP->inputFileNm, cmdlineP->iconCount);
+            cmdlineP->inputFileNm[0] = "-";
         } else {
             unsigned int iconIndex;
 
             cmdlineP->iconCount = argc-1;
-            MALLOCARRAY_NOFAIL(cmdlineP->inputFilespec, cmdlineP->iconCount);
+            MALLOCARRAY_NOFAIL(cmdlineP->inputFileNm, cmdlineP->iconCount);
             for (iconIndex = 0; iconIndex < cmdlineP->iconCount; ++iconIndex)
-                cmdlineP->inputFilespec[iconIndex] = argv[iconIndex+1];
+                cmdlineP->inputFileNm[iconIndex] = argv[iconIndex+1];
         }
         {
             unsigned int iconIndex;
-            MALLOCARRAY_NOFAIL(cmdlineP->andpgmFilespec, cmdlineP->iconCount);
+            MALLOCARRAY_NOFAIL(cmdlineP->andpgmFileNm, cmdlineP->iconCount);
             for (iconIndex = 0; iconIndex < cmdlineP->iconCount; ++iconIndex)
-                cmdlineP->andpgmFilespec[iconIndex] = NULL;
+                cmdlineP->andpgmFileNm[iconIndex] = NULL;
         }
     } else {
         if (argc-1 < 2)
@@ -119,11 +118,11 @@ parseCommandLine(int                 argc,
         else {
             unsigned int iconIndex;
             cmdlineP->iconCount = (argc-1)/2;
-            MALLOCARRAY_NOFAIL(cmdlineP->inputFilespec, cmdlineP->iconCount);
-            MALLOCARRAY_NOFAIL(cmdlineP->andpgmFilespec, cmdlineP->iconCount);
+            MALLOCARRAY_NOFAIL(cmdlineP->inputFileNm, cmdlineP->iconCount);
+            MALLOCARRAY_NOFAIL(cmdlineP->andpgmFileNm, cmdlineP->iconCount);
             for (iconIndex = 0; iconIndex < cmdlineP->iconCount; ++iconIndex) {
-                cmdlineP->inputFilespec[iconIndex] = argv[1 + iconIndex*2];
-                cmdlineP->andpgmFilespec[iconIndex] = argv[2 + iconIndex*2];
+                cmdlineP->inputFileNm[iconIndex] = argv[1 + iconIndex*2];
+                cmdlineP->andpgmFileNm[iconIndex] = argv[2 + iconIndex*2];
             }
         }
     }
@@ -132,429 +131,423 @@ parseCommandLine(int                 argc,
 
 
 
-static void 
-PutByte(int const v) {
-   
-   if (putc(v, ofp) == EOF)
-       pm_error("Unable to write byte to output file.");
+static void
+freeCmdline(struct CmdlineInfo const cmdline) {
+
+    free(cmdline.inputFileNm);
+    free(cmdline.andpgmFileNm);
 }
-   
 
 
-static void 
-PutShort(short const v) {
-   
-   if (pm_writelittleshort(ofp, v) == -1)
-       pm_error("Unable to write short integer to output file");
-}
-   
 
+static void
+writeU1(FILE * const ofP,
+        u1     const v) {
 
-static void 
-PutLong(long const v) {
-   
-   if (pm_writelittlelong(ofp, v) == -1)
-       pm_error("Unable to write long integer to output file");
+    ++fileOffset;
+    pm_writechar(ofP, v);
 }
 
 
-   
-/*
- * These have no purpose but to wrapper the Byte, Short & Long 
- * functions.
- */
-static void 
-writeU1 (u1 const v) {
-   file_offset++;
-   PutByte(v);
-}
 
-static  void 
-writeU2 (u2 const v) {
-   file_offset +=2;
-   PutShort(v);
-}
+static  void
+writeU2(FILE * const ofP,
+        u2     const v) {
 
-static void 
-writeU4 (u4 const v) {
-   file_offset += 4;
-   PutLong(v);
+    fileOffset +=2;
+    pm_writelittleshort(ofP, v);
 }
 
-static MS_Ico 
-createIconFile (void) {
-   MS_Ico MSIconData;
-   
-   MALLOCVAR_NOFAIL(MSIconData);
-
-   MSIconData->reserved     = 0;
-   MSIconData->type         = 1;
-   MSIconData->count        = 0;
-   MSIconData->entries      = NULL;
-   return MSIconData;
+
+
+static void
+writeU4(FILE * const ofP,
+        u4     const v) {
+
+    fileOffset += 4;
+    pm_writelittlelong(ofP, v);
 }
 
 
-/* create andBitmap from pgm */
 
-static ICON_bmp 
-createAndBitmap (gray ** const ba, int const cols, int const rows,
-                 gray const maxval) {
-   /*
-    * How wide should the u1 string for each row be?
-    * each byte is 8 pixels, but must be a multiple of 4 bytes.
-    */
-   unsigned int const xBytes = ROUNDUP(cols, 32)/8;
-   ICON_bmp icBitmap;
-   int y,x;
-   u1 ** rowData;
-
-   MALLOCVAR_NOFAIL(icBitmap);
-
-   MALLOCARRAY_NOFAIL(rowData, rows);
-   icBitmap->xBytes = xBytes;
-   icBitmap->data   = rowData;
-   icBitmap->size   = xBytes * rows;
-   for (y=0;y<rows;y++) {
-      u1 * row;
-      int byteOn = 0;
-      int bitOn = 128;
-
-      MALLOCARRAY_NOFAIL(row, xBytes);
-
-      memset (row, 0, xBytes);
-      rowData[rows-y-1] = row;
-      /* 
-       * Check there's a bit array, otherwise we're just faking this...
-       */
-      if (ba) {
-     for (x=0;x<cols;x++) {
-            /* Black (bit clear) is transparent in PGM alpha maps,
-             * in ICO bit *set* is transparent.
-             */
-            if (ba[y][x] <= maxval/2) row[byteOn] |= bitOn;
-
-        if (bitOn == 1) {
-           byteOn++;
-           bitOn = 128;
-        } else {
-           bitOn >>= 1;
-        }
-     }
-      }
-   }
-   return icBitmap;
+static MS_Ico *
+newIconFile(void) {
+
+   MS_Ico * MSIconDataP;
+
+   MALLOCVAR_NOFAIL(MSIconDataP);
+
+   MSIconDataP->reserved     = 0;
+   MSIconDataP->type         = 1;
+   MSIconDataP->count        = 0;
+   MSIconDataP->entries      = NULL;
+
+   return MSIconDataP;
 }
 
 
-/*
- * Depending on if the image is stored as 1bpp, 4bpp or 8bpp, the 
- * encoding mechanism is different.
- * 
- * I didn't re-use the code from ppmtobmp since I need to keep the
- * bitmaps in memory till I've loaded all ppms.
- * 
- * 8bpp => 1 byte/palette index.
- * 4bpp => High Nibble, Low Nibble
- * 1bpp => 1 palette value per bit, high bit 1st.
- */
-static ICON_bmp 
-create1Bitmap (pixel ** const pa, int const cols, int const rows, 
-               colorhash_table const cht) {
-   /*
-    * How wide should the u1 string for each row be?
-    * each byte is 8 pixels, but must be a multiple of 4 bytes.
-    */
-   ICON_bmp icBitmap;
-   int xBytes,y,x;
-   int wt = cols;
-   u1 ** rowData;
-
-   MALLOCVAR_NOFAIL(icBitmap);
-   
-   wt >>= 3;
-   if (wt & 3) {
-      wt = (wt & ~3) + 4;
-   }
-   xBytes = wt;
-   MALLOCARRAY_NOFAIL(rowData, rows);
-   icBitmap->xBytes = xBytes;
-   icBitmap->data   = rowData;
-   icBitmap->size   = xBytes * rows;
-   for (y=0;y<rows;y++) {
-      u1 * row;
-      int byteOn = 0;
-      int bitOn = 128;
-      int value;
-      
-      MALLOCARRAY_NOFAIL(row, xBytes);
-      memset (row, 0, xBytes);
-      rowData[rows-y-1] = row;
-      /* 
-       * Check there's a pixel array, otherwise we're just faking this...
+
+static ICON_bmp *
+newAndBitmap(gray **      const ba,
+             unsigned int const cols,
+             unsigned int const rows,
+             gray         const maxval) {
+/*----------------------------------------------------------------------------
+  create andBitmap from PGM
+-----------------------------------------------------------------------------*/
+    unsigned int const xByteCt = ROUNDUP(cols, 32)/8;
+       /* How wide the u1 string for each row should be -- Each byte is 8
+          pixels, but must be a multiple of 4 bytes.
        */
-      if (pa) {
-     for (x=0;x<cols;x++) {
-        /*
-         * So we've got a colorhash_table with two colors in it.
-         * Which is black?!
-         * 
-         * Unless the hashing function changes, 0's black.
-         */
-        value = ppm_lookupcolor(cht, &pa[y][x]);
-        if (!value) {
-           /* leave black. */
-        } else {
-           row[byteOn] |= bitOn;
-        }
-        if (bitOn == 1) {
-           byteOn++;
-           bitOn = 128;
+    ICON_bmp * icBitmapP;
+    unsigned int row;
+    u1 ** rowData;
+
+    MALLOCVAR_NOFAIL(icBitmapP);
+
+    MALLOCARRAY_NOFAIL(rowData, rows);
+    icBitmapP->xBytes = xByteCt;
+    icBitmapP->data   = rowData;
+    icBitmapP->size   = xByteCt * rows;
+    for (row = 0; row < rows; ++row) {
+        u1 * thisRow;  /* malloc'ed */
+        unsigned int byteOn;
+        unsigned int bitOn;
+
+        MALLOCARRAY_NOFAIL(thisRow, xByteCt);
+
+        byteOn =   0;  /* initial value */
+        bitOn  = 128;  /* initial value */
+
+        memset (thisRow, 0, xByteCt);
+        rowData[rows - row - 1] = thisRow;
+
+        if (ba) {
+            unsigned int col;
+
+            for (col = 0; col < cols; ++col) {
+                /* Black (bit clear) is transparent in PGM alpha maps,
+                   in ICO bit *set* is transparent.
+                */
+                if (ba[row][col] <= maxval/2) thisRow[byteOn] |= bitOn;
+
+                if (bitOn == 1) {
+                    ++byteOn;
+                    bitOn = 128;
+                } else {
+                    bitOn >>= 1;
+                }
+            }
         } else {
-           bitOn >>= 1;
+            /* No array -- we're just faking this */
         }
-     }
-      }
-   }
-   return icBitmap;
+    }
+    return icBitmapP;
 }
 
 
-static ICON_bmp 
-create4Bitmap (pixel ** const pa, int const cols, int const rows,
-               colorhash_table const cht) {
-   /*
-    * How wide should the u1 string for each row be?
-    * each byte is 8 pixels, but must be a multiple of 4 bytes.
-    */
-   ICON_bmp icBitmap;
-   int xBytes,y,x;
-   int wt = cols;
-   u1 ** rowData;
-
-   MALLOCVAR_NOFAIL(icBitmap);
-
-   wt >>= 1;
-   if (wt & 3) {
-      wt = (wt & ~3) + 4;
-   }
-   xBytes = wt;
-   MALLOCARRAY_NOFAIL(rowData, rows);
-   icBitmap->xBytes = xBytes;
-   icBitmap->data   = rowData;
-   icBitmap->size   = xBytes * rows;
-
-   for (y=0;y<rows;y++) {
-      u1 * row;
-      int byteOn = 0;
-      int nibble = 1;   /* high nibble = 1, low nibble = 0; */
-      int value;
-
-      MALLOCARRAY_NOFAIL(row, xBytes);
-
-      memset (row, 0, xBytes);
-      rowData[rows-y-1] = row;
-      /* 
-       * Check there's a pixel array, otherwise we're just faking this...
-       */
-      if (pa) {
-     for (x=0;x<cols;x++) {
-        value = ppm_lookupcolor(cht, &pa[y][x]);
-        /*
-         * Shift it, if we're putting it in the high nibble.
-         */
-        if (nibble) {
-           value <<= 4;
-        }
-        row[byteOn] |= value;
-        if (nibble) {
-           nibble = 0;
+
+/* Depending on if the image is stored as 1bpp, 4bpp or 8bpp, the
+   encoding mechanism is different.
+
+   I didn't re-use the code from ppmtobmp since I need to keep the
+   bitmaps in memory until I've loaded all ppms.
+
+   8bpp => 1 byte/palette index.
+   4bpp => High Nibble, Low Nibble
+   1bpp => 1 palette value per bit, high bit 1st.
+*/
+
+
+
+static void
+fillInRaster1(u1 **           const rowData,
+              unsigned int    const xByteCt,
+              pixel **        const pa,
+              unsigned int    const cols,
+              unsigned int    const rows,
+              colorhash_table const cht) {
+
+    unsigned int row;
+
+    for (row = 0; row <rows; ++row) {
+        u1 * thisRow;  /* malloc'ed */
+        unsigned int byteOn;
+        unsigned int bitOn;
+
+        MALLOCARRAY_NOFAIL(thisRow, xByteCt);
+        memset (thisRow, 0, xByteCt);
+        rowData[rows - row - 1] = thisRow;
+        byteOn =   0;  /* initial value */
+        bitOn  = 128;  /* initial value */
+
+        if (pa) {
+            unsigned int col;
+
+            for (col = 0; col < cols; ++col) {
+                /* So we've got a colorhash_table with two colors in it.  Which
+                   is black?!
+
+                   Unless the hashing function changes, 0's black.
+                */
+                int const value = ppm_lookupcolor(cht, &pa[row][col]);
+                if (!value) {
+                    /* leave black. */
+                } else {
+                    thisRow[byteOn] |= bitOn;
+                }
+                if (bitOn == 1) {
+                    ++byteOn;
+                    bitOn = 128;
+                } else {
+                    bitOn >>= 1;
+                }
+            }
         } else {
-           nibble = 1;
-           byteOn++;
+            /* No pixel array -- we're just faking this */
         }
-     }
-      }
-   }
-   return icBitmap;
+    }
 }
 
 
 
-static ICON_bmp 
-create8Bitmap (pixel ** const pa, int const cols, int const rows,
-               colorhash_table const cht) {
-   /*
-    * How wide should the u1 string for each row be?
-    * each byte is 8 pixels, but must be a multiple of 4 bytes.
-    */
-   ICON_bmp icBitmap;
-   int xBytes,y,x;
-   int wt = cols;
-   u1 ** rowData;
-
-   MALLOCVAR_NOFAIL(icBitmap);
-
-   if (wt & 3) {
-      wt = (wt & ~3) + 4;
-   }
-   xBytes = wt;
-   MALLOCARRAY_NOFAIL(rowData, rows);
-   icBitmap->xBytes = xBytes;
-   icBitmap->data   = rowData;
-   icBitmap->size   = xBytes * rows;
-
-   for (y=0;y<rows;y++) {
-      u1 * row;
-
-      MALLOCARRAY_NOFAIL(row, xBytes);
-      memset (row, 0, xBytes);
-      rowData[rows-y-1] = row;
-      /* 
-       * Check there's a pixel array, otherwise we're just faking this...
-       */
-      if (pa) {
-     for (x=0;x<cols;x++) {
-        row[x] = ppm_lookupcolor(cht, &pa[y][x]);
-     }
-      }
-   }
-   return icBitmap;
+static void
+fillInRaster4(u1 **           const rowData,
+              unsigned int    const xByteCt,
+              pixel **        const pa,
+              unsigned int    const cols,
+              unsigned int    const rows,
+              colorhash_table const cht) {
+
+    unsigned int row;
+
+    for (row = 0; row < rows; ++row) {
+        u1 * thisRow;
+        unsigned int byteOn;
+        unsigned int nibble;   /* high nibble = 1, low nibble = 0; */
+
+        MALLOCARRAY_NOFAIL(thisRow, xByteCt);
+
+        memset(thisRow, 0, xByteCt);
+        rowData[rows - row - 1] = thisRow;
+        byteOn = 0;  /* initial value */
+        nibble = 1;  /* initial value */
+
+        if (pa) {
+            unsigned int col;
+
+            for (col = 0; col < cols; ++col) {
+                int value;
+
+                value = ppm_lookupcolor(cht, &pa[row][col]);  /* init value */
+                /* Shift it, if we're putting it in the high nibble. */
+                if (nibble)
+                    value <<= 4;
+                thisRow[byteOn] |= value;
+                if (nibble == 1)
+                    nibble = 0;
+                else {
+                    nibble = 1;
+                    ++byteOn;
+                }
+            }
+        } else {
+            /* No pixel array -- we're just faking this */
+        }
+    }
 }
 
 
 
-static IC_InfoHeader 
-createInfoHeader(IC_Entry const entry, ICON_bmp const xbmp,
-                 ICON_bmp const abmp) {
-   IC_InfoHeader ih;
-   
-   MALLOCVAR_NOFAIL(ih);
-
-   ih->size          = 40;
-   ih->width         = entry->width;
-   ih->height        = entry->height * 2;  
-   ih->planes        = 1;  
-   ih->bitcount      = entry->bitcount;
-   ih->compression   = 0;
-   ih->imagesize     = entry->width * entry->height * 8 / entry->bitcount;
-   ih->x_pixels_per_m= 0;
-   ih->y_pixels_per_m= 0;
-   ih->colors_used   = 1 << entry->bitcount;
-   ih->colors_important = 0;
-   return ih;
-}
+static void
+fillInRaster8(u1 **           const rowData,
+              unsigned int    const xByteCt,
+              pixel **        const pa,
+              unsigned int    const cols,
+              unsigned int    const rows,
+              colorhash_table const cht) {
 
+    unsigned int row;
 
+    for (row = 0; row < rows; ++row) {
+        u1 * thisRow;  /* malloc'ed */
 
-static IC_Palette 
-createCleanPalette(void) {
-   IC_Palette palette;
-   int x;
-   
-   MALLOCVAR_NOFAIL(palette);
+        MALLOCARRAY_NOFAIL(thisRow, xByteCt);
+        memset (thisRow, 0, xByteCt);
+        rowData[rows - row - 1] = thisRow;
+        if (pa) {
+            unsigned int col;
 
-   MALLOCARRAY_NOFAIL(palette->colors, MAXCOLORS);
-   for (x=0;x<MAXCOLORS;x++ ){
-      palette->colors[x] = NULL;
-   }
-   return palette;
+            for (col = 0; col < cols; ++col)
+                thisRow[col] = ppm_lookupcolor(cht, &pa[row][col]);
+        } else {
+            /* No pixel array -- we're just faking this */
+        }
+    }
 }
 
 
 
-static void 
-addColorToPalette(IC_Palette const palette, int const i,
-                  int const r, int const g, int const b) {
+static ICON_bmp *
+newBitmap(unsigned int    const bpp,
+          pixel **        const pa,
+          unsigned int    const cols,
+          unsigned int    const rows,
+          colorhash_table const cht) {
 
-    MALLOCVAR_NOFAIL(palette->colors[i]);
+    unsigned int const xByteCt = ROUNDUP(cols, 32)/8;
+       /* How wide the u1 string for each row should be -- Each byte is 8
+          pixels, but must be a multiple of 4 bytes.
+       */
+    ICON_bmp * icBitmapP;  /* malloc'ed */
+    u1 ** rowData;  /* malloc'ed */
 
-    palette->colors[i]->red      = r;
-    palette->colors[i]->green    = g;
-    palette->colors[i]->blue     = b;
-    palette->colors[i]->reserved = 0;
-}
+    assert(cols < 256); assert(rows < 256);  /* required for no overflow */
 
+    MALLOCVAR_NOFAIL(icBitmapP);
 
+    MALLOCARRAY_NOFAIL(rowData, rows);
 
-static ICON_bmp 
-createBitmap (int const bpp, pixel ** const pa, 
-              int const cols, int const rows, 
-              colorhash_table const cht) {
-    
-    ICON_bmp retval;
-    const int assumed_bpp = (pa == NULL) ? 1 : bpp;
+    icBitmapP->xBytes = xByteCt;
+    icBitmapP->data   = rowData;
+    icBitmapP->size   = xByteCt * rows;
 
-    switch (assumed_bpp) {
+    unsigned int const assumedBpp = (pa == NULL) ? 1 : bpp;
+
+    switch (assumedBpp) {
     case 1:
-        retval = create1Bitmap (pa,cols,rows,cht);
+        fillInRaster1(rowData, xByteCt, pa, cols, rows, cht);
         break;
     case 4:
-        retval = create4Bitmap (pa,cols,rows,cht);
+        fillInRaster4(rowData, xByteCt, pa, cols, rows, cht);
         break;
     case 8:
     default:
-        retval = create8Bitmap (pa,cols,rows,cht);
+        fillInRaster8(rowData, xByteCt, pa, cols, rows, cht);
         break;
     }
-    return retval;
+    return icBitmapP;
+}
+
+
+
+static IC_InfoHeader *
+newInfoHeader(IC_Entry const entry) {
+
+   IC_InfoHeader * ihP;
+
+   MALLOCVAR_NOFAIL(ihP);
+
+   ihP->size             = 40;
+   ihP->width            = entry.width;
+   ihP->height           = entry.height * 2;
+   ihP->planes           = 1;
+   ihP->bitcount         = entry.bitcount;
+   ihP->compression      = 0;
+   ihP->imagesize        = entry.width * entry.height * 8 / entry.bitcount;
+   ihP->x_pixels_per_m   = 0;
+   ihP->y_pixels_per_m   = 0;
+   ihP->colors_used      = 1 << entry.bitcount;
+   ihP->colors_important = 0;
+
+   return ihP;
+}
+
+
+
+static IC_Palette *
+newCleanPalette(void) {
+
+    IC_Palette * paletteP;  /* malloc'ed */
+
+    unsigned int i;
+
+    MALLOCVAR_NOFAIL(paletteP);
+
+    MALLOCARRAY_NOFAIL(paletteP->colors, MAXCOLORS);
+
+    for (i=0; i <MAXCOLORS; ++i) {
+        paletteP->colors[i] = NULL;
+    }
+    return paletteP;
+}
+
+
+
+static void
+addColorToPalette(IC_Palette * const paletteP,
+                  unsigned int const i,
+                  unsigned int const r,
+                  unsigned int const g,
+                  unsigned int const b) {
+
+    MALLOCVAR_NOFAIL(paletteP->colors[i]);
+
+    paletteP->colors[i]->red      = r;
+    paletteP->colors[i]->green    = g;
+    paletteP->colors[i]->blue     = b;
+    paletteP->colors[i]->reserved = 0;
 }
 
 
 
 static void
 makePalette(pixel **          const xorPPMarray,
-            int               const xorCols,
-            int               const xorRows,
+            unsigned int      const xorCols,
+            unsigned int      const xorRows,
             pixval            const xorMaxval,
-            IC_Palette *      const paletteP,
+            IC_Palette **     const palettePP,
             colorhash_table * const xorChtP,
-            int *             const colorsP,
+            unsigned int *    const colorsP,
             const char **     const errorP) {
-   /*
-    * Figure out the colormap and turn it into the appropriate GIF
-    * colormap - this code's pretty much straight from ppmtobpm
-    */
+/*----------------------------------------------------------------------------
+   Figure out the colormap and turn it into the appropriate GIF colormap -
+   this code's pretty much straight from 'ppmtobpm'.
+-----------------------------------------------------------------------------*/
+    IC_Palette * const paletteP = newCleanPalette();
+
     colorhist_vector xorChv;
     unsigned int i;
-    int colors;
-    IC_Palette palette = createCleanPalette();
+    int colorCt;
+
+    if (verbose)
+        pm_message("computing colormap...");
 
-    if (verbose) pm_message("computing colormap...");
-    xorChv = ppm_computecolorhist(xorPPMarray, xorCols, xorRows, MAXCOLORS, 
-                                  &colors);
-    if (xorChv == NULL)
+    xorChv = ppm_computecolorhist(xorPPMarray, xorCols, xorRows, MAXCOLORS,
+                                  &colorCt);
+    if (!xorChv)
         pm_asprintf(errorP,
-                    "image has too many colors - try doing a 'pnmquant %d'",
+                    "image has too many colors - try doing a 'pnmquant %u'",
                     MAXCOLORS);
     else {
         *errorP = NULL;
 
-        if (verbose) pm_message("%d colors found", colors);
-        
+        if (verbose)
+            pm_message("%u colors found", colorCt);
+
         if (verbose && (xorMaxval > 255))
             pm_message("maxval is not 255 - automatically rescaling colors");
-        for (i = 0; i < colors; ++i) {
+        for (i = 0; i < colorCt; ++i) {
             if (xorMaxval == 255) {
-                addColorToPalette(palette,i,
+                addColorToPalette(paletteP, i,
                                   PPM_GETR(xorChv[i].color),
                                   PPM_GETG(xorChv[i].color),
                                   PPM_GETB(xorChv[i].color));
             } else {
-                addColorToPalette(palette,i,
+                addColorToPalette(paletteP, i,
                                   PPM_GETR(xorChv[i].color) * 255 / xorMaxval,
                                   PPM_GETG(xorChv[i].color) * 255 / xorMaxval,
                                   PPM_GETB(xorChv[i].color) * 255 / xorMaxval);
             }
         }
-        
+
         /* And make a hash table for fast lookup. */
-        *xorChtP = ppm_colorhisttocolorhash(xorChv, colors);
-        
+        *xorChtP = ppm_colorhisttocolorhash(xorChv, colorCt);
+
         ppm_freecolorhist(xorChv);
-        
-        *paletteP = palette;
-        *colorsP = colors;
+
+        *palettePP = paletteP;
+        *colorsP   = colorCt;
     }
 }
 
@@ -562,15 +555,15 @@ makePalette(pixel **          const xorPPMarray,
 
 static void
 getOrFakeAndMap(const char *      const andPgmFname,
-                int               const xorCols,
-                int               const xorRows,
+                unsigned int      const xorCols,
+                unsigned int      const xorRows,
                 gray ***          const andPGMarrayP,
                 pixval *          const andMaxvalP,
                 colorhash_table * const andChtP,
                 const char **     const errorP) {
 
     int andRows, andCols;
-    
+
     if (!andPgmFname) {
         /* He's not supplying a bitmap for 'and'.  Fake the bitmap. */
         *andPGMarrayP = NULL;
@@ -578,15 +571,15 @@ getOrFakeAndMap(const char *      const andPgmFname,
         *andChtP      = NULL;
         *errorP       = NULL;
     } else {
-        FILE * andfile;
-        andfile = pm_openr(andPgmFname);
-        *andPGMarrayP = pgm_readpgm(andfile, &andCols, &andRows, andMaxvalP);
-        pm_close(andfile);
+        FILE * andFileP;
+        andFileP = pm_openr(andPgmFname);
+        *andPGMarrayP = pgm_readpgm(andFileP, &andCols, &andRows, andMaxvalP);
+        pm_close(andFileP);
 
         if ((andCols != xorCols) || (andRows != xorRows)) {
             pm_asprintf(errorP,
                         "And mask and image have different dimensions "
-                        "(%d x %d vs %d x %d).  Aborting.",
+                        "(%u x %u vs %u x %u).  Aborting.",
                         andCols, xorCols, andRows, xorRows);
         } else
             *errorP = NULL;
@@ -596,18 +589,20 @@ getOrFakeAndMap(const char *      const andPgmFname,
 
 
 static void
-blackenTransparentAreas(pixel ** const xorPPMarray,
-                        int      const cols,
-                        int      const rows,
-                        gray **  const andPGMarray,
-                        pixval   const andMaxval) {
+blackenTransparentAreas(pixel **     const xorPPMarray,
+                        unsigned int const cols,
+                        unsigned int const rows,
+                        gray **      const andPGMarray,
+                        pixval       const andMaxval) {
 
     unsigned int row;
 
-    if (verbose) pm_message("Setting transparent pixels to black");
+    if (verbose)
+        pm_message("Setting transparent pixels to black");
 
     for (row = 0; row < rows; ++row) {
         unsigned int col;
+
         for (col = 0; col < cols; ++col) {
             if (andPGMarray[row][col] < andMaxval)
                 /* It's not opaque here; make it black */
@@ -618,70 +613,69 @@ blackenTransparentAreas(pixel ** const xorPPMarray,
 
 
 
-static void 
-addEntryToIcon(MS_Ico       const MSIconData, 
+static void
+addEntryToIcon(MS_Ico *     const MSIconDataP,
                const char * const xorPpmFname,
                const char * const andPgmFname,
                bool         const trueTransparent) {
 
-    IC_Entry entry;
+    IC_Entry * entryP;
     FILE * xorfile;
     pixel ** xorPPMarray;
     gray ** andPGMarray;
-    ICON_bmp xorBitmap;
-    ICON_bmp andBitmap;
+    ICON_bmp * xorBitmapP;
+    ICON_bmp * andBitmapP;
     int rows, cols;
-    int bpp, colors;
-    int entry_cols;
-    IC_Palette palette;
-    colorhash_table  xorCht;
-    colorhash_table  andCht; 
+    unsigned int bpp;
+    unsigned int colorCt;
+    unsigned int entryCols;
+    IC_Palette * paletteP;
+    colorhash_table xorCht;
+    colorhash_table andCht;
     const char * error;
-   
+
     pixval xorMaxval;
     gray andMaxval;
 
-    MALLOCVAR_NOFAIL(entry);
+    MALLOCVAR_NOFAIL(entryP);
 
-   /*
-    * Read the xor PPM.
-    */
+    /* Read the xor PPM. */
     xorfile = pm_openr(xorPpmFname);
     xorPPMarray = ppm_readppm(xorfile, &cols, &rows, &xorMaxval);
     pm_close(xorfile);
-    /*
-    * Since the entry uses 1 byte to hold the width and height of the icon, the
-    * image can't be more than 256 x 256.
+
+    /* Since the entry uses 1 byte to hold the width and height of the icon,
+       the image can't be more than 256 x 256.
     */
     if (rows > 255 || cols > 255) {
         pm_error("Max size for a icon is 255 x 255 (1 byte fields).  "
-                 "%s is %d x %d", xorPpmFname, cols, rows);
+                 "%s is %u x %u", xorPpmFname, cols, rows);
     }
-   
-    if (verbose) pm_message("read PPM: %dw x %dh, maxval = %d", 
-                            cols, rows, xorMaxval);
 
-    makePalette(xorPPMarray, cols, rows, xorMaxval, 
-                &palette, &xorCht, &colors, &error);
+    if (verbose)
+        pm_message("read PPM: %uw x %uh, maxval = %u", cols, rows, xorMaxval);
+
+    makePalette(xorPPMarray, cols, rows, xorMaxval,
+                &paletteP, &xorCht, &colorCt, &error);
 
     if (error)
         pm_error("Unable to make palette for '%s'.  %s", xorPpmFname, error);
-   /*
-    * All the icons I found seemed to pad the palette to the max entries
-    * for that bitdepth.
-    * 
-    * The spec indicates this isn't necessary, but I'll follow this behaviour
-    * just in case.
+
+    /* All the icons I found seemed to pad the palette to the max entries for
+       that bitdepth.
+
+       The spec indicates this isn't necessary, but I'll follow this behaviour
+       just in case.
     */
-    if (colors < 3) {
+    if (colorCt < 3) {
         bpp = 1;
-        entry_cols = 2;
-    } else if (colors < 17) {
+        entryCols = 2;
+    } else if (colorCt < 17) {
         bpp = 4;
-        entry_cols = 16;
+        entryCols = 16;
     } else {
         bpp = 8;
-        entry_cols = 256;
+        entryCols = 256;
     }
 
     getOrFakeAndMap(andPgmFname, cols, rows,
@@ -690,164 +684,182 @@ addEntryToIcon(MS_Ico       const MSIconData,
         pm_error("Error in and map for '%s'.  %s", xorPpmFname, error);
 
     if (andPGMarray && trueTransparent)
-        blackenTransparentAreas(xorPPMarray, cols, rows, 
+        blackenTransparentAreas(xorPPMarray, cols, rows,
                                 andPGMarray, andMaxval);
 
-    xorBitmap = createBitmap(bpp, xorPPMarray, cols, rows, xorCht);
-    andBitmap = createAndBitmap(andPGMarray, cols, rows, andMaxval);
-    /*
-     * Fill in the entry data fields.
-    */
-    entry->width         = cols;
-    entry->height        = rows;
-    entry->color_count   = entry_cols;
-    entry->reserved      = 0;
-    entry->planes        = 1;
-    /* 
-    * all the icons I looked at ignored this value...
-    */
-    entry->bitcount      = bpp;
-    entry->ih            = createInfoHeader(entry, xorBitmap, andBitmap);
-    entry->colors        = palette->colors;
-    entry->size_in_bytes = 
-        xorBitmap->size + andBitmap->size + 40 + (4 * entry->color_count);
-    if (verbose) 
-        pm_message("entry->size_in_bytes = %d + %d + %d = %d",
-                   xorBitmap->size ,andBitmap->size, 
-                   40, entry->size_in_bytes );
-    /*
-    * We don't know the offset ATM, set to 0 for now.
-    * Have to calculate this at the end.
-    */
-    entry->file_offset   = 0;
-    entry->xorBitmapOut  = xorBitmap->data;
-    entry->andBitmapOut  = andBitmap->data;
-    entry->xBytesXor     = xorBitmap->xBytes;
-    entry->xBytesAnd     = andBitmap->xBytes;  
-    /*
-    * Add the entry to the entries array.
+    xorBitmapP = newBitmap(bpp, xorPPMarray, cols, rows, xorCht);
+    andBitmapP = newAndBitmap(andPGMarray, cols, rows, andMaxval);
+
+    /* Fill in the entry data fields. */
+    entryP->width         = cols;
+    entryP->height        = rows;
+    entryP->color_count   = entryCols;
+    entryP->reserved      = 0;
+    entryP->planes        = 1;
+    entryP->bitcount      = bpp;
+    /* all the icons I looked at ignored this value */
+    entryP->ih            = newInfoHeader(*entryP);
+    entryP->colors        = paletteP->colors;
+    entryP->size_in_bytes =
+        xorBitmapP->size + andBitmapP->size + 40 + (4 * entryCols);
+    if (verbose)
+        pm_message("entry->size_in_bytes = %u + %u + %u = %u",
+                   xorBitmapP->size, andBitmapP->size,
+                   40, entryP->size_in_bytes );
+
+    /* We don't know the offset ATM, set to 0 for now.  Have to calculate this
+       at the end.
     */
-    ++MSIconData->count;
+    entryP->file_offset  = 0;
+    entryP->xorBitmapOut = xorBitmapP->data;
+    entryP->andBitmapOut = andBitmapP->data;
+    entryP->xBytesXor    = xorBitmapP->xBytes;
+    entryP->xBytesAnd    = andBitmapP->xBytes;
+
+    /* Add the entry to the entries array. */
+    ++MSIconDataP->count;
+
     /* Perhaps I should allocate ahead, and take fewer trips to the well. */
-    REALLOCARRAY(MSIconData->entries, MSIconData->count);
-    MSIconData->entries[MSIconData->count-1] = entry;
+    REALLOCARRAY(MSIconDataP->entries, MSIconDataP->count);
+    MSIconDataP->entries[MSIconDataP->count - 1] = entryP;
 }
 
 
 
-static void 
-writeIC_Entry (IC_Entry const entry) {
-   writeU1(entry->width);
-   writeU1(entry->height);
-   writeU1(entry->color_count); /* chops 256->0 on its own.. */
-   writeU1(entry->reserved);
-   writeU2(entry->planes);
-   writeU2(entry->bitcount);
-   writeU4(entry->size_in_bytes);
-   writeU4(entry->file_offset);
+static void
+writeIC_Entry(FILE *     const ofP,
+              IC_Entry * const entryP) {
+
+   writeU1(ofP, entryP->width);
+   writeU1(ofP, entryP->height);
+   writeU1(ofP, entryP->color_count); /* chops 256->0 on its own.. */
+   writeU1(ofP, entryP->reserved);
+   writeU2(ofP, entryP->planes);
+   writeU2(ofP, entryP->bitcount);
+   writeU4(ofP, entryP->size_in_bytes);
+   writeU4(ofP, entryP->file_offset);
 }
 
 
 
-static void 
-writeIC_InfoHeader (IC_InfoHeader const ih) {
-   writeU4(ih->size);
-   writeU4(ih->width);
-   writeU4(ih->height);
-   writeU2(ih->planes);
-   writeU2(ih->bitcount);
-   writeU4(ih->compression);
-   writeU4(ih->imagesize);
-   writeU4(ih->x_pixels_per_m);
-   writeU4(ih->y_pixels_per_m);
-   writeU4(ih->colors_used);
-   writeU4(ih->colors_important);
+static void
+writeIC_InfoHeader(FILE *          const ofP,
+                   IC_InfoHeader * const ihP) {
+
+   writeU4(ofP, ihP->size);
+   writeU4(ofP, ihP->width);
+   writeU4(ofP, ihP->height);
+   writeU2(ofP, ihP->planes);
+   writeU2(ofP, ihP->bitcount);
+   writeU4(ofP, ihP->compression);
+   writeU4(ofP, ihP->imagesize);
+   writeU4(ofP, ihP->x_pixels_per_m);
+   writeU4(ofP, ihP->y_pixels_per_m);
+   writeU4(ofP, ihP->colors_used);
+   writeU4(ofP, ihP->colors_important);
 }
 
 
 
-static void 
-writeIC_Color (IC_Color const col) {
-   /* Since the ppm might not have as many colors in it as we'd like,
-    * (2, 16, 256), stick 0 in the gaps.
-    * 
-    * This means that we lose palette information, but that can't be
-    * helped.  
+static void
+writeIC_Color(FILE *     const ofP,
+              IC_Color * const colorP) {
+
+    /* Since the ppm might not have as many colors in it as we'd like,
+       (2, 16, 256), stick 0 in the gaps.
+
+       This means that we lose palette information, but that can't be helped.
     */
-   if (col == NULL) {
-      writeU1(0);
-      writeU1(0);
-      writeU1(0);
-      writeU1(0);
-   } else {
-      writeU1(col->blue);
-      writeU1(col->green);
-      writeU1(col->red);
-      writeU1(col->reserved);
-   }
+    if (!colorP) {
+        writeU1(ofP, 0);
+        writeU1(ofP, 0);
+        writeU1(ofP, 0);
+        writeU1(ofP, 0);
+    } else {
+        writeU1(ofP, colorP->blue);
+        writeU1(ofP, colorP->green);
+        writeU1(ofP, colorP->red);
+        writeU1(ofP, colorP->reserved);
+    }
 }
 
 
 
 static void
-writeBitmap(u1 ** const bitmap, int const xBytes, int const height) {
-   int y;
-   for (y = 0;y<height;y++) {
-      fwrite (bitmap[y],1,xBytes,ofp);
-      file_offset += xBytes;
-   }
+writeBitmap(FILE *       const ofP,
+            u1 **        const bitmap,
+            unsigned int const xByteCt,
+            unsigned int const height) {
+
+    unsigned int row;
+
+    for (row = 0; row < height; ++row) {
+        fwrite(bitmap[row], 1, xByteCt, ofP);
+        fileOffset += xByteCt;
+    }
 }
 
 
 
-static void 
-writeMS_Ico(MS_Ico       const MSIconData, 
+static void
+writeMS_Ico(MS_Ico *     const MSIconDataP,
             const char * const outFname) {
-    int x,y;
-   
-    ofp = pm_openw(outFname);
-
-    writeU2(MSIconData->reserved);
-    writeU2(MSIconData->type);
-    writeU2(MSIconData->count);
-    for (x=0;x<MSIconData->count;x++) writeIC_Entry(MSIconData->entries[x]);
-    for (x=0;x<MSIconData->count;x++) {
-        writeIC_InfoHeader(MSIconData->entries[x]->ih);
-        for (y=0;y<(MSIconData->entries[x]->color_count);y++) {
-            writeIC_Color(MSIconData->entries[x]->colors[y]);
+
+    FILE * const ofP = pm_openw(outFname);
+
+    unsigned int i;
+
+    writeU2(ofP, MSIconDataP->reserved);
+    writeU2(ofP, MSIconDataP->type);
+    writeU2(ofP, MSIconDataP->count);
+
+    for (i = 0; i < MSIconDataP->count; ++i)
+        writeIC_Entry(ofP, MSIconDataP->entries[i]);
+
+    for (i = 0; i < MSIconDataP->count; ++i) {
+        IC_Entry * const entryP = MSIconDataP->entries[i];
+
+        unsigned int j;
+
+        writeIC_InfoHeader(ofP, MSIconDataP->entries[i]->ih);
+
+        for (j = 0; j < (MSIconDataP->entries[i]->color_count); ++j) {
+            writeIC_Color(ofP, MSIconDataP->entries[i]->colors[j]);
         }
-        if (verbose) pm_message("writing xor bitmap");
-        writeBitmap(MSIconData->entries[x]->xorBitmapOut,
-                    MSIconData->entries[x]->xBytesXor,
-                    MSIconData->entries[x]->height);
-        if (verbose) pm_message("writing and bitmap");
-        writeBitmap(MSIconData->entries[x]->andBitmapOut,
-                    MSIconData->entries[x]->xBytesAnd,
-                    MSIconData->entries[x]->height);
+        if (verbose)
+            pm_message("writing xor bitmap");
+
+        writeBitmap(ofP,
+                    entryP->xorBitmapOut, entryP->xBytesXor, entryP->height);
+        if (verbose)
+            pm_message("writing and bitmap");
+
+        writeBitmap(ofP,
+                    entryP->andBitmapOut, entryP->xBytesAnd, entryP->height);
     }
-    fclose(ofp);
+    fclose(ofP);
 }
 
 
 
-int 
-main(int argc, char ** argv) {
+int
+main(int argc, const char ** argv) {
 
-    struct cmdlineInfo cmdline;
+    MS_Ico * const MSIconDataP = newIconFile();
 
-    MS_Ico const MSIconDataP = createIconFile();
+    struct CmdlineInfo cmdline;
     unsigned int iconIndex;
     unsigned int offset;
-   
-    ppm_init (&argc, argv);
+
+    pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
 
     verbose = cmdline.verbose;
 
     for (iconIndex = 0; iconIndex < cmdline.iconCount; ++iconIndex) {
-        addEntryToIcon(MSIconDataP, cmdline.inputFilespec[iconIndex],
-                       cmdline.andpgmFilespec[iconIndex], 
+        addEntryToIcon(MSIconDataP, cmdline.inputFileNm[iconIndex],
+                       cmdline.andpgmFileNm[iconIndex],
                        cmdline.truetransparent);
     }
     /*
@@ -856,22 +868,24 @@ main(int argc, char ** argv) {
      */
     offset = (MSIconDataP->count * 16) + 6;
     for (iconIndex = 0; iconIndex < MSIconDataP->count; ++iconIndex) {
-        IC_Entry entry = MSIconDataP->entries[iconIndex];
-        entry->file_offset = offset;
-        /* 
+        IC_Entry * const entryP = MSIconDataP->entries[iconIndex];
+
+        entryP->file_offset = offset;
+        /*
          * Increase the offset by the size of this offset & data.
          * this includes the size of the color data.
          */
-        offset += entry->size_in_bytes;
+        offset += entryP->size_in_bytes;
     }
     /*
      * And now, we have to actually SAVE the .ico!
      */
     writeMS_Ico(MSIconDataP, cmdline.output);
 
-    free(cmdline.inputFilespec);
-    free(cmdline.andpgmFilespec);
+    freeCmdline(cmdline);
 
     return 0;
 }
 
+
+
diff --git a/converter/ppm/ppmtoxpm.c b/converter/ppm/ppmtoxpm.c
index 0e316928..2167acb2 100644
--- a/converter/ppm/ppmtoxpm.c
+++ b/converter/ppm/ppmtoxpm.c
@@ -1,4 +1,4 @@
-/* ppmtoxpm.c - read a portable pixmap and produce a (version 3) X11 pixmap
+/* ppmtoxpm.c - read a PPM image and produce a (version 3) X11 pixmap
 **
 ** Copyright (C) 1990 by Mark W. Snitily
 **
@@ -24,7 +24,7 @@
 ** Rainer Sinkwitz sinkwitz@ifi.unizh.ch - 21 Nov 91:
 **  - Bug fix, should should malloc space for rgbn[j].name+1 in line 441
 **    caused segmentation faults
-**    
+**
 **  - lowercase conversion of RGB names def'ed out,
 **    considered harmful.
 **
@@ -37,6 +37,7 @@
 #define _BSD_SOURCE   /* Make sure strdup() is in string.h */
 #define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
 
+#include <stdbool.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
@@ -47,7 +48,7 @@
 #include "nstring.h"
 #include "mallocvar.h"
 
-/* Max number of entries we will put in the XPM color map 
+/* Max number of entries we will put in the XPM color map
    Don't forget the one entry for transparency.
 
    We don't use this anymore.  Ppmtoxpm now has no arbitrary limit on
@@ -75,14 +76,14 @@ static const char * const printable =
 ASDFGHJKLPIUYTREWQ!~^/()_`'][{}|";
 
 
-struct cmdlineInfo {
+struct CmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
-    const char *inputFilename;
-    const char *name;
-    const char *rgb;
-    const char *alpha_filename;
+    const char * inputFilename;
+    const char * name;
+    const char * rgb;
+    const char * alphaFilename;
     unsigned int hexonly;
     unsigned int verbose;
 };
@@ -90,8 +91,8 @@ struct cmdlineInfo {
 
 
 static void
-parseCommandLine(int argc, char ** argv,
-                 struct cmdlineInfo * const cmdlineP) {
+parseCommandLine(int argc, const char ** argv,
+                 struct CmdlineInfo * const cmdlineP) {
 /*----------------------------------------------------------------------------
    Note that the file spec array we return is stored in the storage that
    was passed to us as the argv array.
@@ -108,11 +109,11 @@ parseCommandLine(int argc, char ** argv,
     MALLOCARRAY(option_def, 100);
 
     option_def_index = 0;   /* incremented by OPTENTRY */
-    OPTENT3(0,   "alphamask",   OPT_STRING, &cmdlineP->alpha_filename, 
+    OPTENT3(0,   "alphamask",   OPT_STRING, &cmdlineP->alphaFilename,
             NULL, 0);
-    OPTENT3(0,   "name",        OPT_STRING, &nameOpt,                   
+    OPTENT3(0,   "name",        OPT_STRING, &nameOpt,
             &nameSpec, 0);
-    OPTENT3(0,   "rgb",         OPT_STRING, &cmdlineP->rgb,            
+    OPTENT3(0,   "rgb",         OPT_STRING, &cmdlineP->rgb,
             NULL, 0);
     OPTENT3(0,   "hexonly",     OPT_FLAG, NULL,
             &cmdlineP->hexonly, 0);
@@ -120,17 +121,17 @@ parseCommandLine(int argc, char ** argv,
             &cmdlineP->verbose, 0);
 
     /* Set the defaults */
-    cmdlineP->alpha_filename = NULL;  /* no transparency */
+    cmdlineP->alphaFilename = NULL;  /* no transparency */
     cmdlineP->rgb = NULL;      /* no rgb file specified */
 
     opt.opt_table = option_def;
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
     opt.allowNegNum = FALSE;  /* We may have parms that are negative numbers */
 
-    pm_optParseOptions3(&argc, argv, opt, sizeof(opt), 0);
+    pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0);
         /* Uses and sets argc, argv, and some of *cmdlineP and others. */
 
-    if (argc-1 == 0) 
+    if (argc-1 == 0)
         cmdlineP->inputFilename = "-";
     else if (argc-1 != 1)
         pm_error("Program takes zero or one argument (filename).  You "
@@ -156,28 +157,24 @@ parseCommandLine(int argc, char ** argv,
 }
 
 
-typedef struct {            /* rgb values and ascii names (from
-                             * rgb text file) */
-    int r, g, b;            /* rgb values, range of 0 -> 65535 */
-    char *name;             /* color mnemonic of rgb value */
-} rgb_names;
 
-typedef struct {            
+typedef struct {
     /* Information for an XPM color map entry */
-    char *cixel;    
+    char *cixel;
        /* XPM color number, as might appear in the XPM raster */
-    const char *rgbname;  
+    const char *rgbname;
        /* color name, e.g. "blue" or "#01FF23" */
-} cixel_map;
+} CixelMap;
 
 
 
 static char *
-genNumstr(unsigned int const input, int const digits) {
+numstr(unsigned int const input,
+       unsigned int const digitCt) {
 /*---------------------------------------------------------------------------
    Given a number and a base (MAXPRINTABLE), this routine prints the
    number into a malloc'ed string and returns it.  The length of the
-   string is specified by "digits".  It is not printed in decimal or
+   string is specified by 'digitCt'.  It is not printed in decimal or
    any other number system you're used to.  Rather, each digit is from
    the set printable[], which contains MAXPRINTABLE characters; the
    character printable[n] has value n.
@@ -185,35 +182,35 @@ genNumstr(unsigned int const input, int const digits) {
    The string is printable[0] filled with high order zeroes.
 
    Example:
-     Assume: 
+     Assume:
        printable[0] == 'q'
        printable[1] == '%'
-       MAXPRINTABLE == 2 
-       digits == 5
-       input == 3 
+       MAXPRINTABLE == 2
+       digitCt == 5
+       input == 3
      Result is the malloc'ed string "qqq%%"
 ---------------------------------------------------------------------------*/
-    char *str, *p;
-    int d;
+    char * str;  /* malloc'ed */
+    char * p;
     unsigned int i;
 
     /* Allocate memory for printed number.  Abort if error. */
-    if (!(str = (char *) malloc(digits + 1)))
-        pm_error("out of memory");
+    MALLOCARRAY_NOFAIL(str, digitCt + 1);
 
-    i = input;
+    i = input; /* initial value */
     /* Generate characters starting with least significant digit. */
-    p = str + digits;
+    p = str + digitCt;  /* initial value */
     *p-- = '\0';            /* nul terminate string */
     while (p >= str) {
-        d = i % MAXPRINTABLE;
+        unsigned int const d = i % MAXPRINTABLE;
+
         i /= MAXPRINTABLE;
         *p-- = printable[d];
     }
 
     if (i != 0)
-        pm_error("Overflow converting %d to %d digits in base %d",
-                 input, digits, MAXPRINTABLE);
+        pm_error("Overflow converting %u to %u digits in base %u",
+                 input, digitCt, MAXPRINTABLE);
 
     return str;
 }
@@ -225,10 +222,9 @@ xpmMaxvalFromMaxval(pixval const maxval) {
 
     unsigned int retval;
 
-    /*
-     * Determine how many hex digits we'll be normalizing to if the rgb
-     * value doesn't match a color mnemonic. 
-     */
+    /* Determine how many hex digits we'll be normalizing to if the rgb
+       value doesn't match a color mnemonic.
+    */
     if (maxval <= 0x000F)
         retval = 0x000F;
     else if (maxval <= 0x00FF)
@@ -242,22 +238,21 @@ xpmMaxvalFromMaxval(pixval const maxval) {
 
     return retval;
 }
-    
+
 
 
 static unsigned int
-charsPerPixelForSize(unsigned int const cmapSize) { 
+charsPerPixelForSize(unsigned int const cmapSize) {
 /*----------------------------------------------------------------------------
-   Return the number of characters it will take to represent a pixel in
-   an XPM that has a colormap of size 'cmapSize'.  Each pixel in an XPM
-   represents an index into the colormap with a base-92 scheme where each
-   character is one of 92 printable characters.  Ergo, if the colormap
-   has at most 92 characters, each pixel will be represented by a single
-   character.  If it has more than 92, but at most 92*92, it will take 2, 
-   etc.
-
-   If cmapSize is zero, there's no such thing as an XPM pixel, so we
-   return an undefined value.
+   The number of characters it will take to represent a pixel in an XPM that
+   has a colormap of size 'cmapSize'.  Each pixel in an XPM represents an
+   index into the colormap with a base-92 scheme where each character is one
+   of 92 printable characters.  Ergo, if the colormap has at most 92
+   characters, each pixel will be represented by a single character.  If it
+   has more than 92, but at most 92*92, it will take 2, etc.
+
+   If cmapSize is zero, there's no such thing as an XPM pixel, so we return an
+   undefined value.
 -----------------------------------------------------------------------------*/
     unsigned int charsPerPixel;
 
@@ -268,23 +263,23 @@ charsPerPixelForSize(unsigned int const cmapSize) {
             j /= MAXPRINTABLE;
     }
     return charsPerPixel;
-} 
+}
 
 
 
 static void
-genCmap(colorhist_vector const chv, 
-        int              const ncolors, 
-        pixval           const maxval, 
+genCmap(colorhist_vector const chv,
+        unsigned int     const ncolors,
+        pixval           const maxval,
         colorhash_table  const colornameHash,
-        const char *     const colornames[],
+        const char **    const colornames,
         bool             const includeTransparent,
-        cixel_map **     const cmapP, 
+        CixelMap **      const cmapP,
         unsigned int *   const transIndexP,
         unsigned int *   const cmapSizeP,
         unsigned int *   const charsPerPixelP) {
 /*----------------------------------------------------------------------------
-   Generate the XPM color map in cixel_map format (which is just a step
+   Generate the XPM color map in CixelMap format (which is just a step
    away from the actual text that needs to be written the XPM file).  The
    color map is defined by 'chv', which contains 'ncolors' colors which
    have maxval 'maxval'.
@@ -310,15 +305,14 @@ genCmap(colorhist_vector const chv,
 -----------------------------------------------------------------------------*/
     unsigned int const cmapSize = ncolors + (includeTransparent ? 1 : 0);
 
-    cixel_map * cmap;  /* malloc'ed */
+    CixelMap * cmap;  /* malloc'ed */
     unsigned int cmapIndex;
     unsigned int charsPerPixel;
     unsigned int xpmMaxval;
-    
+
     MALLOCARRAY(cmap, cmapSize);
     if (cmapP == NULL)
-        pm_error("Out of memory allocating %u bytes for a color map.",
-                 (unsigned)sizeof(cixel_map) * (ncolors+1));
+        pm_error("Can't get memory for a %u-entry color map", cmapSize);
 
     xpmMaxval = xpmMaxvalFromMaxval(maxval);
 
@@ -326,7 +320,7 @@ genCmap(colorhist_vector const chv,
 
     /*
      * Generate the character-pixel string and the rgb name for each
-     * colormap entry. 
+     * colormap entry.
      */
     for (cmapIndex = 0; cmapIndex < ncolors; ++cmapIndex) {
         pixel const color = chv[cmapIndex].color;
@@ -338,10 +332,10 @@ genCmap(colorhist_vector const chv,
          * The character-pixel string is simply a printed number in base
          * MAXPRINTABLE where the digits of the number range from
          * printable[0] .. printable[MAXPRINTABLE-1] and the printed length
-         * of the number is 'charsPerPixel'. 
+         * of the number is 'charsPerPixel'.
          */
-        cmap[cmapIndex].cixel = genNumstr(cmapIndex, charsPerPixel);
-        
+        cmap[cmapIndex].cixel = numstr(cmapIndex, charsPerPixel);
+
         PPM_DEPTH(color255, color, maxval, 255);
 
         if (colornameHash == NULL)
@@ -367,7 +361,7 @@ genCmap(colorhist_vector const chv,
             pm_asprintf(&hexString, xpmMaxval == 0x000F ? "#%X%X%X" :
                         xpmMaxval == 0x00FF ? "#%02X%02X%02X" :
                         xpmMaxval == 0x0FFF ? "#%03X%03X%03X" :
-                        "#%04X%04X%04X", 
+                        "#%04X%04X%04X",
                         PPM_GETR(scaledColor),
                         PPM_GETG(scaledColor),
                         PPM_GETB(scaledColor)
@@ -383,7 +377,7 @@ genCmap(colorhist_vector const chv,
         /* Add the special transparency entry to the colormap */
         unsigned int const transIndex = ncolors;
         cmap[transIndex].rgbname = strdup("None");
-        cmap[transIndex].cixel = genNumstr(transIndex, charsPerPixel);
+        cmap[transIndex].cixel = numstr(transIndex, charsPerPixel);
         *transIndexP = transIndex;
     }
     *cmapP          = cmap;
@@ -394,107 +388,111 @@ genCmap(colorhist_vector const chv,
 
 
 static void
-destroyCmap(cixel_map *  const cmap, 
+destroyCmap(CixelMap *   const cmap,
             unsigned int const cmapSize) {
 
-    int i;
+    unsigned int i;
+
     /* Free the real color entries */
-    for (i = 0; i < cmapSize; i++) {
+    for (i = 0; i < cmapSize; ++i) {
         pm_strfree(cmap[i].rgbname);
         free(cmap[i].cixel);
     }
+
     free(cmap);
 }
 
 
 
 static void
-writeXpmFile(FILE *          const outfile, 
-             pixel **        const pixels, 
-             gray **         const alpha, 
-             pixval          const alphamaxval,
-             char            const name[], 
-             int             const cols, 
-             int             const rows, 
-             unsigned int    const cmapSize,
-             unsigned int    const charsPerPixel, 
-             cixel_map       const cmap[],
-             colorhash_table const cht,
-             unsigned int    const transIndex) {
+writeXpmFile(FILE *           const ofP,
+             pixel **         const pixels,
+             gray **          const alpha,
+             pixval           const alphamaxval,
+             char             const name[],
+             unsigned int     const cols,
+             unsigned int     const rows,
+             unsigned int     const cmapSize,
+             unsigned int     const charsPerPixel,
+             const CixelMap * const cmap,
+             colorhash_table  const cht,
+             unsigned int     const transIndex) {
 /*----------------------------------------------------------------------------
-   Write the whole XPM file to the open stream 'outfile'.
+   Write the whole XPM file to the open stream 'ofP'.
 
-   'cmap' is the colormap to be placed in the XPM.  'cmapSize' is the
-   number of entries in it.  'cht' is a hash table that gives you an 
-   index into 'cmap' given a color.  'transIndex' is the index into cmap
-   of the transparent color, and is valid only if 'alpha' is non-null
-   (otherwise, cmap might not contain a transparent color).
+   'cmap' is the colormap to be placed in the XPM.  'cmapSize' is the number
+   of entries in it.  'cht' is a hash table that gives you an index into
+   'cmap' given a color.  'transIndex' is the index into cmap of the
+   transparent color, and is valid only if 'alpha' is non-null (otherwise,
+   cmap might not contain a transparent color).
 -----------------------------------------------------------------------------*/
     /* First the header */
     printf("/* XPM */\n");
-    fprintf(outfile, "static char *%s[] = {\n", name);
-    fprintf(outfile, "/* width height ncolors chars_per_pixel */\n");
-    fprintf(outfile, "\"%d %d %d %d\",\n", cols, rows, 
-            cmapSize, charsPerPixel);
+    fprintf(ofP, "static char *%s[] = {\n", name);
+    fprintf(ofP, "/* width height ncolors chars_per_pixel */\n");
+    fprintf(ofP, "\"%u %u %u %u\",\n", cols, rows, cmapSize, charsPerPixel);
 
     {
-        int i;
+        unsigned int i;
         /* Write out the colormap (part of header) */
-        fprintf(outfile, "/* colors */\n");
-        for (i = 0; i < cmapSize; i++) { 
-            fprintf(outfile, "\"%s c %s\",\n", cmap[i].cixel, cmap[i].rgbname);
+        fprintf(ofP, "/* colors */\n");
+        for (i = 0; i < cmapSize; i++) {
+            fprintf(ofP, "\"%s c %s\",\n", cmap[i].cixel, cmap[i].rgbname);
         }
     }
     {
-        int row;
+        unsigned int row;
 
         /* And now the raster */
-        fprintf(outfile, "/* pixels */\n");
-        for (row = 0; row < rows; row++) {
-            int col;
-            fprintf(outfile, "\"");
-            for (col = 0; col < cols; col++) {
+        fprintf(ofP, "/* pixels */\n");
+        for (row = 0; row < rows; ++row) {
+            unsigned int col;
+            fprintf(ofP, "\"");
+            for (col = 0; col < cols; ++col) {
                 if (alpha && alpha[row][col] <= alphamaxval/2)
                     /* It's a transparent pixel */
-                    fprintf(outfile, "%s", cmap[transIndex].cixel);
-                else 
-                    fprintf(outfile, "%s", 
-                            cmap[ppm_lookupcolor(cht, 
+                    fprintf(ofP, "%s", cmap[transIndex].cixel);
+                else
+                    fprintf(ofP, "%s",
+                            cmap[ppm_lookupcolor(cht,
                                                  &pixels[row][col])].cixel);
             }
-            fprintf(outfile, "\"%s\n", (row == (rows - 1) ? "" : ","));
+            fprintf(ofP, "\"%s\n", (row == (rows - 1) ? "" : ","));
         }
     }
     /* And close up */
-    fprintf(outfile, "};\n");
+    fprintf(ofP, "};\n");
 }
 
 
 
 static void
-readAlpha(const char filespec[], gray *** const alphaP,
-          int const cols, int const rows, pixval * const alphamaxvalP) {
+readAlpha(const char * const fileNm,
+          gray ***     const alphaP,
+          unsigned int const cols,
+          unsigned int const rows,
+          pixval *     const alphamaxvalP) {
 
-    FILE * alpha_file;
+    FILE * alphaFileP;
     int alphacols, alpharows;
-        
-    alpha_file = pm_openr(filespec);
-    *alphaP = pgm_readpgm(alpha_file, &alphacols, &alpharows, alphamaxvalP);
-    pm_close(alpha_file);
-    
+
+    alphaFileP = pm_openr(fileNm);
+    *alphaP = pgm_readpgm(alphaFileP, &alphacols, &alpharows, alphamaxvalP);
+    pm_close(alphaFileP);
+
     if (cols != alphacols || rows != alpharows)
         pm_error("Alpha mask is not the same dimensions as the "
-                 "image.  Image is %d by %d, while mask is %d x %d.",
+                 "image.  Image is %u by %u, while mask is %d x %d.",
                  cols, rows, alphacols, alpharows);
 }
-    
+
 
 
 static void
 computecolorhash(pixel **          const pixels,
                  gray **           const alpha,
-                 int               const cols,
-                 int               const rows,
+                 unsigned int      const cols,
+                 unsigned int      const rows,
                  gray              const alphaMaxval,
                  colorhash_table * const chtP,
                  unsigned int *    const ncolorsP,
@@ -507,49 +505,55 @@ computecolorhash(pixel **          const pixels,
    The value associated with the color in the hash we build is meaningless.
 
    Return the colorhash_table as *chtP, and the number of colors in it
-   as *ncolorsP.  Return *transparentSomewhereP == TRUE iff the image has
+   as *ncolorsP.  Return *transparentSomewhereP == true iff the image has
    at least one pixel that is mostly transparent.
 -----------------------------------------------------------------------------*/
     colorhash_table cht;
-    int row;
-    
-    cht = ppm_alloccolorhash( );
-    *ncolorsP = 0;   /* initial value */
-    *transparentSomewhereP = FALSE;  /* initial assumption */
+    unsigned int row;
+    bool foundTransparent;
+    unsigned int ncolors;
+
+    cht = ppm_alloccolorhash();
 
     /* Go through the entire image, building a hash table of colors. */
-    for (row = 0; row < rows; ++row) {
-        int col;
+    for (row = 0, ncolors = 0, foundTransparent = false; row < rows; ++row) {
+        unsigned int col;
 
         for (col = 0; col < cols; ++col) {
             if (!alpha || alpha[row][col] > alphaMaxval/2) {
                 /* It's mostly opaque, so add this color to the hash
-                   if it's not already there.  
+                   if it's not already there.
                 */
                 pixel const color = pixels[row][col];
                 int const lookupRc = ppm_lookupcolor(cht, &color);
- 
+
                 if (lookupRc < 0) {
                     /* It's not in the hash yet, so add it */
+                    if (ncolors > UINT_MAX - 10)
+                        pm_error("Number of colors (> %u) "
+                                 "is uncomputably large",
+                                 ncolors);
                     ppm_addtocolorhash(cht, &color, 0);
-                    ++(*ncolorsP);
+                    ++ncolors;
                 }
             } else
                 *transparentSomewhereP = TRUE;
         }
     }
-    *chtP = cht;
+    *chtP                  = cht;
+    *ncolorsP              = ncolors;
+    *transparentSomewhereP = foundTransparent;
 }
 
 
 
 static void
-computeColormap(pixel **           const pixels, 
+computeColormap(pixel **           const pixels,
                 gray **            const alpha,
-                int                const cols, 
-                int                const rows,
+                unsigned int       const cols,
+                unsigned int       const rows,
                 gray               const alphaMaxval,
-                colorhist_vector * const chvP, 
+                colorhist_vector * const chvP,
                 colorhash_table *  const chtP,
                 unsigned int *     const ncolorsP,
                 bool *             const transparentSomewhereP) {
@@ -558,23 +562,21 @@ computeColormap(pixel **           const pixels,
    in Netpbm data structures (a colorhist_vector for index-to-color lookups
    and a colorhash_table for color-to-index lookups).
 
-   Exclude pixels that alpha mask 'alpha' (which has maxval
-   'alphaMaxval') says are mostly transparent.  alpha == NULL means all
-   pixels are opaque.
+   Exclude pixels that alpha mask 'alpha' (which has maxval 'alphaMaxval')
+   says are mostly transparent.  alpha == NULL means all pixels are opaque.
 
-   We return as *chvP an array of the colors present in 'pixels',
-   excluding those that are mostly transparent.  We return as
-   *ncolorsP the number of such colors.  We return
-   *transparentSomewhereP == TRUE iff the image has at least one
-   pixel that is mostly transparent.
+   We return as *chvP an array of the colors present in 'pixels', excluding
+   those that are mostly transparent.  We return as *ncolorsP the number of
+   such colors.  We return *transparentSomewhereP == true iff the image has at
+   least one pixel that is mostly transparent.
 -----------------------------------------------------------------------------*/
     colorhash_table histCht;
 
     pm_message("(Computing colormap...");
-    computecolorhash(pixels, alpha, cols, rows, alphaMaxval, 
+    computecolorhash(pixels, alpha, cols, rows, alphaMaxval,
                      &histCht, ncolorsP, transparentSomewhereP);
     pm_message("...Done.  %d colors found.)", *ncolorsP);
-    
+
     *chvP = ppm_colorhashtocolorhist(histCht, *ncolorsP);
     ppm_freecolorhash(histCht);
     /* Despite the name, the following generates an index on *chvP,
@@ -587,9 +589,9 @@ computeColormap(pixel **           const pixels,
 
 
 int
-main(int argc, char *argv[]) {
+main(int argc, const char * *argv) {
 
-    FILE *ifp;
+    FILE * ifP;
     int rows, cols;
     unsigned int ncolors;
     bool transparentSomewhere;
@@ -604,31 +606,31 @@ main(int argc, char *argv[]) {
            array.
         */
 
-    pixel **pixels;
-    gray **alpha;
+    pixel ** pixels;
+    gray ** alpha;
 
     /* Used for rgb value -> character-pixel string mapping */
-    cixel_map *cmap;  /* malloc'ed */
+    CixelMap * cmap;  /* malloc'ed */
         /* The XPM colormap */
     unsigned int cmapSize;
         /* Number of entries in 'cmap' */
     unsigned int transIndex;
         /* Index into 'cmap' of the transparent color, if there is one */
 
-    unsigned int charsPerPixel;  
+    unsigned int charsPerPixel;
 
-    struct cmdlineInfo cmdline;
+    struct CmdlineInfo cmdline;
 
-    ppm_init(&argc, argv);
+    pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
 
-    ifp = pm_openr(cmdline.inputFilename);
-    pixels = ppm_readppm(ifp, &cols, &rows, &maxval);
-    pm_close(ifp);
+    ifP = pm_openr(cmdline.inputFilename);
+    pixels = ppm_readppm(ifP, &cols, &rows, &maxval);
+    pm_close(ifP);
 
-    if (cmdline.alpha_filename) 
-        readAlpha(cmdline.alpha_filename, &alpha, cols, rows, &alphaMaxval);
+    if (cmdline.alphaFilename)
+        readAlpha(cmdline.alphaFilename, &alpha, cols, rows, &alphaMaxval);
     else
         alpha = NULL;
 
@@ -643,14 +645,14 @@ main(int argc, char *argv[]) {
         ppm_readcolornamefile(NULL, FALSE, &colornameHash, &colornames);
 
     /* Now generate the character-pixel colormap table. */
-    genCmap(chv, ncolors, maxval, 
-            colornameHash, colornames, transparentSomewhere, 
+    genCmap(chv, ncolors, maxval,
+            colornameHash, colornames, transparentSomewhere,
             &cmap, &transIndex, &cmapSize, &charsPerPixel);
 
     writeXpmFile(stdout, pixels, alpha, alphaMaxval,
                  cmdline.name, cols, rows, cmapSize,
                  charsPerPixel, cmap, cht, transIndex);
-    
+
     if (colornameHash) {
         ppm_freecolorhash(colornameHash);
         ppm_freecolornames(colornames);
@@ -662,3 +664,5 @@ main(int argc, char *argv[]) {
     return 0;
 }
 
+
+
diff --git a/converter/ppm/ppmtoyuv.c b/converter/ppm/ppmtoyuv.c
index 75f79c1e..3b6f873d 100644
--- a/converter/ppm/ppmtoyuv.c
+++ b/converter/ppm/ppmtoyuv.c
@@ -2,7 +2,7 @@
 **
 ** by Marc Boucher
 ** Internet: marc@PostImage.COM
-** 
+**
 ** Based on Example Conversion Program, A60/A64 Digital Video Interface
 ** Manual, page 69.
 **
@@ -42,7 +42,7 @@ convertRow(const pixel *   const pixelrow,
             pixval const r = PPM_GETR(pixelrow[col]);
             pixval const g = PPM_GETG(pixelrow[col]);
             pixval const b = PPM_GETB(pixelrow[col]);
-            
+
             y1 = 16829 * r + 33039 * g +  6416 * b + (*y2CarryP & 0xffff);
             u1 = -4853 * r -  9530 * g + 14383 * b;
             v1 = 14386 * r - 12046 * g -  2340 * b;
@@ -110,7 +110,7 @@ main(int argc, const char **argv) {
         ppm_readppmrow(ifP, pixelrow, cols, maxval, format);
 
         convertRow(pixelrow, cols, yuvBuf, &u, &v, &u0, &v0, &y2Carry);
-        
+
         fwrite(yuvBuf, cols*2, 1, stdout);
     }
 
@@ -118,3 +118,6 @@ main(int argc, const char **argv) {
 
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ppmtoyuvsplit.c b/converter/ppm/ppmtoyuvsplit.c
index eb89ad29..a8723e32 100644
--- a/converter/ppm/ppmtoyuvsplit.c
+++ b/converter/ppm/ppmtoyuvsplit.c
@@ -209,3 +209,6 @@ main(int argc, const char ** argv) {
     fclose(vf);
     return 0;
 }
+
+
+
diff --git a/converter/ppm/qrttoppm.c b/converter/ppm/qrttoppm.c
index 935463e7..48a395e9 100644
--- a/converter/ppm/qrttoppm.c
+++ b/converter/ppm/qrttoppm.c
@@ -1,4 +1,4 @@
-/* qrttoppm.c - read a QRT ray-tracer output file and produce a portable pixmap
+/* qrttoppm.c - read a QRT ray-tracer output file and produce a PPM
 **
 ** Copyright (C) 1989 by Jef Poskanzer.
 **
@@ -10,60 +10,76 @@
 ** implied warranty.
 */
 
+#include "mallocvar.h"
 #include "ppm.h"
 
+
+
 int
-main( argc, argv )
-    int argc;
-    char* argv[];
-    {
-    FILE* ifp;
-    register pixel* pixelrow;
-    int rows, cols, row, col;
-    pixval maxval;
-    unsigned char* buf;
+main(int argc, const char ** argv) {
 
+    FILE * ifP;
+    pixel * pixelrow;
+    unsigned int rows, cols;
+    unsigned int row;
+    pixval maxval;
+    unsigned char * buf;
 
-    ppm_init( &argc, argv );
+    pm_proginit(&argc, argv);
 
-    if ( argc > 2 )
-	pm_usage( "[qrtfile]" );
+    if (argc-1 > 1)
+        pm_error("Too many arguments (%u).  The only possible argument "
+                 "is the input file name", argc-1);
 
-    if ( argc == 2 )
-	ifp = pm_openr( argv[1] );
+    if (argc-1 >= 1)
+        ifP = pm_openr(argv[1]);
     else
-	ifp = stdin;
+        ifP = stdin;
 
     /* Read in the QRT file.  First the header. */
-    cols = getc( ifp );
-    cols += getc( ifp ) << 8;
-    rows = getc( ifp );
-    rows += getc( ifp ) << 8;
+    cols = (unsigned char)getc(ifP);
+    cols += (unsigned char)getc(ifP) << 8;
+    rows = (unsigned char)getc(ifP);
+    rows += (unsigned char)getc(ifP) << 8;
+
+    if (cols <= 0 || rows <= 0)
+        pm_error("Invalid size: %u %u", cols, rows);
 
-    if ( cols <= 0 || rows <= 0 )
-	pm_error( "invalid size: %d %d", cols, rows );
     maxval = 255;
 
-    ppm_writeppminit( stdout, cols, rows, maxval, 0 );
-    pixelrow = ppm_allocrow( cols );
-    buf = (unsigned char *) malloc( 3 * cols );
-    if ( buf == (unsigned char *) 0 )
-	pm_error( "out of memory" );
-
-    for ( row = 0; row < rows; row++ )
-	{
-        (void) getc( ifp );	/* discard */
-        (void) getc( ifp );	/* linenum */
-	if ( fread( buf, 3 * cols, 1, ifp ) != 1 )
-	    pm_error( "EOF / read error" );
-	for ( col = 0; col < cols; col++ )
-	    PPM_ASSIGN(
-		pixelrow[col], buf[col], buf[cols + col], buf[2 * cols + col] );
-	ppm_writeppmrow( stdout, pixelrow, cols, maxval, 0 );
-	}
-
-    pm_close( ifp );
-    pm_close( stdout );
-
-    exit( 0 );
+    ppm_writeppminit(stdout, cols, rows, maxval, 0);
+
+    pixelrow = ppm_allocrow(cols);
+
+    MALLOCARRAY(buf, 3 * cols);
+
+    if (!buf)
+        pm_error("Failed to allocate buffer for %u columns", cols);
+
+    for (row = 0; row < rows; ++row) {
+        unsigned int col;
+
+        getc(ifP); /* discard */
+        getc(ifP); /* linenum */
+
+        if (fread(buf, 3 * cols, 1, ifP) != 1)
+            pm_error("EOF / read error");
+
+        for (col = 0; col < cols; ++col) {
+            PPM_ASSIGN(pixelrow[col],
+                       buf[col], buf[cols + col], buf[2 * cols + col]);
+        }
+        ppm_writeppmrow(stdout, pixelrow, cols, maxval, 0);
     }
+
+    free(buf);
+    ppm_freerow(pixelrow);
+
+    pm_close(ifP);
+    pm_close(stdout);
+
+    exit(0);
+}
+
+
+
diff --git a/converter/ppm/rawtoppm.c b/converter/ppm/rawtoppm.c
index 44e856da..7ba579ef 100644
--- a/converter/ppm/rawtoppm.c
+++ b/converter/ppm/rawtoppm.c
@@ -201,7 +201,7 @@ main(int argc, const char * argv[]) {
 
     if ( argn + 2 > argc )
         pm_usage( usage );
-    
+
     cols = pm_parse_width(argv[argn++]);
     rows = pm_parse_height(argv[argn++]);
 
@@ -250,3 +250,6 @@ main(int argc, const char * argv[]) {
 
     exit( 0 );
     }
+
+
+
diff --git a/converter/ppm/rgb3toppm.c b/converter/ppm/rgb3toppm.c
index a666553c..00d76916 100644
--- a/converter/ppm/rgb3toppm.c
+++ b/converter/ppm/rgb3toppm.c
@@ -37,7 +37,7 @@ main( argc, argv )
     ppm_init( &argc, argv );
 
     if ( argc != 4 )
-	pm_usage( "<red pgmfile> <green pgmfile> <blue pgmfile> " );
+        pm_usage( "<red pgmfile> <green pgmfile> <blue pgmfile> " );
 
     rfd = pm_openr( argv[1] );
     gfd = pm_openr( argv[2] );
@@ -46,10 +46,10 @@ main( argc, argv )
     pgm_readpgminit( rfd, &cols, &rows, &rmaxval, &rformat );
     pgm_readpgminit( gfd, &tcols, &trows, &gmaxval, &gformat );
     if ( tcols != cols || trows != rows )
-	pm_error( "all three graymaps must be the same size" );
+        pm_error( "all three graymaps must be the same size" );
     pgm_readpgminit( bfd, &tcols, &trows, &bmaxval, &bformat );
     if ( tcols != cols || trows != rows )
-	pm_error( "all three graymaps must be the same size" );
+        pm_error( "all three graymaps must be the same size" );
 
     pmaxval = rmaxval;
     if ( gmaxval > pmaxval ) pmaxval = gmaxval;
@@ -62,22 +62,22 @@ main( argc, argv )
     pixelrow = ppm_allocrow( cols );
 
     for ( row = 0; row < rows; row++ )
-	{
-	pgm_readpgmrow( rfd, rrow, cols, rmaxval, rformat );
-	pgm_readpgmrow( gfd, grow, cols, gmaxval, gformat );
-	pgm_readpgmrow( bfd, brow, cols, bmaxval, bformat );
-
-	for ( col = 0, rP = rrow, gP = grow, bP = brow, pP = pixelrow;
-	      col < cols;
-	      ++col, ++rP, ++gP, ++bP, ++pP )
-	    {
-	    if ( rmaxval != pmaxval ) *rP = (int) *rP * pmaxval / rmaxval;
-	    if ( gmaxval != pmaxval ) *gP = (int) *gP * pmaxval / gmaxval;
-	    if ( bmaxval != pmaxval ) *bP = (int) *bP * pmaxval / bmaxval;
-	    PPM_ASSIGN( *pP, *rP, *gP, *bP );
-	    }
-	ppm_writeppmrow( stdout, pixelrow, cols, pmaxval, 0 );
-	}
+        {
+        pgm_readpgmrow( rfd, rrow, cols, rmaxval, rformat );
+        pgm_readpgmrow( gfd, grow, cols, gmaxval, gformat );
+        pgm_readpgmrow( bfd, brow, cols, bmaxval, bformat );
+
+        for ( col = 0, rP = rrow, gP = grow, bP = brow, pP = pixelrow;
+              col < cols;
+              ++col, ++rP, ++gP, ++bP, ++pP )
+            {
+            if ( rmaxval != pmaxval ) *rP = (int) *rP * pmaxval / rmaxval;
+            if ( gmaxval != pmaxval ) *gP = (int) *gP * pmaxval / gmaxval;
+            if ( bmaxval != pmaxval ) *bP = (int) *bP * pmaxval / bmaxval;
+            PPM_ASSIGN( *pP, *rP, *gP, *bP );
+            }
+        ppm_writeppmrow( stdout, pixelrow, cols, pmaxval, 0 );
+        }
 
     pm_close( rfd );
     pm_close( gfd );
@@ -86,3 +86,6 @@ main( argc, argv )
 
     exit( 0 );
     }
+
+
+
diff --git a/converter/ppm/sldtoppm.c b/converter/ppm/sldtoppm.c
index 2fef0233..35d8c33a 100644
--- a/converter/ppm/sldtoppm.c
+++ b/converter/ppm/sldtoppm.c
@@ -23,6 +23,8 @@
 
 */
 
+#include <limits.h>
+#include <assert.h>
 #include <string.h>
 #include <math.h>
 
@@ -30,35 +32,38 @@
 #include "ppm.h"
 #include "ppmdraw.h"
 #include "nstring.h"
-#include <assert.h>
 
 #include "autocad.h"                  /* AutoCAD standard color assignments */
 
 
 /*  Define a variable type accepting numbers -127 <= n <= 127.  But note
-    that we still expect it to act UNSIGNED. */
+    that we still expect it to act UNSIGNED.
+*/
 
 #define smallint unsigned char        /* Small integers */
 
 #define EOS     '\0'
 
-/* Screen point */
-
 struct spoint {
+/*----------------------------------------------------------------------------
+   A screen point
+-----------------------------------------------------------------------------*/
     int x, y;
 };
 
-/* Screen polygon */
-
 struct spolygon {
-    int npoints,              /* Number of points in polygon */
-          fill;           /* Fill type */
-    struct spoint pt[11];         /* Actual points */
+/*----------------------------------------------------------------------------
+   A screen polygon
+-----------------------------------------------------------------------------*/
+    int npoints;           /* Number of points in polygon */
+    int fill;              /* Fill type */
+    struct spoint pt[11];  /* The points */
 };
 
-/* Screen vector */
-
 struct svector {
+/*----------------------------------------------------------------------------
+   A screen vector
+-----------------------------------------------------------------------------*/
     struct spoint f;          /* From point */
     struct spoint t;          /* To point */
 };
@@ -73,12 +78,8 @@ static int ixdots, iydots;        /* Screen size in dots */
 static FILE * slfile;             /* Slide file descriptor */
 static bool blither;              /* Dump slide file information ? */
 static bool info;                 /* Print header information */
-static pixel **pixels;            /* Pixel map */
+static pixel ** pixels;           /* Pixel map */
 static int pixcols, pixrows;      /* Pixel map size */
-static double uscale = -1;        /* Uniform scale factor */
-static int sxsize = -1, sysize = -1;  /* Scale to X, Y size ? */
-
-/*  Local variables  */
 
 struct slhead {
     char slh[17];             /* Primate-readable header */
@@ -90,7 +91,6 @@ struct slhead {
     char spad;                /* Pad to even byte length */
 };
 
-static bool adjust;           /* Adjust to correct aspect ratio ? */
 static struct slhead slfrof;  /* Slide file header */
 static long xfac, yfac;       /* Aspect ratio scale factors */
 
@@ -99,21 +99,22 @@ static bool sdrawkcab;
 
 
 
-/*  EXTEND  --  Turn a smallint into an int with sign extension, whether
-    or not that happens automatically.
-*/
-
 static int
 extend(unsigned char const ch) {
+/*----------------------------------------------------------------------------
+   Turn a smallint into an int with sign extension, whether
+   or not that happens automatically.
+-----------------------------------------------------------------------------*/
     return ((int) ((ch & 0x80) ? (ch | ~0xFF) : ch));
 }
 
 
 
-/*  SLI  --  Input word from slide file  */
-
 static int
 sli(void) {
+/*----------------------------------------------------------------------------
+   Read and return a word from the slide file.
+-----------------------------------------------------------------------------*/
     short wd;
 
     if (fread(&wd, sizeof wd, 1, slfile) != 1) {
@@ -128,10 +129,11 @@ sli(void) {
 
 
 
-/*  SLIB  --  Input byte from slide file  */
-
 static int
 slib(void) {
+/*----------------------------------------------------------------------------
+   Read and return a byte from the slide file.
+-----------------------------------------------------------------------------*/
     unsigned char ch;
 
     if (fread(&ch, sizeof(ch), 1, slfile) != 1) {
@@ -142,12 +144,12 @@ slib(void) {
 
 
 
-/*  VSCALE -- scale screen coordinates for mismatched display.  */
-
 static void
 vscale(int * const px,
        int * const py) {
-
+/*----------------------------------------------------------------------------
+    Scale screen coordinates for mismatched display.
+-----------------------------------------------------------------------------*/
     *px = (((unsigned) *px) * xfac) >> 16;
     *py = (((unsigned) *py) * yfac) >> 16;
 }
@@ -244,16 +246,17 @@ scanDirectory(FILE *       const slFileP,
     *foundP = found;
 }
 
-/*  SLIDEFIND  --  Find  a  slide  in  a  library  or,  if  DIRONLY is
-           nonzero, print a directory listing of the  library.
-           If  UCASEN  is nonzero, the requested slide name is
-           converted to upper case. */
+
 
 static void
 slidefind(const char * const slideName,
           bool         const dirOnly,
           bool         const ucasen) {
-
+/*----------------------------------------------------------------------------
+   Find a slide in a library or, if DIRONLY is nonzero, print a directory
+   listing of the library.  If UCASEN is nonzero, the requested slide name is
+   converted to upper case.
+-----------------------------------------------------------------------------*/
     char uname[32];  /* upper case translation of 'slideName' */
     char header[32]; /* (supposed) header read from file */
     bool found;
@@ -279,14 +282,14 @@ slidefind(const char * const slideName,
 
 
 
-/*  DRAW  --  Draw a vector in the given AutoCAD color.  */
-
 static slvecfn draw;
 
 static void
 draw(struct svector * vec,
      int              color) {
-
+/*----------------------------------------------------------------------------
+   Draw a vector in the given AutoCAD color.
+-----------------------------------------------------------------------------*/
     pixel rgbcolor;
 
     if (blither) {
@@ -307,14 +310,14 @@ draw(struct svector * vec,
 
 
 
-/*  FLOOD  --  Draw a filled polygon.  */
-
 static slfloodfn flood;
 
 static void
 flood(struct spolygon * const poly,
       int               const color) {
-
+/*----------------------------------------------------------------------------
+  Draw a filled polygon.
+-----------------------------------------------------------------------------*/
     unsigned int i;
     struct fillobj * handle;
     pixel rgbcolor;
@@ -350,16 +353,116 @@ flood(struct spolygon * const poly,
 
 
 
-/*  SLIDER  --  Read slide file.  This is called with the name of the
-        file to be read and function pointers to the routines
-        which process vectors and polygon fill requests
-        respectively.
-*/
-
 static void
-slider(slvecfn   slvec,
-       slfloodfn slflood) {
+computeSize(struct slhead const slfrof,
+            bool          const wantAdjust,
+            double        const uscale,
+            int           const sxsize,
+            int           const sysize,
+            int *         const ixdotsP,
+            int *         const iydotsP,
+            double *      const dsarP) {
+/*----------------------------------------------------------------------------
+-----------------------------------------------------------------------------*/
+    double const originalDsar = ((double) slfrof.sxdots) / slfrof.sydots;
+
+    double ixdots, iydots;
+        /* Algorithmic variables -- value changes as algorithm progresses */
+    bool adjusted;
+
+    /*
+      If the display aspect ratio indicates that the pixels on the sending
+      screen were not square, adjust the size of the generated bitmap to
+      correct the aspect ratio to square the pixels.
+
+      We always correct the aspect ratio by adjusting the width of the image.
+      This guarantees that output from the SHADE command, which is essentially
+      scan-line data written in vector form, will not be corrupted.
+    */
+
+    if (fabs(slfrof.sdsar - originalDsar) > 0.0001) {
+        if (wantAdjust) {
+            ixdots   = slfrof.sxdots * (slfrof.sdsar / originalDsar);
+            iydots   = slfrof.sydots;
+            *dsarP   = ixdots / iydots;
+            adjusted = true;
+        } else {
+            pm_message("Warning - pixels on source screen were non-square.  "
+                       "Specifying -adjust will correct image width "
+                       "to compensate.");
+            ixdots   = slfrof.sxdots;
+            iydots   = slfrof.sydots;
+            *dsarP   = slfrof.sdsar;
+            adjusted = false;
+        }
+    } else {
+        /* Source pixels were square. */
+        ixdots   = slfrof.sxdots;
+        iydots   = slfrof.sydots;
+        *dsarP   = slfrof.sdsar;
+        adjusted = false;
+    }
+
+    if (uscale > 0) {
+        /* There is a uniform scale factor specified.  Apply it. */
+        ixdots *= uscale;
+        iydots *= uscale;
+    }
+
+    /* If the image is to be stretched  to  a  given  width,  set  the
+       output  image  sizes accordingly.  If only a height or width is
+       given, scale the other direction proportionally to preserve the
+       aspect ratio.
+    */
 
+    if (sxsize > 0) {
+        if (sysize > 0)
+            iydots = sysize - 1;
+        else {
+            double const stretchFactor = (sxsize - 1) / ixdots;
+            iydots = iydots * stretchFactor;
+        }
+        ixdots = sxsize - 1;
+    } else if (sysize > 0) {
+        if (sxsize > 0)
+            ixdots = sxsize - 1;
+        else {
+            double const stretchFactor = (sysize - 1) / iydots;
+            ixdots = ixdots * stretchFactor;
+        }
+        iydots = sysize - 1;
+    }
+
+    if (ixdots > INT_MAX-10)
+        pm_error("width is uncomputable large (%f dots)", ixdots);
+    else
+        *ixdotsP = ROUND(ixdots);
+    if (iydots > INT_MAX-10)
+        pm_error("height is uncomputable large (%f dots)", iydots);
+    else
+        *iydotsP = ROUND(iydots);
+
+    if (adjusted) {
+        pm_message(
+            "Resized from %dx%d to %dx%d to correct pixel aspect ratio.",
+            slfrof.sxdots + 1, slfrof.sydots + 1, *ixdotsP + 1, *iydotsP + 1);
+    }
+}
+
+
+
+static void
+slider(slvecfn         slvec,
+       slfloodfn       slflood,
+       bool      const wantAdjust,
+       double    const uscale,
+       int       const sxsize,
+       int       const sysize) {
+/*----------------------------------------------------------------------------
+   Read slide file.  This is called with the name of the file to be read and
+   function pointers to the routines which process vectors and polygon fill
+   requests respectively.
+-----------------------------------------------------------------------------*/
     int i, rescale;
     unsigned char ubfr[4];        /* Utility character buffer */
     int lx, ly;               /* Last x and y point */
@@ -372,7 +475,7 @@ slider(slvecfn   slvec,
     short rtest;              /* Value to test byte reversal */
     short btest = 0x1234;         /* Value to test byte-reversal */
     static struct slhead slhi =       /* Master slide header sample */
-    {"AutoCAD Slide\r\n\32", 86,2, 0,0, 0.0, 0};
+        {"AutoCAD Slide\r\n\32", 86,2, 0,0, 0.0, 0};
     int curcolor = 7;             /* Current vector color */
     pixel rgbcolor;           /* Pixel used to clear pixmap */
 
@@ -434,79 +537,14 @@ slider(slvecfn   slvec,
                    sdrawkcab ? "being reversed" : "the same");
     }
 
-    /* If the display aspect ratio indicates that the  pixels  on  the
-       sending  screen  were  not  square,  adjust  the  size  of  the
-       generated bitmap to correct the  aspect  ratio  to  square  the
-       pixels.
-
-       We  always  correct  the aspect ratio by adjusting the width of
-       the image.  This guarantees that output from the SHADE command,
-       which  is  essentially  scan-line  data written in vector form,
-       will not be corrupted.
-    */
-
-    dsar = ((double) slfrof.sxdots) / slfrof.sydots;
-    if (fabs(slfrof.sdsar - dsar) > 0.0001) {
-        if (adjust) {
-            ixdots = slfrof.sxdots * (slfrof.sdsar / dsar) + 0.5;
-            iydots = slfrof.sydots;
-            dsar = ((double) ixdots) / iydots;
-        } else {
-            pm_message("Warning - pixels on source screen were non-square.  "
-                       "Specifying -adjust will correct image width "
-                       "to compensate.");
-            ixdots = slfrof.sxdots;
-            iydots = slfrof.sydots;
-            dsar = slfrof.sdsar;
-        }
-    } else {
-        /* Source pixels were square. */
-        ixdots = slfrof.sxdots;
-        iydots = slfrof.sydots;
-        dsar = slfrof.sdsar;
-        adjust = false;           /* Mark no adjustment needed */
-    }
-
-    /* If there's a uniform scale factor specified, apply it. */
-
-    if (uscale > 0) {
-        ixdots = (ixdots * uscale) + 0.5;
-        iydots = (iydots * uscale) + 0.5;
-    }
-
-    /* If the image is to be stretched  to  a  given  width,  set  the
-       output  image  sizes accordingly.  If only a height or width is
-       given, scale the other direction proportionally to preserve the
-       aspect ratio.
-    */
-
-    if (sxsize > 0) {
-        if (sysize > 0) {
-            iydots = sysize - 1;
-        } else {
-            iydots = ((((long) iydots) * (sxsize - 1)) +
-                      (iydots / 2)) / ixdots;
-        }
-        ixdots = sxsize - 1;
-    } else if (sysize > 0) {
-        if (sxsize > 0) {
-            ixdots = sxsize - 1;
-        } else {
-            ixdots = ((((long) ixdots) * (sysize - 1)) +
-                      (ixdots / 2)) / iydots;
-        }
-        iydots = sysize - 1;
-    }
-
-    if (adjust) {
-        pm_message(
-            "Resized from %dx%d to %dx%d to correct pixel aspect ratio.",
-            slfrof.sxdots + 1, slfrof.sydots + 1, ixdots + 1, iydots + 1);
-    }
+    computeSize(slfrof, wantAdjust, uscale, sxsize, sysize,
+                &ixdots, &iydots, &dsar);
 
     /* Allocate image buffer and clear it to black. */
 
-    pixels = ppm_allocarray(pixcols = ixdots + 1, pixrows = iydots + 1);
+    pixcols = ixdots + 1;
+    pixrows = iydots + 1;
+    pixels = ppm_allocarray(pixcols, pixrows);
     PPM_ASSIGN(rgbcolor, 0, 0, 0);
     ppmd_filledrectangle(pixels, pixcols, pixrows, pixmaxval, 0, 0,
                          pixcols, pixrows, PPMD_NULLDRAWPROC,
@@ -619,8 +657,6 @@ slider(slvecfn   slvec,
 
 
 
-/*  Main program. */
-
 int
 main(int          argc,
      const char * argv[]) {
@@ -634,7 +670,10 @@ main(int          argc,
     bool widspec;
     bool scalespec;
     bool ucasen;
-    const char * slobber;       /* Slide library item */
+    bool adjust;           /* Adjust to correct aspect ratio ? */
+    double uscale;         /* Uniform scale factor */
+    int sxsize, sysize;    /* Scale to X, Y size ? */
+    const char * slobber;  /* Slide library item */
 
     pm_proginit(&argc, argv);
     argn = 1;
@@ -648,6 +687,9 @@ main(int          argc,
     blither = false;
     info = false;
     adjust = false;
+    uscale = -1.0;
+    sxsize = -1;
+    sysize = -1;
 
     while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') {
         if (pm_keymatch(argv[argn], "-verbose", 2)) {
@@ -725,7 +767,7 @@ main(int          argc,
         slidefind(slobber, dironly, ucasen);
 
     if (!dironly) {
-        slider(draw, flood);
+        slider(draw, flood, adjust, uscale, sxsize, sysize);
         ppm_writeppm(stdout, pixels, pixcols, pixrows, pixmaxval, 0);
     }
     pm_close(slfile);
@@ -733,3 +775,6 @@ main(int          argc,
 
     return 0;
 }
+
+
+
diff --git a/converter/ppm/spctoppm.c b/converter/ppm/spctoppm.c
index d2a48187..a20fcfd4 100644
--- a/converter/ppm/spctoppm.c
+++ b/converter/ppm/spctoppm.c
@@ -41,19 +41,19 @@ main( argc, argv )
 
     /* Check args. */
     if ( argc > 2 )
-	pm_usage( "[spcfile]" );
+        pm_usage( "[spcfile]" );
 
     if ( argc == 2 )
-	ifp = pm_openr( argv[1] );
+        ifp = pm_openr( argv[1] );
     else
-	ifp = stdin;
+        ifp = stdin;
 
     /* Check SPC file header. */
     c1 = getc( ifp );
     c2 = getc( ifp );
 
     if ( ( c1 != 'S' ) || ( c2 != 'P' ) )
-	pm_error( "not a Spectrum picture" );
+        pm_error( "not a Spectrum picture" );
 
     /* Skip reserved bytes. */
     getc( ifp );
@@ -78,35 +78,35 @@ main( argc, argv )
     pixelrow = ppm_allocrow( COLS );
 
     for ( row = 0; row < ROWS; ++row )
-	{
-	for ( col = 0, pP = pixelrow; col < COLS; ++col, ++pP )
-	    {
-	    int c, ind, b, plane, x1;
-
-	    /* Compute pixel value. */
-	    ind = ( 80 * row ) + ( ( col >> 4 ) << 2 );
-	    b = 0x8000 >> (col & 0xf);
-	    c = 0;
-	    for ( plane = 0; plane < 4; ++plane )
-		if ( b & sscreen[ind+plane] )
-		    c |= (1 << plane);
-
-	    /* Compute palette index. */
-	    x1 = 10 * c;
-	    if ( c & 1 )
-		x1 -= 5;
-	    else
-		++x1;
-	    if ( ( col >= x1 ) && ( col < ( x1 + 160 ) ) )
-		c += 16;
-	    if ( col >= ( x1 + 160 ) )
-		c += 32;
-
-	    /* Store the proper color. */
-	    *pP = pal[row][c];
-	    }
-	ppm_writeppmrow( stdout, pixelrow, COLS, (pixval) MAXVAL, 0 );
-	}
+        {
+        for ( col = 0, pP = pixelrow; col < COLS; ++col, ++pP )
+            {
+            int c, ind, b, plane, x1;
+
+            /* Compute pixel value. */
+            ind = ( 80 * row ) + ( ( col >> 4 ) << 2 );
+            b = 0x8000 >> (col & 0xf);
+            c = 0;
+            for ( plane = 0; plane < 4; ++plane )
+                if ( b & sscreen[ind+plane] )
+                    c |= (1 << plane);
+
+            /* Compute palette index. */
+            x1 = 10 * c;
+            if ( c & 1 )
+                x1 -= 5;
+            else
+                ++x1;
+            if ( ( col >= x1 ) && ( col < ( x1 + 160 ) ) )
+                c += 16;
+            if ( col >= ( x1 + 160 ) )
+                c += 32;
+
+            /* Store the proper color. */
+            *pP = pal[row][c];
+            }
+        ppm_writeppmrow( stdout, pixelrow, COLS, (pixval) MAXVAL, 0 );
+        }
 
     pm_close( stdout );
 
@@ -123,7 +123,7 @@ DoBitmap( ifp )
 
     /* Zero out first scan line. */
     for ( i = 0; i < 160; ++i )
-	screen[i] = 0;
+        screen[i] = 0;
 
     /* 'count' counts number of input bytes. */
     count = 0;
@@ -132,37 +132,37 @@ DoBitmap( ifp )
     data = 0;
 
     while ( count < bitmap_length )
-	{
-	/* Get next record header. */
-	h = getc( ifp );
-	++count;
-
-	if ( ( h >= 0 ) && ( count < bitmap_length ) )
-	    {
-	    for ( i = 0; i <= h; ++i )
-		{
-		c = getc( ifp );
-		++count;
-		DoChar( data, c );
-		++data;
-		}
-	    }
-	else if ( ( h < 0 ) && ( count < bitmap_length ) )
-	    {
-	    c = getc( ifp );
-	    ++count;
-
-	    for ( i = 0; i < ( 2 - h ); ++i )
-		{
-		DoChar( data, c );
-		++data;
-		}
-	    }
+        {
+        /* Get next record header. */
+        h = getc( ifp );
+        ++count;
+
+        if ( ( h >= 0 ) && ( count < bitmap_length ) )
+            {
+            for ( i = 0; i <= h; ++i )
+                {
+                c = getc( ifp );
+                ++count;
+                DoChar( data, c );
+                ++data;
+                }
+            }
+        else if ( ( h < 0 ) && ( count < bitmap_length ) )
+            {
+            c = getc( ifp );
+            ++count;
+
+            for ( i = 0; i < ( 2 - h ); ++i )
+                {
+                DoChar( data, c );
+                ++data;
+                }
+            }
     }
 
     /* Convert the char version of the screen to short. */
     for ( i = 0; i < ROWS*COLS/4; ++i )
-	sscreen[i] = ( screen[i<<1] << 8 ) + ( 0xff & screen[(i<<1)+1] );
+        sscreen[i] = ( screen[i<<1] << 8 ) + ( 0xff & screen[(i<<1)+1] );
     }
 
 static void
@@ -184,22 +184,25 @@ DoColormap( ifp )
 
     /* Clear first three palettes. */
     for ( j = 0; j < 48; ++j )
-	PPM_ASSIGN( pal[0][j], 0, 0, 0 );
+        PPM_ASSIGN( pal[0][j], 0, 0, 0 );
 
     /* Read the palettes. */
     for ( i = 1; i < ROWS; ++i )
-	for ( j = 0; j < 3; ++j )
-	    {
-	    (void) pm_readbigshort( ifp, &mask );
-	    for ( b = 0; b < 15; ++b )
-		if ( mask & ( 1 << b ) )
-		    {
-		    short k;
-		    (void) pm_readbigshort( ifp, &k );
-		    PPM_ASSIGN( pal[i][(j*16)+b],
-			( k & 0x700 ) >> 8,
-			( k & 0x070 ) >> 4,
-			( k & 0x007 ) );
-		    }
-	    }
+        for ( j = 0; j < 3; ++j )
+            {
+            (void) pm_readbigshort( ifp, &mask );
+            for ( b = 0; b < 15; ++b )
+                if ( mask & ( 1 << b ) )
+                    {
+                    short k;
+                    (void) pm_readbigshort( ifp, &k );
+                    PPM_ASSIGN( pal[i][(j*16)+b],
+                        ( k & 0x700 ) >> 8,
+                        ( k & 0x070 ) >> 4,
+                        ( k & 0x007 ) );
+                    }
+            }
     }
+
+
+
diff --git a/converter/ppm/tgatoppm.c b/converter/ppm/tgatoppm.c
index 662f741b..82225516 100644
--- a/converter/ppm/tgatoppm.c
+++ b/converter/ppm/tgatoppm.c
@@ -94,7 +94,6 @@ parseCommandLine(int argc, char ** argv,
 
 
 
-
 static unsigned char
 getbyte(FILE * const ifP) {
 
diff --git a/converter/ppm/vidtoppm.c b/converter/ppm/vidtoppm.c
index f3c20404..b0abe731 100644
--- a/converter/ppm/vidtoppm.c
+++ b/converter/ppm/vidtoppm.c
@@ -1,15 +1,15 @@
 /* Bryan got this from mm.ftp-cs.berkeley.edu from the package
-   mpeg-encode-1.5b-src under the name vidtoppm.c on March 30, 2000.  
-   The file was dated January 19, 1995.  
+   mpeg-encode-1.5b-src under the name vidtoppm.c on March 30, 2000.
+   The file was dated January 19, 1995.
 
    This program does not use the netpbm libraries, but generates its
    output via the program rawtoppm.  If any work is ever done on it
    (or, more to the point, any interest ever expressed in it), it
    should be converted just to call ppmwrite(), etc. directly.
 
-   There was no attached documentation, but the program appears to 
+   There was no attached documentation, but the program appears to
    convert from Parallax XVideo JPEG format to a sequence of PPM files.  It
-   does this conversion by putting each frame in a window and then 
+   does this conversion by putting each frame in a window and then
    reading it out of the window, using libXvid.
 
    Because it requires special libraries and there is no known
@@ -57,6 +57,8 @@ char *p;
     exit (1);
 }
 
+
+
 static char buffer[300000];
 
 Visual *
@@ -67,11 +69,11 @@ FindFullColorVisual (dpy, depth)
   XVisualInfo vinfo;
   XVisualInfo *vinfo_ret;
   int numitems, maxdepth;
-  
+
   vinfo.class = TrueColor;
-  
+
   vinfo_ret = XGetVisualInfo(dpy, VisualClassMask, &vinfo, &numitems);
-  
+
   if (numitems == 0) return NULL;
 
   maxdepth = 0;
@@ -85,15 +87,17 @@ FindFullColorVisual (dpy, depth)
 
   if (maxdepth < 24) return NULL;
 
-  if (XMatchVisualInfo(dpy, DefaultScreen(dpy), maxdepth, 
-		       TrueColor, &vinfo)) {
+  if (XMatchVisualInfo(dpy, DefaultScreen(dpy), maxdepth,
+                       TrueColor, &vinfo)) {
     *depth = maxdepth;
     return vinfo.visual;
   }
-  
+
   return NULL;
 }
 
+
+
 Window
 CreateFullColorWindow (dpy, x, y, w, h)
     Display *dpy;
@@ -107,21 +111,23 @@ CreateFullColorWindow (dpy, x, y, w, h)
     int screen;
 
     screen = XDefaultScreen(dpy);
-    class = InputOutput;	/* Could be InputOnly */
+    class = InputOutput;        /* Could be InputOnly */
     visual = FindFullColorVisual (dpy, &depth);
     if (visual == NULL) {
-	return 0;
+        return 0;
     }
     mask = CWBackPixel | CWColormap | CWBorderPixel;
     xswa.colormap = XCreateColormap(dpy, XRootWindow(dpy, screen),
-		    visual, AllocNone);
+                    visual, AllocNone);
     xswa.background_pixel = BlackPixel(dpy, DefaultScreen(dpy));
     xswa.border_pixel = WhitePixel(dpy, DefaultScreen(dpy));
 
     return XCreateWindow(dpy, RootWindow(dpy, screen), x, y, w, h,
-	1, depth, class, visual, mask, &xswa);
+        1, depth, class, visual, mask, &xswa);
 }
 
+
+
 main (argc, argv)
 int argc;
 char **argv;
@@ -169,16 +175,16 @@ char **argv;
   obase = argv[6];
 
   quality = 100;
-  
+
   if (argc > 7)
     quality = atoi (argv[7]);
-  
+
   dpy = XOpenDisplay (NULL);
   screen = DefaultScreen(dpy);
   root = DefaultRootWindow(dpy);
 /*  gc = DefaultGC(dpy, screen); */
 /*  win = XCreateSimpleWindow (dpy, root, 0, 0, width, height,
-			     0, NULL, NULL);
+                             0, NULL, NULL);
 */
   win = CreateFullColorWindow(dpy, 0, 0, width+4, height+4);
   gc = XCreateGC(dpy, win, 0, NULL);
@@ -195,7 +201,7 @@ char **argv;
   XPlxPutTable(dpy, win, gc, qTable, size, 0);
   XPlxPutTable(dpy, win, gc, qTable, size, 1);
   XPlxVideoTag (dpy, win, gc, PLX_VIDEO);
-  
+
   inFile = fopen(filename, "rb");
   if (inFile == NULL) {
     perror (filename);
@@ -215,7 +221,7 @@ char **argv;
       exit();
     }
   }
-    
+
   for (i=start; i<=end; i++) {
     fprintf(stdout, "GRABBING FRAME %d\n", i);
 
@@ -228,15 +234,15 @@ char **argv;
       perror("End of file.");
       exit();
     }
-    
+
     XPlxPutCImage (dpy, win, gc, &image, 0, 0, image.width,
-		   image.height, 0, 0, width+2, height+2, 1);
+                   image.height, 0, 0, width+2, height+2, 1);
 
     XFlush(dpy);
 
     ximage = XGetImage(dpy, win, 0, 0, width, height, 0x00ffffff,
-		       ZPixmap);
-    
+                       ZPixmap);
+
     if (i == 0) {
       fprintf(stderr, "Depth %d\n", ximage->depth);
       fprintf(stderr, "Height: %d Width: %d\n", height, width );
@@ -252,10 +258,10 @@ char **argv;
 
     for (r=0; r<height; r++) {
       for (j=0; j<width; j++) {
-	fputc(*(tdata+3), outFile);
-	fputc(*(tdata+2), outFile);
-	fputc(*(tdata+1), outFile);
-	tdata += 4;
+        fputc(*(tdata+3), outFile);
+        fputc(*(tdata+2), outFile);
+        fputc(*(tdata+1), outFile);
+        tdata += 4;
       }
     }
 
@@ -264,7 +270,10 @@ char **argv;
     free(tdata);
 
     sprintf(command, "rawtoppm %d %d < /tmp/foobar > %s",
-	    width, height, ofname);
+            width, height, ofname);
     system(command);
   }
 }
+
+
+
diff --git a/converter/ppm/winico.h b/converter/ppm/winico.h
index c6133ef0..de05ca4d 100644
--- a/converter/ppm/winico.h
+++ b/converter/ppm/winico.h
@@ -11,19 +11,19 @@ typedef unsigned char      u1;
 typedef unsigned short int u2;
 typedef unsigned int       u4;
 
-typedef struct MS_Ico_ *          MS_Ico;
-typedef struct IC_Entry_ *        IC_Entry;
-typedef struct IC_InfoHeader_ *   IC_InfoHeader;
-typedef struct IC_Color_ *        IC_Color;
+typedef struct MS_Ico_           MS_Ico;
+typedef struct IC_Entry_         IC_Entry;
+typedef struct IC_InfoHeader_    IC_InfoHeader;
+typedef struct IC_Color_         IC_Color;
 /* Not part of the spec, but useful in constructing the icon. */
-typedef struct IC_Palette_ *      IC_Palette;
-typedef struct ICON_bmp_ *        ICON_bmp;
+typedef struct IC_Palette_       IC_Palette;
+typedef struct ICON_bmp_         ICON_bmp;
 
 struct MS_Ico_ {
    u2 reserved;
    u2 type;
    u2 count;
-   IC_Entry * entries;
+   IC_Entry ** entries;
 };
 
 
@@ -40,8 +40,8 @@ struct IC_Entry_ {
    u2 bitcount;    /* 0, 1, 4, or 8 */
    u4 size_in_bytes;
    u4 file_offset;
-   IC_InfoHeader ih;
-   IC_Color * colors;
+   IC_InfoHeader * ih;
+   IC_Color ** colors;
    /*
     * Below here, I have useful fields which aren't in the spec, but
     * save having to keep stoopid amounts of global data.
@@ -77,7 +77,7 @@ struct IC_Color_ {
 
 struct IC_Palette_ {
    u4 col_amount;
-   IC_Color * colors;
+   IC_Color ** colors;
 };
 
 struct ICON_bmp_ {
diff --git a/converter/ppm/winicontoppm.c b/converter/ppm/winicontoppm.c
index ede0a2b9..54bc0809 100644
--- a/converter/ppm/winicontoppm.c
+++ b/converter/ppm/winicontoppm.c
@@ -115,7 +115,6 @@ parseCommandLine (int argc, const char ** argv,
 
 
 
-
 static int
 GetByte(FILE * const ifP) {
 
@@ -216,17 +215,17 @@ readU4 (FILE * const ifP) {
 
 
 
-static IC_Entry
+static IC_Entry *
 readICEntry(FILE * const ifP) {
 
-    IC_Entry entryP;
+    IC_Entry * entryP;  /* malloc'ed */
     u1 widthFld;   /* 0 means 256 */
     u1 heightFld;  /* 0 means 256 */
     u1 colorCtFld; /* 0 means 256 */
 
     MALLOCVAR(entryP);
 
-    if (entryP == NULL)
+    if (!entryP)
         pm_error("Unable to allocate memory for IC entry");
 
     widthFld              = readU1(ifP);
@@ -255,15 +254,15 @@ readICEntry(FILE * const ifP) {
 
 
 
-static IC_InfoHeader
-readInfoHeader (FILE *   const ifP,
-                IC_Entry const entryP) {
+static IC_InfoHeader *
+readInfoHeader(FILE *           const ifP,
+               const IC_Entry * const entryP) {
 
-    IC_InfoHeader ihP;
+    IC_InfoHeader * ihP;  /* malloc'ed */
 
     MALLOCVAR(ihP);
 
-    if (ihP == NULL)
+    if (!ihP)
         pm_error("Unable to allocate memory for info header");
 
     ihP->size             = readU4(ifP);  /* never referenced */
@@ -315,14 +314,14 @@ readInfoHeader (FILE *   const ifP,
 
 
 
-static IC_Color
+static IC_Color *
 readICColor(FILE * const ifP)  {
 
-    IC_Color colorP;
+    IC_Color * colorP;  /* malloc'ed */
 
     MALLOCVAR(colorP);
 
-    if (colorP == NULL)
+    if (!colorP)
         pm_error("Unable to allocate memory for color");
 
     /* I don't know why this isn't the same as the spec, it just isn't.
@@ -514,40 +513,40 @@ readXBitmap (FILE *       const ifP,
 
 
 
-static MS_Ico
+static MS_Ico *
 readIconFile(FILE * const ifP,
              bool   const verbose) {
 
     unsigned int i;
 
-    MS_Ico MSIconData;
+    MS_Ico * MSIconDataP;  /* malloc'ed */
 
-    MALLOCVAR(MSIconData);
+    MALLOCVAR(MSIconDataP);
 
-    MSIconData->reserved = readU2(ifP);  /* should be 0 */
-    MSIconData->type     = readU2(ifP);  /* should be 1 (ICO) or 2 (CUR) */
-    MSIconData->count    = readU2(ifP);  /* # icons in file */
+    MSIconDataP->reserved = readU2(ifP);  /* should be 0 */
+    MSIconDataP->type     = readU2(ifP);  /* should be 1 (ICO) or 2 (CUR) */
+    MSIconDataP->count    = readU2(ifP);  /* # icons in file */
 
-    if (MSIconData->reserved != 0)
+    if (MSIconDataP->reserved != 0)
        pm_message("Signature 'reserved' field is %u (should be 0)",
-                  MSIconData->reserved);
+                  MSIconDataP->reserved);
 
-    if (MSIconData->type != 1 && MSIconData->type != 2)
+    if (MSIconDataP->type != 1 && MSIconDataP->type != 2)
         pm_error("Type %u file.  Can handle only type 1 or 2.",
-                 MSIconData->type);
+                 MSIconDataP->type);
 
-    if (MSIconData->count == 0)
+    if (MSIconDataP->count == 0)
         pm_error("Invalid image count: 0");
     else if (verbose)
-        pm_message("File contains %u images", MSIconData->count);
+        pm_message("File contains %u images", MSIconDataP->count);
 
-    MALLOCARRAY(MSIconData->entries, MSIconData->count);
-    if (MSIconData->entries == NULL)
+    MALLOCARRAY(MSIconDataP->entries, MSIconDataP->count);
+    if (MSIconDataP->entries == NULL)
         pm_error("out of memory");
 
     /* Read in each of the entries */
-    for (i = 0; i < MSIconData->count; ++i)
-        MSIconData->entries[i] = readICEntry(ifP);
+    for (i = 0; i < MSIconDataP->count; ++i)
+        MSIconDataP->entries[i] = readICEntry(ifP);
 
     /* Read in the infoheader, color map (if any) and the actual bit/pix maps
        for the icons.
@@ -555,12 +554,12 @@ readIconFile(FILE * const ifP,
     if (verbose)
         pm_message("#\tColors\tBPP\tWidth\tHeight\n");
 
-    for (i = 0; i < MSIconData->count; ++i) {
-        IC_Entry const entryP = MSIconData->entries[i];
+    for (i = 0; i < MSIconDataP->count; ++i) {
+        IC_Entry * const entryP = MSIconDataP->entries[i];
 
         unsigned int bpp;  /* bits per pixel */
 
-        entryP->ih = readInfoHeader(ifP, MSIconData->entries[i]);
+        entryP->ih = readInfoHeader(ifP, MSIconDataP->entries[i]);
 
         bpp  = entryP->bitcount ? entryP->bitcount : entryP->ih->bitcount;
 
@@ -633,7 +632,7 @@ readIconFile(FILE * const ifP,
         }
 
     }
-    return MSIconData;
+    return MSIconDataP;
 }
 
 
@@ -655,15 +654,15 @@ trimmedOutputName(const char inputName[]) {
 
 
 static int
-getBestQualityIcon(MS_Ico MSIconData)
-{
+getBestQualityIcon(MS_Ico * const MSIconDataP) {
+
     unsigned int i;
     unsigned int best;
     unsigned int bestSize;
     unsigned int bestBpp;
 
-    for (i = 0, bestSize = 0, bestBpp = 0; i < MSIconData->count; ++i) {
-        IC_Entry const entryP = MSIconData->entries[i];
+    for (i = 0, bestSize = 0, bestBpp = 0; i < MSIconDataP->count; ++i) {
+        IC_Entry * const entryP = MSIconDataP->entries[i];
         unsigned int const size = entryP->width * entryP->height;
         unsigned int const bpp  =
             entryP->bitcount ? entryP->bitcount : entryP->ih->bitcount;
@@ -682,12 +681,12 @@ getBestQualityIcon(MS_Ico MSIconData)
 
 
 static void
-writeXors(FILE *   const multiOutF,
-          char *   const outputFileBase,
-          IC_Entry const entryP,
-          int      const entryNum,
-          bool     const multiple,
-          bool     const xor) {
+writeXors(FILE *     const multiOutF,
+          char *     const outputFileBase,
+          IC_Entry * const entryP,
+          int        const entryNum,
+          bool       const multiple,
+          bool       const xor) {
 /*----------------------------------------------------------------------------
    Write an "xor" image (i.e. the main image) out.
 
@@ -751,7 +750,7 @@ writeXors(FILE *   const multiOutF,
                     pm_error("Invalid color index %u (max is %u)",
                               colorIndex, entryP->color_count - 1);
                 } else {
-                    IC_Color const colorP = entryP->colors[colorIndex];
+                    IC_Color * const colorP = entryP->colors[colorIndex];
                     PPM_ASSIGN(pixArray[row][col],
                                colorP->red, colorP->green, colorP->blue);
                 }
@@ -775,7 +774,7 @@ writeXors(FILE *   const multiOutF,
 static void
 writeAnds(FILE *       const multiOutF,
           char         const outputFileBase[],
-          IC_Entry     const entryP,
+          IC_Entry *   const entryP,
           unsigned int const entryNum,
           bool         const multiple) {
 /*----------------------------------------------------------------------------
@@ -866,7 +865,7 @@ openMultiAnd(char    const outputFileBase[],
 
 
 static void
-freeIconentry(IC_Entry const entryP) {
+freeIconentry(IC_Entry * const entryP) {
 
     if (entryP->colors && entryP->color_count) {
         unsigned int i;
@@ -883,7 +882,7 @@ freeIconentry(IC_Entry const entryP) {
 
 
 static void
-freeIcondata(MS_Ico const MSIconDataP) {
+freeIcondata(MS_Ico * const MSIconDataP) {
 
     unsigned int i;
     for (i = 0; i < MSIconDataP->count; ++i)
@@ -900,7 +899,7 @@ main(int argc, const char *argv[]) {
     struct cmdlineInfo cmdline;
     FILE * ifP;
     unsigned int startEntry, endEntry;
-    MS_Ico MSIconDataP;
+    MS_Ico * MSIconDataP;
     char * outputFileBase;
     FILE * multiOutF;
     FILE * multiAndOutF;
@@ -961,7 +960,7 @@ main(int argc, const char *argv[]) {
         unsigned int entryNum;
 
         for (entryNum = startEntry; entryNum < endEntry; ++entryNum) {
-            IC_Entry const entryP = MSIconDataP->entries[entryNum];
+            IC_Entry * const entryP = MSIconDataP->entries[entryNum];
 
             writeXors(multiOutF, outputFileBase, entryP, entryNum,
                       cmdline.allicons, cmdline.writeands);
@@ -980,3 +979,6 @@ main(int argc, const char *argv[]) {
 
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ximtoppm.c b/converter/ppm/ximtoppm.c
index d839e770..b82463c3 100644
--- a/converter/ppm/ximtoppm.c
+++ b/converter/ppm/ximtoppm.c
@@ -17,6 +17,7 @@
 #include <string.h>
 
 #include "pm_c_util.h"
+#include "mallocvar.h"
 #include "ppm.h"
 #include "xim.h"
 #include "shhopt.h"
@@ -28,9 +29,9 @@ struct CmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
-    const char *input_filename;
-    const char *alpha_filename;
-    bool alpha_stdout;
+    const char * inputFilename;
+    const char * alphaFilename;
+    bool         alphaStdout;
 };
 
 
@@ -53,7 +54,7 @@ parseCommandLine(int argc, const char ** argv,
 
     option_def_index = 0;   /* incremented by OPTENT3 */
     OPTENT3(0,   "alphaout",   OPT_STRING,
-            &cmdlineP->alpha_filename, &alphaoutSpec, 0);
+            &cmdlineP->alphaFilename, &alphaoutSpec, 0);
 
     opt.opt_table = option_def;
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
@@ -63,21 +64,21 @@ parseCommandLine(int argc, const char ** argv,
         /* Uses and sets argc, argv, and all of *cmdlineP. */
 
     if (!alphaoutSpec)
-        cmdlineP->alpha_filename = NULL;
+        cmdlineP->alphaFilename = NULL;
 
     if (argc - 1 == 0)
-        cmdlineP->input_filename = "-";  /* he wants stdin */
+        cmdlineP->inputFilename = "-";  /* he wants stdin */
     else if (argc - 1 == 1)
-        cmdlineP->input_filename = strdup(argv[1]);
+        cmdlineP->inputFilename = pm_strdup(argv[1]);
     else
         pm_error("Too many arguments.  The only argument accepted "
                  "is the input file specification");
 
-    if (cmdlineP->alpha_filename &&
-        streq(cmdlineP->alpha_filename, "-"))
-        cmdlineP->alpha_stdout = TRUE;
+    if (cmdlineP->alphaFilename &&
+        streq(cmdlineP->alphaFilename, "-"))
+        cmdlineP->alphaStdout = true;
     else
-        cmdlineP->alpha_stdout = FALSE;
+        cmdlineP->alphaStdout = false;
 }
 
 
@@ -87,191 +88,202 @@ parseCommandLine(int argc, const char ** argv,
 */
 
 static int
-ReadXimHeader(FILE *     const in_fp,
-              XimImage * const header) {
+readXimHeader(FILE *     const ifP,
+              XimImage * const headerP) {
 
-    int  i;
-    char *cp;
-    XimAsciiHeader  a_head;
+    unsigned int  i;
+    XimAsciiHeader  aHead;
 
-    cp = (char *) header;
-    for (i = 0; i < sizeof(XimImage); ++i )
-    *cp++ = 0;
+    {
+        unsigned char * cp;
+        cp = (unsigned char *)headerP;
+        for (i = 0; i < sizeof(XimImage); ++i)
+            *cp++ = 0;
+    }
     /* Read header and verify image file formats */
-    if (fread((char *)&a_head, sizeof(ImageHeader), 1, in_fp) != 1) {
+    if (fread((char *)&aHead, sizeof(ImageHeader), 1, ifP) != 1) {
         pm_message("ReadXimHeader: unable to read file header" );
-        return(0);
+        return 0;
     }
     /* Force broken ASCIIZ strings to at least be valid ASCIIZ */
-    a_head.author [sizeof(a_head.author)  - 1] = '\0';
-    a_head.date   [sizeof(a_head.date)    - 1] = '\0';
-    a_head.program[sizeof(a_head.program) - 1] = '\0';
+    aHead.author [sizeof(aHead.author)  - 1] = '\0';
+    aHead.date   [sizeof(aHead.date)    - 1] = '\0';
+    aHead.program[sizeof(aHead.program) - 1] = '\0';
 
-    if (atoi(a_head.header_size) != sizeof(ImageHeader)) {
+    if (atoi(aHead.header_size) != sizeof(ImageHeader)) {
         pm_message("ReadXimHeader: header size mismatch" );
         return(0);
     }
-    if (atoi(a_head.file_version) != IMAGE_VERSION) {
+    if (atoi(aHead.file_version) != IMAGE_VERSION) {
         pm_message("ReadXimHeader: incorrect Image_file version" );
         return(0);
     }
-    header->width = atoi(a_head.image_width);
-    header->height = atoi(a_head.image_height);
-    header->ncolors = atoi(a_head.num_colors);
-    header->nchannels = atoi(a_head.num_channels);
-    header->bytes_per_line = atoi(a_head.bytes_per_line);
+    headerP->width          = atoi(aHead.image_width);
+    headerP->height         = atoi(aHead.image_height);
+    headerP->ncolors        = atoi(aHead.num_colors);
+    headerP->nchannels      = atoi(aHead.num_channels);
+    headerP->bytes_per_line = atoi(aHead.bytes_per_line);
 #if 0
-    header->npics = atoi(a_head.num_pictures);
+    headerP->npics          = atoi(aHead.num_pictures);
 #endif
-    header->bits_channel = atoi(a_head.bits_per_channel);
-    header->alpha_flag = atoi(a_head.alpha_channel);
-    header->author = pm_strdup(a_head.author);
-    header->date = pm_strdup(a_head.date);
-    header->program = pm_strdup(a_head.program);
+    headerP->bits_channel   = atoi(aHead.bits_per_channel);
+    headerP->alpha_flag     = atoi(aHead.alpha_channel);
+    headerP->author         = pm_strdup(aHead.author);
+    headerP->date           = pm_strdup(aHead.date);
+    headerP->program        = pm_strdup(aHead.program);
 
     /* Do double checking for backwards compatibility */
-    if (header->npics == 0)
-        header->npics = 1;
-    if (header->bits_channel == 0)
-        header->bits_channel = 8;
-    else if (header->bits_channel == 24) {
-        header->nchannels = 3;
-        header->bits_channel = 8;
+    if (headerP->npics == 0)
+        headerP->npics = 1;
+    if (headerP->bits_channel == 0)
+        headerP->bits_channel = 8;
+    else if (headerP->bits_channel == 24) {
+        headerP->nchannels = 3;
+        headerP->bits_channel = 8;
     }
-    if ((int)header->bytes_per_line == 0)
-        header->bytes_per_line =
-            (header->bits_channel == 1 && header->nchannels == 1) ?
-                (header->width + 7) / 8 :
-                header->width;
-    header->datasize =(unsigned int)header->bytes_per_line * header->height;
-    if (header->nchannels == 3 && header->bits_channel == 8)
-        header->ncolors = 0;
-    else if (header->nchannels == 1 && header->bits_channel == 8) {
-        header->colors = (Color *)calloc((unsigned int)header->ncolors,
-                sizeof(Color));
-        if (header->colors == NULL) {
-            pm_message("ReadXimHeader: can't calloc colors" );
-            return(0);
-        }
-        for (i=0; i < header->ncolors; i++) {
-            header->colors[i].red = a_head.c_map[i][0];
-            header->colors[i].grn = a_head.c_map[i][1];
-            header->colors[i].blu = a_head.c_map[i][2];
+    if (headerP->bytes_per_line == 0)
+        headerP->bytes_per_line =
+            (headerP->bits_channel == 1 && headerP->nchannels == 1) ?
+                (headerP->width + 7) / 8 :
+                headerP->width;
+    headerP->datasize =
+        (unsigned int)headerP->bytes_per_line * headerP->height;
+    if (headerP->nchannels == 3 && headerP->bits_channel == 8)
+        headerP->ncolors = 0;
+    else if (headerP->nchannels == 1 && headerP->bits_channel == 8) {
+        unsigned int i;
+
+        MALLOCARRAY_NOFAIL(headerP->colors, headerP->ncolors);
+
+        for (i=0; i < headerP->ncolors; ++i) {
+            headerP->colors[i].red = aHead.c_map[i][0];
+            headerP->colors[i].grn = aHead.c_map[i][1];
+            headerP->colors[i].blu = aHead.c_map[i][2];
         }
     }
-    return(1);
+    return 1;
 }
 
 
 
 static int
-ReadImageChannel(FILE *         const infp,
+readImageChannel(FILE *         const ifP,
                  byte *         const buf,
-                 unsigned int * const bufsize,
-                 int            const encoded) {
+                 unsigned int * const bufsizeP,
+                 bool           const encoded) {
 
-    int  i, runlen, nbytes;
-    unsigned int  j;
-    byte *line;
+    unsigned int j;
     long  marker;
 
     if (!encoded)
-        j = fread((char *)buf, 1, (int)*bufsize, infp);
+        j = fread((char *)buf, 1, (int)*bufsizeP, ifP);
     else {
-        if ((line=(byte *)malloc((unsigned int)BUFSIZ)) == NULL) {
+        byte * line;
+
+        MALLOCARRAY(line, BUFSIZ);
+        if (!line) {
             pm_message("ReadImageChannel: can't malloc() fread string" );
-            return(0);
-        }
-        /* Unrunlength encode data */
-        marker = ftell(infp);
-        j = 0;
-        while (((nbytes=fread((char *)line, 1, BUFSIZ, infp)) > 0) &&
-            (j < *bufsize)) {
-            for (i=0; (i < nbytes) && (j < *bufsize); i++) {
-                runlen = (int)line[i]+1;
-                i++;
-                while (runlen--)
-                    buf[j++] = line[i];
+            return 0;
+        } else {
+            /* Unrunlength encode data */
+            unsigned int byteCt;
+
+            marker = ftell(ifP);
+            j = 0;
+            while (((byteCt = fread((char *)line, 1, BUFSIZ, ifP)) > 0) &&
+                   (j < *bufsizeP)) {
+                unsigned int i;
+                for (i=0; (i < byteCt) && (j < *bufsizeP); ++i) {
+                    unsigned int runlen;
+                    runlen = (unsigned int)line[i] + 1;
+                    ++i;
+                    while (runlen--)
+                        buf[j++] = line[i];
+                }
+                marker += i;
             }
-            marker += i;
-        }
-        /* return to the beginning of the next image's buffer */
-        if (fseek(infp, marker, 0) == -1) {
-            pm_message("ReadImageChannel: can't fseek to location "
-                       "in image buffer");
-            return(0);
+            /* return to the beginning of the next image's buffer */
+            if (fseek(ifP, marker, 0) == -1) {
+                pm_message("ReadImageChannel: can't fseek to location "
+                           "in image buffer");
+                return 0;
+            }
+            free(line);
         }
-        free((char *)line);
     }
-    if (j != *bufsize) {
-        pm_message("unable to complete channel: %u / %u (%d%%)",
-            j, *bufsize, (int)(j*100.0 / *bufsize) );
-        *bufsize = j;
+    if (j != *bufsizeP) {
+        pm_message("unable to complete channel: %u / %u (%f%%)",
+                   j, *bufsizeP, j * 100.0 / *bufsizeP);
+        *bufsizeP = j;
     }
-    return(1);
+    return 1;
 }
 
 
 
 static int
-ReadXimImage(FILE *     const in_fp,
-             XimImage * const xim) {
+readXimImage(FILE *     const ifP,
+             XimImage * const ximP) {
 
-    if (xim->data) {
-        free((char *)xim->data);
-        xim->data = (byte *)0;
+    if (ximP->data) {
+        free(ximP->data);
+        ximP->data = NULL;
     }
-    if (xim->grn_data) {
-        free((char *)xim->grn_data);
-        xim->grn_data = (byte *)0;
+    if (ximP->grn_data) {
+        free(ximP->grn_data);
+        ximP->grn_data = NULL;
     }
-    if (xim->blu_data) {
-        free((char *)xim->blu_data);
-        xim->blu_data = (byte *)0;
+    if (ximP->blu_data) {
+        free(ximP->blu_data);
+        ximP->blu_data = NULL;
     }
-    if (xim->other) {
-        free((char *)xim->other);
-        xim->other = (byte *)0;
+    if (ximP->other) {
+        free(ximP->other);
+        ximP->other = NULL;
     }
-    xim->npics = 0;
-    if (!(xim->data = (byte *)calloc(xim->datasize, 1))) {
-        pm_message("ReadXimImage: can't malloc pixmap data" );
-        return(0);
+    ximP->npics = 0;
+    MALLOCARRAY(ximP->data, ximP->datasize);
+    if (!ximP->data) {
+        pm_message("ReadXimImage: can't malloc pixmap data");
+        return 0;
     }
-    if (!ReadImageChannel(in_fp, xim->data, &xim->datasize, 0)) {
-        pm_message("ReadXimImage: end of the images" );
-        return(0);
+    if (!readImageChannel(ifP, ximP->data, &ximP->datasize, false)) {
+        pm_message("ReadXimImage: end of the images");
+        return 0;
     }
-    if (xim->nchannels == 3) {
-        xim->grn_data = (byte *)malloc(xim->datasize);
-        xim->blu_data = (byte *)malloc(xim->datasize);
-        if (xim->grn_data == NULL || xim->blu_data == NULL) {
-            pm_message("ReadXimImage: can't malloc rgb channel data" );
-            free((char *)xim->data);
-            if (xim->grn_data)  free((char *)xim->grn_data);
-            if (xim->blu_data)  free((char *)xim->blu_data);
-            xim->data = xim->grn_data = xim->blu_data = (byte*)0;
-            return(0);
+    if (ximP->nchannels == 3) {
+        MALLOCARRAY(ximP->grn_data, ximP->datasize);
+        MALLOCARRAY(ximP->blu_data, ximP->datasize);
+        if (!ximP->grn_data || !ximP->blu_data) {
+            pm_message("ReadXimImage: can't malloc rgb channel data");
+            free(ximP->data);
+            if (ximP->grn_data)
+                free(ximP->grn_data);
+            if (ximP->blu_data)
+                free(ximP->blu_data);
+            ximP->data = ximP->grn_data = ximP->blu_data = NULL;
+            return 0;
         }
-        if (!ReadImageChannel(in_fp, xim->grn_data, &xim->datasize, 0))
-            return(0);
-        if (!ReadImageChannel(in_fp, xim->blu_data, &xim->datasize, 0))
-            return(0);
-    }
-    if (xim->nchannels > 3) {
-        /* In theory, this can be any fourth channel, but the only one we
-           know about is an Alpha channel, so we'll call it that, even
-           though we process it generically.
-           */
-        if ((xim->other = (byte *)malloc(xim->datasize)) == NULL) {
-            pm_message("ReadXimImage: can't malloc alpha data" );
-            return(0);
+        if (!readImageChannel(ifP, ximP->grn_data, &ximP->datasize, false))
+            return 0;
+        if (!readImageChannel(ifP, ximP->blu_data, &ximP->datasize, false))
+            return 0;
+    } else if (ximP->nchannels > 3) {
+        /* In theory, this can be any fourth channel, but the only one we know
+           about is an Alpha channel, so we'll call it that, even though we
+           process it generically.
+        */
+        MALLOCARRAY(ximP->other, ximP->datasize);
+        if (!ximP->other) {
+            pm_message("ReadXimImage: can't malloc alpha data");
+            return 0;
         }
-        if (!ReadImageChannel(in_fp, xim->other, &xim->datasize, 0))
+        if (!readImageChannel(ifP, ximP->other, &ximP->datasize, false))
             return(0);
     }
-    xim->npics = 1;
-    return(1);
+    ximP->npics = 1;
+
+    return 1;
 }
 
 
@@ -307,17 +319,21 @@ ReadXimImage(FILE *     const in_fp,
 ***********************************************************************/
 
 static int
-ReadXim(FILE *     const in_fp,
-        XimImage * const xim) {
+readXim(FILE *     const ifP,
+        XimImage * const ximP) {
 
-    if (!ReadXimHeader(in_fp, xim)) {
-        pm_message("can't read xim header" );
-        return 0;
-    } else if (!ReadXimImage(in_fp, xim)) {
-        pm_message("can't read xim data" );
-        return 0;
+    int retval;
+
+    if (!readXimHeader(ifP, ximP)) {
+        pm_message("can't read xim header");
+        retval = 0;
+    } else if (!readXimImage(ifP, ximP)) {
+        pm_message("can't read xim data");
+        retval = 0;
     } else
-        return 1;
+        retval = 1;
+
+    return retval;
 }
 
 
@@ -327,44 +343,48 @@ main(int          argc,
      const char **argv) {
 
     struct CmdlineInfo cmdline;
-    FILE *ifP, *imageout_file, *alpha_file;
+    FILE * ifP;
+    FILE * imageoutFileP;
+    FILE * alphaFileP;
     XimImage xim;
-    pixel *pixelrow, colormap[256];
-    gray *alpharow;
-        /* The alpha channel of the row we're currently converting, in
-           pgm fmt
+    pixel * pixelrow;
+    pixel colormap[256];
+    gray * alpharow;
+        /* The alpha channel of the row we're currently converting, in PGM fmt
         */
-    int rows, cols, row, mapped;
+    unsigned int rows, cols;
+    unsigned int row;
+    bool mapped;
     pixval maxval;
-    bool success;
+    bool succeeded;
 
     pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
 
-    ifP = pm_openr(cmdline.input_filename);
+    ifP = pm_openr(cmdline.inputFilename);
 
-    if (cmdline.alpha_stdout)
-        alpha_file = stdout;
-    else if (cmdline.alpha_filename == NULL)
-        alpha_file = NULL;
+    if (cmdline.alphaStdout)
+        alphaFileP = stdout;
+    else if (cmdline.alphaFilename == NULL)
+        alphaFileP = NULL;
     else
-        alpha_file = pm_openw(cmdline.alpha_filename);
+        alphaFileP = pm_openw(cmdline.alphaFilename);
 
-    if (cmdline.alpha_stdout)
-        imageout_file = NULL;
+    if (cmdline.alphaStdout)
+        imageoutFileP = NULL;
     else
-        imageout_file = stdout;
+        imageoutFileP = stdout;
 
-    success = ReadXim(ifP, &xim);
-    if (!success)
+    succeeded = readXim(ifP, &xim);
+    if (!succeeded)
         pm_error("can't read Xim file");
 
     rows = xim.height;
     cols = xim.width;
 
     if (xim.nchannels == 1 && xim.bits_channel == 8) {
-        int i;
+        unsigned int i;
 
         mapped = true;
         maxval = 255;
@@ -382,27 +402,29 @@ main(int          argc,
             "unknown Xim file type, nchannels == %d, bits_channel == %d",
             xim.nchannels, xim.bits_channel);
 
-    if (imageout_file)
-        ppm_writeppminit(imageout_file, cols, rows, maxval, 0);
-    if (alpha_file)
-        pgm_writepgminit(alpha_file, cols, rows, maxval, 0);
+    if (imageoutFileP)
+        ppm_writeppminit(imageoutFileP, cols, rows, maxval, 0);
+    if (alphaFileP)
+        pgm_writepgminit(alphaFileP, cols, rows, maxval, 0);
 
     pixelrow = ppm_allocrow(cols);
     alpharow = pgm_allocrow(cols);
 
     for (row = 0; row < rows; ++row) {
         if (mapped) {
-            byte * const ximrow = xim.data + row * xim.bytes_per_line;
+            byte * const ximrow = &xim.data[row * xim.bytes_per_line];
+
             unsigned int col;
 
             for (col = 0; col < cols; ++col)
                 pixelrow[col] = colormap[ximrow[col]];
+
             alpharow[col] = 0;
         } else {
-            byte * const redrow = xim.data     + row * xim.bytes_per_line;
-            byte * const grnrow = xim.grn_data + row * xim.bytes_per_line;
-            byte * const blurow = xim.blu_data + row * xim.bytes_per_line;
-            byte * const othrow = xim.other    + row * xim.bytes_per_line;
+            byte * const redrow = &xim.data     [row * xim.bytes_per_line];
+            byte * const grnrow = &xim.grn_data [row * xim.bytes_per_line];
+            byte * const blurow = &xim.blu_data [row * xim.bytes_per_line];
+            byte * const othrow = &xim.other    [row * xim.bytes_per_line];
 
             unsigned int col;
 
@@ -415,16 +437,16 @@ main(int          argc,
                     alpharow[col] = 0;
             }
         }
-        if (imageout_file)
-            ppm_writeppmrow(imageout_file, pixelrow, cols, maxval, 0);
-        if (alpha_file)
-            pgm_writepgmrow(alpha_file, alpharow, cols, maxval, 0);
+        if (imageoutFileP)
+            ppm_writeppmrow(imageoutFileP, pixelrow, cols, maxval, 0);
+        if (alphaFileP)
+            pgm_writepgmrow(alphaFileP, alpharow, cols, maxval, 0);
     }
     pm_close(ifP);
-    if (imageout_file)
-        pm_close(imageout_file);
-    if (alpha_file)
-        pm_close(alpha_file);
+    if (imageoutFileP)
+        pm_close(imageoutFileP);
+    if (alphaFileP)
+        pm_close(alphaFileP);
 
     return 0;
 }
diff --git a/converter/ppm/yuvsplittoppm.c b/converter/ppm/yuvsplittoppm.c
index 5343a21e..b734be91 100644
--- a/converter/ppm/yuvsplittoppm.c
+++ b/converter/ppm/yuvsplittoppm.c
@@ -43,12 +43,12 @@ struct cmdlineInfo {
 
 
 static void
-parseCommandLine(int                 argc, 
+parseCommandLine(int                 argc,
                  char **             argv,
                  struct cmdlineInfo *cmdlineP ) {
 /*----------------------------------------------------------------------------
    Parse program command line described in Unix standard form by argc
-   and argv.  Return the information in the options as *cmdlineP.  
+   and argv.  Return the information in the options as *cmdlineP.
 
    If command line is internally inconsistent (invalid options, etc.),
    issue error message to stderr and abort program.
@@ -64,7 +64,7 @@ parseCommandLine(int                 argc,
     unsigned int option_def_index;
 
     option_def_index = 0;   /* incremented by OPTENT3 */
-    OPTENT3(0, "ccir601",     OPT_FLAG,   NULL,                  
+    OPTENT3(0, "ccir601",     OPT_FLAG,   NULL,
             &cmdlineP->ccir601,       0);
 
     opt.opt_table = option_def;
@@ -103,13 +103,13 @@ computeTwoOutputRows(int             const cols,
                      unsigned char * const vbuf,
                      pixel *         const pixelrow1,
                      pixel *         const pixelrow2) {
-                     
+
     int col;
 
     for (col = 0; col < cols; col += 2) {
         long int r0,g0,b0,r1,g1,b1,r2,g2,b2,r3,g3,b3;
         long int  u,v,y0,y1,y2,y3,u0,u1,u2,u3,v0,v1,v2,v3;
-        
+
         y0 = y1buf[col];
         y1 = y1buf[col+1];
         y2 = y2buf[col];
@@ -117,7 +117,7 @@ computeTwoOutputRows(int             const cols,
 
         u = ubuf[col/2] - 128;
         v = vbuf[col/2] - 128;
-        
+
         if (ccir601) {
             y0 = ((y0-16)*255)/219;
             y1 = ((y1-16)*255)/219;
@@ -128,7 +128,7 @@ computeTwoOutputRows(int             const cols,
             v  = (v*255)/224 ;
         }
         /* mean the chroma for subsampling */
-        
+
         u0=u1=u2=u3=u;
         v0=v1=v2=v3=v;
 
@@ -138,25 +138,25 @@ computeTwoOutputRows(int             const cols,
            [Y]   [65496        0   91880] [R]
            [U] = [65533   -22580  -46799] [G]
            [V]   [65537   116128      -8] [B]
-           
+
         */
 
         r0 = 65536 * y0               + 91880 * v0;
         g0 = 65536 * y0 -  22580 * u0 - 46799 * v0;
         b0 = 65536 * y0 + 116128 * u0             ;
-        
+
         r1 = 65536 * y1               + 91880 * v1;
         g1 = 65536 * y1 -  22580 * u1 - 46799 * v1;
         b1 = 65536 * y1 + 116128 * u1             ;
-        
+
         r2 = 65536 * y2               + 91880 * v2;
         g2 = 65536 * y2 -  22580 * u2 - 46799 * v2;
         b2 = 65536 * y2 + 116128 * u2             ;
-        
+
         r3 = 65536 * y3               + 91880 * v3;
         g3 = 65536 * y3 -  22580 * u3 - 46799 * v3;
         b3 = 65536 * y3 + 116128 * u3             ;
-        
+
         r0 = limit(r0);
         r1 = limit(r1);
         r2 = limit(r2);
@@ -195,7 +195,7 @@ main(int argc, char **argv) {
     ppm_init(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
-        
+
     pm_asprintf(&ufname, "%s.U", cmdline.filenameBase);
     pm_asprintf(&vfname, "%s.V", cmdline.filenameBase);
     pm_asprintf(&yfname, "%s.Y", cmdline.filenameBase);
@@ -215,7 +215,7 @@ main(int argc, char **argv) {
     if (cmdline.height % 2 != 0) {
         pm_message("Warning: odd height; last row ignored");
         rows = cmdline.height - 1;
-    } else 
+    } else
         rows = cmdline.height;
 
     pixelrow1 = ppm_allocrow(cols);
@@ -251,3 +251,6 @@ main(int argc, char **argv) {
 
     exit(0);
 }
+
+
+
diff --git a/converter/ppm/yuvtoppm.c b/converter/ppm/yuvtoppm.c
index 9c5d79c4..87f541e5 100644
--- a/converter/ppm/yuvtoppm.c
+++ b/converter/ppm/yuvtoppm.c
@@ -2,7 +2,7 @@
 **
 ** by Marc Boucher
 ** Internet: marc@PostImage.COM
-** 
+**
 ** Based on Example Conversion Program, A60/A64 Digital Video Interface
 ** Manual, page 69
 **
@@ -72,7 +72,7 @@ parseCommandLine(int argc, const char ** argv,
 
         cmdlineP->cols = widthArg;
         cmdlineP->rows = heightArg;
-                 
+
         if (cmdlineP->cols % 2 != 0)
             pm_error("Number of columns (%u) is odd.  "
                      "A YUV image must have an "
@@ -213,9 +213,12 @@ main (int argc, const char ** argv) {
     ifP = pm_openr(cmdline.inputFileName);
 
     yuvtoppm(ifP, cmdline.cols, cmdline.rows, stdout);
-    
+
     pm_close(ifP);
     pm_close(stdout);
 
     return 0;
 }
+
+
+