about summary refs log tree commit diff
path: root/editor/pnmremap.c
diff options
context:
space:
mode:
Diffstat (limited to 'editor/pnmremap.c')
-rw-r--r--editor/pnmremap.c77
1 files changed, 45 insertions, 32 deletions
diff --git a/editor/pnmremap.c b/editor/pnmremap.c
index db35e2c0..ed758aa3 100644
--- a/editor/pnmremap.c
+++ b/editor/pnmremap.c
@@ -30,17 +30,18 @@
 #include "nstring.h"
 #include "shhopt.h"
 #include "pam.h"
+#include "ppm.h"
 #include "pammap.h"
 
 #define MAXCOLORS 32767u
 
-enum missingMethod {
+enum MissingMethod {
     MISSING_FIRST,
     MISSING_SPECIFIED,
     MISSING_CLOSE
 };
 
-struct cmdlineInfo {
+struct CmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
@@ -48,7 +49,7 @@ struct cmdlineInfo {
     const char * mapFilespec;    /* Filespec of colormap file */
     unsigned int floyd;   /* Boolean: -floyd/-fs option */
     unsigned int norandom;
-    enum missingMethod missingMethod;
+    enum MissingMethod missingMethod;
     char * missingcolor;      
         /* -missingcolor value.  Null if not specified */
     unsigned int verbose;
@@ -57,8 +58,8 @@ struct cmdlineInfo {
 
 
 static void
-parseCommandLine (int argc, char ** argv,
-                  struct cmdlineInfo *cmdlineP) {
+parseCommandLine (int argc, const char ** argv,
+                  struct CmdlineInfo * const cmdlineP) {
 /*----------------------------------------------------------------------------
    parse program command line described in Unix standard form by argc
    and argv.  Return the information in the options as *cmdlineP.  
@@ -70,7 +71,7 @@ parseCommandLine (int argc, char ** argv,
    was passed to us as the argv array.  We also trash *argv.
 -----------------------------------------------------------------------------*/
     optEntry * option_def;
-        /* Instructions to optParseOptions3 on how to parse our options.
+        /* Instructions to pm_optParseOptions3 on how to parse our options.
          */
     optStruct3 opt;
 
@@ -82,24 +83,24 @@ parseCommandLine (int argc, char ** argv,
     MALLOCARRAY_NOFAIL(option_def, 100);
     
     option_def_index = 0;   /* incremented by OPTENT3 */
-    OPTENT3(0,   "floyd",        OPT_FLAG,   
-            NULL,                       &cmdlineP->floyd, 0);
-    OPTENT3(0,   "fs",           OPT_FLAG,   
-            NULL,                       &cmdlineP->floyd, 0);
-    OPTENT3(0,   "nofloyd",      OPT_FLAG,   
-            NULL,                       &nofloyd, 0);
-    OPTENT3(0,   "nofs",         OPT_FLAG,   
-            NULL,                       &nofloyd, 0);
-    OPTENT3(0,   "norandom",     OPT_FLAG,   
+    OPTENT3(0,   "floyd",          OPT_FLAG,   
+            NULL,                       &cmdlineP->floyd,    0);
+    OPTENT3(0,   "fs",             OPT_FLAG,   
+            NULL,                       &cmdlineP->floyd,    0);
+    OPTENT3(0,   "nofloyd",        OPT_FLAG,   
+            NULL,                       &nofloyd,            0);
+    OPTENT3(0,   "nofs",           OPT_FLAG,   
+            NULL,                       &nofloyd,            0);
+    OPTENT3(0,   "norandom",       OPT_FLAG,   
             NULL,                       &cmdlineP->norandom, 0);
     OPTENT3(0,   "firstisdefault", OPT_FLAG,   
-            NULL,                       &firstisdefault, 0);
-    OPTENT3(0,   "mapfile",      OPT_STRING, 
-            &cmdlineP->mapFilespec,    &mapfileSpec, 0);
-    OPTENT3(0,   "missingcolor", OPT_STRING, 
-            &cmdlineP->missingcolor,   &missingSpec, 0);
-    OPTENT3(0, "verbose",        OPT_FLAG,   NULL,                  
-            &cmdlineP->verbose,        0 );
+            NULL,                       &firstisdefault,     0);
+    OPTENT3(0,   "mapfile",        OPT_STRING, 
+            &cmdlineP->mapFilespec,    &mapfileSpec,         0);
+    OPTENT3(0,   "missingcolor",   OPT_STRING, 
+            &cmdlineP->missingcolor,   &missingSpec,         0);
+    OPTENT3(0, "verbose",          OPT_FLAG,   NULL,                  
+            &cmdlineP->verbose,                              0);
 
     opt.opt_table = option_def;
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
@@ -107,7 +108,7 @@ parseCommandLine (int argc, char ** argv,
 
     cmdlineP->missingcolor = NULL;  /* default value */
     
-    optParseOptions3( &argc, argv, opt, sizeof(opt), 0 );
+    pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0);
         /* Uses and sets argc, argv, and some of *cmdline_p and others. */
 
     if (cmdlineP->floyd && nofloyd)
@@ -134,6 +135,8 @@ parseCommandLine (int argc, char ** argv,
         cmdlineP->inputFilespec = "-";
     else
         cmdlineP->inputFilespec = argv[1];
+
+    free(option_def);
 }
 
 
@@ -267,7 +270,7 @@ selectDepthAdjustment(const struct pam * const pamP,
     if (newDepth == pamP->depth)
         *adjustmentP = ADJUST_NONE;
     else {
-        if (stripeq(pamP->tuple_type, "RGB")) {
+        if (pm_stripeq(pamP->tuple_type, "RGB")) {
             if (newDepth != 1) {
                 pm_error("Map image depth of %u differs from input image "
                          "depth of %u, and the tuple type is RGB.  "
@@ -276,8 +279,8 @@ selectDepthAdjustment(const struct pam * const pamP,
                          newDepth, pamP->depth);
             } else
                 *adjustmentP = ADJUST_RGBTO1;
-        } else if (stripeq(pamP->tuple_type, "GRAYSCALE") ||
-                   stripeq(pamP->tuple_type, "BLACKANDWHITE")) {
+        } else if (pm_stripeq(pamP->tuple_type, "GRAYSCALE") ||
+                   pm_stripeq(pamP->tuple_type, "BLACKANDWHITE")) {
             if (newDepth != 3) {
                 pm_error("Map image depth of %u differs from input image "
                          "depth of %u, and the tuple type is GRAYSCALE "
@@ -748,7 +751,7 @@ lookupThroughHash(struct pam *            const pamP,
         } else 
             searchColormapClose(pamP, tuple, colorFinderP, colormapIndexP);
         if (*usehashP) {
-            bool fits;
+            int fits;
             pnm_addtotuplehash(pamP, colorhash, tuple, *colormapIndexP, 
                                &fits);
             if (!fits) {
@@ -1062,7 +1065,7 @@ remap(FILE *             const ifP,
    same as that of the input even though the individual pixels have different
    colors.
 -----------------------------------------------------------------------------*/
-    bool eof;
+    int eof;
     eof = FALSE;
     while (!eof) {
         struct pam inpam, outpam;
@@ -1102,7 +1105,14 @@ processMapFile(const char *   const mapFileName,
                tupletable *   const colormapP,
                unsigned int * const colormapSizeP,
                tuple *        const firstColorP) {
+/*----------------------------------------------------------------------------
+   Read a color map from the file named 'mapFileName'.  It's a map that
+   associates each color in that file with a unique whole number.  Return the
+   map as *colormapP, with the number of entries in it as *colormapSizeP.
 
+   Also determine the first color (top left) in the map file and return that
+   as *firstColorP.
+-----------------------------------------------------------------------------*/
     FILE * mapfile;
     struct pam mappam;
     tuple ** maptuples;
@@ -1142,7 +1152,7 @@ getSpecifiedMissingColor(struct pam * const pamP,
             specColor[PAM_GRN_PLANE] = PPM_GETG(color);
             specColor[PAM_BLU_PLANE] = PPM_GETB(color);
         } else if (pamP->depth == 1) {
-            specColor[0] = PPM_LUMIN(color);
+            specColor[0] = ppm_luminosity(color);
         } else {
             pm_error("You may not use -missing with a colormap that is not "
                      "of depth 1 or 3.  Yours has depth %u",
@@ -1155,9 +1165,9 @@ getSpecifiedMissingColor(struct pam * const pamP,
 
 
 int
-main(int argc, char * argv[] ) {
+main(int argc, const char * argv[] ) {
 
-    struct cmdlineInfo cmdline;
+    struct CmdlineInfo cmdline;
     FILE * ifP;
     struct pam outpamCommon;
         /* Describes the output images.  Width and height fields are
@@ -1180,7 +1190,7 @@ main(int argc, char * argv[] ) {
            color (i.e. we'll choose an approximate match from the map).
         */
 
-    pnm_init(&argc, argv);
+    pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
 
@@ -1216,3 +1226,6 @@ main(int argc, char * argv[] ) {
 
     return 0;
 }
+
+
+