Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / media / libtheora / lib / dec / bitwise.h
blobbce0c4de4b8e563539f9d0a4330a6e5248cd2a08
1 /********************************************************************
2 * *
3 * THIS FILE IS PART OF THE OggVorbis 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 OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
10 * *
11 ********************************************************************
13 function: packing variable sized words into an octet stream
14 last mod: $Id: bitwise.c 7675 2004-09-01 00:34:39Z xiphmont $
16 ********************************************************************/
17 #if !defined(_bitwise_H)
18 # define _bitwise_H (1)
19 # include <ogg/ogg.h>
21 void theorapackB_reset(oggpack_buffer *b);
22 void theorapackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
23 /* Read in bits without advancing the bitptr; bits <= 32 */
24 static int theorapackB_look(oggpack_buffer *b,int bits,long *_ret);
25 int theorapackB_look1(oggpack_buffer *b,long *_ret);
26 static void theorapackB_adv(oggpack_buffer *b,int bits);
27 void theorapackB_adv1(oggpack_buffer *b);
28 /* bits <= 32 */
29 int theorapackB_read(oggpack_buffer *b,int bits,long *_ret);
30 int theorapackB_read1(oggpack_buffer *b,long *_ret);
31 long theorapackB_bytes(oggpack_buffer *b);
32 long theorapackB_bits(oggpack_buffer *b);
33 unsigned char *theorapackB_get_buffer(oggpack_buffer *b);
35 /*These two functions are only used in one place, and declaring them static so
36 they can be inlined saves considerable function call overhead.*/
38 /* Read in bits without advancing the bitptr; bits <= 32 */
39 static int theorapackB_look(oggpack_buffer *b,int bits,long *_ret){
40 long ret;
41 long m;
42 m=32-bits;
43 bits+=b->endbit;
44 if(b->endbyte+4>=b->storage){
45 /* not the main path */
46 if(b->endbyte>=b->storage){
47 *_ret=0L;
48 return -1;
50 /*If we have some bits left, but not enough, return the ones we have.*/
51 if((b->storage-b->endbyte)*8<bits)bits=(b->storage-b->endbyte)*8;
53 ret=b->ptr[0]<<(24+b->endbit);
54 if(bits>8){
55 ret|=b->ptr[1]<<(16+b->endbit);
56 if(bits>16){
57 ret|=b->ptr[2]<<(8+b->endbit);
58 if(bits>24){
59 ret|=b->ptr[3]<<(b->endbit);
60 if(bits>32&&b->endbit)
61 ret|=b->ptr[4]>>(8-b->endbit);
65 *_ret=((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
66 return 0;
69 static void theorapackB_adv(oggpack_buffer *b,int bits){
70 bits+=b->endbit;
71 b->ptr+=bits/8;
72 b->endbyte+=bits/8;
73 b->endbit=bits&7;
76 #endif