From 853d1761ee6b8796373a977603b31707b9c6459d Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 16 May 2015 01:53:28 +0000 Subject: Add and use pbm_cleanrowend_packed git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2488 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/libpbm2.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'lib/libpbm2.c') 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 #include #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; + } +} -- cgit 1.4.1