diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-05-16 01:53:28 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-05-16 01:53:28 +0000 |
commit | 853d1761ee6b8796373a977603b31707b9c6459d (patch) | |
tree | f6868aaddee86c1a6894eb52532377ba288af252 /lib | |
parent | 4c050566e208acbbc2ac94d21208a93637a815c0 (diff) | |
download | netpbm-mirror-853d1761ee6b8796373a977603b31707b9c6459d.tar.gz netpbm-mirror-853d1761ee6b8796373a977603b31707b9c6459d.tar.xz netpbm-mirror-853d1761ee6b8796373a977603b31707b9c6459d.zip |
Add and use pbm_cleanrowend_packed
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2488 9d0c8265-081b-0410-96cb-a4ca84ce46f8
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, |