about summary refs log tree commit diff
path: root/converter/ppm
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-09-28 21:22:12 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-09-28 21:22:12 +0000
commit63998e9059ce5556dab0be7e8ad779b6f9a3203d (patch)
treef3353c4e67ef55c12013e555c2e512d932efeb68 /converter/ppm
parent3176a9dcca385378fb065ebf9bfbd9ac472a6263 (diff)
downloadnetpbm-mirror-63998e9059ce5556dab0be7e8ad779b6f9a3203d.tar.gz
netpbm-mirror-63998e9059ce5556dab0be7e8ad779b6f9a3203d.tar.xz
netpbm-mirror-63998e9059ce5556dab0be7e8ad779b6f9a3203d.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4702 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/ppm')
-rw-r--r--converter/ppm/ppmtomitsu.c88
1 files changed, 55 insertions, 33 deletions
diff --git a/converter/ppm/ppmtomitsu.c b/converter/ppm/ppmtomitsu.c
index 50b790d6..8ab740b2 100644
--- a/converter/ppm/ppmtomitsu.c
+++ b/converter/ppm/ppmtomitsu.c
@@ -20,6 +20,7 @@
 ** implied warranty.
 */
 
+#include <stdbool.h>
 #include <assert.h>
 #include <string.h>
 #include <stdio.h>
@@ -35,23 +36,42 @@
 #define HASHSIZE 2048
 #define myhash(x) ((PPM_GETR(x)*3 + PPM_GETG(x)*5 + PPM_GETB(x)*7) % HASHSIZE)
 
-typedef struct hashinfo {
+typedef struct Hashinfo {
         pixel     color;
         long      flag;
-        struct hashinfo * next;
-} hashinfo;
+        struct Hashinfo * next;
+} Hashinfo;
 
-#define cmd(arg)           fputc((arg), stdout)
-#define datum(arg)         fputc((char)(arg), stdout)
-#define data(arg,num)      fwrite((arg), sizeof(char), (num), stdout)
+static void
+cmd(char const arg) {
+
+    fputc(arg, stdout);
+}
 
 
 
 static void
-check_and_rotate(int              const cols,
-                 int              const rows,
-                 int              const enlarge,
-                 struct mediasize const medias) {
+datum(unsigned char const arg) {
+
+    fputc(arg, stdout);
+}
+
+
+
+static void
+data(unsigned char * const arg,
+     size_t          const len) {
+
+    fwrite((unsigned char *)arg, 1, len, stdout);
+}
+
+
+
+static void
+checkAndRotate(int              const cols,
+               int              const rows,
+               int              const enlarge,
+               struct mediasize const medias) {
 
     if (cols > rows) {
         ROTATEIMG(DOROTATE);                        /* rotate image */
@@ -132,7 +152,7 @@ lineputinit(int              const cols,
     default:
         SHARPNESS(SP_USER);
     }
-    check_and_rotate(cols, rows, enlarge, medias);
+    checkAndRotate(cols, rows, enlarge, medias);
     DATASTART;
 }
 
@@ -203,7 +223,7 @@ lookuptabledata(int              const cols,
                 struct mediasize const medias) {
 
     DONELOOKUPTABLE;
-    check_and_rotate(cols, rows, enlarge, medias);
+    checkAndRotate(cols, rows, enlarge, medias);
     DATASTART;
 }
 
@@ -265,7 +285,7 @@ frametransferinit(int              const cols,
     default:
         SHARPNESS(SP_USER);
     }
-    check_and_rotate(cols, rows, enlarge, medias);
+    checkAndRotate(cols, rows, enlarge, medias);
 }
 
 
@@ -273,14 +293,14 @@ frametransferinit(int              const cols,
 static void
 doLookupTableColors(colorhist_vector const table,
                     unsigned int     const nColor,
-                    hashinfo *       const colorhashtable) {
+                    Hashinfo *       const colorhashtable) {
 
     unsigned int colval;
     for (colval = 0; colval < nColor; ++colval) {
-        struct hashinfo * const hashchain =
+        struct Hashinfo * const hashchain =
             &colorhashtable[myhash((table[colval]).color)];
 
-        struct hashinfo * hashrun;
+        struct Hashinfo * hashrun;
 
         cmd('$');
         datum(colval);
@@ -310,13 +330,13 @@ doLookupTableColors(colorhist_vector const table,
 static void
 doLookupTableGrays(colorhist_vector const table,
                    unsigned int     const nColor,
-                   hashinfo *       const colorhashtable) {
+                   Hashinfo *       const colorhashtable) {
 
     unsigned int colval;
     for (colval = 0; colval < nColor; ++colval) {
-        struct hashinfo * const hashchain =
+        struct Hashinfo * const hashchain =
             &colorhashtable[myhash((table[colval]).color)];
-        struct hashinfo * hashrun;
+        struct Hashinfo * hashrun;
 
         cmd('$');
         datum(colval);
@@ -353,7 +373,7 @@ generateLookupTable(colorhist_vector const table,
                     int              const enlarge,
                     int              const copy,
                     struct mediasize const medias,
-                    hashinfo **      const colorhashtableP) {
+                    Hashinfo **      const colorhashtableP) {
 /*----------------------------------------------------------------------------
    Write to the output file the palette (color lookup table) indicated by
    'table' and generate a hash table to use with it: *colorhashtableP.
@@ -361,7 +381,7 @@ generateLookupTable(colorhist_vector const table,
    Also write the various properties 'sharpness', 'enlarge', 'copy', and
    'medias' to the output file.
 -----------------------------------------------------------------------------*/
-    hashinfo * colorhashtable;
+    Hashinfo * colorhashtable;
 
     lookuptableinit(sharpness, enlarge, copy, medias);
 
@@ -394,7 +414,7 @@ static void
 writeColormapRaster(pixel **         const pixels,
                     unsigned int     const cols,
                     unsigned int     const rows,
-                    hashinfo *       const colorhashtable) {
+                    Hashinfo *       const colorhashtable) {
 /*----------------------------------------------------------------------------
    Write a colormapped raster: write the pixels pixels[][] (dimensions cols x
    rows) as indices into the colormap (palette; lookup table) indicated by
@@ -407,9 +427,9 @@ writeColormapRaster(pixel **         const pixels,
 
         for (col = 0; col < cols; ++col) {
             pixel * const pixrow = pixels[row];
-            struct hashinfo * const hashchain =
+            struct Hashinfo * const hashchain =
                 &colorhashtable[myhash(pixrow[col])];
-            struct hashinfo * p;
+            struct Hashinfo * p;
 
             p = hashchain;
             while (!PPM_EQUAL((p->color), pixrow[col])) {
@@ -435,7 +455,7 @@ useLookupTable(pixel **         const pixels,
                int              const format,
                unsigned int     const nColor) {
 
-    hashinfo * colorhashtable;
+    Hashinfo * colorhashtable;
 
     pm_message("found %u colors - using the lookuptable-method", nColor);
 
@@ -596,26 +616,28 @@ doTiny(FILE *           const ifP,
 
 
 int
-main(int argc, char * argv[]) {
-    FILE * ifP;
+main(int argc, const char ** argv) {
+
+    FILE *           ifP;
     int              argn;
     bool             dpi300;
+    bool             tiny;
     int              cols, rows, format;
     pixval           maxval;
-    int              sharpness, enlarge, copy, tiny;
+    int              sharpness, enlarge, copy;
     struct mediasize medias;
     char             media[16];
     const char * const usage = "[-sharpness <1-4>] [-enlarge <1-3>] [-media <a,a4,as,a4s>] [-copy <1-9>] [-tiny] [-dpi300] [ppmfile]";
 
-    ppm_init(&argc, argv);
+    pm_proginit(&argc, argv);
 
-    dpi300 = FALSE;
+    dpi300 = false;
     argn = 1;
     sharpness = 32;
     enlarge   = 1;
     copy      = 1;
     memset(media, '\0', 16);
-    tiny      = FALSE;
+    tiny      = false;
 
     /* check for flags */
     while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') {
@@ -648,9 +670,9 @@ main(int argc, char * argv[]) {
             pm_usage(usage);
         }
     else if (pm_keymatch(argv[argn], "-dpi300", 2))
-        dpi300 = TRUE;
+        dpi300 = true;
     else if (pm_keymatch(argv[argn], "-tiny", 2))
-        tiny = TRUE;
+        tiny = true;
     else
         pm_usage(usage);
     ++argn;