Lines Matching refs:bs

156    BitStream *bs = malloc ( sizeof(BitStream) );  in bsOpenReadStream()  local
157 if (bs == NULL) mallocFail ( sizeof(BitStream) ); in bsOpenReadStream()
158 bs->handle = stream; in bsOpenReadStream()
159 bs->buffer = 0; in bsOpenReadStream()
160 bs->buffLive = 0; in bsOpenReadStream()
161 bs->mode = 'r'; in bsOpenReadStream()
162 return bs; in bsOpenReadStream()
169 BitStream *bs = malloc ( sizeof(BitStream) ); in bsOpenWriteStream() local
170 if (bs == NULL) mallocFail ( sizeof(BitStream) ); in bsOpenWriteStream()
171 bs->handle = stream; in bsOpenWriteStream()
172 bs->buffer = 0; in bsOpenWriteStream()
173 bs->buffLive = 0; in bsOpenWriteStream()
174 bs->mode = 'w'; in bsOpenWriteStream()
175 return bs; in bsOpenWriteStream()
180 static void bsPutBit ( BitStream* bs, Int32 bit ) in bsPutBit() argument
182 if (bs->buffLive == 8) { in bsPutBit()
183 Int32 retVal = putc ( (UChar) bs->buffer, bs->handle ); in bsPutBit()
186 bs->buffLive = 1; in bsPutBit()
187 bs->buffer = bit & 0x1; in bsPutBit()
189 bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) ); in bsPutBit()
190 bs->buffLive++; in bsPutBit()
199 static Int32 bsGetBit ( BitStream* bs ) in bsGetBit() argument
201 if (bs->buffLive > 0) { in bsGetBit()
202 bs->buffLive --; in bsGetBit()
203 return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 ); in bsGetBit()
205 Int32 retVal = getc ( bs->handle ); in bsGetBit()
210 bs->buffLive = 7; in bsGetBit()
211 bs->buffer = retVal; in bsGetBit()
212 return ( ((bs->buffer) >> 7) & 0x1 ); in bsGetBit()
218 static void bsClose ( BitStream* bs ) in bsClose() argument
222 if ( bs->mode == 'w' ) { in bsClose()
223 while ( bs->buffLive < 8 ) { in bsClose()
224 bs->buffLive++; in bsClose()
225 bs->buffer <<= 1; in bsClose()
227 retVal = putc ( (UChar) (bs->buffer), bs->handle ); in bsClose()
230 retVal = fflush ( bs->handle ); in bsClose()
233 retVal = fclose ( bs->handle ); in bsClose()
235 if (bs->mode == 'w') writeError(); else readError(); in bsClose()
237 free ( bs ); in bsClose()
242 static void bsPutUChar ( BitStream* bs, UChar c ) in bsPutUChar() argument
246 bsPutBit ( bs, (((UInt32) c) >> i) & 0x1 ); in bsPutUChar()
251 static void bsPutUInt32 ( BitStream* bs, UInt32 c ) in bsPutUInt32() argument
256 bsPutBit ( bs, (c >> i) & 0x1 ); in bsPutUInt32()