1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * bitio_mem.c -- Functions for bitio to memory
|
---|
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_mem.c 439 1999-08-10 21:23:37Z sjboddie $
|
---|
21 | *
|
---|
22 | **************************************************************************/
|
---|
23 |
|
---|
24 | /*
|
---|
25 | $Log$
|
---|
26 | Revision 1.1 1999/08/10 21:16:45 sjboddie
|
---|
27 | renamed mg-1.3d directory mg
|
---|
28 |
|
---|
29 | Revision 1.1 1998/11/17 09:31:47 rjmcnab
|
---|
30 | *** empty log message ***
|
---|
31 |
|
---|
32 | * Revision 1.1 1994/08/22 00:24:39 tes
|
---|
33 | * Initial placement under CVS.
|
---|
34 | *
|
---|
35 | */
|
---|
36 |
|
---|
37 | static char *RCSID = "$Id: bitio_mem.c 439 1999-08-10 21:23:37Z sjboddie $";
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | #include "sysfuncs.h"
|
---|
42 |
|
---|
43 | #include "bitio_m_mem.h"
|
---|
44 | #include "bitio_m.h"
|
---|
45 |
|
---|
46 | int fprintf (FILE *, const char *,...);
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | void
|
---|
51 | BIO_Mem_Encode_Start (void *buf, int rem, mem_bitio_state * bs)
|
---|
52 | {
|
---|
53 | ENCODE_START (buf, rem)
|
---|
54 | ENCODE_PAUSE (*bs)
|
---|
55 | }
|
---|
56 |
|
---|
57 | void
|
---|
58 | BIO_Mem_Encode_Done (mem_bitio_state * bs)
|
---|
59 | {
|
---|
60 | ENCODE_CONTINUE (*bs)
|
---|
61 | ENCODE_DONE
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | void
|
---|
66 | BIO_Mem_Decode_Start (void *buf, int rem, mem_bitio_state * bs)
|
---|
67 | {
|
---|
68 | DECODE_START (buf, rem)
|
---|
69 | DECODE_PAUSE (*bs)
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 | void
|
---|
76 | BIO_Mem_Unary_Encode (unsigned long val, mem_bitio_state * bs,
|
---|
77 | unsigned long *bits)
|
---|
78 | {
|
---|
79 | ENCODE_CONTINUE (*bs)
|
---|
80 | if (bits)
|
---|
81 | UNARY_ENCODE_L (val, *bits);
|
---|
82 | else
|
---|
83 | UNARY_ENCODE (val);
|
---|
84 | ENCODE_PAUSE (*bs)
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | unsigned long
|
---|
89 | BIO_Mem_Unary_Decode (mem_bitio_state * bs,
|
---|
90 | unsigned long *bits)
|
---|
91 | {
|
---|
92 | register unsigned long val;
|
---|
93 | DECODE_CONTINUE (*bs)
|
---|
94 | if (bits)
|
---|
95 | UNARY_DECODE_L (val, *bits);
|
---|
96 | else
|
---|
97 | UNARY_DECODE (val);
|
---|
98 | DECODE_PAUSE (*bs)
|
---|
99 | return (val);
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | void
|
---|
109 | BIO_Mem_Binary_Encode (unsigned long val, unsigned long b,
|
---|
110 | mem_bitio_state * bs, unsigned long *bits)
|
---|
111 | {
|
---|
112 | ENCODE_CONTINUE (*bs)
|
---|
113 | if (bits)
|
---|
114 | BINARY_ENCODE_L (val, b, *bits);
|
---|
115 | else
|
---|
116 | BINARY_ENCODE (val, b);
|
---|
117 | ENCODE_PAUSE (*bs)
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | unsigned long
|
---|
122 | BIO_Mem_Binary_Decode (unsigned long b, mem_bitio_state * bs,
|
---|
123 | unsigned long *bits)
|
---|
124 | {
|
---|
125 | register unsigned long val;
|
---|
126 | DECODE_CONTINUE (*bs)
|
---|
127 | if (bits)
|
---|
128 | BINARY_DECODE_L (val, b, *bits);
|
---|
129 | else
|
---|
130 | BINARY_DECODE (val, b);
|
---|
131 | DECODE_PAUSE (*bs)
|
---|
132 | return (val);
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 | void
|
---|
142 | BIO_Mem_Gamma_Encode (unsigned long val, mem_bitio_state * bs,
|
---|
143 | unsigned long *bits)
|
---|
144 | {
|
---|
145 | ENCODE_CONTINUE (*bs)
|
---|
146 | if (bits)
|
---|
147 | GAMMA_ENCODE_L (val, *bits);
|
---|
148 | else
|
---|
149 | GAMMA_ENCODE (val);
|
---|
150 | ENCODE_PAUSE (*bs)
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | unsigned long
|
---|
155 | BIO_Mem_Gamma_Decode (mem_bitio_state * bs, unsigned long *bits)
|
---|
156 | {
|
---|
157 | register unsigned long val;
|
---|
158 | DECODE_CONTINUE (*bs)
|
---|
159 | if (bits)
|
---|
160 | GAMMA_DECODE_L (val, *bits);
|
---|
161 | else
|
---|
162 | GAMMA_DECODE (val);
|
---|
163 | DECODE_PAUSE (*bs)
|
---|
164 | return (val);
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 | void
|
---|
171 | BIO_Mem_Delta_Encode (unsigned long val, mem_bitio_state * bs,
|
---|
172 | unsigned long *bits)
|
---|
173 | {
|
---|
174 | ENCODE_CONTINUE (*bs)
|
---|
175 | if (bits)
|
---|
176 | DELTA_ENCODE_L (val, *bits);
|
---|
177 | else
|
---|
178 | DELTA_ENCODE (val);
|
---|
179 | ENCODE_PAUSE (*bs)
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | unsigned long
|
---|
184 | BIO_Mem_Delta_Decode (mem_bitio_state * bs, unsigned long *bits)
|
---|
185 | {
|
---|
186 | register unsigned long val;
|
---|
187 | DECODE_CONTINUE (*bs)
|
---|
188 | if (bits)
|
---|
189 | DELTA_DECODE_L (val, *bits);
|
---|
190 | else
|
---|
191 | DELTA_DECODE (val);
|
---|
192 | DECODE_PAUSE (*bs)
|
---|
193 | return (val);
|
---|
194 | }
|
---|
195 |
|
---|
196 | void
|
---|
197 | BIO_Mem_Elias_Encode (unsigned long val, unsigned long b, double s,
|
---|
198 | mem_bitio_state * bs, unsigned long *bits)
|
---|
199 | {
|
---|
200 | ENCODE_CONTINUE (*bs)
|
---|
201 | if (bits)
|
---|
202 | ELIAS_ENCODE_L (val, b, s, *bits);
|
---|
203 | else
|
---|
204 | ELIAS_ENCODE (val, b, s);
|
---|
205 | ENCODE_PAUSE (*bs)
|
---|
206 | }
|
---|
207 |
|
---|
208 |
|
---|
209 | unsigned long
|
---|
210 | BIO_Mem_Elias_Decode (unsigned long b, double s,
|
---|
211 | mem_bitio_state * bs, unsigned long *bits)
|
---|
212 | {
|
---|
213 | register unsigned long val;
|
---|
214 | DECODE_CONTINUE (*bs)
|
---|
215 | if (bits)
|
---|
216 | ELIAS_DECODE_L (val, b, s, *bits);
|
---|
217 | else
|
---|
218 | ELIAS_DECODE (val, b, s);
|
---|
219 | DECODE_PAUSE (*bs)
|
---|
220 | return (val);
|
---|
221 | }
|
---|
222 |
|
---|
223 | void
|
---|
224 | BIO_Mem_Bblock_Encode (unsigned long val, unsigned long b,
|
---|
225 | mem_bitio_state * bs, unsigned long *bits)
|
---|
226 | {
|
---|
227 | ENCODE_CONTINUE (*bs)
|
---|
228 | if (bits)
|
---|
229 | BBLOCK_ENCODE_L (val, b, *bits);
|
---|
230 | else
|
---|
231 | BBLOCK_ENCODE (val, b);
|
---|
232 | ENCODE_PAUSE (*bs)
|
---|
233 | }
|
---|
234 |
|
---|
235 |
|
---|
236 | unsigned long
|
---|
237 | BIO_Mem_Bblock_Decode (unsigned long b, mem_bitio_state * bs,
|
---|
238 | unsigned long *bits)
|
---|
239 | {
|
---|
240 | register unsigned long val;
|
---|
241 | DECODE_CONTINUE (*bs)
|
---|
242 | if (bits)
|
---|
243 | BBLOCK_DECODE_L (val, b, *bits);
|
---|
244 | else
|
---|
245 | BBLOCK_DECODE (val, b);
|
---|
246 | DECODE_PAUSE (*bs)
|
---|
247 | return (val);
|
---|
248 | }
|
---|
249 |
|
---|
250 | void
|
---|
251 | BIO_Mem_Decode_Seek (unsigned long pos, mem_bitio_state * bs)
|
---|
252 | {
|
---|
253 | DECODE_CONTINUE (*bs)
|
---|
254 | DECODE_SEEK (pos);
|
---|
255 | DECODE_PAUSE (*bs)
|
---|
256 | }
|
---|