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 <stddef.h>
  18. # include <limits.h>
  19. typedef size_t oc_pb_window;
  20. typedef struct oc_pack_buf oc_pack_buf;
  21. # define OC_PB_WINDOW_SIZE ((int)sizeof(oc_pb_window)*CHAR_BIT)
  22. /*This is meant to be a large, positive constant that can still be efficiently
  23. loaded as an immediate (on platforms like ARM, for example).
  24. Even relatively modest values like 100 would work fine.*/
  25. # define OC_LOTS_OF_BITS (0x40000000)
  26. struct oc_pack_buf{
  27. oc_pb_window window;
  28. const unsigned char *ptr;
  29. const unsigned char *stop;
  30. int bits;
  31. int eof;
  32. };
  33. void oc_pack_readinit(oc_pack_buf *_b,unsigned char *_buf,long _bytes);
  34. int oc_pack_look1(oc_pack_buf *_b);
  35. void oc_pack_adv1(oc_pack_buf *_b);
  36. /*Here we assume 0<=_bits&&_bits<=32.*/
  37. long oc_pack_read(oc_pack_buf *_b,int _bits);
  38. int oc_pack_read1(oc_pack_buf *_b);
  39. /* returns -1 for read beyond EOF, or the number of whole bytes available */
  40. long oc_pack_bytes_left(oc_pack_buf *_b);
  41. /*These two functions are implemented locally in huffdec.c*/
  42. /*Read in bits without advancing the bitptr.
  43. Here we assume 0<=_bits&&_bits<=32.*/
  44. /*static int oc_pack_look(oc_pack_buf *_b,int _bits);*/
  45. /*static void oc_pack_adv(oc_pack_buf *_b,int _bits);*/
  46. #endif