about summary refs log tree commit diff
path: root/converter/ppm
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-11-01 02:39:33 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-11-01 02:39:33 +0000
commitc2b6d05b0a72ed21ab1bb06f8cc6374f68896239 (patch)
treedc51b96e9da12e16a2ea32042d715790bd89794a /converter/ppm
parentc33154e65f9233a9958dbc40825eabb13b6b84b2 (diff)
downloadnetpbm-mirror-c2b6d05b0a72ed21ab1bb06f8cc6374f68896239.tar.gz
netpbm-mirror-c2b6d05b0a72ed21ab1bb06f8cc6374f68896239.tar.xz
netpbm-mirror-c2b6d05b0a72ed21ab1bb06f8cc6374f68896239.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3410 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/ppm')
-rw-r--r--converter/ppm/tgatoppm.c107
1 files changed, 63 insertions, 44 deletions
diff --git a/converter/ppm/tgatoppm.c b/converter/ppm/tgatoppm.c
index 7dc15cb8..9f3db277 100644
--- a/converter/ppm/tgatoppm.c
+++ b/converter/ppm/tgatoppm.c
@@ -30,7 +30,6 @@ static int mapped, rlencoded;
 
 static pixel ColorMap[MAXCOLORS];
 static gray AlphaMap[MAXCOLORS];
-static int RLE_count = 0, RLE_flag = 0;
 
 struct cmdlineInfo {
     /* All the information the user supplied in the command line,
@@ -109,18 +108,14 @@ getbyte(FILE * const ifP) {
 
 
 
-static void
-getPixel(FILE *  const ifP,
-         pixel * const dest,
-         int     const size,
-         gray *  const alphaP) {
+static int RLE_count = 0, RLE_flag = 0;
+
 
-    static pixval red, grn, blu;
-    static pixval alpha;
-    static unsigned int l;
-    unsigned char j, k;
 
-    /* Check if run length encoded. */
+static void
+handleRun(FILE * const ifP,
+          bool * const repeatP) {
+
     if (rlencoded) {
         if (RLE_count == 0) {
             /* Have to restart run. */
@@ -136,50 +131,74 @@ getPixel(FILE *  const ifP,
             }
             /* Decrement count & get pixel. */
             --RLE_count;
+            *repeatP = false;
         } else {
             /* Have already read count & (at least) first pixel. */
             --RLE_count;
             if (RLE_flag != 0) {
                 /* Replicated pixels. */
-                goto PixEncode;
-            }
+                *repeatP = true;
+            } else
+                *repeatP = false;
         }
-    }
-    /* Read appropriate number of bytes, break into RGB. */
-    switch (size) {
-    case 8:             /* Grayscale, read and triplicate. */
-        red = grn = blu = l = getbyte(ifP);
-        alpha = 0;
-        break;
+    } else
+        *repeatP = false;
+}
 
-    case 16:            /* 5 bits each of red green and blue. */
-    case 15:            /* Watch byte order. */
-        j = getbyte(ifP);
-        k = getbyte(ifP);
-        l = ((unsigned int)k << 8) + j;
-        red = (k & 0x7C) >> 2;
-        grn = ((k & 0x03) << 3) + ((j & 0xE0) >> 5);
-        blu = j & 0x1F;
-        alpha = 0;
-        break;
 
-    case 32:            /* 8 bits each of blue, green, red, and alpha */
-    case 24:            /* 8 bits each of blue, green, and red. */
-        blu = getbyte(ifP);
-        grn = getbyte(ifP);
-        red = getbyte(ifP);
-        if (size == 32)
-            alpha = getbyte(ifP);
-        else
+
+static void
+getPixel(FILE *  const ifP,
+         pixel * const dest,
+         int     const size,
+         gray *  const alphaP) {
+
+    static pixval red, grn, blu;
+    static pixval alpha;
+    static unsigned int l;
+    unsigned char j, k;
+    bool repeat;
+        /* Next pixel is just a repeat (from an encoded run) */
+
+    handleRun(ifP, &repeat);
+
+    if (repeat) {
+        /* Use red, grn, blu, alpha, and l from prior call to getPixel */
+    } else {
+        /* Read appropriate number of bytes, break into RGB. */
+        switch (size) {
+        case 8:             /* Grayscale, read and triplicate. */
+            red = grn = blu = l = getbyte(ifP);
             alpha = 0;
-        l = 0;
-        break;
+            break;
 
-    default:
-        pm_error("unknown pixel size (#2) - %d", size);
-    }
+        case 16:            /* 5 bits each of red green and blue. */
+        case 15:            /* Watch byte order. */
+            j = getbyte(ifP);
+            k = getbyte(ifP);
+            l = ((unsigned int)k << 8) + j;
+            red = (k & 0x7C) >> 2;
+            grn = ((k & 0x03) << 3) + ((j & 0xE0) >> 5);
+            blu = j & 0x1F;
+            alpha = 0;
+            break;
+
+        case 32:            /* 8 bits each of blue, green, red, and alpha */
+        case 24:            /* 8 bits each of blue, green, and red. */
+            blu = getbyte(ifP);
+            grn = getbyte(ifP);
+            red = getbyte(ifP);
+            if (size == 32)
+                alpha = getbyte(ifP);
+            else
+                alpha = 0;
+            l = 0;
+            break;
 
-PixEncode:
+        default:
+            pm_error("unknown pixel size (#2) - %d", size);
+        }
+    }
     if (mapped) {
         *dest = ColorMap[l];
         *alphaP = AlphaMap[l];