bitpack.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggTheora SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
  9. * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: packing variable sized words into an octet stream
  13. last mod: $Id: bitwise.c 7675 2004-09-01 00:34:39Z xiphmont $
  14. ********************************************************************/
  15. #if !defined(_bitpack_H)
  16. # define _bitpack_H (1)
  17. # include <limits.h>
  18. typedef unsigned long oc_pb_window;
  19. typedef struct oc_pack_buf oc_pack_buf;
  20. # define OC_PB_WINDOW_SIZE ((int)sizeof(oc_pb_window)*CHAR_BIT)
  21. /*This is meant to be a large, positive constant that can still be efficiently
  22. loaded as an immediate (on platforms like ARM, for example).
  23. Even relatively modest values like 100 would work fine.*/
  24. # define OC_LOTS_OF_BITS (0x40000000)
  25. struct oc_pack_buf{
  26. oc_pb_window window;
  27. const unsigned char *ptr;
  28. const unsigned char *stop;
  29. int bits;
  30. int eof;
  31. };
  32. void oc_pack_readinit(oc_pack_buf *_b,unsigned char *_buf,long _bytes);
  33. int oc_pack_look1(oc_pack_buf *_b);
  34. void oc_pack_adv1(oc_pack_buf *_b);
  35. /*Here we assume 0<=_bits&&_bits<=32.*/
  36. long oc_pack_read(oc_pack_buf *_b,int _bits);
  37. int oc_pack_read1(oc_pack_buf *_b);
  38. /* returns -1 for read beyond EOF, or the number of whole bytes available */
  39. long oc_pack_bytes_left(oc_pack_buf *_b);
  40. /*These two functions are implemented locally in huffdec.c*/
  41. /*Read in bits without advancing the bitptr.
  42. Here we assume 0<=_bits&&_bits<=32.*/
  43. /*static int oc_pack_look(oc_pack_buf *_b,int _bits);*/
  44. /*static void oc_pack_adv(oc_pack_buf *_b,int _bits);*/
  45. #endif