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 | **************************************************************************
|
---|
21 | *
|
---|
22 | * This file contains function definitions for doing bitwise input and output
|
---|
23 | * of number on a FILE*. With these function you cannot mix reads and writes
|
---|
24 | * on the FILE, or multiple writes, at the same time and guarantee them to
|
---|
25 | * work, also you cannot seek to a point and do a write. The decode function
|
---|
26 | * can detect when you run off the end of the file and will produce an
|
---|
27 | * approate error message.
|
---|
28 | *
|
---|
29 | *
|
---|
30 | **************************************************************************/
|
---|
31 |
|
---|
32 | #ifndef H_BITIO_STDIO
|
---|
33 | #define H_BITIO_STDIO
|
---|
34 |
|
---|
35 |
|
---|
36 | typedef struct stdio_bitio_state
|
---|
37 | {
|
---|
38 | FILE *File;
|
---|
39 | unsigned char Buff;
|
---|
40 | unsigned char Btg;
|
---|
41 | }
|
---|
42 | stdio_bitio_state;
|
---|
43 |
|
---|
44 |
|
---|
45 | /* NOTE : All bytes are filled high bit first */
|
---|
46 |
|
---|
47 |
|
---|
48 | void BIO_Stdio_Encode_Start (FILE * f, stdio_bitio_state * bs);
|
---|
49 | void BIO_Stdio_Encode_Done (stdio_bitio_state * bs);
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | void BIO_Stdio_Decode_Start (FILE * f, stdio_bitio_state * bs);
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | void BIO_Stdio_Encode_Bit (int bit, stdio_bitio_state * bs);
|
---|
58 | int BIO_Stdio_Decode_Bit (stdio_bitio_state * bs);
|
---|
59 |
|
---|
60 |
|
---|
61 | void BIO_Stdio_Unary_Encode (unsigned long val, stdio_bitio_state * bs,
|
---|
62 | unsigned long *bits);
|
---|
63 | unsigned long BIO_Stdio_Unary_Decode (stdio_bitio_state * bs,
|
---|
64 | unsigned long *bits);
|
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 | void BIO_Stdio_Binary_Encode (unsigned long val, unsigned long b,
|
---|
69 | stdio_bitio_state * bs, unsigned long *bits);
|
---|
70 | unsigned long BIO_Stdio_Binary_Decode (unsigned long b, stdio_bitio_state * bs,
|
---|
71 | unsigned long *bits);
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 | void BIO_Stdio_Gamma_Encode (unsigned long val, stdio_bitio_state * bs,
|
---|
76 | unsigned long *bits);
|
---|
77 | unsigned long BIO_Stdio_Gamma_Decode (stdio_bitio_state * bs,
|
---|
78 | unsigned long *bits);
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 | void BIO_Stdio_Delta_Encode (unsigned long val, stdio_bitio_state * bs,
|
---|
83 | unsigned long *bits);
|
---|
84 | unsigned long BIO_Stdio_Delta_Decode (stdio_bitio_state * bs,
|
---|
85 | unsigned long *bits);
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | void BIO_Stdio_Elias_Encode (unsigned long val, unsigned long b, double s,
|
---|
90 | stdio_bitio_state * bs, unsigned long *bits);
|
---|
91 | unsigned long BIO_Stdio_Elias_Decode (unsigned long b, double s,
|
---|
92 | stdio_bitio_state * bs,
|
---|
93 | unsigned long *bits);
|
---|
94 |
|
---|
95 |
|
---|
96 | void BIO_Stdio_Bblock_Encode (unsigned long val, unsigned long b,
|
---|
97 | stdio_bitio_state * bs, unsigned long *bits);
|
---|
98 | unsigned long BIO_Stdio_Bblock_Decode (unsigned long b, stdio_bitio_state * bs,
|
---|
99 | unsigned long *bits);
|
---|
100 |
|
---|
101 |
|
---|
102 | void BIO_Stdio_Decode_Seek (unsigned long pos, stdio_bitio_state * bs);
|
---|
103 |
|
---|
104 | #endif
|
---|