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 | mg_u_long Base;
|
---|
46 | mg_u_long Used;
|
---|
47 | mg_u_long pos;
|
---|
48 | mg_u_long len;
|
---|
49 | mg_u_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, mg_u_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, mg_u_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 (mg_u_long val, random_bitio_state * bs,
|
---|
72 | mg_u_long *bits);
|
---|
73 | mg_u_long BIO_Random_Unary_Decode (random_bitio_state * bs,
|
---|
74 | mg_u_long *bits);
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 | void BIO_Random_Binary_Encode (mg_u_long val, mg_u_long b,
|
---|
79 | random_bitio_state * bs, mg_u_long *bits);
|
---|
80 | mg_u_long BIO_Random_Binary_Decode (mg_u_long b, random_bitio_state * bs,
|
---|
81 | mg_u_long *bits);
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 | void BIO_Random_Gamma_Encode (mg_u_long val, random_bitio_state * bs,
|
---|
86 | mg_u_long *bits);
|
---|
87 | mg_u_long BIO_Random_Gamma_Decode (random_bitio_state * bs,
|
---|
88 | mg_u_long *bits);
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 | void BIO_Random_Delta_Encode (mg_u_long val, random_bitio_state * bs,
|
---|
93 | mg_u_long *bits);
|
---|
94 | mg_u_long BIO_Random_Delta_Decode (random_bitio_state * bs,
|
---|
95 | mg_u_long *bits);
|
---|
96 |
|
---|
97 |
|
---|
98 | void BIO_Random_Elias_Encode (mg_u_long val, mg_u_long b, double s,
|
---|
99 | random_bitio_state * bs, mg_u_long *bits);
|
---|
100 | mg_u_long BIO_Random_Elias_Decode (mg_u_long b, double s,
|
---|
101 | random_bitio_state * bs,
|
---|
102 | mg_u_long *bits);
|
---|
103 |
|
---|
104 |
|
---|
105 | void BIO_Random_Bblock_Encode (mg_u_long val, mg_u_long b,
|
---|
106 | random_bitio_state * bs, mg_u_long *bits);
|
---|
107 | mg_u_long BIO_Random_Bblock_Decode (mg_u_long b,
|
---|
108 | random_bitio_state * bs,
|
---|
109 | mg_u_long *bits);
|
---|
110 |
|
---|
111 |
|
---|
112 | void BIO_Random_Seek (mg_u_long pos, random_bitio_state * bs);
|
---|
113 |
|
---|
114 | void BIO_Random_Flush (random_bitio_state * bs);
|
---|
115 |
|
---|
116 | mg_u_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
|
---|