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