about summary refs log tree commit diff
path: root/analyzer
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-05-20 06:27:52 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-05-20 06:27:52 +0000
commit7b979b5c0baa306f22ba3586b88ae7445ce13a8c (patch)
tree5840da05a457600d4a11563eaf9130c27deebfc5 /analyzer
parentf2ff9238d250c961c3a3889ab37ff575e25c314b (diff)
downloadnetpbm-mirror-7b979b5c0baa306f22ba3586b88ae7445ce13a8c.tar.gz
netpbm-mirror-7b979b5c0baa306f22ba3586b88ae7445ce13a8c.tar.xz
netpbm-mirror-7b979b5c0baa306f22ba3586b88ae7445ce13a8c.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@631 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'analyzer')
-rw-r--r--analyzer/pnmhistmap.c84
1 files changed, 45 insertions, 39 deletions
diff --git a/analyzer/pnmhistmap.c b/analyzer/pnmhistmap.c
index 0b1eeb1f..a7ed6b10 100644
--- a/analyzer/pnmhistmap.c
+++ b/analyzer/pnmhistmap.c
@@ -152,16 +152,16 @@ clipHistogram(unsigned int * const hist,
               unsigned int   const hist_width,
               unsigned int   const hmax) {
 
-            unsigned int i;
+    unsigned int i;
 
-            for (i = 0; i < hist_width; ++i)
-                hist[i] = MIN(hmax, hist[i]);
+    for (i = 0; i < hist_width; ++i)
+        hist[i] = MIN(hmax, hist[i]);
 }
 
 
 
 static void
-pgm_hist(FILE *       const fp,
+pgm_hist(FILE *       const ifP,
          int          const cols,
          int          const rows,
          xelval       const maxval,
@@ -186,41 +186,44 @@ pgm_hist(FILE *       const fp,
     unsigned int * ghist;
     double vscale;
     unsigned int hmax;
-
-    if ((ghist = calloc(hist_width, sizeof(int))) == NULL)
-        pm_error ("Not enough memory for histogram array (%d bytes)",
+    
+    MALLOCARRAY(ghist, hist_width);
+    if (ghist == NULL)
+        pm_error("Not enough memory for histogram array (%d bytes)",
                   hist_width * sizeof(int));
-    if ((bits = pbm_allocarray (hist_width, hist_height)) == NULL)
-        pm_error ("no space for output array (%d bits)",
-                  hist_width * hist_height);
-    memset (ghist, 0, sizeof (ghist));
+    bits = pbm_allocarray(hist_width, hist_height);
+    if (bits == NULL)
+        pm_error("no space for output array (%d bits)",
+                 hist_width * hist_height);
+    memset(ghist, 0, hist_width * sizeof(ghist[0]));
 
     /* read the pixel values into the histogram arrays */
-    grayrow = pgm_allocrow (cols);
-    /*XX error-check! */
-    if (verbose) pm_message ("making histogram...");
+    grayrow = pgm_allocrow(cols);
+
+    if (verbose)
+        pm_message("making histogram...");
+
     for (i = rows; i > 0; --i) {
-        pgm_readpgmrow (fp, grayrow, cols, maxval, format);
+        pgm_readpgmrow (ifP, grayrow, cols, maxval, format);
         for (j = cols-1; j >= 0; --j) {
-            int value;
+            int const value = grayrow[j];
 
-            if ((value = grayrow[j]) >= startval && value <= endval)
-                ghist[SCALE_H(value-startval)]++;
+            if (value >= startval && value <= endval)
+                ++ghist[SCALE_H(value-startval)];
         }
     }
-    pgm_freerow (grayrow);
-    fclose (fp);
+    pgm_freerow(grayrow);
 
     /* find the highest-valued slot and set the vertical scale value */
     if (verbose)
-        pm_message ("finding max. slot height...");
+        pm_message("finding max. slot height...");
     if (clipSpec)
         hmax = clipCount;
     else 
         hmax = maxSlotCount(ghist, hist_width, no_white, no_black);
 
     if (verbose)
-        pm_message ("Done: height = %u", hmax);
+        pm_message("Done: height = %u", hmax);
 
     clipHistogram(ghist, hist_width, hmax);
 
@@ -236,7 +239,7 @@ pgm_hist(FILE *       const fp,
             bits[j][i] = dots ? PBM_BLACK : PBM_WHITE;
     }
 
-    pbm_writepbm (stdout, bits, hist_width, hist_height, 0);
+    pbm_writepbm(stdout, bits, hist_width, hist_height, 0);
 }
 
 
@@ -309,7 +312,7 @@ clipHistogramAll(unsigned int * const hist[3],
 
 
 static void
-ppm_hist(FILE *       const fp,
+ppm_hist(FILE *       const ifP,
          int          const cols,
          int          const rows,
          xelval       const maxval,
@@ -329,8 +332,8 @@ ppm_hist(FILE *       const fp,
 
     bool const hscale_unity = hscale - 1 < epsilon;
 
-    pixel *pixrow;
-    pixel **pixels;
+    pixel * pixrow;
+    pixel ** pixels;
     int i, j;
     unsigned int * hist[3];  /* Subscript is enum wantedColor */
     double vscale;
@@ -339,17 +342,19 @@ ppm_hist(FILE *       const fp,
     createHist(colorWanted, hist_width, &hist);
 
     if ((pixels = ppm_allocarray (hist_width, hist_height)) == NULL)
-        pm_error ("no space for output array (%d pixels)",
-                  hist_width * hist_height);
+        pm_error("no space for output array (%d pixels)",
+                 hist_width * hist_height);
     for (i = 0; i < hist_height; ++i)
-        memset (pixels[i], 0, hist_width * sizeof (pixel));
+        memset(pixels[i], 0, hist_width * sizeof(pixels[i][0]));
 
     /* read the pixel values into the histogram arrays */
-    pixrow = ppm_allocrow (cols);
-    /*XX error-check! */
-    if (verbose) pm_message ("making histogram...");
+    pixrow = ppm_allocrow(cols);
+
+    if (verbose)
+        pm_message("making histogram...");
+
     for (i = rows; i > 0; --i) {
-        ppm_readppmrow (fp, pixrow, cols, maxval, format);
+        ppm_readppmrow(ifP, pixrow, cols, maxval, format);
         for (j = cols-1; j >= 0; --j) {
             int value;
 
@@ -367,12 +372,11 @@ ppm_hist(FILE *       const fp,
                 hist[WANT_BLU][SCALE_H(value-startval)]++;
         }
     }
-    ppm_freerow (pixrow);
-    fclose (fp);
+    ppm_freerow(pixrow);
 
     /* find the highest-valued slot and set the vertical scale value */
     if (verbose)
-        pm_message ("finding max. slot height...");
+        pm_message("finding max. slot height...");
     if (clipSpec)
         hmax = clipCount;
     else 
@@ -420,16 +424,16 @@ ppm_hist(FILE *       const fp,
             }
         }
     }
-    ppm_writeppm (stdout, pixels, hist_width, hist_height, maxval, 0);
+    ppm_writeppm(stdout, pixels, hist_width, hist_height, maxval, 0);
 }
 
 
 
 int
-main (int argc, char ** argv) {
+main(int argc, char ** argv) {
 
     struct cmdlineInfo cmdline;
-    FILE* ifP;
+    FILE * ifP;
     int cols, rows;
     xelval maxval;
     int format;
@@ -479,5 +483,7 @@ main (int argc, char ** argv) {
         pm_error("Cannot do a histogram of a a PBM file");
         break;
     }
+    pm_close(ifP);
+
     return 0;
 }