OSDN Git Service

test for replaceBitmapData Lossless with alpha0
[swfed/swfed.git] / src / bitstream.h
1 #ifndef __BITSTREAM_H__
2 #define __BITSTREAM_H__
3
4 #include "swf_define.h" /* for malloc */
5
6 /*
7  * bit stream routine
8  *                     (C) 2008/03/09- yoya@awm.jp
9  */
10
11 #ifndef BITOPERATION_OPTIMIZE
12 #define BITOPERATION_OPTIMIZE 0
13 #endif
14
15 typedef struct bitstream_ {
16     /* raw data */
17     unsigned char *data;
18     unsigned long data_len;
19     unsigned long data_alloc_len;
20     /* seek position */
21     unsigned long byte_offset;
22     unsigned long bit_offset;
23     /* error */
24     int error;
25     
26 } bitstream_t;
27
28 #define BITSTREAM_DATA_LEN_MIN 0x100
29
30 #define BITSTREAM_ERROR_NONE 0
31 #define BITSTREAM_ERROR_NOMORE_DATA 1
32
33 extern bitstream_t *bitstream_open(void);
34 extern void bitstream_close(bitstream_t * bs);
35
36 /* load/save */
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);
41
42 /* put/get */
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);
50
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);
62
63 /* seeking */
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);
70
71 extern int bitstream_realloc(bitstream_t *bs);
72
73 /* direct access */
74 extern unsigned char *bitstream_buffer(bitstream_t *bs, unsigned long byte_offset);
75 extern unsigned long bitstream_length(bitstream_t *bs);
76
77 /* utility */
78
79 extern signed long bitstream_unsigned2signed(unsigned long num, int size);
80 extern unsigned long bitstream_signed2unsigned(signed long num, int size);
81
82 extern int bitstream_need_bits_unsigned(unsigned long n);
83 extern int bitstream_need_bits_signed(signed long n);
84
85 /* error handling  */
86 extern int bitstream_iserror(bitstream_t *bs);
87 extern void bitstream_printerror(bitstream_t *bs);
88
89 /* for debug */
90 extern void bitstream_hexdump(bitstream_t *bs, int length);
91 extern void bitstream_print(bitstream_t *bs);
92
93
94 #ifdef BITSTREAM_DEBUG /* bitstream debug */
95
96 extern void bitstream_debug_start(void);
97 extern void bitstream_debug_end(void);
98
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);
103
104 #else // BITSTREAM_DEBUG
105
106 #define bitstream_debug_start()
107 #define bitstream_debug_end()
108
109 #endif // BITSTREAM_DEBUG
110
111 #endif /* __BITSTREAM_H__ */