diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libpbm2.c | 22 | ||||
-rw-r--r-- | lib/pbm.h | 4 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/libpbm2.c b/lib/libpbm2.c index 0d824877..e12b1e33 100644 --- a/lib/libpbm2.c +++ b/lib/libpbm2.c @@ -10,6 +10,7 @@ ** implied warranty. */ +#include <assert.h> #include <limits.h> #include "pbm.h" @@ -257,7 +258,26 @@ pbm_readpbmrow_bitoffset(FILE * const ifP, window[last] = leftBits | rightBits; } -} +} + + + +void +pbm_cleanrowend_packed(unsigned char * const packedBits, + unsigned int const cols) { +/*---------------------------------------------------------------------------- + Set fractional "don't care" bits at end of row to zero. +----------------------------------------------------------------------------*/ + unsigned int const last = pbm_packed_bytes(cols) - 1; + unsigned int const bitsPerChar = 8; + + assert(cols > 0); + + if (cols % bitsPerChar > 0) { + packedBits[last] >>= bitsPerChar - cols % bitsPerChar; + packedBits[last] <<= bitsPerChar - cols % bitsPerChar; + } +} diff --git a/lib/pbm.h b/lib/pbm.h index 520e4331..a29adb48 100644 --- a/lib/pbm.h +++ b/lib/pbm.h @@ -88,6 +88,10 @@ pbm_readpbmrow_bitoffset(FILE * const fileP, unsigned int const offset); void +pbm_cleanrowend_packed(unsigned char * const packedBits, + unsigned int const cols); + +void pbm_writepbminit(FILE * const fileP, int const cols, int const rows, |