1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * bitio_random.h -- Functions for bitio to a file (random access)
|
---|
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 numbers on an array of chars. These routines are slower than the ones
|
---|
24 | * in "mem" files. but with these routines you can mix reads and writes, or
|
---|
25 | * multiple writes, on the array of chars at the same time and guarantee
|
---|
26 | * them to work, also you can seek to a point and do a write. The decode and
|
---|
27 | * encode functions cannot detect when the end off the character is reached
|
---|
28 | * and just continue processing.
|
---|
29 | *
|
---|
30 | * Modified:
|
---|
31 | * - long long seek and tell ops
|
---|
32 | * (1999-08-03 Tim Bell <[email protected]>)
|
---|
33 | **************************************************************************/
|
---|
34 |
|
---|
35 | #ifndef H_BITIO_RANDOM
|
---|
36 | #define H_BITIO_RANDOM
|
---|
37 |
|
---|
38 | #include "longlong.h"
|
---|
39 |
|
---|
40 |
|
---|
41 | typedef struct random_bitio_state
|
---|
42 | {
|
---|
43 | FILE *File;
|
---|
44 | unsigned char *Buf;
|
---|
45 | unsigned long Base;
|
---|
46 | unsigned long Used;
|
---|
47 | unsigned long pos;
|
---|
48 | unsigned long len;
|
---|
49 | unsigned long sft;
|
---|
50 | }
|
---|
51 | random_bitio_state;
|
---|
52 |
|
---|
53 |
|
---|
54 | /* NOTE : All bytes are filled high bit first */
|
---|
55 |
|
---|
56 |
|
---|
57 | void BIO_Random_Start (FILE * f, unsigned long len,
|
---|
58 | random_bitio_state * bs);
|
---|
59 | void BIO_Random_Done (random_bitio_state * bs);
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 | void BIO_Random_Decode_Start (void *buf, unsigned long pos,
|
---|
64 | random_bitio_state * bs);
|
---|
65 |
|
---|
66 | void BIO_Random_Encode_Bit (int bit, random_bitio_state * bs);
|
---|
67 |
|
---|
68 | int BIO_Random_Decode_Bit (random_bitio_state * bs);
|
---|
69 |
|
---|
70 |
|
---|
71 | void BIO_Random_Unary_Encode (unsigned long val, random_bitio_state * bs,
|
---|
72 | unsigned long *bits);
|
---|
73 | unsigned long BIO_Random_Unary_Decode (random_bitio_state * bs,
|
---|
74 | unsigned long *bits);
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 | void BIO_Random_Binary_Encode (unsigned long val, unsigned long b,
|
---|
79 | random_bitio_state * bs, unsigned long *bits);
|
---|
80 | unsigned long BIO_Random_Binary_Decode (unsigned long b, random_bitio_state * bs,
|
---|
81 | unsigned long *bits);
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 | void BIO_Random_Gamma_Encode (unsigned long val, random_bitio_state * bs,
|
---|
86 | unsigned long *bits);
|
---|
87 | unsigned long BIO_Random_Gamma_Decode (random_bitio_state * bs,
|
---|
88 | unsigned long *bits);
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 | void BIO_Random_Delta_Encode (unsigned long val, random_bitio_state * bs,
|
---|
93 | unsigned long *bits);
|
---|
94 | unsigned long BIO_Random_Delta_Decode (random_bitio_state * bs,
|
---|
95 | unsigned long *bits);
|
---|
96 |
|
---|
97 |
|
---|
98 | void BIO_Random_Elias_Encode (unsigned long val, unsigned long b, double s,
|
---|
99 | random_bitio_state * bs, unsigned long *bits);
|
---|
100 | unsigned long BIO_Random_Elias_Decode (unsigned long b, double s,
|
---|
101 | random_bitio_state * bs,
|
---|
102 | unsigned long *bits);
|
---|
103 |
|
---|
104 |
|
---|
105 | void BIO_Random_Bblock_Encode (unsigned long val, unsigned long b,
|
---|
106 | random_bitio_state * bs, unsigned long *bits);
|
---|
107 | unsigned long BIO_Random_Bblock_Decode (unsigned long b,
|
---|
108 | random_bitio_state * bs,
|
---|
109 | unsigned long *bits);
|
---|
110 |
|
---|
111 |
|
---|
112 | void BIO_Random_Seek (unsigned long pos, random_bitio_state * bs);
|
---|
113 |
|
---|
114 | void BIO_Random_Flush (random_bitio_state * bs);
|
---|
115 |
|
---|
116 | unsigned long BIO_Random_Tell (random_bitio_state * bs);
|
---|
117 |
|
---|
118 | #ifdef USE_LONG_LONG
|
---|
119 |
|
---|
120 | void BIO_Random_Seek_LL (mg_ullong pos, random_bitio_state * bs);
|
---|
121 | mg_ullong BIO_Random_Tell_LL (random_bitio_state * bs);
|
---|
122 |
|
---|
123 | #endif /* USE_LONG_LONG */
|
---|
124 |
|
---|
125 | #endif
|
---|