diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2008-08-13 02:12:37 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2008-08-13 02:12:37 +0000 |
commit | 047b52250344ac6e341d4c7b03315bee1b422280 (patch) | |
tree | 23f55b35d060686453ea663a9adf27058219a99d /editor | |
parent | f126a6e2c3a22b6cf6de4058915b418f4a560fe9 (diff) | |
download | netpbm-mirror-047b52250344ac6e341d4c7b03315bee1b422280.tar.gz netpbm-mirror-047b52250344ac6e341d4c7b03315bee1b422280.tar.xz netpbm-mirror-047b52250344ac6e341d4c7b03315bee1b422280.zip |
Move bit masking functions to library
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@701 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor')
-rw-r--r-- | editor/pnmcat.c | 51 |
1 files changed, 9 insertions, 42 deletions
diff --git a/editor/pnmcat.c b/editor/pnmcat.c index ef553a2c..e5d8fc35 100644 --- a/editor/pnmcat.c +++ b/editor/pnmcat.c @@ -12,9 +12,13 @@ #include <assert.h> -#include "pnm.h" #include "mallocvar.h" #include "shhopt.h" +#include "bitarith.h" +#include "pnm.h" + +#define LEFTBITS pm_byteLeftBits +#define RIGHTBITS pm_byteRightBits enum backcolor {BACK_WHITE, BACK_BLACK, BACK_AUTO}; @@ -219,43 +223,6 @@ computeOutputParms(unsigned int const nfiles, } -static unsigned char -leftBits(unsigned char const x, - unsigned int const n) { -/*---------------------------------------------------------------------------- - Clear rightmost (8-n) bits, retain leftmost (=high) n bits. ------------------------------------------------------------------------------*/ - unsigned char retval; - - assert(n < 8); - - retval = x; - retval >>= (8-n); - retval <<= (8-n); - - return retval; -} - - - -static unsigned char -rightBits(unsigned char const x, - unsigned int const n){ -/*---------------------------------------------------------------------------- - Return rightmost (=low) n bits of x. ------------------------------------------------------------------------------*/ - unsigned char retval; - - assert(n < 8); - - retval = x; - retval <<= (8-n); - retval >>= (8-n); - - return retval; -} - - static void copyBitrow(const unsigned char * const source, @@ -289,10 +256,10 @@ copyBitrow(const unsigned char * const source, dest[i] = source[i]; if (rs > 0) - dest[0] = leftBits(origHead, rs) | rightBits(dest[0], 8-rs); + dest[0] = LEFTBITS(origHead, rs) | RIGHTBITS(dest[0], 8-rs); if (trs > 0) - dest[last] = leftBits(dest[last], trs) | rightBits(origEnd, 8-trs); + dest[last] = LEFTBITS(dest[last], trs) | RIGHTBITS(origEnd, 8-trs); } @@ -323,10 +290,10 @@ padFillBitrow(unsigned char * const destBitrow, dest[i] = padColor; if (rs > 0) - dest[0] = leftBits(origHead, rs) | rightBits(dest[0], 8-rs); + dest[0] = LEFTBITS(origHead, rs) | RIGHTBITS(dest[0], 8-rs); if (trs > 0) - dest[last] = leftBits(dest[last], trs) | rightBits(origEnd, 8-trs); + dest[last] = LEFTBITS(dest[last], trs) | RIGHTBITS(origEnd, 8-trs); } |