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