Home | History | Annotate | Download | only in libjasper

Lines Matching defs:bitstream

97     jpc_bitstream_t *bitstream;
106 if (!(bitstream = jpc_bitstream_alloc())) {
112 bitstream->flags_ = JPC_BITSTREAM_NOCLOSE;
114 bitstream->stream_ = stream;
115 bitstream->openmode_ = (mode[0] == 'w') ? JPC_BITSTREAM_WRITE :
119 bitstream->cnt_ = (bitstream->openmode_ == JPC_BITSTREAM_READ) ? 0 : 8;
120 bitstream->buf_ = 0;
122 return bitstream;
126 int jpc_bitstream_close(jpc_bitstream_t *bitstream)
132 if (jpc_bitstream_align(bitstream)) {
137 if (!(bitstream->flags_ & JPC_BITSTREAM_NOCLOSE) && bitstream->stream_) {
138 if (jas_stream_close(bitstream->stream_)) {
141 bitstream->stream_ = 0;
144 jas_free(bitstream);
151 jpc_bitstream_t *bitstream;
154 if (!(bitstream = jas_malloc(sizeof(jpc_bitstream_t)))) {
158 bitstream->stream_ = 0;
159 bitstream->cnt_ = 0;
160 bitstream->flags_ = 0;
161 bitstream->openmode_ = 0;
163 return bitstream;
171 int jpc_bitstream_getbit_func(jpc_bitstream_t *bitstream)
174 JAS_DBGLOG(1000, ("jpc_bitstream_getbit_func(%p)\n", bitstream));
175 ret = jpc_bitstream_getbit_macro(bitstream);
181 int jpc_bitstream_putbit_func(jpc_bitstream_t *bitstream, int b)
184 JAS_DBGLOG(1000, ("jpc_bitstream_putbit_func(%p, %d)\n", bitstream, b));
185 ret = jpc_bitstream_putbit_macro(bitstream, b);
191 long jpc_bitstream_getbits(jpc_bitstream_t *bitstream, int n)
203 if ((u = jpc_bitstream_getbit(bitstream)) < 0) {
212 int jpc_bitstream_putbits(jpc_bitstream_t *bitstream, int n, long v)
225 if (jpc_bitstream_putbit(bitstream, (v >> m) & 1) == EOF) {
238 int jpc_bitstream_fillbuf(jpc_bitstream_t *bitstream)
242 assert(bitstream->openmode_ & JPC_BITSTREAM_READ);
243 assert(bitstream->cnt_ <= 0);
245 if (bitstream->flags_ & JPC_BITSTREAM_ERR) {
246 bitstream->cnt_ = 0;
250 if (bitstream->flags_ & JPC_BITSTREAM_EOF) {
251 bitstream->buf_ = 0x7f;
252 bitstream->cnt_ = 7;
256 bitstream->buf_ = (bitstream->buf_ << 8) & 0xffff;
257 if ((c = jas_stream_getc((bitstream)->stream_)) == EOF) {
258 bitstream->flags_ |= JPC_BITSTREAM_EOF;
261 bitstream->cnt_ = (bitstream->buf_ == 0xff00) ? 6 : 7;
262 bitstream->buf_ |= c & ((1 << (bitstream->cnt_ + 1)) - 1);
263 return (bitstream->buf_ >> bitstream->cnt_) & 1;
273 int jpc_bitstream_needalign(jpc_bitstream_t *bitstream)
275 if (bitstream->openmode_ & JPC_BITSTREAM_READ) {
280 if ((bitstream->cnt_ < 8 && bitstream->cnt_ > 0) ||
281 ((bitstream->buf_ >> 8) & 0xff) == 0xff) {
284 } else if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) {
289 if ((bitstream->cnt_ < 8 && bitstream->cnt_ >= 0) ||
290 ((bitstream->buf_ >> 8) & 0xff) == 0xff) {
302 int jpc_bitstream_pending(jpc_bitstream_t *bitstream)
304 if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) {
308 if (bitstream->cnt_ < 8) {
312 if (bitstream->cnt_ < 8) {
313 if (((bitstream->buf_ >> 8) & 0xff) == 0xff) {
328 int jpc_bitstream_align(jpc_bitstream_t *bitstream)
331 if (bitstream->openmode_ & JPC_BITSTREAM_READ) {
332 ret = jpc_bitstream_inalign(bitstream, 0, 0);
333 } else if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) {
334 ret = jpc_bitstream_outalign(bitstream, 0);
342 int jpc_bitstream_inalign(jpc_bitstream_t *bitstream, int fillmask,
354 if (bitstream->cnt_ > 0) {
355 n = bitstream->cnt_;
356 } else if (!bitstream->cnt_) {
357 n = ((bitstream->buf_ & 0xff) == 0xff) ? 7 : 0;
362 if ((u = jpc_bitstream_getbits(bitstream, n)) < 0) {
368 if ((bitstream->buf_ & 0xff) == 0xff) {
369 if ((u = jpc_bitstream_getbits(bitstream, 7)) < 0) {
390 int jpc_bitstream_outalign(jpc_bitstream_t *bitstream, int filldata)
396 assert(bitstream->openmode_ & JPC_BITSTREAM_WRITE);
404 if (!bitstream->cnt_) {
405 if ((bitstream->buf_ & 0xff) == 0xff) {
412 } else if (bitstream->cnt_ > 0 && bitstream->cnt_ < 8) {
413 n = bitstream->cnt_;
423 if (jpc_bitstream_putbits(bitstream, n, v)) {
427 if (bitstream->cnt_ < 8) {
428 assert(bitstream->cnt_ >= 0 && bitstream->cnt_ < 8);
429 assert((bitstream->buf_ & 0xff) != 0xff);
432 if (jas_stream_putc(bitstream->stream_, bitstream->buf_ & 0xff) == EOF) {
435 bitstream->cnt_ = 8;
436 bitstream->buf_ = (bitstream->buf_ << 8) & 0xffff;