michael@0: /******************************************************************** michael@0: * * michael@0: * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * michael@0: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * michael@0: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * michael@0: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * michael@0: * * michael@0: * THE OggTheora SOURCE CODE IS (C) COPYRIGHT 1994-2009 * michael@0: * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * michael@0: * * michael@0: ******************************************************************** michael@0: michael@0: function: packing variable sized words into an octet stream michael@0: last mod: $Id: bitwise.c 7675 2004-09-01 00:34:39Z xiphmont $ michael@0: michael@0: ********************************************************************/ michael@0: #if !defined(_bitpack_H) michael@0: # define _bitpack_H (1) michael@0: # include michael@0: # include michael@0: # include "internal.h" michael@0: michael@0: michael@0: michael@0: typedef size_t oc_pb_window; michael@0: typedef struct oc_pack_buf oc_pack_buf; michael@0: michael@0: michael@0: michael@0: /*Custom bitpacker implementations.*/ michael@0: # if defined(OC_ARM_ASM) michael@0: # include "arm/armbits.h" michael@0: # endif michael@0: michael@0: # if !defined(oc_pack_read) michael@0: # define oc_pack_read oc_pack_read_c michael@0: # endif michael@0: # if !defined(oc_pack_read1) michael@0: # define oc_pack_read1 oc_pack_read1_c michael@0: # endif michael@0: # if !defined(oc_huff_token_decode) michael@0: # define oc_huff_token_decode oc_huff_token_decode_c michael@0: # endif michael@0: michael@0: # define OC_PB_WINDOW_SIZE ((int)sizeof(oc_pb_window)*CHAR_BIT) michael@0: /*This is meant to be a large, positive constant that can still be efficiently michael@0: loaded as an immediate (on platforms like ARM, for example). michael@0: Even relatively modest values like 100 would work fine.*/ michael@0: # define OC_LOTS_OF_BITS (0x40000000) michael@0: michael@0: michael@0: michael@0: struct oc_pack_buf{ michael@0: const unsigned char *stop; michael@0: const unsigned char *ptr; michael@0: oc_pb_window window; michael@0: int bits; michael@0: int eof; michael@0: }; michael@0: michael@0: void oc_pack_readinit(oc_pack_buf *_b,unsigned char *_buf,long _bytes); michael@0: int oc_pack_look1(oc_pack_buf *_b); michael@0: void oc_pack_adv1(oc_pack_buf *_b); michael@0: /*Here we assume 0<=_bits&&_bits<=32.*/ michael@0: long oc_pack_read_c(oc_pack_buf *_b,int _bits); michael@0: int oc_pack_read1_c(oc_pack_buf *_b); michael@0: /* returns -1 for read beyond EOF, or the number of whole bytes available */ michael@0: long oc_pack_bytes_left(oc_pack_buf *_b); michael@0: michael@0: /*These two functions are implemented locally in huffdec.c*/ michael@0: /*Read in bits without advancing the bitptr. michael@0: Here we assume 0<=_bits&&_bits<=32.*/ michael@0: /*static int oc_pack_look(oc_pack_buf *_b,int _bits);*/ michael@0: /*static void oc_pack_adv(oc_pack_buf *_b,int _bits);*/ michael@0: michael@0: #endif