zlib writer no longer calls finish() on it's output writer
[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_U 2
30 #define READER_TYPE_ZLIB_C 3
31 #define READER_TYPE_ZLIB READER_TYPE_ZLIB_U
32
33 #define WRITER_TYPE_FILE 0
34 #define WRITER_TYPE_MEM  1
35 #define WRITER_TYPE_ZLIB_C 2
36 #define WRITER_TYPE_ZLIB_U 3
37 #define WRITER_TYPE_NULL 4
38 #define WRITER_TYPE_ZLIB WRITER_TYPE_ZLIB_C
39
40 struct reader_t
41 {
42     int (*read)(struct reader_t*, void*data, int len);
43
44     void *internal;
45     int type;
46     unsigned char mybyte;
47     unsigned char bitpos;
48     int pos;
49 };
50
51 struct writer_t
52 {
53     int (*write)(struct writer_t*, void*data, int len);
54     void (*finish)(struct writer_t*);
55
56     void *internal;
57     int type;
58     unsigned char mybyte;
59     unsigned char bitpos;
60     int pos;
61 };
62
63 void reader_resetbits(struct reader_t*r);
64 unsigned int reader_readbit(struct reader_t*r);
65 unsigned int reader_readbits(struct reader_t*r, int num);
66
67 void writer_resetbits(struct writer_t*w);
68 void writer_writebit(struct writer_t*w, int bit);
69 void writer_writebits(struct writer_t*w, unsigned int data, int bits);
70
71 /* standard readers / writers */
72
73 void reader_init_filereader(struct reader_t*r, int handle);
74 void reader_init_zlibinflate(struct reader_t*r, struct reader_t*input);
75 void reader_init_memreader(struct reader_t*r, void*data, int length);
76
77 void writer_init_filewriter(struct writer_t*w, int handle);
78 void writer_init_filewriter2(struct writer_t*w, char*filename);
79 void writer_init_zlibdeflate(struct writer_t*w, struct writer_t*output);
80 void writer_init_memwriter(struct writer_t*r, void*data, int length);
81 void writer_init_nullwriter(struct writer_t*w);
82
83 #endif //__rfxswf_bitio_h__