about summary refs log tree commit diff
path: root/converter/pbm/pbmtoybm.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-05-20 02:04:00 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-05-20 02:04:00 +0000
commitf0214c9232cd715b97f124b152b5d57033022c6d (patch)
treed3251eec1b401d0221eb99fc897c237973a98cdb /converter/pbm/pbmtoybm.c
parent5ab4a1dc87de3cb51d817b7c09be2050e4d6e6e9 (diff)
downloadnetpbm-mirror-f0214c9232cd715b97f124b152b5d57033022c6d.tar.gz
netpbm-mirror-f0214c9232cd715b97f124b152b5d57033022c6d.tar.xz
netpbm-mirror-f0214c9232cd715b97f124b152b5d57033022c6d.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2502 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/pbm/pbmtoybm.c')
-rw-r--r--converter/pbm/pbmtoybm.c84
1 files changed, 22 insertions, 62 deletions
diff --git a/converter/pbm/pbmtoybm.c b/converter/pbm/pbmtoybm.c
index 3fdd805d..7de1b98d 100644
--- a/converter/pbm/pbmtoybm.c
+++ b/converter/pbm/pbmtoybm.c
@@ -19,26 +19,11 @@
 
 #include "pm.h"
 #include "pbm.h"
+#include "bitreverse.h"
 
 #define YBM_MAGIC  ( ( '!' << 8 ) | '!' )
 #define INT16MAX 32767
 
-static long item;
-static int bitsperitem, bitshift;
-
-
-static void
-putitem(void) {
-
-    pm_writebigshort(stdout, item);
-
-    item        = 0;
-    bitsperitem = 0;
-    bitshift    = 0;
-}
-
-
-
 static void
 putinit(int const cols,
         int const rows) {
@@ -46,35 +31,6 @@ putinit(int const cols,
     pm_writebigshort(stdout, YBM_MAGIC);
     pm_writebigshort(stdout, cols);
     pm_writebigshort(stdout, rows);
-
-    item        = 0;
-    bitsperitem = 0;
-    bitshift    = 0;
-}
-
-
-
-static void
-putbit(bit const b) {
-
-    if (bitsperitem == 16)
-        putitem();
-
-    ++bitsperitem;
-
-    if (b == PBM_BLACK)
-        item += 1 << bitshift;
-
-    ++bitshift;
-}
-
-
-
-static void
-putrest(void) {
-
-    if (bitsperitem > 0)
-        putitem();
 }
 
 
@@ -87,51 +43,55 @@ main(int argc, const char *argv[]) {
     int rows;
     int cols;
     int format;
-    unsigned int padright;
     unsigned int row;
-    const char * inputFile;
+    const char * inputFileName;
 
     pm_proginit(&argc, argv);
 
     if (argc-1 < 1)
-        inputFile = "-";
+        inputFileName = "-";
     else {
-        inputFile = argv[1];
+        inputFileName = argv[1];
 
         if (argc-1 > 2)
             pm_error("Too many arguments.  The only argument is the optional "
                      "input file name");
     }
 
-    ifP = pm_openr(inputFile);
+    ifP = pm_openr(inputFileName);
 
     pbm_readpbminit(ifP, &cols, &rows, &format);
 
     if (rows > INT16MAX || cols > INT16MAX)
         pm_error("Input image is too large.");
 
-    bitrow = pbm_allocrow(cols);
+    bitrow = pbm_allocrow_packed(cols + 8);
     
-    /* Compute padding to round cols up to the nearest multiple of 16. */
-    padright = ((cols + 15) / 16) * 16 - cols;
-
     putinit(cols, rows);
+
+    bitrow[pbm_packed_bytes(cols + 8) - 1] = 0x00;
     for (row = 0; row < rows; ++row) {
-        unsigned int col;
+        uint16_t *   const itemrow = (uint16_t *) bitrow;
+        unsigned int const itemCt   = (cols + 15) / 16;
+
+        unsigned int i;
 
-        pbm_readpbmrow(ifP, bitrow, cols, format);
+        pbm_readpbmrow_packed(ifP, bitrow, cols, format);
+        pbm_cleanrowend_packed(bitrow, cols);
 
-        for (col = 0; col < cols; ++col)
-            putbit(bitrow[col]);
+        for (i = 0; i < pbm_packed_bytes(cols); ++i)
+            bitrow[i] = bitreverse[bitrow[i]];
 
-        for (col = 0; col < padright; ++col)
-            putbit(0);
+        for (i = 0; i < itemCt; ++i)
+            pm_writebigshort(stdout, itemrow[i]);
     }
 
+    pbm_freerow_packed(bitrow);
+
     if (ifP != stdin)
         fclose(ifP);
 
-    putrest();
-
     return 0;
 }
+
+