getbit.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* getbit.h -- bit-buffer access
  2. This file is part of the UCL data compression library.
  3. Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
  4. All Rights Reserved.
  5. The UCL library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. The UCL library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with the UCL library; see the file COPYING.
  15. If not, write to the Free Software Foundation, Inc.,
  16. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. Markus F.X.J. Oberhumer
  18. <markus@oberhumer.com>
  19. http://www.oberhumer.com/opensource/ucl/
  20. */
  21. /***********************************************************************
  22. //
  23. ************************************************************************/
  24. #if 1
  25. #define getbit_8(bb, src, ilen) \
  26. (((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1)
  27. #elif 1
  28. #define getbit_8(bb, src, ilen) \
  29. (bb*=2,bb&0xff ? (bb>>8)&1 : ((bb=src[ilen++]*2+1)>>8)&1)
  30. #else
  31. #define getbit_8(bb, src, ilen) \
  32. (((bb*=2, (bb&0xff ? bb : (bb=src[ilen++]*2+1,bb))) >> 8) & 1)
  33. #endif
  34. #define getbit_le16(bb, src, ilen) \
  35. (bb*=2,bb&0xffff ? (bb>>16)&1 : (ilen+=2,((bb=(src[ilen-2]+src[ilen-1]*256u)*2+1)>>16)&1))
  36. #if 1 && defined(UCL_UNALIGNED_OK_4) && (UCL_BYTE_ORDER == UCL_LITTLE_ENDIAN)
  37. #define getbit_le32(bb, bc, src, ilen) \
  38. (bc > 0 ? ((bb>>--bc)&1) : (bc=31,\
  39. bb=*(const ucl_uint32p)((src)+ilen),ilen+=4,(bb>>31)&1))
  40. #else
  41. #define getbit_le32(bb, bc, src, ilen) \
  42. (bc > 0 ? ((bb>>--bc)&1) : (bc=31,\
  43. bb=src[ilen]+src[ilen+1]*0x100+src[ilen+2]*UCL_UINT32_C(0x10000)+src[ilen+3]*UCL_UINT32_C(0x1000000),\
  44. ilen+=4,(bb>>31)&1))
  45. #endif
  46. /*
  47. vi:ts=4:et
  48. */