about summary refs log tree commit diff
path: root/analyzer/pgmhist.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2012-11-30 16:55:36 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2012-11-30 16:55:36 +0000
commit19052ac45340a3f66a100f77be072b8774a74eb1 (patch)
treeb6fded554d1ef8194e012c561ff13960c7642fc3 /analyzer/pgmhist.c
parent7c8ef33b1c9556156d660c2403944fa183a478fa (diff)
downloadnetpbm-mirror-19052ac45340a3f66a100f77be072b8774a74eb1.tar.gz
netpbm-mirror-19052ac45340a3f66a100f77be072b8774a74eb1.tar.xz
netpbm-mirror-19052ac45340a3f66a100f77be072b8774a74eb1.zip
Add -machine option
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1790 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'analyzer/pgmhist.c')
-rw-r--r--analyzer/pgmhist.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/analyzer/pgmhist.c b/analyzer/pgmhist.c
index 032f9ecc..d97d97ee 100644
--- a/analyzer/pgmhist.c
+++ b/analyzer/pgmhist.c
@@ -25,6 +25,7 @@ struct cmdline_info {
        in a form easy for the program to use.
     */
     const char * inputFileName;  /* Filename of input files */
+    unsigned int machine;
 };
 
 
@@ -44,7 +45,8 @@ parseCommandLine(int argc, const char ** argv,
 
     option_def_index = 0;   /* incremented by OPTENT3 */
 
-    OPTENTINIT;
+    OPTENT3(0,   "machine",       OPT_FLAG,  NULL,
+            &cmdlineP->machine,             0);
 
     opt.opt_table = option_def;
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
@@ -142,25 +144,24 @@ countCumulative(unsigned int    const hist[],
 
 
 static void
-report(unsigned int const hist[],
-       unsigned int const rcount[],
-       gray         const maxval) {
+reportHumanFriendly(unsigned int const hist[],
+                    unsigned int const rcount[],
+                    gray         const maxval) {
 
     unsigned int const totalPixels = rcount[0];
-    unsigned int count;
+
+    unsigned int cumCount;
     unsigned int i;
 
     printf("value  count  b%%      w%%   \n");
     printf("-----  -----  ------  ------\n");
 
-    count = 0;
-
-    for (i = 0; i <= maxval; ++i) {
+    for (i = 0, cumCount = 0; i <= maxval; ++i) {
         if (hist[i] > 0) {
-            count += hist[i];
+            cumCount += hist[i];
             printf(
                 "%5d  %5d  %5.3g%%  %5.3g%%\n", i, hist[i],
-                (float) count * 100.0 / totalPixels, 
+                (float) cumCount * 100.0 / totalPixels, 
                 (float) rcount[i] * 100.0 / totalPixels);
         }
     }
@@ -168,6 +169,19 @@ report(unsigned int const hist[],
 
 
 
+static void
+reportMachineFriendly(unsigned int const hist[],
+                      gray         const maxval) {
+
+    unsigned int i;
+
+    for (i = 0; i <= maxval; ++i) {
+        printf("%u %u\n", i, hist[i]);
+    }
+}
+
+
+
 int
 main(int argc, const char ** argv) {
 
@@ -187,7 +201,10 @@ main(int argc, const char ** argv) {
 
     countCumulative(hist, maxval, &rcount);
 
-    report(hist, rcount, maxval);
+    if (cmdline.machine)
+        reportMachineFriendly(hist, maxval);
+    else
+        reportHumanFriendly(hist, rcount, maxval);
 
     free(rcount);
     free(hist);