1 #ifndef __BITSTREAM_H__
2 #define __BITSTREAM_H__
4 #include "swf_define.h" /* for malloc */
8 * (C) 2008/03/09- yoya@awm.jp
11 #ifndef BITOPERATION_OPTIMIZE
12 #define BITOPERATION_OPTIMIZE 0
15 typedef struct bitstream_ {
18 unsigned long data_len;
19 unsigned long data_alloc_len;
21 unsigned long byte_offset;
22 unsigned long bit_offset;
28 #define BITSTREAM_DATA_LEN_MIN 0x100
30 #define BITSTREAM_ERROR_NONE 0
31 #define BITSTREAM_ERROR_NOMORE_DATA 1
33 extern bitstream_t *bitstream_open(void);
34 extern void bitstream_close(bitstream_t * bs);
37 extern int bitstream_input(bitstream_t *bs, unsigned char *data,
38 unsigned long data_len);
39 extern unsigned char *bitstream_steal(bitstream_t *bs, unsigned long *length);
40 extern unsigned char *bitstream_output_sub(bitstream_t *bs, unsigned long offset, unsigned long length);
43 extern int bitstream_putbyte(bitstream_t *bs, int byte);
44 extern int bitstream_getbyte(bitstream_t *bs);
45 extern int bitstream_putstring(bitstream_t *bs,
46 unsigned char *data, signed long data_len);
47 extern int bitstream_getstring(bitstream_t *bs,
48 unsigned char *data, signed long data_len);
49 extern unsigned char *bitstream_outputstring(bitstream_t *bs);
51 extern int bitstream_putbytesLE(bitstream_t *bs, unsigned long bytes, int byte_width);
52 extern int bitstream_putbytesBE(bitstream_t *bs, unsigned long bytes, int byte_width);
53 extern unsigned long bitstream_getbytesLE(bitstream_t *bs, int byte_width);
54 extern unsigned long bitstream_getbytesBE(bitstream_t *bs, int byte_width);
55 extern int bitstream_putbit(bitstream_t *bs, int bit);
56 extern int bitstream_getbit(bitstream_t *bs);
57 extern int bitstream_putbits(bitstream_t *bs, unsigned long bits, int bit_width);
58 extern int bitstream_putbits_signed(bitstream_t *bs, signed long bits, int bit_width);
59 extern unsigned long bitstream_getbits(bitstream_t *bs, int bit_width);
60 extern signed long bitstream_getbits_signed(bitstream_t *bs, int bit_width);
61 extern void bitstream_align(bitstream_t *bs);
64 extern int bitstream_incrpos(bitstream_t *bs, signed long byte_incr,
65 signed long bit_incr);
66 extern int bitstream_setpos(bitstream_t *bs, unsigned long byte_offset,
67 unsigned long bit_offset);
68 extern unsigned long bitstream_getbytepos(bitstream_t *bs);
69 extern unsigned long bitstream_getbitpos(bitstream_t *bs);
71 extern int bitstream_realloc(bitstream_t *bs);
74 extern unsigned char *bitstream_buffer(bitstream_t *bs, unsigned long byte_offset);
75 extern unsigned long bitstream_length(bitstream_t *bs);
79 extern signed long bitstream_unsigned2signed(unsigned long num, int size);
80 extern unsigned long bitstream_signed2unsigned(signed long num, int size);
82 extern int bitstream_need_bits_unsigned(unsigned long n);
83 extern int bitstream_need_bits_signed(signed long n);
86 extern int bitstream_iserror(bitstream_t *bs);
87 extern void bitstream_printerror(bitstream_t *bs);
90 extern void bitstream_hexdump(bitstream_t *bs, int length);
91 extern void bitstream_print(bitstream_t *bs);
94 #ifdef BITSTREAM_DEBUG /* bitstream debug */
96 extern void bitstream_debug_start(void);
97 extern void bitstream_debug_end(void);
99 #define bitstream_open() bitstream_open_debug(__FILE__, __LINE__)
100 #define bitstream_close(bs) bitstream_close_debug(bs, __FILE__, __LINE__)
101 extern bitstream_t *bitstream_open_debug(char *filename, int linenum);
102 extern void bitstream_close_debug(bitstream_t *bs, char *filename, int linenum);
104 #else // BITSTREAM_DEBUG
106 #define bitstream_debug_start()
107 #define bitstream_debug_end()
109 #endif // BITSTREAM_DEBUG
111 #endif /* __BITSTREAM_H__ */