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 13 function: packing variable sized words into an octet stream 14 last mod: $Id: bitwise.c 7675 2004-09-01 00:34:39Z xiphmont $ 15 16 ********************************************************************/ 17 #if !defined(_bitpack_H) 18 # define _bitpack_H (1) 19 # include <limits.h> 20 21 22 23 typedef unsigned long oc_pb_window; 24 typedef struct oc_pack_buf oc_pack_buf; 25 26 27 28 # define OC_PB_WINDOW_SIZE ((int)sizeof(oc_pb_window)*CHAR_BIT) 29 /*This is meant to be a large, positive constant that can still be efficiently 30 loaded as an immediate (on platforms like ARM, for example). 31 Even relatively modest values like 100 would work fine.*/ 32 # define OC_LOTS_OF_BITS (0x40000000) 33 34 35 36 struct oc_pack_buf{ 37 oc_pb_window window; 38 const unsigned char *ptr; 39 const unsigned char *stop; 40 int bits; 41 int eof; 42 }; 43 44 void oc_pack_readinit(oc_pack_buf *_b,unsigned char *_buf,long _bytes); 45 int oc_pack_look1(oc_pack_buf *_b); 46 void oc_pack_adv1(oc_pack_buf *_b); 47 /*Here we assume 0<=_bits&&_bits<=32.*/ 48 long oc_pack_read(oc_pack_buf *_b,int _bits); 49 int oc_pack_read1(oc_pack_buf *_b); 50 /* returns -1 for read beyond EOF, or the number of whole bytes available */ 51 long oc_pack_bytes_left(oc_pack_buf *_b); 52 53 /*These two functions are implemented locally in huffdec.c*/ 54 /*Read in bits without advancing the bitptr. 55 Here we assume 0<=_bits&&_bits<=32.*/ 56 /*static int oc_pack_look(oc_pack_buf *_b,int _bits);*/ 57 /*static void oc_pack_adv(oc_pack_buf *_b,int _bits);*/ 58 59 #endif 60