fixed graphics bug
[swftools.git] / lib / bitio.h
1 /* bitio.h
2    Generic object-oriented reading/writing.
3
4    Part of the swftools package.
5    
6    Copyright (c) 2001 Matthias Kramm <kramm@quiss.org> 
7  
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
21
22 #include <stdio.h>
23
24 #ifndef __rfxswf_bitio_h__
25 #define __rfxswf_bitio_h__
26
27 #define READER_TYPE_FILE 0
28 #define READER_TYPE_MEM  1
29 #define READER_TYPE_ZLIB 2
30 #define WRITER_TYPE_FILE 0
31 #define WRITER_TYPE_MEM  1
32 #define WRITER_TYPE_ZLIB 2
33 #define WRITER_TYPE_NULL 3
34
35 struct reader_t
36 {
37     int (*read)(struct reader_t*, void*data, int len);
38
39     void *internal;
40     int type;
41     unsigned char mybyte;
42     unsigned char bitpos;
43     int pos;
44 };
45
46 struct writer_t
47 {
48     int (*write)(struct writer_t*, void*data, int len);
49     void (*finish)(struct writer_t*);
50
51     void *internal;
52     int type;
53     unsigned char mybyte;
54     unsigned char bitpos;
55     int pos;
56 };
57
58 void reader_resetbits(struct reader_t*r);
59 unsigned int reader_readbit(struct reader_t*r);
60 unsigned int reader_readbits(struct reader_t*r, int num);
61
62 void writer_resetbits(struct writer_t*w);
63 void writer_writebit(struct writer_t*w, int bit);
64 void writer_writebits(struct writer_t*w, unsigned int data, int bits);
65
66 /* standard readers / writers */
67
68 void reader_init_filereader(struct reader_t*r, int handle);
69 void reader_init_zlibinflate(struct reader_t*r, struct reader_t*input);
70 void reader_init_memreader(struct reader_t*r, void*data, int length);
71
72 void writer_init_filewriter(struct writer_t*w, int handle);
73 void writer_init_filewriter2(struct writer_t*w, char*filename);
74 void writer_init_zlibdeflate(struct writer_t*w, struct writer_t*output);
75 void writer_init_memwriter(struct writer_t*r, void*data, int length);
76 void writer_init_nullwriter(struct writer_t*w);
77
78 #endif //__rfxswf_bitio_h__