1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * bitio_stdio.h -- Functions for bitio to a file
|
---|
4 | * Copyright (C) 1994 Neil Sharman
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | * $Id: bitio_stdio.h 3745 2003-02-20 21:20:24Z mdewsnip $
|
---|
21 | *
|
---|
22 | **************************************************************************
|
---|
23 | *
|
---|
24 | * This file contains function definitions for doing bitwise input and output
|
---|
25 | * of number on a FILE*. With these function you cannot mix reads and writes
|
---|
26 | * on the FILE, or multiple writes, at the same time and guarantee them to
|
---|
27 | * work, also you cannot seek to a point and do a write. The decode function
|
---|
28 | * can detect when you run off the end of the file and will produce an
|
---|
29 | * approate error message.
|
---|
30 | *
|
---|
31 | *
|
---|
32 | **************************************************************************/
|
---|
33 |
|
---|
34 | #ifndef H_BITIO_STDIO
|
---|
35 | #define H_BITIO_STDIO
|
---|
36 |
|
---|
37 |
|
---|
38 | typedef struct stdio_bitio_state
|
---|
39 | {
|
---|
40 | FILE *File;
|
---|
41 | unsigned char Buff;
|
---|
42 | unsigned char Btg;
|
---|
43 | }
|
---|
44 | stdio_bitio_state;
|
---|
45 |
|
---|
46 |
|
---|
47 | /* NOTE : All bytes are filled high bit first */
|
---|
48 |
|
---|
49 |
|
---|
50 | void BIO_Stdio_Encode_Start (FILE * f, stdio_bitio_state * bs);
|
---|
51 | void BIO_Stdio_Encode_Done (stdio_bitio_state * bs);
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 | void BIO_Stdio_Decode_Start (FILE * f, stdio_bitio_state * bs);
|
---|
56 |
|
---|
57 |
|
---|
58 |
|
---|
59 | void BIO_Stdio_Encode_Bit (int bit, stdio_bitio_state * bs);
|
---|
60 | int BIO_Stdio_Decode_Bit (stdio_bitio_state * bs);
|
---|
61 |
|
---|
62 |
|
---|
63 | void BIO_Stdio_Unary_Encode (unsigned long val, stdio_bitio_state * bs,
|
---|
64 | unsigned long *bits);
|
---|
65 | unsigned long BIO_Stdio_Unary_Decode (stdio_bitio_state * bs,
|
---|
66 | unsigned long *bits);
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 | void BIO_Stdio_Binary_Encode (unsigned long val, unsigned long b,
|
---|
71 | stdio_bitio_state * bs, unsigned long *bits);
|
---|
72 | unsigned long BIO_Stdio_Binary_Decode (unsigned long b, stdio_bitio_state * bs,
|
---|
73 | unsigned long *bits);
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 | void BIO_Stdio_Gamma_Encode (unsigned long val, stdio_bitio_state * bs,
|
---|
78 | unsigned long *bits);
|
---|
79 | unsigned long BIO_Stdio_Gamma_Decode (stdio_bitio_state * bs,
|
---|
80 | unsigned long *bits);
|
---|
81 |
|
---|
82 |
|
---|
83 |
|
---|
84 | void BIO_Stdio_Delta_Encode (unsigned long val, stdio_bitio_state * bs,
|
---|
85 | unsigned long *bits);
|
---|
86 | unsigned long BIO_Stdio_Delta_Decode (stdio_bitio_state * bs,
|
---|
87 | unsigned long *bits);
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 | void BIO_Stdio_Elias_Encode (unsigned long val, unsigned long b, double s,
|
---|
92 | stdio_bitio_state * bs, unsigned long *bits);
|
---|
93 | unsigned long BIO_Stdio_Elias_Decode (unsigned long b, double s,
|
---|
94 | stdio_bitio_state * bs,
|
---|
95 | unsigned long *bits);
|
---|
96 |
|
---|
97 |
|
---|
98 | void BIO_Stdio_Bblock_Encode (unsigned long val, unsigned long b,
|
---|
99 | stdio_bitio_state * bs, unsigned long *bits);
|
---|
100 | unsigned long BIO_Stdio_Bblock_Decode (unsigned long b, stdio_bitio_state * bs,
|
---|
101 | unsigned long *bits);
|
---|
102 |
|
---|
103 |
|
---|
104 | void BIO_Stdio_Decode_Seek (unsigned long pos, stdio_bitio_state * bs);
|
---|
105 |
|
---|
106 | #endif
|
---|