about summary refs log tree commit diff
path: root/editor/pnminvert.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-06-28 23:07:55 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2019-06-28 23:07:55 +0000
commit11fd0bc3fdbe7b5eb9266a728a81d0bcac91fe32 (patch)
tree7c40f096dd973943ef563ec87b2a68d8205db4fb /editor/pnminvert.c
parent89c6ec14eb7514630aea5abc4b90b51d1473d33a (diff)
downloadnetpbm-mirror-11fd0bc3fdbe7b5eb9266a728a81d0bcac91fe32.tar.gz
netpbm-mirror-11fd0bc3fdbe7b5eb9266a728a81d0bcac91fe32.tar.xz
netpbm-mirror-11fd0bc3fdbe7b5eb9266a728a81d0bcac91fe32.zip
Promote Stable to Super_stable
git-svn-id: http://svn.code.sf.net/p/netpbm/code/super_stable@3640 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor/pnminvert.c')
-rw-r--r--editor/pnminvert.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/editor/pnminvert.c b/editor/pnminvert.c
index 40fee9be..4bee8837 100644
--- a/editor/pnminvert.c
+++ b/editor/pnminvert.c
@@ -12,6 +12,17 @@
 
 #include "pnm.h"
 
+/* Implementation note: A suitably advanced compiler, such as Gcc 4,
+   implements the for statements in our algorithm with instructions that do 16
+   bytes at a time on CPUs that have them (movdqa on x86).  This is "tree
+   vectorization."  A more primitive compiler will do one byte at a time; we
+   could change the code to use libnetpbm's wordaccess.h facility and it will
+   do one word at a time.  (But we don't think it's worth complicating the
+   code for that).
+*/
+
+
+
 #define CHARBITS (sizeof(unsigned char)*8)
 
 
@@ -25,9 +36,6 @@ invertPbm(FILE * const ifP,
 /*----------------------------------------------------------------------------
    Invert a PBM image.  Use the "packed" PBM functions for speed.
 -----------------------------------------------------------------------------*/
-    /* We could make this faster by inverting whole words at a time,
-       using libnetpbm's wordaccess.h facility.
-    */
     int const colChars = pbm_packed_bytes(cols);
 
     unsigned char * bitrow; 
@@ -42,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);