diff options
Diffstat (limited to 'editor/pnminvert.c')
-rw-r--r-- | editor/pnminvert.c | 21 |
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); |