about summary refs log tree commit diff
path: root/generator
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-06-28 23:54:29 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-06-28 23:54:29 +0000
commitbe0a23cddaf0182d1fda4f623a3b23f67db91d73 (patch)
tree5d46db6bd85005728f7821965e66e3e5f0018d62 /generator
parentb13ba8b9b606c916e0bda39348ee009e920df22e (diff)
downloadnetpbm-mirror-be0a23cddaf0182d1fda4f623a3b23f67db91d73.tar.gz
netpbm-mirror-be0a23cddaf0182d1fda4f623a3b23f67db91d73.tar.xz
netpbm-mirror-be0a23cddaf0182d1fda4f623a3b23f67db91d73.zip
Promote Development to Advanced
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@3647 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator')
-rw-r--r--generator/pbmpage.c392
-rw-r--r--generator/pbmtext.c6
-rw-r--r--generator/ppmforge.c205
3 files changed, 366 insertions, 237 deletions
diff --git a/generator/pbmpage.c b/generator/pbmpage.c
index a2f47bcc..96dca876 100644
--- a/generator/pbmpage.c
+++ b/generator/pbmpage.c
@@ -1,6 +1,6 @@
-/***************************************************************************
+/*=============================================================================
                                 pbmpage
-
+===============================================================================
   This program produces a printed page test pattern in PBM format.
 
   This was adapted from Tim Norman's 'pbmtpg' program, part of his
@@ -10,7 +10,7 @@
 
   For copyright and licensing information, see the pbmtoppa program,
   which was also derived from the same package.
-****************************************************************************/
+=============================================================================*/
 
 #include <stdlib.h>
 #include <string.h>
@@ -18,73 +18,139 @@
 #include <stdio.h>
 
 #include "pm_c_util.h"
+#include "mallocvar.h"
+#include "shhopt.h"
+#include "nstring.h"
 #include "pbm.h"
 
+enum Pattern {PAT_GRID, PAT_VERTICAL, PAT_DIAGONAL};
+
 /* US is 8.5 in by 11 in */
 
-#define USWIDTH  (5100)
-#define USHEIGHT (6600)
+static unsigned int const usWidth  = 5100;
+static unsigned int const usHeight = 6600;
 
 /* A4 is 210 mm by 297 mm == 8.27 in by 11.69 in */
 
-#define A4WIDTH  (4960)
-#define A4HEIGHT (7016)
+static unsigned int const a4Width  = 4960;
+static unsigned int const a4Height = 7016;
 
 
-struct bitmap {
-    unsigned int Width;      /* width and height in 600ths of an inch */
-    unsigned int Height;
-    bit ** bitmap;
+struct CmdlineInfo {
+    /* All the information the user supplied in the command line,
+       in a form easy for the program to use.
+    */
+    enum Pattern pattern;
+    unsigned int a4;
 };
 
-static struct bitmap bitmap;
+
+
+static void
+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.
+-----------------------------------------------------------------------------*/
+    optEntry * option_def;
+        /* Instructions to OptParseOptions3 on how to parse our options.
+         */
+    optStruct3 opt;
+
+    unsigned int option_def_index;
+
+    MALLOCARRAY_NOFAIL(option_def, 100);
+
+    option_def_index = 0;   /* incremented by OPTENTRY */
+    OPTENT3(0, "a4",         OPT_FLAG, NULL, &cmdlineP->a4,       0);
+
+    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. */
+
+    if (argc-1 < 1)
+        cmdlineP->pattern = PAT_GRID;
+    else {
+        if (argc-1 > 1)
+            pm_error("Too many arguments (%u).  The only possible argument "
+                     "is the pattern number", argc-1);
+        if (streq(argv[1], "1"))
+            cmdlineP->pattern = PAT_GRID;
+        else if (streq(argv[1], "2"))
+            cmdlineP->pattern = PAT_VERTICAL;
+        else if (streq(argv[1], "3"))
+            cmdlineP->pattern = PAT_DIAGONAL;
+        else
+            pm_error("Invalid test pattern name '%s'.  "
+                     "We recognize only '1', '2', and '3'", argv[1]);
+    }
+    free(option_def);
+}
+
+
+
+struct Bitmap {
+    /* width and height in 600ths of an inch */
+    unsigned int width;
+    unsigned int height;
+
+    unsigned char ** bitmap;
+};
 
 
 
 static void
-setpixel(unsigned int const x,
-         unsigned int const y,
-         unsigned int const c) {
+setpixel(struct Bitmap * const bitmapP,
+         unsigned int    const x,
+         unsigned int    const y,
+         bit             const c) {
 
     char const bitmask = 128 >> (x % 8);
 
-    if (x < 0 || x >= bitmap.Width)
-        return;
-    if (y < 0 || y >= bitmap.Height)
-        return;
-
-    if (c)
-        bitmap.bitmap[y][x/8] |= bitmask;
-    else
-        bitmap.bitmap[y][x/8] &= ~bitmask;
+    if (x < 0 || x >= bitmapP->width) {
+        /* Off the edge of the canvas */
+    } else if (y < 0 || y >= bitmapP->height) {
+        /* Off the edge of the canvas */
+    } else {
+        if (c == PBM_BLACK)
+            bitmapP->bitmap[y][x/8] |= bitmask;
+        else
+            bitmapP->bitmap[y][x/8] &= ~bitmask;
+    }
 }
 
 
 
-static void 
-setplus(unsigned int const x,
-        unsigned int const y,
-        unsigned int const s) {
+static void
+setplus(struct Bitmap * const bitmapP,
+        unsigned int    const x,
+        unsigned int    const y,
+        unsigned int    const s) {
 /*----------------------------------------------------------------------------
-   Draw a black plus sign centered at (x,y) with arms 's' pixels long.  
+   Draw a black plus sign centered at (x,y) with arms 's' pixels long.
    Leave the exact center of the plus white.
 -----------------------------------------------------------------------------*/
     unsigned int i;
 
     for (i = 0; i < s; ++i) {
-        setpixel(x+i, y,   1);
-        setpixel(x-i, y,   1);
-        setpixel(x,   y+i, 1);
-        setpixel(x,   y-i, 1);
+        setpixel(bitmapP, x + i, y,     PBM_BLACK);
+        setpixel(bitmapP, x - i, y,     PBM_BLACK);
+        setpixel(bitmapP, x ,    y + i, PBM_BLACK);
+        setpixel(bitmapP, x ,    y - i, PBM_BLACK);
     }
 }
 
 
 
-static void 
-setblock(unsigned int const x,
-         unsigned int const y,
-         unsigned int const s) {
+static void
+setblock(struct Bitmap * const bitmapP,
+         unsigned int    const x,
+         unsigned int    const y,
+         unsigned int    const s) {
 
     unsigned int i;
 
@@ -92,16 +158,17 @@ setblock(unsigned int const x,
         unsigned int j;
 
         for (j = 0; j < s; ++j)
-            setpixel(x+i, y+j, 1);
+            setpixel(bitmapP, x + i, y + j, PBM_BLACK);
     }
 }
 
 
 
-static void 
-setchar(unsigned int const x,
-        unsigned int const y,
-        char         const c) {
+static void
+setchar(struct Bitmap * const bitmapP,
+        unsigned int    const x,
+        unsigned int    const y,
+        char            const c) {
 
     static char const charmap[10][5]= { { 0x3e, 0x41, 0x41, 0x41, 0x3e },
                                         { 0x00, 0x42, 0x7f, 0x40, 0x00 },
@@ -113,7 +180,7 @@ setchar(unsigned int const x,
                                         { 0x01, 0x01, 0x61, 0x19, 0x07 },
                                         { 0x36, 0x49, 0x49, 0x49, 0x36 },
                                         { 0x26, 0x49, 0x49, 0x49, 0x3e } };
-    
+
     if (c <= '9' && c >= '0') {
         unsigned int xo;
 
@@ -122,7 +189,7 @@ setchar(unsigned int const x,
 
             for (yo = 0; yo < 8; ++yo) {
                 if ((charmap[c-'0'][xo] >> yo) & 0x01)
-                    setblock(x + xo*3, y + yo*3, 3);
+                    setblock(bitmapP, x + xo*3, y + yo*3, 3);
             }
         }
     }
@@ -130,23 +197,25 @@ setchar(unsigned int const x,
 
 
 
-static void 
-setstring(unsigned int const x,
-          unsigned int const y,
-          const char * const s) {
+static void
+setstring(struct Bitmap * const bitmapP,
+          unsigned int    const x,
+          unsigned int    const y,
+          const char *    const s) {
 
     const char * p;
     unsigned int xo;
 
     for (xo = 0, p = s; *p; xo += 21, ++p)
-        setchar(x + xo, y, *p);
+        setchar(bitmapP, x + xo, y, *p);
 }
 
 
 
-static void 
-setCG(unsigned int const x,
-      unsigned int const y) {
+static void
+setCG(struct Bitmap * const bitmapP,
+      unsigned int    const x,
+      unsigned int    const y) {
 
     unsigned int xo;
 
@@ -155,16 +224,16 @@ setCG(unsigned int const x,
 
         unsigned int zo;
 
-        setpixel(x + xo, y + yo, 1);
-        setpixel(x+yo,   y + xo, 1);
-        setpixel(x-1-xo, y-1-yo, 1);
-        setpixel(x-1-yo, y-1-xo, 1);
-        setpixel(x+xo,   y-1-yo, 1);
-        setpixel(x-1-xo, y+yo,   1);
+        setpixel(bitmapP, x + xo    , y + yo    , PBM_BLACK);
+        setpixel(bitmapP, x + yo    , y + xo    , PBM_BLACK);
+        setpixel(bitmapP, x - 1 - xo, y - 1 - yo, PBM_BLACK);
+        setpixel(bitmapP, x - 1 - yo, y - 1 - xo, PBM_BLACK);
+        setpixel(bitmapP, x + xo    , y - 1 - yo, PBM_BLACK);
+        setpixel(bitmapP, x - 1 - xo, y + yo    , PBM_BLACK);
 
-        for(zo = 0; zo < yo; ++zo) {
-            setpixel(x + xo, y-1-zo, 1);
-            setpixel(x-1-xo, y+zo,   1);
+        for (zo = 0; zo < yo; ++zo) {
+            setpixel(bitmapP, x + xo    , y - 1 - zo, PBM_BLACK);
+            setpixel(bitmapP, x - 1 - xo, y + zo    , PBM_BLACK);
         }
     }
 }
@@ -173,129 +242,178 @@ setCG(unsigned int const x,
 
 static void
 outputPbm(FILE *        const ofP,
-          struct bitmap const bitmap) {
+          struct Bitmap const bitmap) {
 /*----------------------------------------------------------------------------
   Create a pbm file containing the image from the global variable bitmap[].
 -----------------------------------------------------------------------------*/
     int const forceplain = 0;
 
     unsigned int row;
-    
-    pbm_writepbminit(ofP, bitmap.Width, bitmap.Height, forceplain);
-    
-    for (row = 0; row < bitmap.Height; ++row) {
+
+    pbm_writepbminit(ofP, bitmap.width, bitmap.height, forceplain);
+
+    for (row = 0; row < bitmap.height; ++row) {
         pbm_writepbmrow_packed(ofP, bitmap.bitmap[row],
-                               bitmap.Width, forceplain); 
+                               bitmap.width, forceplain);
     }
 }
 
 
 
 static void
-framePerimeter(unsigned int const Width, 
-               unsigned int const Height) {
+framePerimeter(struct Bitmap * const bitmapP) {
 
     unsigned int x, y;
 
     /* Top edge */
-    for (x = 0; x < Width; ++x)
-        setpixel(x, 0, 1);
+    for (x = 0; x < bitmapP->width; ++x)
+        setpixel(bitmapP, x, 0, PBM_BLACK);
 
     /* Bottom edge */
-    for (x = 0; x < Width; ++x)
-        setpixel(x, Height-1, 1);
+    for (x = 0; x < bitmapP->width; ++x)
+        setpixel(bitmapP, x, bitmapP->height - 1, PBM_BLACK);
 
     /* Left edge */
-    for (y = 0; y < Height; ++y)
-        setpixel(0, y, 1);
+    for (y = 0; y < bitmapP->height; ++y)
+        setpixel(bitmapP, 0, y, PBM_BLACK);
 
     /* Right edge */
-    for (y = 0; y < Height; ++y)
-        setpixel(Width-1, y, 1);
+    for (y = 0; y < bitmapP->height; ++y)
+        setpixel(bitmapP, bitmapP->width - 1, y, PBM_BLACK);
 }
 
 
 
-int 
-main(int argc, const char** argv) {
+static void
+makeWhite(struct Bitmap * const bitmapP) {
 
-    int TP;
-    unsigned int x, y;
-    char buf[128];
-    /* width and height in 600ths of an inch */
-    unsigned int Width;
-    unsigned int Height;
+    unsigned int y;
 
-    pm_proginit(&argc, argv);
-
-    if (argc > 1 && strcmp(argv[1], "-a4") == 0) {
-        Width  = A4WIDTH;
-        Height = A4HEIGHT;
-        --argc;
-        ++argv;
-    } else {
-        Width  = USWIDTH;
-        Height = USHEIGHT;
+    for (y = 0; y < bitmapP->height; ++y) {
+        unsigned int x;
+        for (x = 0; x < pbm_packed_bytes(bitmapP->width); ++x)
+            bitmapP->bitmap[y][x] = 0x00;  /* 8 white pixels */
     }
+}
 
-    if (argc > 1)
-        TP = atoi(argv[1]);
-    else
-        TP = 1;
 
-    bitmap.Width  = Width;
-    bitmap.Height = Height;
-    bitmap.bitmap = pbm_allocarray_packed(Width, bitmap.Height);
 
-    for (y = 0; y < bitmap.Height; ++y) {
-        unsigned int x;
-        for (x = 0; x < pbm_packed_bytes(bitmap.Width); ++x) 
-            bitmap.bitmap[y][x] = 0x00; 
-    }
+static void
+drawGrid(struct Bitmap * const bitmapP) {
 
-    switch (TP) {
-    case 1:
-        framePerimeter(Width, Height);
-        for (x = 0; x < Width; x += 100) {
+    char buf[128];
+
+    framePerimeter(bitmapP);
+    {
+        unsigned int x;
+        for (x = 0; x < bitmapP->width; x += 100) {
             unsigned int y;
-            for(y = 0; y < Height; y += 100)
-                setplus(x, y, 4);
+            for (y = 0; y < bitmapP->height; y += 100)
+                setplus(bitmapP, x, y, 4);
         }
-        for(x = 0; x < Width; x += 100) {
-            sprintf(buf,"%d", x);
-            setstring(x + 3, (Height/200) * 100 + 3, buf);
+    }
+    {
+        unsigned int x;
+        for (x = 0; x < bitmapP->width; x += 100) {
+            sprintf(buf,"%u", x);
+            setstring(bitmapP, x + 3, (bitmapP->height/200) * 100 + 3, buf);
         }
-        for (y = 0; y < Height; y += 100) {
-            sprintf(buf, "%d", y);
-            setstring((Width/200) * 100 + 3, y + 3, buf);
+    }
+    {
+        unsigned int y;
+        for (y = 0; y < bitmapP->height; y += 100) {
+            sprintf(buf, "%u", y);
+            setstring(bitmapP, (bitmapP->width/200) * 100 + 3, y + 3, buf);
         }
-        for (x = 0; x < Width; x += 10)
-            for (y = 0; y < Height; y += 100)
-                setplus(x, y, ((x%100) == 50) ? 2 : 1);
-        for (x = 0; x < Width; x += 100) {
+    }
+    {
+        unsigned int x;
+        for (x = 0; x < bitmapP->width; x += 10) {
             unsigned int y;
-            for (y = 0; y < Height; y += 10)
-                setplus(x, y, ((y%100) == 50) ? 2 : 1);
+            for (y = 0; y < bitmapP->height; y += 100)
+                setplus(bitmapP, x, y, ((x%100) == 50) ? 2 : 1);
         }
-        setCG(Width/2, Height/2);
+    }
+    {
+        unsigned int x;
+        for (x = 0; x < bitmapP->width; x += 100) {
+            unsigned int y;
+            for (y = 0; y < bitmapP->height; y += 10)
+                setplus(bitmapP, x, y, ((y%100) == 50) ? 2 : 1);
+        }
+    }
+    setCG(bitmapP, bitmapP->width/2, bitmapP->height/2);
+}
+
+
+
+static void
+drawVertical(struct Bitmap * const bitmapP) {
+
+    unsigned int y;
+
+    for (y = 0; y < 300; ++y)
+        setpixel(bitmapP, bitmapP->width/2, bitmapP->height/2 - y, PBM_BLACK);
+}
+
+
+
+static void
+drawDiagonal(struct Bitmap * const bitmapP) {
+
+    unsigned int y;
+
+    for (y = 0; y < 300; ++y) {
+        setpixel(bitmapP, y, y, PBM_BLACK);
+        setpixel(bitmapP, bitmapP->width - 1 - y, bitmapP->height - 1 - y,
+                 PBM_BLACK);
+    }
+}
+
+
+
+int
+main(int argc, const char** argv) {
+
+    struct CmdlineInfo cmdline;
+    /* width and height in 600ths of an inch */
+    unsigned int width;
+    unsigned int height;
+    struct Bitmap bitmap;
+
+    pm_proginit(&argc, argv);
+
+    parseCommandLine(argc, argv, &cmdline);
+
+    if (cmdline.a4) {
+        width  = a4Width;
+        height = a4Height;
+    } else {
+        width  = usWidth;
+        height = usHeight;
+    }
+
+    bitmap.width  = width;
+    bitmap.height = height;
+    bitmap.bitmap = pbm_allocarray_packed(width, height);
+
+    makeWhite(&bitmap);
+
+    switch (cmdline.pattern) {
+    case PAT_GRID:
+        drawGrid(&bitmap);
         break;
-    case 2:
-        for (y = 0; y < 300; ++y)
-            setpixel(Width/2, Height/2-y, 1);
+    case PAT_VERTICAL:
+        drawVertical(&bitmap);
         break;
-    case 3:
-        for (y = 0; y < 300; ++y) {
-            setpixel(y, y, 1);
-            setpixel(Width-1-y, Height-1-y, 1);
-        }
+    case PAT_DIAGONAL:
+        drawDiagonal(&bitmap);
         break;
-    default:
-        pm_error("unknown test pattern (%d)", TP);
     }
 
     outputPbm(stdout, bitmap);
 
-    pbm_freearray(bitmap.bitmap, Height);
+    pbm_freearray(bitmap.bitmap, height);
 
     pm_close(stdout);
 
diff --git a/generator/pbmtext.c b/generator/pbmtext.c
index e6f27865..a840d1df 100644
--- a/generator/pbmtext.c
+++ b/generator/pbmtext.c
@@ -153,6 +153,9 @@ parseCommandLine(int argc, const char ** argv,
     else if (cmdlineP->lspace < -pbm_maxfontheight())
         pm_error("negative -lspace value too large");
 
+    if (cmdlineP->font != NULL && cmdlineP->builtin != NULL)
+        pm_error("You cannot specify both -font and -builtin");
+
     if (cmdlineP->textdump) {
         if (cmdlineP->dryrun)
             pm_error("You cannot specify both -dry-run and -text-dump");
@@ -170,9 +173,8 @@ parseCommandLine(int argc, const char ** argv,
             pm_error("-wchar is not valid when text is from command line");
 
         cmdlineP->text = textFmCmdLine(argc, argv);
-
-
     }
+
     free(option_def);
 }
 
diff --git a/generator/ppmforge.c b/generator/ppmforge.c
index 390180e3..fe80f529 100644
--- a/generator/ppmforge.c
+++ b/generator/ppmforge.c
@@ -54,21 +54,14 @@ static double const hugeVal = 1e50;
 typedef struct {
     double x;
     double y;
-    double z; 
-} vector;
+    double z;
+} Vector;
 
 /* Definition for obtaining random numbers. */
 
 #define nrand 4               /* Gauss() sample count */
 #define Cast(low, high) ((low)+(((high)-(low)) * ((rand() & 0x7FFF) / arand)))
 
-/* prototypes */
-static void fourn ARGS((float data[], int nn[], int ndim, int isign));
-static void initgauss ARGS((unsigned int seed));
-static double gauss ARGS((void));
-static void spectralsynth ARGS((float **x, unsigned int n, double h));
-static void temprgb ARGS((double temp, double *r, double *g, double *b));
-static void etoile ARGS((pixel *pix));
 /*  Local variables  */
 
 static double arand, gaussadd, gaussfac; /* Gaussian random parameters */
@@ -111,11 +104,11 @@ static void
 parseCommandLine(int argc, const char **argv,
                  struct CmdlineInfo * const cmdlineP) {
 /*----------------------------------------------------------------------------
-  Convert program invocation arguments (argc,argv) into a format the 
+  Convert program invocation arguments (argc,argv) into a format the
   program can use easily, struct cmdlineInfo.  Validate arguments along
   the way and exit program with message if invalid.
 
-  Note that some string information we return as *cmdlineP is in the storage 
+  Note that some string information we return as *cmdlineP is in the storage
   argv[] points to.
 -----------------------------------------------------------------------------*/
     optEntry * option_def;
@@ -243,9 +236,16 @@ parseCommandLine(int argc, const char **argv,
 }
 
 
-/*  FOURN  --  Multi-dimensional fast Fourier transform
 
-    Called with arguments:
+static void
+fourn(float *     const data,
+      const int * const nn,
+      int         const ndim,
+      int         const isign) {
+/*----------------------------------------------------------------------------
+    Multi-dimensional fast Fourier transform
+
+    Arguments:
 
        data       A  one-dimensional  array  of  floats  (NOTE!!!   NOT
               DOUBLES!!), indexed from one (NOTE!!!   NOT  ZERO!!),
@@ -265,13 +265,8 @@ parseCommandLine(int argc, const char **argv,
 
         This  function  is essentially as given in Press et al., "Numerical
         Recipes In C", Section 12.11, pp.  467-470.
-*/
-
-static void fourn(data, nn, ndim, isign)
-    float data[];
-    int nn[], ndim, isign;
-{
-    register int i1, i2, i3;
+-----------------------------------------------------------------------------*/
+    int i1, i2, i3;
     int i2rev, i3rev, ip1, ip2, ip3, ifp1, ifp2;
     int ibit, idim, k1, k2, n, nprev, nrem, ntot;
     float tempi, tempr;
@@ -339,12 +334,15 @@ static void fourn(data, nn, ndim, isign)
 }
 #undef SWAP
 
-/*  INITGAUSS  --  Initialize random number generators.  As given in
-           Peitgen & Saupe, page 77. */
 
-static void initgauss(seed)
-    unsigned int seed;
-{
+
+static void
+initgauss(unsigned int const seed) {
+/*----------------------------------------------------------------------------
+  Initialize random number generators.
+
+  As given in Peitgen & Saupe, page 77.
+-----------------------------------------------------------------------------*/
     /* Range of random generator */
     arand = pow(2.0, 15.0) - 1.0;
     gaussadd = sqrt(3.0 * nrand);
@@ -352,30 +350,36 @@ static void initgauss(seed)
     srand(seed);
 }
 
-/*  GAUSS  --  Return a Gaussian random number.  As given in Peitgen
-           & Saupe, page 77. */
 
-static double gauss()
-{
+
+static double
+gauss() {
+/*----------------------------------------------------------------------------
+  A Gaussian random number.
+
+  As given in Peitgen & Saupe, page 77.
+-----------------------------------------------------------------------------*/
     int i;
-    double sum = 0.0;
+    double sum;
 
-    for (i = 1; i <= nrand; i++) {
+    for (i = 1, sum = 0.0; i <= nrand; ++i) {
         sum += (rand() & 0x7FFF);
     }
     return gaussfac * sum - gaussadd;
 }
 
-/*  SPECTRALSYNTH  --  Spectrally  synthesized  fractal  motion in two
-               dimensions.  This algorithm is given under  the
-               name   SpectralSynthesisFM2D  on  page  108  of
-               Peitgen & Saupe. */
 
-static void spectralsynth(x, n, h)
-    float **x;
-    unsigned int n;
-    double h;
-{
+
+static void
+spectralsynth(float **     const x,
+              unsigned int const n,
+              double        const h) {
+/*----------------------------------------------------------------------------
+  Spectrally synthesized fractal motion in two dimensions.
+
+  This algorithm is given under the name SpectralSynthesisFM2D on page 108 of
+  Peitgen & Saupe.
+-----------------------------------------------------------------------------*/
     unsigned bl;
     int i, j, i0, j0, nsize[3];
     double rad, phase, rcos, rsin;
@@ -430,20 +434,20 @@ static void spectralsynth(x, n, h)
 
 
 
-/*  TEMPRGB  --  Calculate the relative R, G, and B components  for  a
-         black  body  emitting  light  at a given temperature.
-         The Planck radiation equation is solved directly  for
-         the R, G, and B wavelengths defined for the CIE  1931
-         Standard    Colorimetric    Observer.    The   color
-         temperature is specified in degrees Kelvin. */
-
-static void temprgb(temp, r, g, b)
-    double temp;
-    double *r, *g, *b;
-{
-    double c1 = 3.7403e10,
-        c2 = 14384.0,
-        er, eg, eb, es;
+static void
+temprgb(double   const temp,
+        double * const r,
+        double * const g,
+        double * const b) {
+/*----------------------------------------------------------------------------
+  Calculate the relative R, G, and B components for a black body emitting
+  light at a given temperature.  We solve the Planck radiation equation
+  directly for the R, G, and B wavelengths defined for the CIE 1931 Standard
+  Colorimetric Observer.  The color temperature is specified in kelvins.
+-----------------------------------------------------------------------------*/
+    double const c1 = 3.7403e10;
+    double const c2 = 14384.0;
+    double er, eg, eb, es;
 
 /* Lambda is the wavelength in microns: 5500 angstroms is 0.55 microns. */
 
@@ -462,11 +466,13 @@ static void temprgb(temp, r, g, b)
         *b = eb * es;
 }
 
-/*  ETOILE  --  Set a pixel in the starry sky.  */
 
-static void etoile(pix)
-    pixel *pix;
-{
+
+static void
+etoile(pixel * const pix) {
+/*----------------------------------------------------------------------------
+    Set a pixel in the starry sky.
+-----------------------------------------------------------------------------*/
     if ((rand() % 1000) < starfraction) {
 #define StarQuality 0.5       /* Brightness distribution exponent */
 #define StarIntensity   8         /* Brightness scale factor */
@@ -494,7 +500,7 @@ static void etoile(pix)
             temp = 5500 + starcolor *
                 pow(1 / (1 - Cast(0, 0.9999)), StarTintExp) *
                 ((rand() & 7) ? -1 : 1);
-            /* Constrain temperature to a reasonable value: >= 2600K 
+            /* Constrain temperature to a reasonable value: >= 2600K
                (S Cephei/R Andromedae), <= 28,000 (Spica). */
             temp = MAX(2600, MIN(28000, temp));
             temprgb(temp, &r, &g, &b);
@@ -567,7 +573,7 @@ createPlanetStuff(bool             const clouds,
                   unsigned int **  const bxfP,
                   unsigned int **  const bxcP,
                   unsigned char ** const cpP,
-                  vector *         const sunvecP,
+                  Vector *         const sunvecP,
                   unsigned int     const cols,
                   pixval           const maxval) {
 
@@ -614,23 +620,23 @@ createPlanetStuff(bool             const clouds,
        (N.b. the pictures would undoubtedly look better when generated
        with small grids if  a  more  well-behaved  interpolation  were
        used.)
-       
+
        Also compute the line-level interpolation parameters that
-       caller will need every time around his inner loop.  
+       caller will need every time around his inner loop.
     */
 
     MALLOCARRAY(u,   cols);
     MALLOCARRAY(u1,  cols);
     MALLOCARRAY(bxf, cols);
     MALLOCARRAY(bxc, cols);
-    
-    if (u == NULL || u1 == NULL || bxf == NULL || bxc == NULL) 
+
+    if (u == NULL || u1 == NULL || bxf == NULL || bxc == NULL)
         pm_error("Cannot allocate %d element interpolation tables.", cols);
     {
         unsigned int j;
         for (j = 0; j < cols; j++) {
             double const bx = (n - 1) * uprj(j, cols);
-            
+
             bxf[j] = floor(bx);
             bxc[j] = MIN(bxf[j] + 1, n - 1);
             u[j] = bx - bxf[j];
@@ -645,15 +651,15 @@ createPlanetStuff(bool             const clouds,
 
 
 static void
-generateStarrySkyRow(pixel *      const pixels, 
+generateStarrySkyRow(pixel *      const pixels,
                      unsigned int const cols) {
 /*----------------------------------------------------------------------------
   Generate a starry sky.  Note  that no FFT is performed;
   the output is  generated  directly  from  a  power  law
-  mapping  of  a  pseudorandom sequence into intensities. 
+  mapping  of  a  pseudorandom sequence into intensities.
 -----------------------------------------------------------------------------*/
     unsigned int j;
-    
+
     for (j = 0; j < cols; j++)
         etoile(pixels + j);
 }
@@ -681,7 +687,7 @@ generateCloudRow(pixel *         const pixels,
     for (col = 0; col < cols; ++col) {
         double r;
         pixval w;
-        
+
         r = 0.0;  /* initial value */
         /* Note that where t1 and t are zero, the cp[] element
            referenced below does not exist.
@@ -692,9 +698,9 @@ generateCloudRow(pixel *         const pixels,
         if (t > 0.0)
             r += t * u1[col] * cp[byc + bxf[col]] +
                 t * u[col]  * cp[byc + bxc[col]];
-        
+
         w = (r > 127.0) ? (maxval * ((r - 127.0) / 128.0)) : 0;
-        
+
         PPM_ASSIGN(pixels[col], w, w, maxval);
     }
 }
@@ -747,11 +753,11 @@ makeLand(int *  const irP,
     };
 
     unsigned int const ix = ((r - 128) * (ARRAY_SIZE(pgnd) - 1)) / 127;
-    
+
     *irP = pgnd[ix][0];
     *igP = pgnd[ix][1];
     *ibP = pgnd[ix][2];
-} 
+}
 
 
 
@@ -781,9 +787,9 @@ addIce(int *  const irP,
        pixval const maxval) {
 
     /* Generate polar ice caps. */
-    
+
     double const icet = pow(fabs(sin(azimuth)), 1.0 / icelevel) - 0.5;
-    double const ice = MAX(0.0, 
+    double const ice = MAX(0.0,
                            (icet + glaciers * MAX(-0.5, (r - 128) / 128.0)));
     if  (ice > 0.125) {
         *irP = maxval;
@@ -802,11 +808,11 @@ limbDarken(int *          const irP,
            unsigned int   const row,
            unsigned int   const cols,
            unsigned int   const rows,
-           vector         const sunvec,
+           Vector         const sunvec,
            pixval         const maxval) {
 
     /* With Gcc 2.95.3 compiler optimization level > 1, I have seen this
-       function confuse all the variables and ultimately generate a 
+       function confuse all the variables and ultimately generate a
        completely black image.  Adding an extra reference to 'rows' seems
        to put things back in order, and the assert() below does that.
        Take it out, and the problem comes back!  04.02.21.
@@ -828,9 +834,9 @@ limbDarken(int *          const irP,
     double const dxsq = dx * dx;
 
     double const ds = MIN(1.0, sqrt(dxsq + dysq));
-    
+
     /* Calculate atmospheric absorption based on the thickness of
-       atmosphere traversed by light on its way to the surface.  
+       atmosphere traversed by light on its way to the surface.
     */
     double const dsq = ds * ds;
     double const dsat = atSatFac * ((sqrt(atthick * atthick - dsq) -
@@ -848,7 +854,7 @@ limbDarken(int *          const irP,
         double const svx = sunvec.x;
         double const svy = sunvec.y * dy;
         double const svz = sunvec.z * sqomdysq;
-        double const di = 
+        double const di =
             MAX(0, MIN(1.0, svx * dx + svy + svz * sqrt(1.0 - dxsq)));
         double const inx = PlanetAmbient * 1.0 + (1.0 - PlanetAmbient) * di;
 
@@ -874,7 +880,7 @@ generatePlanetRow(pixel *         const pixelrow,
                   unsigned int *  const bxf,
                   int             const byc,
                   int             const byf,
-                  vector          const sunvec,
+                  Vector          const sunvec,
                   pixval          const maxval) {
 
     unsigned int const StarClose = 2;
@@ -892,9 +898,9 @@ generatePlanetRow(pixel *         const pixelrow,
         int ir, ig, ib;
 
         r = 0.0;   /* initial value */
-        
+
         /* Note that where t1 and t are zero, the cp[] element
-           referenced below does not exist.  
+           referenced below does not exist.
         */
         if (t1 > 0.0)
             r += t1 * u1[col] * cp[byf + bxf[col]] +
@@ -903,9 +909,9 @@ generatePlanetRow(pixel *         const pixelrow,
             r += t * u1[col] * cp[byc + bxf[col]] +
                 t * u[col]  * cp[byc + bxc[col]];
 
-        if (r >= 128) 
+        if (r >= 128)
             makeLand(&ir, &ig, &ib, r);
-        else 
+        else
             makeWater(&ir, &ig, &ib, r, maxval);
 
         addIce(&ir, &ig, &ib, r, azimuth, icelevel, glaciers, maxval);
@@ -928,10 +934,10 @@ generatePlanetRow(pixel *         const pixelrow,
 
 
 
-static void 
+static void
 genplanet(bool         const stars,
           bool         const clouds,
-          float *      const a, 
+          float *      const a,
           unsigned int const cols,
           unsigned int const rows,
           unsigned int const n,
@@ -950,21 +956,21 @@ genplanet(bool         const stars,
     pixel *pixelrow;
     unsigned int row;
 
-    vector sunvec;
+    Vector sunvec;
 
     ppm_writeppminit(stdout, cols, rows, maxval, FALSE);
 
     if (stars) {
         pm_message("night: -seed %d -stars %d -saturation %d.",
                    rseed, starfraction, starcolor);
-        cp = NULL; 
+        cp = NULL;
         u = NULL; u1 = NULL;
         bxf = NULL; bxc = NULL;
     } else {
         pm_message("%s: -seed %d -dimension %.2f -power %.2f -mesh %d",
                    clouds ? "clouds" : "planet",
                    rseed, fracdim, powscale, meshsize);
-        createPlanetStuff(clouds, a, n, &u, &u1, &bxf, &bxc, &cp, &sunvec, 
+        createPlanetStuff(clouds, a, n, &u, &u1, &bxf, &bxc, &cp, &sunvec,
                           cols, maxval);
     }
 
@@ -983,7 +989,7 @@ genplanet(bool         const stars,
                 generateCloudRow(pixelrow, cols,
                                  t, t1, u, u1, cp, bxc, bxf, byc, byf,
                                  maxval);
-            else 
+            else
                 generatePlanetRow(pixelrow, row, rows, cols,
                                   t, t1, u, u1, cp, bxc, bxf, byc, byf,
                                   sunvec,
@@ -1009,7 +1015,7 @@ applyPowerLawScaling(float * const a,
                      double  const powscale) {
 
     /* Apply power law scaling if non-unity scale is requested. */
-    
+
     if (powscale != 1.0) {
         unsigned int i;
         for (i = 0; i < meshsize; i++) {
@@ -1030,7 +1036,7 @@ computeExtremeReal(const float * const a,
                    int           const meshsize,
                    double *      const rminP,
                    double *      const rmaxP) {
-    
+
     /* Compute extrema for autoscaling. */
 
     double rmin, rmax;
@@ -1043,7 +1049,7 @@ computeExtremeReal(const float * const a,
         unsigned int j;
         for (j = 0; j < meshsize; j++) {
             double r = Real(a, i, j);
-            
+
             rmin = MIN(rmin, r);
             rmax = MAX(rmax, r);
         }
@@ -1094,7 +1100,7 @@ planet(unsigned int const cols,
     bool error;
 
     initgauss(rseed);
-    
+
     if (stars) {
         a = NULL;
         error = FALSE;
@@ -1104,7 +1110,7 @@ planet(unsigned int const cols,
             error = TRUE;
         } else {
             applyPowerLawScaling(a, meshsize, powscale);
-                
+
             replaceWithSpread(a, meshsize);
 
             error = FALSE;
@@ -1121,7 +1127,7 @@ planet(unsigned int const cols,
 
 
 
-int 
+int
 main(int argc, const char ** argv) {
 
     struct CmdlineInfo cmdline;
@@ -1147,7 +1153,7 @@ main(int argc, const char ** argv) {
 
     /* Force  screen to be at least  as wide as it is high.  Long,
        skinny screens  cause  crashes  because  picture  width  is
-       calculated based on height.  
+       calculated based on height.
     */
 
     cols = (MAX(cmdline.height, cmdline.width) + 1) & (~1);
@@ -1157,3 +1163,6 @@ main(int argc, const char ** argv) {
 
     exit(success ? 0 : 1);
 }
+
+
+