1 /*
2 * p64-huff.h --
3 *
4 * P64 Huffman tables.
5 *
6 * Copyright (c) 1993-2002 The Regents of the University of California.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * A. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * B. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * C. Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
22 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * @(#) $Header: /usr/mash/src/repository/mash/mash-1/codec/p64/p64-huff.h,v 1.7 2002/04/26 21:16:51 lim Exp $
34 */
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 #define SYM_ESCAPE 0
41 #define SYM_EOB -1
42 #define SYM_STUFFBITS 0
43 #define SYM_STARTCODE -1
44 #define SYM_ILLEGAL -2
45 #define SYM_EOMB -3
46
47 /*
48 * Flags that indicate which types of encoding apply
49 * to a given macroblock type code.
50 *
51 * MT_QUANT new quantization factor present
52 * MT_CBP bit vector of which blocks present
53 * MT_INTRA this block is intra-coded (e.g., not differenced)
54 * MT_MFM motion vectors present (e.g., displacement of difference)
55 * MT_FILTER old block should be filtered before summing with xmitted blk
56 * MT_TCOEFF block present
57 */
58 #define MT_TCOEFF 0x01
59 #define MT_CBP 0x02
60 #define MT_MVD 0x04
61 #define MT_MQUANT 0x08
62 #define MT_FILTER 0x10
63 #define MT_INTRA 0x20
64
65 #ifndef HUFFSTRINGS
66
67 struct huffent {
68 int val;
69 int nb;
70 };
71
72 extern const unsigned char skiptab[];
73
74 /*
75 * Lookup tables that map an encoded prefix of the bit string,
76 * into the next symbol (for decoding).
77 */
78 extern const short htd_mtype[];
79 extern const short htd_mba[];
80 extern const short htd_cbp[];
81 extern const short htd_dvm[];
82 extern const short htd_tcoeff[];
83 extern const short htd_tcoeff_noeob[];
84
85 extern const int htd_mtype_width;
86 extern const int htd_mba_width;
87 extern const int htd_cbp_width;
88 extern const int htd_dvm_width;
89 extern const int htd_tcoeff_width;
90 extern const int htd_tcoeff_noeob_width;
91
92 /*
93 * Look up tables that produce a huffman encoding string
94 * from a symbol or group of symbols (for encoding).
95 */
96 extern struct huffent hte_mba[];
97 extern struct huffent hte_tc[];
98
99 #else
100 struct huffcode {
101 int val;
102 char* str;
103 };
104
105 static const struct huffcode hc_mtype[] = {
106 { MT_CBP|MT_TCOEFF, "1" },
107 { MT_FILTER|MT_MVD|MT_CBP|MT_TCOEFF, "01" },
108 { MT_FILTER|MT_MVD, "001" },
109 { MT_INTRA|MT_TCOEFF, "0001" },
110 { MT_MQUANT|MT_CBP|MT_TCOEFF, "00001" },
111 { MT_MQUANT|MT_FILTER|MT_MVD|MT_CBP|MT_TCOEFF, "000001" },
112 { MT_INTRA|MT_MQUANT|MT_TCOEFF, "0000001" },
113 { MT_MVD|MT_CBP|MT_TCOEFF, "00000001" },
114 { MT_MVD, "000000001" },
115 { MT_MQUANT|MT_CBP|MT_MVD|MT_TCOEFF, "0000000001" },
116 { 0, 0 }
117 };
118
119 static const struct huffcode hc_mba[] = {
120 { SYM_STUFFBITS, "00000001111" },
121 { SYM_STARTCODE, "0000000000000001" },
122 { 1, "1" },
123 { 2, "011" },
124 { 3, "010" },
125 { 4, "0011" },
126 { 5, "0010" },
127 { 6, "00011" },
128 { 7, "00010" },
129 { 8, "0000111" },
130 { 9, "0000110" },
131 { 10, "00001011" },
132 { 11, "00001010" },
133 { 12, "00001001" },
134 { 13, "00001000" },
135 { 14, "00000111" },
136 { 15, "00000110" },
137 { 16, "0000010111" },
138 { 17, "0000010110" },
139 { 18, "0000010101" },
140 { 19, "0000010100" },
141 { 20, "0000010011" },
142 { 21, "0000010010" },
143 { 22, "00000100011" },
144 { 23, "00000100010" },
145 { 24, "00000100001" },
146 { 25, "00000100000" },
147 { 26, "00000011111" },
148 { 27, "00000011110" },
149 { 28, "00000011101" },
150 { 29, "00000011100" },
151 { 30, "00000011011" },
152 { 31, "00000011010" },
153 { 32, "00000011001" },
154 { 33, "00000011000" },
155 { 0, 0 }
156 };
157
158 static const huffcode hc_cbp[] = {
159 { 1, "01011" },
160 { 2, "01001" },
161 { 3, "001101" },
162 { 4, "1101" },
163 { 5, "0010111" },
164 { 6, "0010011" },
165 { 7, "00011111" },
166 { 8, "1100" },
167 { 9, "0010110" },
168 { 10, "0010010" },
169 { 11, "00011110" },
170 { 12, "10011" },
171 { 13, "00011011" },
172 { 14, "00010111" },
173 { 15, "00010011" },
174 { 16, "1011" },
175 { 17, "0010101" },
176 { 18, "0010001" },
177 { 19, "00011101" },
178 { 20, "10001" },
179 { 21, "00011001" },
180 { 22, "00010101" },
181 { 23, "00010001" },
182 { 24, "001111" },
183 { 25, "00001111" },
184 { 26, "00001101" },
185 { 27, "000000011" },
186 { 28, "01111" },
187 { 29, "00001011" },
188 { 30, "00000111" },
189 { 31, "000000111" },
190 { 32, "1010" },
191 { 33, "0010100" },
192 { 34, "0010000" },
193 { 35, "00011100" },
194 { 36, "001110" },
195 { 37, "00001110" },
196 { 38, "00001100" },
197 { 39, "000000010" },
198 { 40, "10000" },
199 { 41, "00011000" },
200 { 42, "00010100" },
201 { 43, "00010000" },
202 { 44, "01110" },
203 { 45, "00001010" },
204 { 46, "00000110" },
205 { 47, "000000110" },
206 { 48, "10010" },
207 { 49, "00011010" },
208 { 50, "00010110" },
209 { 51, "00010010" },
210 { 52, "01101" },
211 { 53, "00001001" },
212 { 54, "00000101" },
213 { 55, "000000101" },
214 { 56, "01100" },
215 { 57, "00001000" },
216 { 58, "00000100" },
217 { 59, "000000100" },
218 { 60, "111" },
219 { 61, "01010" },
220 { 62, "01000" },
221 { 63, "001100" },
222 { 0, 0 }
223 };
224
225 static const struct huffcode hc_dvm[] = {
226 { -16, "00000011001" },
227 { -15, "00000011011" },
228 { -14, "00000011101" },
229 { -13, "00000011111" },
230 { -12, "00000100001" },
231 { -11, "00000100011" },
232 { -10, "0000010011" },
233 { -9, "0000010101" },
234 { -8, "0000010111" },
235 { -7, "00000111" },
236 { -6, "00001001" },
237 { -5, "00001011" },
238 { -4, "0000111" },
239 { -3, "00011" },
240 { -2, "0011" },
241 { -1, "011" },
242 { 0, "1" },
243 { 1, "010" },
244 { 2, "0010" },
245 { 3, "00010" },
246 { 4, "0000110" },
247 { 5, "00001010" },
248 { 6, "00001000" },
249 { 7, "00000110" },
250 { 8, "0000010110" },
251 { 9, "0000010100" },
252 { 10, "0000010010" },
253 { 11, "00000100010" },
254 { 12, "00000100000" },
255 { 13, "00000011110" },
256 { 14, "00000011100" },
257 { 15, "00000011010" },
258 { 0, 0 }
259 };
260
261 /*
262 * The signs of the values below are determined by the last
263 * bit in the huffman code. Rather than special case them
264 * in the decoding process, we make this table twice as big.
265 * (Note that we have to be careful that SYM_ESCAPE = -1
266 * or SYM_ILLEGAL = -2 don't crop up here -- they don't.)
267 */
268 static const struct huffcode hc_tcoeff[] = {
269 { SYM_EOB, "10" },
270 { SYM_ESCAPE, "000001" },
271 #define TC_RUN(x) (x)
272 #define TC_LEVEL(x) (((x) & 0x1f) << 5)
273 { TC_RUN(0)|TC_LEVEL(1), "110" },
274 { TC_RUN(0)|TC_LEVEL(-1), "111" },
275 { TC_RUN(0)|TC_LEVEL(2), "01000" },
276 { TC_RUN(0)|TC_LEVEL(-2), "01001" },
277 { TC_RUN(0)|TC_LEVEL(3), "001010" },
278 { TC_RUN(0)|TC_LEVEL(-3), "001011" },
279 { TC_RUN(0)|TC_LEVEL(4), "00001100" },
280 { TC_RUN(0)|TC_LEVEL(-4), "00001101" },
281 { TC_RUN(0)|TC_LEVEL(5), "001001100" },
282 { TC_RUN(0)|TC_LEVEL(-5), "001001101" },
283 { TC_RUN(0)|TC_LEVEL(6), "001000010" },
284 { TC_RUN(0)|TC_LEVEL(-6), "001000011" },
285 { TC_RUN(0)|TC_LEVEL(7), "00000010100" },
286 { TC_RUN(0)|TC_LEVEL(-7), "00000010101" },
287 { TC_RUN(0)|TC_LEVEL(8), "0000000111010" },
288 { TC_RUN(0)|TC_LEVEL(-8), "0000000111011" },
289 { TC_RUN(0)|TC_LEVEL(9), "0000000110000" },
290 { TC_RUN(0)|TC_LEVEL(-9), "0000000110001" },
291 { TC_RUN(0)|TC_LEVEL(10), "0000000100110" },
292 { TC_RUN(0)|TC_LEVEL(-10), "0000000100111" },
293 { TC_RUN(0)|TC_LEVEL(11), "0000000100000" },
294 { TC_RUN(0)|TC_LEVEL(-11), "0000000100001" },
295 { TC_RUN(0)|TC_LEVEL(12), "00000000110100" },
296 { TC_RUN(0)|TC_LEVEL(-12), "00000000110101" },
297 { TC_RUN(0)|TC_LEVEL(13), "00000000110010" },
298 { TC_RUN(0)|TC_LEVEL(-13), "00000000110011" },
299 { TC_RUN(0)|TC_LEVEL(14), "00000000110000" },
300 { TC_RUN(0)|TC_LEVEL(-14), "00000000110001" },
301 { TC_RUN(0)|TC_LEVEL(15), "00000000101110" },
302 { TC_RUN(0)|TC_LEVEL(-15), "00000000101111" },
303 { TC_RUN(1)|TC_LEVEL(1), "0110" },
304 { TC_RUN(1)|TC_LEVEL(-1), "0111" },
305 { TC_RUN(1)|TC_LEVEL(2), "0001100" },
306 { TC_RUN(1)|TC_LEVEL(-2), "0001101" },
307 { TC_RUN(1)|TC_LEVEL(3), "001001010" },
308 { TC_RUN(1)|TC_LEVEL(-3), "001001011" },
309 { TC_RUN(1)|TC_LEVEL(4), "00000011000" },
310 { TC_RUN(1)|TC_LEVEL(-4), "00000011001" },
311 { TC_RUN(1)|TC_LEVEL(5), "0000000110110" },
312 { TC_RUN(1)|TC_LEVEL(-5), "0000000110111" },
313 { TC_RUN(1)|TC_LEVEL(6), "00000000101100" },
314 { TC_RUN(1)|TC_LEVEL(-6), "00000000101101" },
315 { TC_RUN(1)|TC_LEVEL(7), "00000000101010" },
316 { TC_RUN(1)|TC_LEVEL(-7), "00000000101011" },
317 { TC_RUN(2)|TC_LEVEL(1), "01010" },
318 { TC_RUN(2)|TC_LEVEL(-1), "01011" },
319 { TC_RUN(2)|TC_LEVEL(2), "00001000" },
320 { TC_RUN(2)|TC_LEVEL(-2), "00001001" },
321 { TC_RUN(2)|TC_LEVEL(3), "00000010110" },
322 { TC_RUN(2)|TC_LEVEL(-3), "00000010111" },
323 { TC_RUN(2)|TC_LEVEL(4), "0000000101000" },
324 { TC_RUN(2)|TC_LEVEL(-4), "0000000101001" },
325 { TC_RUN(2)|TC_LEVEL(5), "00000000101000" },
326 { TC_RUN(2)|TC_LEVEL(-5), "00000000101001" },
327 { TC_RUN(3)|TC_LEVEL(1), "001110" },
328 { TC_RUN(3)|TC_LEVEL(-1), "001111" },
329 { TC_RUN(3)|TC_LEVEL(2), "001001000" },
330 { TC_RUN(3)|TC_LEVEL(-2), "001001001" },
331 { TC_RUN(3)|TC_LEVEL(3), "0000000111000" },
332 { TC_RUN(3)|TC_LEVEL(-3), "0000000111001" },
333 { TC_RUN(3)|TC_LEVEL(4), "00000000100110" },
334 { TC_RUN(3)|TC_LEVEL(-4), "00000000100111" },
335 { TC_RUN(4)|TC_LEVEL(1), "001100" },
336 { TC_RUN(4)|TC_LEVEL(-1), "001101" },
337 { TC_RUN(4)|TC_LEVEL(2), "00000011110" },
338 { TC_RUN(4)|TC_LEVEL(-2), "00000011111" },
339 { TC_RUN(4)|TC_LEVEL(3), "0000000100100" },
340 { TC_RUN(4)|TC_LEVEL(-3), "0000000100101" },
341 { TC_RUN(5)|TC_LEVEL(1), "0001110" },
342 { TC_RUN(5)|TC_LEVEL(-1), "0001111" },
343 { TC_RUN(5)|TC_LEVEL(2), "00000010010" },
344 { TC_RUN(5)|TC_LEVEL(-2), "00000010011" },
345 { TC_RUN(5)|TC_LEVEL(3), "00000000100100" },
346 { TC_RUN(5)|TC_LEVEL(-3), "00000000100101" },
347 { TC_RUN(6)|TC_LEVEL(1), "0001010" },
348 { TC_RUN(6)|TC_LEVEL(-1), "0001011" },
349 { TC_RUN(6)|TC_LEVEL(2), "0000000111100" },
350 { TC_RUN(6)|TC_LEVEL(-2), "0000000111101" },
351 { TC_RUN(7)|TC_LEVEL(1), "0001000" },
352 { TC_RUN(7)|TC_LEVEL(-1), "0001001" },
353 { TC_RUN(7)|TC_LEVEL(2), "0000000101010" },
354 { TC_RUN(7)|TC_LEVEL(-2), "0000000101011" },
355 { TC_RUN(8)|TC_LEVEL(1), "00001110" },
356 { TC_RUN(8)|TC_LEVEL(-1), "00001111" },
357 { TC_RUN(8)|TC_LEVEL(2), "0000000100010" },
358 { TC_RUN(8)|TC_LEVEL(-2), "0000000100011" },
359 { TC_RUN(9)|TC_LEVEL(1), "00001010" },
360 { TC_RUN(9)|TC_LEVEL(-1), "00001011" },
361 { TC_RUN(9)|TC_LEVEL(2), "00000000100010" },
362 { TC_RUN(9)|TC_LEVEL(-2), "00000000100011" },
363 { TC_RUN(10)|TC_LEVEL(1), "001001110" },
364 { TC_RUN(10)|TC_LEVEL(-1), "001001111" },
365 { TC_RUN(10)|TC_LEVEL(2), "00000000100000" },
366 { TC_RUN(10)|TC_LEVEL(-2), "00000000100001" },
367 { TC_RUN(11)|TC_LEVEL(1), "001000110" },
368 { TC_RUN(11)|TC_LEVEL(-1), "001000111" },
369 { TC_RUN(12)|TC_LEVEL(1), "001000100" },
370 { TC_RUN(12)|TC_LEVEL(-1), "001000101" },
371 { TC_RUN(13)|TC_LEVEL(1), "001000000" },
372 { TC_RUN(13)|TC_LEVEL(-1), "001000001" },
373 { TC_RUN(14)|TC_LEVEL(1), "00000011100" },
374 { TC_RUN(14)|TC_LEVEL(-1), "00000011101" },
375 { TC_RUN(15)|TC_LEVEL(1), "00000011010" },
376 { TC_RUN(15)|TC_LEVEL(-1), "00000011011" },
377 { TC_RUN(16)|TC_LEVEL(1), "00000010000" },
378 { TC_RUN(16)|TC_LEVEL(-1), "00000010001" },
379 { TC_RUN(17)|TC_LEVEL(1), "0000000111110" },
380 { TC_RUN(17)|TC_LEVEL(-1), "0000000111111" },
381 { TC_RUN(18)|TC_LEVEL(1), "0000000110100" },
382 { TC_RUN(18)|TC_LEVEL(-1), "0000000110101" },
383 { TC_RUN(19)|TC_LEVEL(1), "0000000110010" },
384 { TC_RUN(19)|TC_LEVEL(-1), "0000000110011" },
385 { TC_RUN(20)|TC_LEVEL(1), "0000000101110" },
386 { TC_RUN(20)|TC_LEVEL(-1), "0000000101111" },
387 { TC_RUN(21)|TC_LEVEL(1), "0000000101100" },
388 { TC_RUN(21)|TC_LEVEL(-1), "0000000101101" },
389 { TC_RUN(22)|TC_LEVEL(1), "00000000111110" },
390 { TC_RUN(22)|TC_LEVEL(-1), "00000000111111" },
391 { TC_RUN(23)|TC_LEVEL(1), "00000000111100" },
392 { TC_RUN(23)|TC_LEVEL(-1), "00000000111101" },
393 { TC_RUN(24)|TC_LEVEL(1), "00000000111010" },
394 { TC_RUN(24)|TC_LEVEL(-1), "00000000111011" },
395 { TC_RUN(25)|TC_LEVEL(1), "00000000111000" },
396 { TC_RUN(25)|TC_LEVEL(-1), "00000000111001" },
397 { TC_RUN(26)|TC_LEVEL(1), "00000000110110" },
398 { TC_RUN(26)|TC_LEVEL(-1), "00000000110111" },
399 { 0, 0 }
400 };
401 #endif
402 #ifdef __cplusplus
403 }
404 #endif
405
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.