about summary refs log tree commit diff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/pamenlarge.c7
-rw-r--r--editor/pbmclean.c12
-rw-r--r--editor/pbmpscale.c11
-rw-r--r--editor/pnminvert.c7
4 files changed, 10 insertions, 27 deletions
diff --git a/editor/pamenlarge.c b/editor/pamenlarge.c
index dd61f2cf..187bfb6e 100644
--- a/editor/pamenlarge.c
+++ b/editor/pamenlarge.c
@@ -312,11 +312,8 @@ enlargePbm(struct pam * const inpamP,
         pbm_readpbmrow_packed(inpamP->file, inrow, inpamP->width,
                               inpamP->format);
 
-        if (outcols % 8 > 0) {
-            /* clean final partial byte */ 
-            inrow[inColChars-1] >>= 8 - inpamP->width % 8;
-            inrow[inColChars-1] <<= 8 - inpamP->width % 8;
-        }
+        if (outcols % 8 > 0)           /* clean final partial byte */ 
+            pbm_cleanrowend_packed(inrow, inpamP->width);
 
         enlargePbmRowHorizontally(inpamP, inrow, inColChars, outColChars,
                                   scaleFactor, outrow);
diff --git a/editor/pbmclean.c b/editor/pbmclean.c
index 6d813090..46e7dee6 100644
--- a/editor/pbmclean.c
+++ b/editor/pbmclean.c
@@ -361,10 +361,8 @@ setupInputBuffers(FILE *       const ifP,
 
     pbm_readpbmrow_packed(ifP, nextRow, cols, format);
 
-    if (cols % 8 > 0){
-        nextRow[pbm_packed_bytes(cols) -1 ] >>= (8 - cols % 8);
-        nextRow[pbm_packed_bytes(cols) -1 ] <<= (8 - cols % 8);
-    }
+    pbm_cleanrowend_packed(nextRow, cols);
+
     *bufferP  = buffer;
     *edgeRowP = edgeRow;
     *thisRowP = &edgeRow[1];
@@ -418,10 +416,8 @@ cleanSimple(FILE *             const ifP,
                handling of the initial edgerow.
             */
             pbm_readpbmrow_packed(ifP, nextRow, cols, format);
-            if (cols % 8 > 0){
-                nextRow[pbm_packed_bytes(cols) -1 ] >>= (8 - cols % 8);
-                nextRow[pbm_packed_bytes(cols) -1 ] <<= (8 - cols % 8);
-            }
+            pbm_cleanrowend_packed(nextRow, cols);
+
         } else  /* Bottom of image.  */
             nextRow = &edgeRow[1];
 
diff --git a/editor/pbmpscale.c b/editor/pbmpscale.c
index 15302c56..9ab89350 100644
--- a/editor/pbmpscale.c
+++ b/editor/pbmpscale.c
@@ -412,11 +412,7 @@ main(int argc, const char ** argv) {
     /* Read the top line into nextrow and clean the right end. */
 
     pbm_readpbmrow_packed(ifP, nextrow, cols, format);
-
-    if (cols % 8 > 0) {
-        nextrow[pbm_packed_bytes(cols) - 1] >>= (8 - cols % 8);
-        nextrow[pbm_packed_bytes(cols) - 1] <<= (8 - cols % 8);
-    }
+    pbm_cleanrowend_packed(nextrow, cols);
 
     outrow = pbm_allocrow_packed(outcols);
     for (i = 0; i < pbm_packed_bytes(outcols); ++i)
@@ -440,10 +436,7 @@ main(int argc, const char ** argv) {
                This provision is for proper handling of the initial edgerow.
             */
             pbm_readpbmrow_packed(ifP, nextrow, cols, format);
-            if (cols % 8 > 0) {
-                nextrow[pbm_packed_bytes(cols) - 1] >>= (8 - cols % 8);
-                nextrow[pbm_packed_bytes(cols) - 1] <<= (8 - cols % 8);
-            }
+            pbm_cleanrowend_packed(nextrow, cols);
         } else
             /* Bottom of image.  */
             nextrow = edgerow;
diff --git a/editor/pnminvert.c b/editor/pnminvert.c
index ceb1ef81..4bee8837 100644
--- a/editor/pnminvert.c
+++ b/editor/pnminvert.c
@@ -50,11 +50,8 @@ invertPbm(FILE * const ifP,
         for (colChar = 0; colChar < colChars; ++colChar)
             bitrow[colChar] = ~ bitrow[colChar];
         
-        /* Clean off remainder of fractional last character */
-        if (cols % CHARBITS > 0) {
-            bitrow[colChars-1] >>= CHARBITS - cols % CHARBITS;
-            bitrow[colChars-1] <<= CHARBITS - cols % CHARBITS;
-        }
+        /* Clean off remainder of fractional last character and write */
+        pbm_cleanrowend_packed(bitrow, cols);
         pbm_writepbmrow_packed(ofP, bitrow, cols, 0);
     }
     pbm_freerow_packed(bitrow);