about summary refs log tree commit diff
path: root/converter
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-12-26 06:13:41 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-12-26 06:13:41 +0000
commit51ffbae51ba9379bad460566cdf9babaa63b14c3 (patch)
tree441f6e9297c478261bdce544497decaf6abc31a4 /converter
parentd6f45222d7b29adb9defdd79dd8ad1dbc97bb3e1 (diff)
downloadnetpbm-mirror-51ffbae51ba9379bad460566cdf9babaa63b14c3.tar.gz
netpbm-mirror-51ffbae51ba9379bad460566cdf9babaa63b14c3.tar.xz
netpbm-mirror-51ffbae51ba9379bad460566cdf9babaa63b14c3.zip
Update to current Development release - 10.65.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2083 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter')
-rw-r--r--converter/other/cameratopam/Makefile4
-rw-r--r--converter/other/jpeg2000/libjasper/common.mk3
-rw-r--r--converter/other/pnmtopalm/Makefile2
-rw-r--r--converter/other/pnmtops.c55
-rw-r--r--converter/other/pstopnm.c80
-rw-r--r--converter/pbm/brushtopbm.c178
-rw-r--r--converter/pbm/pbmtoepsi.c128
7 files changed, 274 insertions, 176 deletions
diff --git a/converter/other/cameratopam/Makefile b/converter/other/cameratopam/Makefile
index 20a95aa2..4470d472 100644
--- a/converter/other/cameratopam/Makefile
+++ b/converter/other/cameratopam/Makefile
@@ -9,7 +9,7 @@ EXTERN_INCLUDES =
 ifneq ($(JPEGLIB),NONE)
   ifneq ($(JPEGHDR_DIR)x,x)
     EXTERN_INCLUDES += -I$(JPEGHDR_DIR)
-    CFLAGS += -DHAVE_JPEG
+    HAVE_JPEG_DEFINE = -DHAVE_JPEG
   endif
 endif
 
@@ -22,6 +22,8 @@ all: cameratopam
 OBJECTS = util.o identify.o cameratopam.o camera.o foveon.o decode.o \
 	canon.o ljpeg.o dng.o
 
+camera.o camera.o2: CFLAGS_TARGET = $(HAVE_JPEG_DEFINE)
+
 MERGE_OBJECTS =
 
 BINARIES = cameratopam
diff --git a/converter/other/jpeg2000/libjasper/common.mk b/converter/other/jpeg2000/libjasper/common.mk
index b31b1209..a333f5d6 100644
--- a/converter/other/jpeg2000/libjasper/common.mk
+++ b/converter/other/jpeg2000/libjasper/common.mk
@@ -13,8 +13,7 @@ partlist: $(SUBDIRS:%=%/partlist)
 	cat /dev/null $(SUBDIRS:%=%/partlist) >$@
 	echo $(LIB_OBJECTS:%=$(CURDIR)/%) >>$@
 
-.PHONY: $(SUBDIRS:%=%/partlist)
-$(SUBDIRS:%=%/partlist): %/partlist: $(CURDIR)/%
+$(SUBDIRS:%=%/partlist):
 	$(MAKE) -C $(dir $@) -f $(SRCDIR)/$(SUBDIR)/$(dir $@)Makefile \
 	    SRCDIR=$(SRCDIR) BUILDDIR=$(BUILDDIR) $(notdir $@) 
 
diff --git a/converter/other/pnmtopalm/Makefile b/converter/other/pnmtopalm/Makefile
index 7f99f95a..65790002 100644
--- a/converter/other/pnmtopalm/Makefile
+++ b/converter/other/pnmtopalm/Makefile
@@ -25,7 +25,7 @@ $(BINARIES): %: %.o palmcolormap.o $(NETPBMLIB) $(LIBOPT)
 	  $(MATHLIB) $(LDFLAGS) $(LDLIBS) $(RPATH) $(LADD)
 
 gen_palm_colormap : % : %.c palmcolormap.o
-	$(CC) -I importinc $(CPPFLAGS) $(CFLAGS) -o $@ \
+	$(CC) -I importinc $(CFLAGS_ALL) -o $@ \
 	  $< palmcolormap.o \
 	  $(LIBOPTS) $(MATHLIB) $(LDFLAGS) $(LDLIBS) $(LADD)
 
diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c
index 150331a1..316b7626 100644
--- a/converter/other/pnmtops.c
+++ b/converter/other/pnmtops.c
@@ -114,8 +114,10 @@ struct cmdlineInfo {
     unsigned int dict;
     unsigned int vmreclaim;
     unsigned int verbose;
+    unsigned int debug;
 };
 
+static bool debug;
 static bool verbose;
 
 
@@ -248,6 +250,7 @@ parseCommandLine(int argc, const char ** argv,
     OPTENT3(0, "vmreclaim",   OPT_FLAG,  NULL, &cmdlineP->vmreclaim,     0);
     OPTENT3(0, "showpage",    OPT_FLAG,  NULL, &showpage,                0);
     OPTENT3(0, "verbose",     OPT_FLAG,  NULL, &cmdlineP->verbose,       0);
+    OPTENT3(0, "debug",       OPT_FLAG,  NULL, &cmdlineP->debug,         0);
     OPTENT3(0, "level",       OPT_UINT, &cmdlineP->level, 
             &cmdlineP->levelSpec,              0);
     
@@ -395,6 +398,16 @@ writeFileChar(const char * const buffer,
 
 
 
+static void
+writeFileByte(unsigned char const byte,
+              const char *  const name,
+              FILE *        const ofP) {
+
+    writeFile(&byte, 1, name, ofP);
+}
+
+
+
 #define MAX_FILTER_CT 10
     /* The maximum number of filters this code is capable of applying */
 
@@ -621,17 +634,28 @@ flateFilter(FILE *          const ifP,
 
 
 static void
-rlePutBuffer (unsigned int    const repeat,
+rlePutBuffer (bool            const repeatMode,
               unsigned int    const count,
-              unsigned int    const repeatitem,
+              unsigned char   const repeatitem,
               unsigned char * const itembuf,
               FILE *          const fP) {
+/*----------------------------------------------------------------------------
+   Output some RLE data.  There are two forms of output:
 
-    if (repeat) {
-        fputc(257 - count,  fP);
-        fputc(repeatitem, fP);
+     'repeatMode' true: output a repeat sequence, indicating to repeat byte
+     'repeatitem' 'count' times.
+
+     'repeatMode' false: output a non-repeat sequence indicating the
+     'count' characters in itembuf[].
+-----------------------------------------------------------------------------*/
+    assert(count > 0);
+    assert(count <= 128);
+
+    if (repeatMode) {
+        writeFileByte((257 - count) % 256, "rlePutBuffer", fP);
+        writeFileByte(repeatitem, "rlePutBuffer", fP);
     } else {
-        fputc(count - 1, fP);
+        writeFileByte(count - 1, "rlePutBuffer", fP);
         writeFile(itembuf, count, "rlePutBuffer", fP);
     }
 }
@@ -975,6 +999,12 @@ addFilter(const char *    const description,
         pm_message("%s filter spawned: pid %u",
                    description, (unsigned)pid);
     
+    if (debug) {
+        int const outFd    = fileno(oldFeedFileP);
+        int const supplyFd = fileno(newFeedFileP);
+        pm_message("PID %u writes to FD %u, its supplier writes to FD %u",
+                   (unsigned)pid, outFd, supplyFd);
+    }
     fclose(oldFeedFileP);  /* Child keeps this open now */
 
     addToPidList(pidList, pid);
@@ -1937,7 +1967,17 @@ convertRaster(struct pam * const inpamP,
               unsigned int const bitsPerSample,
               bool         const psFilter,
               FILE *       const fP) {
+/*----------------------------------------------------------------------------
+   Read the raster described by *inpamP, and write a bit stream of samples
+   to *fP.  This stream has to be compressed and converted to text before it
+   can be part of a Postscript program.
+   
+   'psFilter' means to do the conversion using built in Postscript filters, as
+   opposed to our own filters via /readstring.
 
+   'bitsPerSample' is how many bits each sample is to take in the Postscript
+   output.
+-----------------------------------------------------------------------------*/
     if (PAM_FORMAT_TYPE(inpamP->format) == PBM_TYPE && bitsPerSample == 1)  {
         unsigned char * bitrow;
         unsigned int row;
@@ -2097,7 +2137,8 @@ main(int argc, const char * argv[]) {
 
     parseCommandLine(argc, argv, &cmdline);
 
-    verbose = cmdline.verbose;
+    verbose = cmdline.verbose || cmdline.debug;
+    debug   = cmdline.debug;
 
     if (cmdline.flate && !progIsFlateCapable())
         pm_error("This program cannot do flate compression.  "
diff --git a/converter/other/pstopnm.c b/converter/other/pstopnm.c
index f4081464..c0d6a4ee 100644
--- a/converter/other/pstopnm.c
+++ b/converter/other/pstopnm.c
@@ -496,42 +496,72 @@ computeBoxToExtract(struct Box const cmdlineExtractBox,
 static enum Orientation
 computeOrientation(struct CmdlineInfo const cmdline, 
                    struct Box         const extractBox) {
-
-    unsigned int const inputWidth  = extractBox.urx - extractBox.llx;
-    unsigned int const inputHeight = extractBox.ury - extractBox.lly;
+/*----------------------------------------------------------------------------
+   The proper orientation of the image on the page, given the user's
+   parameters 'cmdline' and the image dimensions 'extractBox'.
+-----------------------------------------------------------------------------*/
+    /* We're putting an _image_ on a _page_.  Either one can have portrait or
+       landscape aspect ratio.  In our return value, orientation just means
+       whether the image is rotated on the page: Portrait means it isn't
+       Landscape means it is.  The result can be confusing: Consider an image
+       which is a landscape, wider than it is tall, being printed on a page
+       which is also wider than it is tall.  The orientation we would return
+       for that case is Portrait.
+
+       The decision is simple: if the user didn't request a particular
+       orientation, we return the value that makes the image orientation match
+       the page orientation.  If both possibilities match equally (because the
+       image or the page is square), we return Portrait.
+    */
 
     enum Orientation retval;
 
     if (cmdline.orientation != UNSPECIFIED)
         retval = cmdline.orientation;
     else {
-        if ((!cmdline.xsize || !cmdline.ysize) &
-            (cmdline.xsize || cmdline.ysize)) {
-            /* User specified one output dimension, but not the other,
-               so we can't use output dimensions to make the decision.  So
-               just use the input dimensions.
-            */
-            if (inputHeight > inputWidth) retval = PORTRAIT;
-            else retval = LANDSCAPE;
+        /* Dimensions of image to print, in points */
+        unsigned int const imageWidPt = extractBox.urx - extractBox.llx;
+        unsigned int const imageHgtPt = extractBox.ury - extractBox.lly;
+        
+        /* Dimensions of image to print, in pixels (possibly of assumed
+           resolution)
+        */
+        unsigned int imageWidXel;
+        unsigned int imageHgtXel;
+
+        /* We have to deal with the awkward case that the printed pixels are
+           not square.  We match up the aspect ratio of the image in _pixels_
+           and the aspect ratio of the page in _pixels_.  But only the ratio
+           matters; we don't care what the absolute size of the pixels is.
+           And that's good, because if the user didn't specify xsize/ysize, we
+           don't know the absolute size in pixels.  In that case, fortunately,
+           the pixels are guaranteed to be square so we can just pretend it is
+           one point per pixel and get the right result.
+        */
+
+        if (cmdline.xsize && cmdline.ysize) {
+            imageWidXel = cmdline.xsize;
+            imageHgtXel = cmdline.ysize;
         } else {
-            unsigned int outputWidth, outputHeight;
-            if (cmdline.xsize) {
-                /* He gave xsize and ysize, so that's the output size */
-                outputWidth  = cmdline.xsize;
-                outputHeight = cmdline.ysize;
-            } else {
-                /* Well then we'll just use his (or default) xmax, ymax */
-                outputWidth  = cmdline.xmax;
-                outputHeight = cmdline.ymax;
-            }
+            /* Pixels are square, so it doesn't matter what the resolution
+               is; just call it one pixel per point.
+            */
+            imageWidXel = imageWidPt;
+            imageHgtXel = imageHgtPt;
 
-            if (inputHeight > inputWidth && outputHeight > outputWidth)
+            if (imageHgtXel >= imageWidXel && cmdline.ymax >= cmdline.xmax) {
+                /* Both image and page are higher than wide, so no rotation */
                 retval = PORTRAIT;
-            else if (inputHeight < inputWidth && 
-                     outputHeight < outputWidth)
+            } else if (imageHgtXel < imageWidXel &&
+                       cmdline.ymax < cmdline.xmax) {
+                /* Both image and page are wider than high, so no rotation */
                 retval = PORTRAIT;
-            else 
+            } else {
+                /* Image and pixel have opposite aspect ratios, so rotate
+                   for best fit.
+                */
                 retval = LANDSCAPE;
+            }
         }
     }
     return retval;
diff --git a/converter/pbm/brushtopbm.c b/converter/pbm/brushtopbm.c
index 0cffaa4d..c50fe8a1 100644
--- a/converter/pbm/brushtopbm.c
+++ b/converter/pbm/brushtopbm.c
@@ -1,4 +1,4 @@
-/* brushtopbm.c - read a doodle brush file and write a portable bitmap
+/* brushtopbm.c - read a doodle brush file and write a PBM image
 **
 ** Copyright (C) 1988 by Jef Poskanzer.
 **
@@ -12,96 +12,100 @@
 
 #include "pbm.h"
 
-static void getinit ARGS(( FILE* file, int* colsP, int* rowsP ));
-static bit getbit ARGS(( FILE* file ));
+#define HEADERSIZE 16   /* 16 is just a guess at the header size */
 
-int
-main( argc, argv )
-    int argc;
-    char* argv[];
-    {
-    FILE* ifp;
-    bit* bitrow;
-    register bit* bP;
-    int rows, cols, padright, row, col;
-
-
-    pbm_init( &argc, argv );
-
-    if ( argc > 2 )
-	pm_usage( "[brushfile]" );
-
-    if ( argc == 2 )
-	ifp = pm_openr( argv[1] );
-    else
-	ifp = stdin;
-
-    getinit( ifp, &cols, &rows );
-
-    pbm_writepbminit( stdout, cols, rows, 0 );
-    bitrow = pbm_allocrow( cols );
-
-    /* Compute padding to round cols up to the next multiple of 16. */
-    padright = ( ( cols + 15 ) / 16 ) * 16 - cols;
-
-    for ( row = 0; row < rows; ++row )
-	{
-	/* Get data. */
-        for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
-	    *bP = getbit( ifp );
-	/* Discard line padding. */
-        for ( col = 0; col < padright; ++col )
-	    (void) getbit( ifp );
-	/* Write row. */
-	pbm_writepbmrow( stdout, bitrow, cols, 0 );
-	}
-
-    pm_close( ifp );
-    pm_close( stdout );
-    
-    exit( 0 );
-    }
 
 
-static int item, bitsperitem, bitshift;
+static void
+getinit(FILE *         const ifP,
+        unsigned int * const colsP,
+        unsigned int * const rowsP) {
+
+    unsigned char header[HEADERSIZE];
+    size_t bytesRead;
+
+    bytesRead = fread(header, sizeof(header), 1, ifP);
+    if (bytesRead !=1)
+        pm_error("Error reading header");   
+
+    if (header[0] != 1)
+        pm_error("bad magic number 1");
+    if (header[1] != 0)
+        pm_error("bad magic number 2");
+
+    *colsP =  (header[2] << 8) + header[3];  /* Max 65535 */
+    *rowsP =  (header[4] << 8) + header[5];  /* Max 65535 */
+}
+
+
 
 static void
-getinit( file, colsP, rowsP )
-    FILE* file;
-    int* colsP;
-    int* rowsP;
-    {
-    int i;
-
-    if ( getc( file ) != 1 )
-	pm_error( "bad magic number 1" );
-    if ( getc( file ) != 0 )
-	pm_error( "bad magic number 2" );
-    *colsP = getc( file ) << 8;
-    *colsP += getc( file );
-    *rowsP = getc( file ) << 8;
-    *rowsP += getc( file );
-    bitsperitem = 8;
-
-    /* Junk rest of header. */
-    for ( i = 0; i < 10; ++i )  /* 10 is just a guess at the header size */
-	(void) getc( file );
-    }
+validateEof(FILE * const ifP) {
+
+    int rc;
+    rc = getc(ifP);
+    if (rc != EOF)
+        pm_message("Extraneous data at end of file");
+}
+
+
+/*
+   The routine for converting the raster closely resembles the pbm
+   case of pnminvert.  Input is padded up to 16 bit border.
+   afu December 2013
+ */
+
+
 
-static bit
-getbit( file )
-    FILE* file;
-    {
-    bit b;
-
-    if ( bitsperitem == 8 )
-	{
-	item = getc( file );
-	bitsperitem = 0;
-	bitshift = 7;
-	}
-    ++bitsperitem;
-    b = ( ( item >> bitshift) & 1 ) ? PBM_WHITE : PBM_BLACK;
-    --bitshift;
-    return b;
+int
+main(int argc, const char ** argv)  {
+
+    FILE * ifP;
+    bit * bitrow;
+    unsigned int rows, cols, row;
+
+    pm_proginit(&argc, argv);
+
+    if (argc-1 > 0) {
+        ifP = pm_openr(argv[1]);
+        if (argc-1 > 1)
+            pm_error("Too many arguments (%u).  "
+                     "The only argument is the brush file name.", argc-1);
+    } else
+        ifP = stdin;
+
+    getinit(ifP, &cols, &rows);
+
+    pbm_writepbminit(stdout, cols, rows, 0);
+
+    bitrow = pbm_allocrow_packed(cols + 16);
+
+    for (row = 0; row < rows; ++row) {
+        unsigned int const inRowBytes = ((cols + 15) / 16) * 2;
+        unsigned int i;
+        size_t bytesRead;
+
+        bytesRead = fread (bitrow, 1, inRowBytes, ifP); 
+        if (bytesRead != inRowBytes)
+            pm_error("Error reading a row of data from brushfile");
+
+        for (i = 0; i < inRowBytes; ++i)
+            bitrow[i] = ~bitrow[i];
+
+        /* Clean off remainder of fractional last character */
+        if (cols % 8 > 0) {
+            unsigned int const colChars = pbm_packed_bytes(cols);
+            bitrow[colChars-1] >>= 8 - cols % 8;
+            bitrow[colChars-1] <<= 8 - cols % 8;
+        }
+
+        pbm_writepbmrow_packed(stdout, bitrow, cols, 0);
     }
+
+    validateEof(ifP);
+
+    pm_close(ifP);
+    pm_close(stdout);
+    
+    return 0;
+}
diff --git a/converter/pbm/pbmtoepsi.c b/converter/pbm/pbmtoepsi.c
index 6d2065dc..87985a1f 100644
--- a/converter/pbm/pbmtoepsi.c
+++ b/converter/pbm/pbmtoepsi.c
@@ -16,19 +16,24 @@
 ** implied warranty.
 */
 
+/*
+ *
+ * Official guide from Adobe:
+ *
+ * Encapsulated PostScript File Format Specification
+ * http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf
+ *
+*/
+
 #include "pm_c_util.h"
 #include "pbm.h"
 #include "shhopt.h"
 
-#if !defined(MAXINT)
-#define MAXINT (0x7fffffff)
-#endif
-
 struct cmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
-    const char *inputFilespec;  /* Filespecs of input files */
+    const char *inputFileName;
 
     unsigned int dpiX;     /* horiz component of DPI option */
     unsigned int dpiY;     /* vert component of DPI option */
@@ -40,8 +45,9 @@ struct cmdlineInfo {
 
 
 static void
-parse_dpi(char * const dpiOpt, 
-          unsigned int * const dpiXP, unsigned int * const dpiYP) {
+parseDpi(char *         const dpiOpt, 
+         unsigned int * const dpiXP,
+         unsigned int * const dpiYP) {
 
     char *dpistr2;
     unsigned int dpiX, dpiY;
@@ -72,7 +78,7 @@ parse_dpi(char * const dpiOpt,
 
 
 static void
-parseCommandLine(int argc, char ** const argv,
+parseCommandLine(int argc, const char ** const argv,
                  struct cmdlineInfo * const cmdlineP) {
 /*----------------------------------------------------------------------------
    Note that the file spec array we return is stored in the storage that
@@ -97,48 +103,58 @@ parseCommandLine(int argc, char ** const argv,
     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 (dpiOptSpec)
-        parse_dpi(dpiOpt, &cmdlineP->dpiX, &cmdlineP->dpiY);
+        parseDpi(dpiOpt, &cmdlineP->dpiX, &cmdlineP->dpiY);
     else
         cmdlineP->dpiX = cmdlineP->dpiY = 72;
     
     if ((argc-1) > 1)
-        pm_error("Too many arguments (%d).  Only argument is input filespec",
+        pm_error("Too many arguments (%d).  Only argument is input file name",
                  argc-1);
     
     if (argc-1 == 0)
-        cmdlineP->inputFilespec = "-";
+        cmdlineP->inputFileName = "-";
     else
-        cmdlineP->inputFilespec = argv[1];
+        cmdlineP->inputFileName = argv[1];
 }
 
 
 
 static void
-findPrincipalImage(bit ** const bits, 
-                   int    const rows,
-                   int    const cols,
-                   int *  const topP,
-                   int *  const bottomP,
-                   int *  const leftP,
-                   int *  const rightP) {
+findPrincipalImage(bit **         const bits, 
+                   unsigned int   const rows,
+                   unsigned int   const cols,
+                   unsigned int * const topP,
+                   unsigned int * const bottomP,
+                   unsigned int * const leftP,
+                   unsigned int * const rightP) {
+/*----------------------------------------------------------------------------
+   Find the foreground image on a white background.
+
+   Find the image in the pixels bits[][], which is 'rows' rows by
+   'cols' columns.
 
-    int top, bottom, left, right;
-    int row;
+   Return the boundaries of the foreground image as *topP, *bottomP, *leftP,
+   and *rightP.
+
+   If the image is all white, consider the entire image foreground.
+-----------------------------------------------------------------------------*/
+    unsigned int top, bottom, left, right;
+    unsigned int row;
 
     /* Initial values */
-    top = MAXINT;
-    bottom = -MAXINT;
-    left = MAXINT;
-    right = -MAXINT;
+    top    = rows;
+    bottom = 0;
+    left   = cols;
+    right  = 0;
  
-    for (row = 0; row < rows; row++) {
-        int col;
-        for (col = 0; col < cols; col++) {
+    for (row = 0; row < rows; ++row) {
+        unsigned int col;
+        for (col = 0; col < cols; ++col) {
             if (bits[row][col] == PBM_BLACK) {
                 if (row < top) 
                     top = row;
@@ -152,16 +168,19 @@ findPrincipalImage(bit ** const bits,
         }
     }
 
-    if(bottom == -MAXINT) {  /* No black pixels encountered */ 
+    if (top > bottom) {
+        /* No black pixels encountered */ 
         pm_message("Blank page");
-        top = left = 0;
-        bottom = rows-1;  right = cols-1;
-	}
+        top    = 0;
+        left   = 0;
+        bottom = rows - 1;
+        right  = cols - 1;
+    }
 
-    *topP = top;
+    *topP    = top;
     *bottomP = bottom;
-    *leftP = left;
-    *rightP = right;
+    *leftP   = left;
+    *rightP  = right;
 }
 
 
@@ -190,7 +209,8 @@ eightPixels(bit ** const bits,
 /*----------------------------------------------------------------------------
   Compute a byte that represents the 8 pixels starting at Column 'col' of
   row 'row' of the raster 'bits'.  The most significant bit of the result
-  represents the leftmost pixel, with 1 meaning black.
+  represents the leftmost pixel, with 1 meaning black.  (Note that this is
+  the opposite of Postscript.)
 
   The row is 'cols' columns wide, so fill on the right with white if there
   are not eight pixels in the row starting with Column 'col'.
@@ -212,23 +232,23 @@ eightPixels(bit ** const bits,
 
 
 int
-main(int argc, char * argv[]) {
+main(int argc, const char * argv[]) {
 
     struct cmdlineInfo cmdline;
-    FILE *ifP;
-    bit **bits;
+    FILE * ifP;
+    bit ** bits;
     int rows, cols;
-    int top, bottom, left, right;
+    unsigned int top, bottom, left, right;
         /* boundaries of principal part of image -- i.e. excluding white
            borders
         */
 
-    pbm_init( &argc, argv );
+    pm_proginit(&argc, argv);
     
     parseCommandLine(argc, argv, &cmdline);
 
-    ifP = pm_openr(cmdline.inputFilespec);
-    bits = pbm_readpbm( ifP, &cols, &rows );
+    ifP = pm_openr(cmdline.inputFileName);
+    bits = pbm_readpbm(ifP, &cols, &rows);
     pm_close(ifP);
 
     findPrincipalImage(bits, rows, cols, &top, &bottom, &left, &right);
@@ -244,24 +264,26 @@ main(int argc, char * argv[]) {
                right - left + 1, bottom - top + 1, bottom - top + 1);
 
         for (row = top; row <= bottom; row++) {
-            int col;
-	    int outChars = 2;
-	    printf("%% ");
+            unsigned int col;
+            unsigned int outChars;
+            printf("%% ");
+
+            outChars = 2;  /* initial value */
 
             for (col = left; col <= right; col += 8) {
                 if (outChars == 72) {
-		  printf("\n%% ");
-                  outChars = 2;
-		}  
+                    printf("\n%% ");
+                    outChars = 2;
+                }  
 
                 printf("%02x", eightPixels(bits, row, col, cols));
                 outChars += 2;
-	    }
-	    if (outChars > 0)
+            }
+            if (outChars > 0)
                 printf("\n");
         }
         printf("%%%%EndImage\n");
         printf("%%%%EndPreview\n");
     }
-    exit(0);
+    return 0;
 }