about summary refs log tree commit diff
path: root/converter/other
diff options
context:
space:
mode:
Diffstat (limited to 'converter/other')
-rw-r--r--converter/other/bmptopnm.c11
-rw-r--r--converter/other/pnmtops.c8
2 files changed, 4 insertions, 15 deletions
diff --git a/converter/other/bmptopnm.c b/converter/other/bmptopnm.c
index 84d39989..a069092f 100644
--- a/converter/other/bmptopnm.c
+++ b/converter/other/bmptopnm.c
@@ -1442,8 +1442,6 @@ writeRasterPbm(unsigned char ** const bmpRaster,
   
   We destroy *bmpRaster as a side effect.
 -----------------------------------------------------------------------------*/
-    unsigned int const charBits = (sizeof(unsigned char) * 8);
-        /* Number of bits in a character */
     unsigned int const colChars = pbm_packed_bytes(cols);
     
     int row;
@@ -1463,13 +1461,8 @@ writeRasterPbm(unsigned char ** const bmpRaster,
             for (i = 0; i < colChars; ++i) 
                 bitrow[i] = ~bitrow[i]; /* flip all pixels */ 
         }   
-            
-        if (cols % 8 > 0) {
-            /* adjust final partial byte */
-            bitrow[colChars-1] >>= charBits - cols % charBits;
-            bitrow[colChars-1] <<= charBits - cols % charBits;
-        }
-        
+
+        pbm_cleanrowend_packed(bitrow, cols);
         pbm_writepbmrow_packed(stdout, bitrow, cols, FALSE);
     }
 }
diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c
index cf6b2873..6cd6be95 100644
--- a/converter/other/pnmtops.c
+++ b/converter/other/pnmtops.c
@@ -1853,18 +1853,14 @@ convertRowPbm(struct pam *     const pamP,
 ----------------------------------------------------------------------*/
     unsigned int colChar;
     unsigned int const colChars = pbm_packed_bytes(pamP->width);
-    unsigned int const padRight = (8 - pamP->width %8) %8;
 
     pbm_readpbmrow_packed(pamP->file, bitrow, pamP->width, pamP->format);
 
     for (colChar = 0; colChar < colChars; ++colChar)
         bitrow[colChar] =  ~ bitrow[colChar];
 
-    if (padRight > 0) {
-        bitrow[colChars-1] >>= padRight;  /* Zero clear padding beyond */
-        bitrow[colChars-1] <<= padRight;  /* right edge */
-    }
-
+    /* Zero clear padding beyond right edge */
+    pbm_cleanrowend_packed(bitrow, pamP->width);
     writeFile(bitrow, colChars, "PBM reader", fP);
 }