about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile3
-rw-r--r--lib/libpbmfont2.c51
-rw-r--r--lib/libppmfloyd.c312
-rw-r--r--lib/ppmfloyd.h69
-rw-r--r--lib/util/shhopt.README18
5 files changed, 43 insertions, 410 deletions
diff --git a/lib/Makefile b/lib/Makefile
index d42658a2..d7dfc993 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -33,7 +33,6 @@ LIBOBJECTS = libpm.o pmfileio.o fileio.o colorname.o \
 	libpgm1.o libpgm2.o \
 	libppm1.o libppm2.o libppmcmap.o libppmcolor.o libppmfuzzy.o \
 	libppmd.o ppmdfont.o standardppmdfont.o path.o \
-	libppmfloyd.o \
 	libpnm1.o libpnm2.o libpnm3.o \
 	libpam.o libpamread.o libpamwrite.o \
 	libpamn.o libpammap.o libpamcolor.o \
@@ -63,7 +62,7 @@ MANUALS5 = pbm pgm ppm pnm pam
 INTERFACE_HEADERS = colorname.h \
 	pam.h pamdraw.h pammap.h pbm.h pbmfont.h pbmfontdata.h \
 	pgm.h pm.h pm_gamma.h pm_system.h pnm.h \
-	ppm.h ppmcmap.h ppmdfont.h ppmdraw.h ppmfloyd.h \
+	ppm.h ppmcmap.h ppmdfont.h ppmdraw.h \
 	util/mallocvar.h util/runlength.h util/shhopt.h \
 
 DATAFILES = rgb.txt
diff --git a/lib/libpbmfont2.c b/lib/libpbmfont2.c
index 6007d7f6..7c0415c1 100644
--- a/lib/libpbmfont2.c
+++ b/lib/libpbmfont2.c
@@ -193,9 +193,12 @@ pm_selector_mark(struct pm_selector * const selectorP,
     }
 }
 
+
+
 /* There is no function for erasing a marked bit */
 
 
+
 int  /* boolean */
 pm_selector_is_marked(const struct pm_selector * const selectorP,
                       unsigned int               const index) {
@@ -312,14 +315,13 @@ tokenize(char *         const s,
 
     while (*p) {
         if (!ISGRAPH(*p)) {
-            if(!ISSPACE(*p)) {
-              /* Control chars excluding 09 - 0d (space), 80-ff */
-            pm_message("Warning: non-ASCII character '%x' in "
-                       "BDF font file", *p);
+            if (!ISSPACE(*p)) {
+                /* Control chars excluding 09 - 0d (space), 80-ff */
+                pm_message("Warning: non-ASCII character '%x' in "
+                           "BDF font file", *p);
             }
             *p++ = '\0';
-        }
-        else {
+        } else {
             words[n++] = p;
             if (n >= wordsSz - 1)
                 break;
@@ -395,6 +397,7 @@ parseBitmapRow(const char *    const hex,
                         glyphWidth, hex);
         else {
             char const hdig = *p++;
+
             unsigned int hdigValue;
 
             if (hdig >= '0' && hdig <= '9')
@@ -517,7 +520,7 @@ static void
 validateWordCount(Readline *    const readlineP,
                   unsigned int  const nWords) {
 
-    if( readlineP->wordCt != nWords )
+    if (readlineP->wordCt != nWords)
         pm_error("Wrong number of arguments in '%s' line in BDF font file",
                  readlineP->arg[0]);
 
@@ -536,7 +539,6 @@ readExpectedStatement(Readline *    const readlineP,
   beginning of the line is that, e.g. "STARTFONT").  Check for the number
   of words: 'nWords'.  If either condition is not met, fail the program.
 -----------------------------------------------------------------------------*/
-
     bool eof;
 
     readline_read(readlineP, &eof);
@@ -561,7 +563,6 @@ skipCharacter(Readline * const readlineP) {
 
   At entry the stream must be positioned at the end of the ENCODING line.
 -----------------------------------------------------------------------------*/
-
     char * rc;
     do {
         rc = fgets(readlineP->line, MAXBDFLINE+1, readlineP->ifP);
@@ -625,10 +626,12 @@ interpEncoding(const char **  const arg,
 
    'maxmaxglyph' is the maximum codepoint in the font.
 -----------------------------------------------------------------------------*/
-    bool gotCodepoint = false;   /* initial value */
+    bool gotCodepoint;
     bool badCodepoint;
     unsigned int codepoint;
 
+    gotCodepoint = false;  /* initial value */
+
     if (wordToInt(arg[1]) >= 0) {
         codepoint = wordToInt(arg[1]);
         gotCodepoint = true;
@@ -662,8 +665,9 @@ readEncoding(Readline *     const readlineP,
              bool *         const badCodepointP,
              PM_WCHAR       const maxmaxglyph) {
 
+    const char * const expected = "ENCODING";
+
     bool eof;
-    const char * expected = "ENCODING";
 
     readline_read(readlineP, &eof);
 
@@ -672,7 +676,7 @@ readEncoding(Readline *     const readlineP,
     else if (!streq(readlineP->arg[0], expected))
         pm_error("Statement of type '%s' where '%s' expected in BDF font file",
                  readlineP->arg[0], expected);
-    else if(readlineP->wordCt != 2 &&  readlineP->wordCt != 3)
+    else if (readlineP->wordCt != 2 &&  readlineP->wordCt != 3)
         pm_error("Wrong number of arguments in '%s' line in BDF font file",
                  readlineP->arg[0]);
 
@@ -747,7 +751,7 @@ validateGlyphLimits(const struct font2 * const font2P,
 static void
 readStartchar(Readline * const readlineP,
               const char ** charNameP) {
-        
+
         const char * charName;
         bool eof;
 
@@ -786,6 +790,7 @@ readGlyph(Readline * const readlineP,
           struct glyph ** const glyphPP) {
 
     struct glyph * glyphP;
+
     MALLOCVAR(glyphP);
     if (glyphP == NULL)
         pm_error("no memory for font glyph for '%s' character",
@@ -959,8 +964,11 @@ loadCharsetString(const char *  const registry,
 }
 
 
+
 static unsigned int const maxTokenLen = 60;
 
+
+
 static void
 doCharsetRegistry(Readline *    const readlineP,
                   bool *        const gotRegistryP,
@@ -1178,7 +1186,6 @@ initializeGlyphArray(struct font2 * const font2P,
            It may not be defined in the font, but the program may try
            to use space as a substitute char
         */
-
 }
 
 
@@ -1220,7 +1227,7 @@ pbm_loadbdffont2select(const char *               const filename,
     if (font2P->selectorP == NULL) {
         PM_WCHAR i;
 
-        for(i = 0; i <= maxmaxglyph; ++i)
+        for (i = 0; i <= maxmaxglyph; ++i)
             font2P->glyph[i] = NULL;
             /* Initial value.  Overwrite later if codepoint i is defined. */
     }
@@ -1252,10 +1259,10 @@ pbm_loadbdffont2select(const char *               const filename,
     }
     fclose(ifP);
 
-    if(font2P->total_chars == 0)
+    if (font2P->total_chars == 0)
         pm_error("No glyphs found in BDF font file "
                  "in codepoint range 0 - %u", (unsigned int) maxmaxglyph);
-    if(font2P->chars == 0)
+    if (font2P->chars == 0)
         pm_error("Not any requested glyphs found in BDF font file "
                  "in codepoint range 0 - %u", (unsigned int) maxmaxglyph);
 
@@ -1272,23 +1279,21 @@ pbm_loadbdffont2select(const char *               const filename,
 }
 
 
+
 struct font2 *
 pbm_loadbdffont2(const char * const filename,
                  PM_WCHAR     const maxmaxglyph) {
 
-  return (pbm_loadbdffont2select(filename, maxmaxglyph, NULL));
-
-  return(0);
+    return pbm_loadbdffont2select(filename, maxmaxglyph, NULL);
 }
 
 
 
-
 static struct font *
 font2ToFont(const struct font2 * const font2P) {
 
-            struct font  * fontP;
-            unsigned int   codePoint;
+    struct font  * fontP;
+    unsigned int   codePoint;
 
     MALLOCVAR(fontP);
     if (fontP == NULL)
diff --git a/lib/libppmfloyd.c b/lib/libppmfloyd.c
deleted file mode 100644
index a7117c8e..00000000
--- a/lib/libppmfloyd.c
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
-These functions were taken from Ingo Wilken's ilbm package by Bryan
-Henderson on 01.03.10.  Because ppmtoilbm and ilbmtoppm are the only
-programs that will use these in the foreseeable future, they remain
-lightly documented and tested.
-
-But they look like they would be useful in other Netpbm programs that
-do Floyd-Steinberg.
-*/
-
-
-
-/* libfloyd.c - generic Floyd-Steinberg error distribution routines for PBMPlus
-**
-** Copyright (C) 1994 Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
-**
-** Permission to use, copy, modify, and distribute this software and its
-** documentation for any purpose and without fee is hereby granted, provided
-** that the above copyright notice appear in all copies and that both that
-** copyright notice and this permission notice appear in supporting
-** documentation.  This software is provided "as is" without express or
-** implied warranty.
-*/
-
-#include "netpbm/mallocvar.h"
-#include "ppm.h"
-#include "ppmfloyd.h"
-
-
-
-static void
-fs_adjust(ppm_fs_info * const fi,
-          int           const col) {
-
-    int     const errcol = col+1;
-    pixel * const pP     = &(fi->pixrow[col]);
-    pixval  const maxval = fi->maxval;
-
-    long r, g, b;
-
-    /* Use Floyd-Steinberg errors to adjust actual color. */
-    r = fi->thisrederr  [errcol]; if( r < 0 ) r -= 8; else r += 8; r /= 16;
-    g = fi->thisgreenerr[errcol]; if( g < 0 ) g -= 8; else g += 8; g /= 16;
-    b = fi->thisblueerr [errcol]; if( b < 0 ) b -= 8; else b += 8; b /= 16;
-
-    r += PPM_GETR(*pP); if ( r < 0 ) r = 0; else if ( r > maxval ) r = maxval;
-    g += PPM_GETG(*pP); if ( g < 0 ) g = 0; else if ( g > maxval ) g = maxval;
-    b += PPM_GETB(*pP); if ( b < 0 ) b = 0; else if ( b > maxval ) b = maxval;
-
-    PPM_ASSIGN(*pP, r, g, b);
-    fi->red = r; fi->green = g; fi->blue = b;
-}
-
-
-
-static ppm_fs_info *
-allocateFi(int const cols) {
-
-    ppm_fs_info * fi;
-
-    MALLOCVAR(fi);
-
-    if (fi != NULL) {
-        MALLOCARRAY(fi->thisrederr  , cols + 2);
-        MALLOCARRAY(fi->thisgreenerr, cols + 2);
-        MALLOCARRAY(fi->thisblueerr , cols + 2);
-        MALLOCARRAY(fi->nextrederr  , cols + 2);
-        MALLOCARRAY(fi->nextgreenerr, cols + 2);
-        MALLOCARRAY(fi->nextblueerr , cols + 2);
-
-        if (fi->thisrederr   == NULL ||
-            fi->thisgreenerr == NULL ||
-            fi->thisblueerr  == NULL ||
-            fi->nextrederr   == NULL ||
-            fi->nextgreenerr == NULL ||
-            fi->nextblueerr  == NULL)
-            pm_error("out of memory allocating "
-                     "Floyd-Steinberg control structure");
-    } else
-        pm_error("out of memory allocating Floyd-Steinberg control structure");
-
-    return(fi);
-}
-
-
-
-ppm_fs_info *
-ppm_fs_init(unsigned int const cols,
-            pixval       const maxval,
-            unsigned int const flags) {
-
-    ppm_fs_info * fiP;
-
-    fiP = allocateFi(cols);
-
-    fiP->lefttoright = 1;
-    fiP->cols        = cols;
-    fiP->maxval      = maxval;
-    fiP->flags       = flags;
-
-    if (flags & FS_RANDOMINIT) {
-        unsigned int i;
-        srand(pm_randseed());
-        for (i = 0; i < cols +2; ++i) {
-            /* random errors in [-1..+1] */
-            fiP->thisrederr[i]   = rand() % 32 - 16;
-            fiP->thisgreenerr[i] = rand() % 32 - 16;
-            fiP->thisblueerr[i]  = rand() % 32 - 16;
-        }
-    } else {
-        unsigned int i;
-
-        for (i = 0; i < cols + 2; ++i)
-            fiP->thisrederr[i] = fiP->thisgreenerr[i] =
-                fiP->thisblueerr[i] = 0;
-    }
-    return fiP;
-}
-
-
-
-void
-ppm_fs_free(ppm_fs_info * const fiP) {
-
-    if (fiP) {
-        free(fiP->thisrederr); free(fiP->thisgreenerr); free(fiP->thisblueerr);
-        free(fiP->nextrederr); free(fiP->nextgreenerr); free(fiP->nextblueerr);
-        free(fiP);
-    }
-}
-
-
-
-int
-ppm_fs_startrow(ppm_fs_info * const fiP,
-                pixel *       const pixrow) {
-
-    int retval;
-
-    if (!fiP)
-        retval = 0;
-    else {
-        unsigned int col;
-
-        fiP->pixrow = pixrow;
-
-        for (col = 0; col < fiP->cols + 2; ++col) {
-            fiP->nextrederr  [col] = 0;
-            fiP->nextgreenerr[col] = 0;
-            fiP->nextblueerr [col] = 0;
-        }
-
-        if(fiP->lefttoright) {
-            fiP->col_end = fiP->cols;
-            col = 0;
-        } else {
-            fiP->col_end = -1;
-            col = fiP->cols - 1;
-        }
-        fs_adjust(fiP, col);
-
-        retval = col;
-    }
-    return retval;
-}
-
-
-
-int
-ppm_fs_next(ppm_fs_info * const fiP,
-            int           const startCol) {
-
-    int col;
-
-    col = startCol;  /* initial value */
-
-    if (!fiP)
-        ++col;
-    else {
-        if (fiP->lefttoright)
-            ++col;
-        else
-            --col;
-        if (col == fiP->col_end)
-            col = fiP->cols;
-        else
-            fs_adjust(fiP, col);
-    }
-    return col;
-}
-
-
-
-void
-ppm_fs_endrow(ppm_fs_info * const fiP) {
-
-    if (fiP) {
-        {
-            long * const tmp = fiP->thisrederr;
-            fiP->thisrederr = fiP->nextrederr;
-            fiP->nextrederr = tmp;
-        }
-        {
-            long * const tmp = fiP->thisgreenerr;
-            fiP->thisgreenerr = fiP->nextgreenerr;
-            fiP->nextgreenerr = tmp;
-        }
-        {
-            long * const tmp = fiP->thisblueerr;
-            fiP->thisblueerr = fiP->nextblueerr;
-            fiP->nextblueerr = tmp;
-        }
-        if (fiP->flags & FS_ALTERNATE)
-            fiP->lefttoright = !fiP->lefttoright;
-    }
-}
-
-
-
-void
-ppm_fs_update(ppm_fs_info * const fiP,
-              int           const col,
-              pixel *       const pP) {
-
-    if (fiP)
-        ppm_fs_update3(fiP, col, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP));
-}
-
-
-
-void
-ppm_fs_update3(ppm_fs_info * const fiP,
-               int           const col,
-               pixval        const r,
-               pixval        const g,
-               pixval        const b) {
-
-    int const errcol = col + 1;
-
-    if (fiP) {
-        long const rerr = (long)(fiP->red)   - (long)r;
-        long const gerr = (long)(fiP->green) - (long)g;
-        long const berr = (long)(fiP->blue)  - (long)b;
-
-        if ( fiP->lefttoright ) {
-            {
-                long const two_err = 2*rerr;
-
-                long err;
-
-                err = rerr;     fiP->nextrederr[errcol+1] += err;    /* 1/16 */
-                err += two_err; fiP->nextrederr[errcol-1] += err;    /* 3/16 */
-                err += two_err; fiP->nextrederr[errcol  ] += err;    /* 5/16 */
-                err += two_err; fiP->thisrederr[errcol+1] += err;    /* 7/16 */
-            }
-            {
-                long const two_err = 2*gerr;
-
-                long err;
-
-                err = gerr;     fiP->nextgreenerr[errcol+1] += err;  /* 1/16 */
-                err += two_err; fiP->nextgreenerr[errcol-1] += err;  /* 3/16 */
-                err += two_err; fiP->nextgreenerr[errcol  ] += err;  /* 5/16 */
-                err += two_err; fiP->thisgreenerr[errcol+1] += err;  /* 7/16 */
-            }
-            {
-                long const two_err = 2*berr;
-
-                long err;
-
-                err = berr;     fiP->nextblueerr[errcol+1] += err;  /* 1/16 */
-                err += two_err; fiP->nextblueerr[errcol-1] += err;  /* 3/16 */
-                err += two_err; fiP->nextblueerr[errcol  ] += err;  /* 5/16 */
-                err += two_err; fiP->thisblueerr[errcol+1] += err;  /* 7/16 */
-            }
-        } else {
-            {
-                long const two_err = 2*rerr;
-
-                long err;
-
-                err = rerr;     fiP->nextrederr[errcol-1] += err;    /* 1/16 */
-                err += two_err; fiP->nextrederr[errcol+1] += err;    /* 3/16 */
-                err += two_err; fiP->nextrederr[errcol  ] += err;    /* 5/16 */
-                err += two_err; fiP->thisrederr[errcol-1] += err;    /* 7/16 */
-            }
-            {
-                long const two_err = 2*gerr;
-
-                long err;
-
-                err = gerr;     fiP->nextgreenerr[errcol-1] += err;  /* 1/16 */
-                err += two_err; fiP->nextgreenerr[errcol+1] += err;  /* 3/16 */
-                err += two_err; fiP->nextgreenerr[errcol  ] += err;  /* 5/16 */
-                err += two_err; fiP->thisgreenerr[errcol-1] += err;  /* 7/16 */
-            }
-            {
-                long const two_err = 2*berr;
-
-                long err;
-
-                err = berr;     fiP->nextblueerr[errcol-1] += err;  /* 1/16 */
-                err += two_err; fiP->nextblueerr[errcol+1] += err;  /* 3/16 */
-                err += two_err; fiP->nextblueerr[errcol  ] += err;  /* 5/16 */
-                err += two_err; fiP->thisblueerr[errcol-1] += err;  /* 7/16 */
-            }
-        }
-    }
-}
-
-
-
diff --git a/lib/ppmfloyd.h b/lib/ppmfloyd.h
deleted file mode 100644
index 264fc0b6..00000000
--- a/lib/ppmfloyd.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* These declarations were supposed to be in the libfloyd.h file in the ilbm
-   package, but that file was missing, so I made them up myself.  
-   - Bryan 01.03.10.
-*/
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-} /* to fake out automatic code indenters */
-#endif
-
-struct ppm_fs_info {
-    /* thisXerr and nextXerr are dynamically allocated arrays each of whose
-       dimension is the width of the image plus 2
-       */
-    long * thisrederr;
-    long * thisgreenerr;
-    long * thisblueerr;
-    long * nextrederr;
-    long * nextgreenerr;
-    long * nextblueerr;
-    int lefttoright;
-    int cols;
-    pixval maxval;
-    int flags;
-    pixel * pixrow;
-    int col_end;
-    pixval red, green, blue;
-};
-
-typedef struct ppm_fs_info ppm_fs_info;
-
-/* Bitmasks for ppm_fs_info.flags */
-#define FS_RANDOMINIT 0x01
-#define FS_ALTERNATE  0x02
-
-ppm_fs_info *
-ppm_fs_init(unsigned int const cols,
-            pixval       const maxval,
-            unsigned int const flags);
-
-void
-ppm_fs_free(ppm_fs_info *fi);
-
-int
-ppm_fs_startrow(ppm_fs_info *fi, pixel *pixrow);
-
-int
-ppm_fs_next(ppm_fs_info *fi, int col);
-
-void
-ppm_fs_endrow(ppm_fs_info *fi);
-
-void
-ppm_fs_update(    ppm_fs_info *fi, int col, pixel *pP);
-
-
-void
-ppm_fs_update3(ppm_fs_info * const fi, 
-               int           const col, 
-               pixval        const r, 
-               pixval        const g, 
-               pixval        const b);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/lib/util/shhopt.README b/lib/util/shhopt.README
index 2d241edf..f34f9a39 100644
--- a/lib/util/shhopt.README
+++ b/lib/util/shhopt.README
@@ -7,19 +7,20 @@ The file LICENSE.TXT in this directory contains the license (the
 Artistic License) under which Bryan took and redistributed Shhopt and
 the license under which Bryan offers the modified Shhopt to others.
 
-Bryan made the following changes to shhopt for Netpbm.  It is fully
-backward compatible with the original.
+Bryan made the following changes to shhopt for Netpbm.  
 
 - OPT_FLOAT (floating point number) data type added
 
-- optParseOptions2() added.  Advantages over optParseOptions(): You
+- symbols prefixed with "pm_".
+
+- pm_optParseOptions2() added.  Advantages over pm_optParseOptions(): You
   can have a syntax where there is no such thing as a short option
   (e.g. -a.  Maybe stacked like -tanp).  Then the long options can
   have either 1 or 2 dashes (e.g. -width or --width).  Of course, -w
   could be an abbreviation of -width; that's not the same thing as a
   short option.
 
-- optParseOptions3() added.  Advantages over optParseOptions2(): 
+- pm_optParseOptions3() added.  Advantages over pm_optParseOptions2(): 
   Tells you whether (how many times, actually) an option was
   specified - no need to play games with defaults.  Also, no need
   to initialize an option value variable.
@@ -34,6 +35,15 @@ backward compatible with the original.
 - replace isdigit() with ISDIGIT() from Netpbm nstring.h so weird 
   8-bit characters don't cause incorrect results.
 
+- OPT_NAMELIST and OPT_STRINGLIST added.
+
+WARNING: pm_optParseOptionsX modify their argv argument (the array of
+pointers, not the the things to which they point).
+
+WARNING: The option values returned by pm_optParseOptionsX for options of type
+OPT_STRING reside in the program's argument space (the memory addressed by the
+program's argv array).
+
 ------------------------------------------------------------------------------