bitpack.h 2.6 KB

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