79#include "jasper/jas_types.h"
80#include "jasper/jas_stream.h"
91#define JPC_BITSTREAM_READ 0x01
93#define JPC_BITSTREAM_WRITE 0x02
100#define JPC_BITSTREAM_NOCLOSE 0x01
102#define JPC_BITSTREAM_EOF 0x02
104#define JPC_BITSTREAM_ERR 0x04
124 jas_stream_t *stream_;
136jpc_bitstream_t *jpc_bitstream_sopen(jas_stream_t *stream,
char *mode);
139int jpc_bitstream_close(jpc_bitstream_t *bitstream);
147#define jpc_bitstream_getbit(bitstream) \
148 jpc_bitstream_getbit_func(bitstream)
150#define jpc_bitstream_getbit(bitstream) \
151 jpc_bitstream_getbit_macro(bitstream)
156#define jpc_bitstream_putbit(bitstream, v) \
157 jpc_bitstream_putbit_func(bitstream, v)
159#define jpc_bitstream_putbit(bitstream, v) \
160 jpc_bitstream_putbit_macro(bitstream, v)
164long jpc_bitstream_getbits(jpc_bitstream_t *bitstream,
int n);
167int jpc_bitstream_putbits(jpc_bitstream_t *bitstream,
int n,
long v);
175int jpc_bitstream_align(jpc_bitstream_t *bitstream);
180int jpc_bitstream_inalign(jpc_bitstream_t *bitstream,
int fillmask,
185int jpc_bitstream_outalign(jpc_bitstream_t *bitstream,
int filldata);
188int jpc_bitstream_needalign(jpc_bitstream_t *bitstream);
191int jpc_bitstream_pending(jpc_bitstream_t *bitstream);
198#define jpc_bitstream_eof(bitstream) \
199 ((bitstream)->flags_ & JPC_BITSTREAM_EOF)
208int jpc_bitstream_getbit_func(jpc_bitstream_t *bitstream);
210int jpc_bitstream_putbit_func(jpc_bitstream_t *bitstream,
int v);
212int jpc_bitstream_fillbuf(jpc_bitstream_t *bitstream);
214#define jpc_bitstream_getbit_macro(bitstream) \
215 (assert((bitstream)->openmode_ & JPC_BITSTREAM_READ), \
216 (--(bitstream)->cnt_ >= 0) ? \
217 ((int)(((bitstream)->buf_ >> (bitstream)->cnt_) & 1)) : \
218 jpc_bitstream_fillbuf(bitstream))
220#define jpc_bitstream_putbit_macro(bitstream, bit) \
221 (assert((bitstream)->openmode_ & JPC_BITSTREAM_WRITE), \
222 (--(bitstream)->cnt_ < 0) ? \
223 ((bitstream)->buf_ = ((bitstream)->buf_ << 8) & 0xffff, \
224 (bitstream)->cnt_ = ((bitstream)->buf_ == 0xff00) ? 6 : 7, \
225 (bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \
226 (jas_stream_putc((bitstream)->stream_, (bitstream)->buf_ >> 8) == EOF) \
227 ? (EOF) : ((bit) & 1)) : \
228 ((bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \