77 #include "jasper/jas_types.h"
78 #include "jasper/jas_stream.h"
92 #define JPC_BITSTREAM_READ 0x01
94 #define JPC_BITSTREAM_WRITE 0x02
101 #define JPC_BITSTREAM_NOCLOSE 0x01
103 #define JPC_BITSTREAM_EOF 0x02
105 #define JPC_BITSTREAM_ERR 0x04
125 jas_stream_t *stream_;
137 jpc_bitstream_t *jpc_bitstream_sopen(jas_stream_t *stream,
const char *mode);
140 int jpc_bitstream_close(jpc_bitstream_t *bitstream);
148 #define jpc_bitstream_getbit(bitstream) \
149 jpc_bitstream_getbit_func(bitstream)
151 #define jpc_bitstream_getbit(bitstream) \
152 jpc_bitstream_getbit_macro(bitstream)
157 #define jpc_bitstream_putbit(bitstream, v) \
158 jpc_bitstream_putbit_func(bitstream, v)
160 #define jpc_bitstream_putbit(bitstream, v) \
161 jpc_bitstream_putbit_macro(bitstream, v)
165 long jpc_bitstream_getbits(jpc_bitstream_t *bitstream,
int n);
168 int jpc_bitstream_putbits(jpc_bitstream_t *bitstream,
int n,
long v);
176 int jpc_bitstream_align(jpc_bitstream_t *bitstream);
181 int jpc_bitstream_inalign(jpc_bitstream_t *bitstream,
int fillmask,
186 int jpc_bitstream_outalign(jpc_bitstream_t *bitstream,
int filldata);
190 int jpc_bitstream_needalign(
const jpc_bitstream_t *bitstream);
194 int jpc_bitstream_pending(
const jpc_bitstream_t *bitstream);
201 #define jpc_bitstream_eof(bitstream) \
202 ((bitstream)->flags_ & JPC_BITSTREAM_EOF)
211 int jpc_bitstream_getbit_func(jpc_bitstream_t *bitstream);
213 int jpc_bitstream_putbit_func(jpc_bitstream_t *bitstream,
int v);
215 int jpc_bitstream_fillbuf(jpc_bitstream_t *bitstream);
217 #define jpc_bitstream_getbit_macro(bitstream) \
218 (assert((bitstream)->openmode_ & JPC_BITSTREAM_READ), \
219 (--(bitstream)->cnt_ >= 0) ? \
220 ((int)(((bitstream)->buf_ >> (bitstream)->cnt_) & 1)) : \
221 jpc_bitstream_fillbuf(bitstream))
223 #define jpc_bitstream_putbit_macro(bitstream, bit) \
224 (assert((bitstream)->openmode_ & JPC_BITSTREAM_WRITE), \
225 (--(bitstream)->cnt_ < 0) ? \
226 ((bitstream)->buf_ = ((bitstream)->buf_ << 8) & 0xffff, \
227 (bitstream)->cnt_ = ((bitstream)->buf_ == 0xff00) ? 6 : 7, \
228 (bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \
229 (jas_stream_putc((bitstream)->stream_, (bitstream)->buf_ >> 8) == EOF) \
230 ? (EOF) : ((bit) & 1)) : \
231 ((bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \