Import the current wip animation datatype and subclasses. further development will...
[AROS.git] / workbench / classes / datatypes / mpegvideo / mpegdecoders.c
blob9c7c7a6efddb646688dacbe86f7268b1c125a3d9
2 /*
3 **
4 ** $VER: mpegdecoders.c 1.8 (27.5.97)
5 ** mpegvideo.datatype 1.8
6 **
7 ** This file contains all the routines for
8 ** Huffman decoding required in MPEG
9 **
10 ** Written 1996 by Roland 'Gizzy' Mainz
15 /* ansi includes */
16 #include <stdlib.h>
17 #include <string.h>
19 /* project includes */
20 #include "mpegproto.h"
21 #include "mpegmyassert.h"
22 #include "mpegdecoders.h"
23 #include "mpegutil.h"
25 /* local prototypes */
26 static void init_mb_addr_inc(void);
27 static void init_mb_type_P(void);
28 static void init_mb_type_B(void);
29 static void init_motion_vectors(void);
31 /* Decoding table for macroblock_address_increment */
32 mb_addr_inc_entry mb_addr_inc[ 2048 ];
34 /* Decoding table for macroblock_type in predictive-coded pictures */
35 mb_type_entry mb_type_P[ 64 ];
37 /* Decoding table for macroblock_type in bidirectionally-coded pictures */
38 mb_type_entry mb_type_B[ 64 ];
40 /* Decoding table for motion vectors */
41 motion_vectors_entry motion_vectors[ 2048 ];
43 /* Decoding table for coded_block_pattern */
44 const
45 coded_block_pattern_entry coded_block_pattern[ 512 ] =
47 {ERROR, 0}, {ERROR, 0},
48 {39, 9}, {27, 9}, {59, 9}, {55, 9}, {47, 9}, {31, 9},
49 {58, 8}, {58, 8}, {54, 8}, {54, 8}, {46, 8}, {46, 8}, {30, 8}, {30, 8},
50 {57, 8}, {57, 8}, {53, 8}, {53, 8}, {45, 8}, {45, 8}, {29, 8}, {29, 8},
51 {38, 8}, {38, 8}, {26, 8}, {26, 8}, {37, 8}, {37, 8}, {25, 8}, {25, 8},
52 {43, 8}, {43, 8}, {23, 8}, {23, 8}, {51, 8}, {51, 8}, {15, 8}, {15, 8},
53 {42, 8}, {42, 8}, {22, 8}, {22, 8}, {50, 8}, {50, 8}, {14, 8}, {14, 8},
54 {41, 8}, {41, 8}, {21, 8}, {21, 8}, {49, 8}, {49, 8}, {13, 8}, {13, 8},
55 {35, 8}, {35, 8}, {19, 8}, {19, 8}, {11, 8}, {11, 8}, { 7, 8}, { 7, 8},
56 {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
57 {10, 7}, {10, 7}, {10, 7}, {10, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7},
58 {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
59 { 9, 7}, { 9, 7}, { 9, 7}, { 9, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7},
60 {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6},
61 { 3, 6}, {3, 6}, { 3, 6}, { 3, 6}, { 3, 6}, { 3, 6}, { 3, 6}, { 3, 6},
62 {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6},
63 {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6},
64 {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
65 {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
66 { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5},
67 { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5}, { 2, 5},
68 {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5},
69 {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5},
70 { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5},
71 { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5}, { 1, 5},
72 {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5},
73 {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5},
74 {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5},
75 {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5},
76 {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5},
77 {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5},
78 {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5},
79 {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5},
80 {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5},
81 {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5},
82 {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5},
83 {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5},
84 {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5},
85 {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5},
86 {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
87 {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5},
88 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
89 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
90 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
91 {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
92 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
93 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
94 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
95 {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
96 { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4},
97 { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4},
98 { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4},
99 { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4}, { 8, 4},
100 { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4},
101 { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4},
102 { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4},
103 { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4}, { 4, 4},
104 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
105 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
106 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
107 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
108 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
109 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
110 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3},
111 {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}
114 /* Decoding table for dct_dc_size_luminance */
115 const
116 dct_dc_size_entry dct_dc_size_luminance[ 128 ] =
118 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
119 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
120 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
121 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
122 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
123 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
124 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
125 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
126 {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3},
127 {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {0, 3},
128 {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
129 {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
130 {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3},
131 {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3},
132 {5, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4},
133 {6, 5}, {6, 5}, {6, 5}, {6, 5}, {7, 6}, {7, 6}, {8, 7}, {(unsigned int)ERROR, 0}
136 /* Decoding table for dct_dc_size_chrominance */
137 const
138 dct_dc_size_entry dct_dc_size_chrominance[ 256 ] =
140 {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
141 {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
142 {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
143 {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
144 {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
145 {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
146 {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
147 {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
148 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
149 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
150 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
151 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
152 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
153 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
154 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
155 {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
156 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
157 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
158 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
159 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
160 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
161 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
162 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
163 {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
164 {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
165 {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
166 {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
167 {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
168 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
169 {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
170 {5, 5}, {5, 5}, {5, 5}, {5, 5}, {5, 5}, {5, 5}, {5, 5}, {5, 5},
171 {6, 6}, {6, 6}, {6, 6}, {6, 6}, {7, 7}, {7, 7}, {8, 8}, {(unsigned int)ERROR, 0}
174 /* DCT coeff tables. */
175 const
176 UWORD dct_coeff_tbl_0[ 256 ] =
178 0xffff, 0xffff, 0xffff, 0xffff,
179 0xffff, 0xffff, 0xffff, 0xffff,
180 0xffff, 0xffff, 0xffff, 0xffff,
181 0xffff, 0xffff, 0xffff, 0xffff,
182 0x052f, 0x051f, 0x050f, 0x04ff,
183 0x183f, 0x402f, 0x3c2f, 0x382f,
184 0x342f, 0x302f, 0x2c2f, 0x7c1f,
185 0x781f, 0x741f, 0x701f, 0x6c1f,
186 0x028e, 0x028e, 0x027e, 0x027e,
187 0x026e, 0x026e, 0x025e, 0x025e,
188 0x024e, 0x024e, 0x023e, 0x023e,
189 0x022e, 0x022e, 0x021e, 0x021e,
190 0x020e, 0x020e, 0x04ee, 0x04ee,
191 0x04de, 0x04de, 0x04ce, 0x04ce,
192 0x04be, 0x04be, 0x04ae, 0x04ae,
193 0x049e, 0x049e, 0x048e, 0x048e,
194 0x01fd, 0x01fd, 0x01fd, 0x01fd,
195 0x01ed, 0x01ed, 0x01ed, 0x01ed,
196 0x01dd, 0x01dd, 0x01dd, 0x01dd,
197 0x01cd, 0x01cd, 0x01cd, 0x01cd,
198 0x01bd, 0x01bd, 0x01bd, 0x01bd,
199 0x01ad, 0x01ad, 0x01ad, 0x01ad,
200 0x019d, 0x019d, 0x019d, 0x019d,
201 0x018d, 0x018d, 0x018d, 0x018d,
202 0x017d, 0x017d, 0x017d, 0x017d,
203 0x016d, 0x016d, 0x016d, 0x016d,
204 0x015d, 0x015d, 0x015d, 0x015d,
205 0x014d, 0x014d, 0x014d, 0x014d,
206 0x013d, 0x013d, 0x013d, 0x013d,
207 0x012d, 0x012d, 0x012d, 0x012d,
208 0x011d, 0x011d, 0x011d, 0x011d,
209 0x010d, 0x010d, 0x010d, 0x010d,
210 0x282c, 0x282c, 0x282c, 0x282c,
211 0x282c, 0x282c, 0x282c, 0x282c,
212 0x242c, 0x242c, 0x242c, 0x242c,
213 0x242c, 0x242c, 0x242c, 0x242c,
214 0x143c, 0x143c, 0x143c, 0x143c,
215 0x143c, 0x143c, 0x143c, 0x143c,
216 0x0c4c, 0x0c4c, 0x0c4c, 0x0c4c,
217 0x0c4c, 0x0c4c, 0x0c4c, 0x0c4c,
218 0x085c, 0x085c, 0x085c, 0x085c,
219 0x085c, 0x085c, 0x085c, 0x085c,
220 0x047c, 0x047c, 0x047c, 0x047c,
221 0x047c, 0x047c, 0x047c, 0x047c,
222 0x046c, 0x046c, 0x046c, 0x046c,
223 0x046c, 0x046c, 0x046c, 0x046c,
224 0x00fc, 0x00fc, 0x00fc, 0x00fc,
225 0x00fc, 0x00fc, 0x00fc, 0x00fc,
226 0x00ec, 0x00ec, 0x00ec, 0x00ec,
227 0x00ec, 0x00ec, 0x00ec, 0x00ec,
228 0x00dc, 0x00dc, 0x00dc, 0x00dc,
229 0x00dc, 0x00dc, 0x00dc, 0x00dc,
230 0x00cc, 0x00cc, 0x00cc, 0x00cc,
231 0x00cc, 0x00cc, 0x00cc, 0x00cc,
232 0x681c, 0x681c, 0x681c, 0x681c,
233 0x681c, 0x681c, 0x681c, 0x681c,
234 0x641c, 0x641c, 0x641c, 0x641c,
235 0x641c, 0x641c, 0x641c, 0x641c,
236 0x601c, 0x601c, 0x601c, 0x601c,
237 0x601c, 0x601c, 0x601c, 0x601c,
238 0x5c1c, 0x5c1c, 0x5c1c, 0x5c1c,
239 0x5c1c, 0x5c1c, 0x5c1c, 0x5c1c,
240 0x581c, 0x581c, 0x581c, 0x581c,
241 0x581c, 0x581c, 0x581c, 0x581c,
244 const
245 UWORD dct_coeff_tbl_1[ 16 ] =
247 0x00bb, 0x202b, 0x103b, 0x00ab,
248 0x084b, 0x1c2b, 0x541b, 0x501b,
249 0x009b, 0x4c1b, 0x481b, 0x045b,
250 0x0c3b, 0x008b, 0x182b, 0x441b,
253 const
254 UWORD dct_coeff_tbl_2[ 4 ] =
256 0x4019, 0x1429, 0x0079, 0x0839,
259 const
260 UWORD dct_coeff_tbl_3[ 4 ] =
262 0x0449, 0x3c19, 0x3819, 0x1029,
265 const
266 UWORD dct_coeff_next[ 256 ] =
268 0xffff, 0xffff, 0xffff, 0xffff,
269 0xf7d5, 0xf7d5, 0xf7d5, 0xf7d5,
270 0x0826, 0x0826, 0x2416, 0x2416,
271 0x0046, 0x0046, 0x2016, 0x2016,
272 0x1c15, 0x1c15, 0x1c15, 0x1c15,
273 0x1815, 0x1815, 0x1815, 0x1815,
274 0x0425, 0x0425, 0x0425, 0x0425,
275 0x1415, 0x1415, 0x1415, 0x1415,
276 0x3417, 0x0067, 0x3017, 0x2c17,
277 0x0c27, 0x0437, 0x0057, 0x2817,
278 0x0034, 0x0034, 0x0034, 0x0034,
279 0x0034, 0x0034, 0x0034, 0x0034,
280 0x1014, 0x1014, 0x1014, 0x1014,
281 0x1014, 0x1014, 0x1014, 0x1014,
282 0x0c14, 0x0c14, 0x0c14, 0x0c14,
283 0x0c14, 0x0c14, 0x0c14, 0x0c14,
284 0x0023, 0x0023, 0x0023, 0x0023,
285 0x0023, 0x0023, 0x0023, 0x0023,
286 0x0023, 0x0023, 0x0023, 0x0023,
287 0x0023, 0x0023, 0x0023, 0x0023,
288 0x0813, 0x0813, 0x0813, 0x0813,
289 0x0813, 0x0813, 0x0813, 0x0813,
290 0x0813, 0x0813, 0x0813, 0x0813,
291 0x0813, 0x0813, 0x0813, 0x0813,
292 0x0412, 0x0412, 0x0412, 0x0412,
293 0x0412, 0x0412, 0x0412, 0x0412,
294 0x0412, 0x0412, 0x0412, 0x0412,
295 0x0412, 0x0412, 0x0412, 0x0412,
296 0x0412, 0x0412, 0x0412, 0x0412,
297 0x0412, 0x0412, 0x0412, 0x0412,
298 0x0412, 0x0412, 0x0412, 0x0412,
299 0x0412, 0x0412, 0x0412, 0x0412,
300 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
301 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
302 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
303 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
304 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
305 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
306 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
307 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
308 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
309 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
310 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
311 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
312 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
313 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
314 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
315 0xfbe1, 0xfbe1, 0xfbe1, 0xfbe1,
316 0x0011, 0x0011, 0x0011, 0x0011,
317 0x0011, 0x0011, 0x0011, 0x0011,
318 0x0011, 0x0011, 0x0011, 0x0011,
319 0x0011, 0x0011, 0x0011, 0x0011,
320 0x0011, 0x0011, 0x0011, 0x0011,
321 0x0011, 0x0011, 0x0011, 0x0011,
322 0x0011, 0x0011, 0x0011, 0x0011,
323 0x0011, 0x0011, 0x0011, 0x0011,
324 0x0011, 0x0011, 0x0011, 0x0011,
325 0x0011, 0x0011, 0x0011, 0x0011,
326 0x0011, 0x0011, 0x0011, 0x0011,
327 0x0011, 0x0011, 0x0011, 0x0011,
328 0x0011, 0x0011, 0x0011, 0x0011,
329 0x0011, 0x0011, 0x0011, 0x0011,
330 0x0011, 0x0011, 0x0011, 0x0011,
331 0x0011, 0x0011, 0x0011, 0x0011,
334 const
335 UWORD dct_coeff_first[ 256 ] =
337 0xffff, 0xffff, 0xffff, 0xffff,
338 0xf7d5, 0xf7d5, 0xf7d5, 0xf7d5,
339 0x0826, 0x0826, 0x2416, 0x2416,
340 0x0046, 0x0046, 0x2016, 0x2016,
341 0x1c15, 0x1c15, 0x1c15, 0x1c15,
342 0x1815, 0x1815, 0x1815, 0x1815,
343 0x0425, 0x0425, 0x0425, 0x0425,
344 0x1415, 0x1415, 0x1415, 0x1415,
345 0x3417, 0x0067, 0x3017, 0x2c17,
346 0x0c27, 0x0437, 0x0057, 0x2817,
347 0x0034, 0x0034, 0x0034, 0x0034,
348 0x0034, 0x0034, 0x0034, 0x0034,
349 0x1014, 0x1014, 0x1014, 0x1014,
350 0x1014, 0x1014, 0x1014, 0x1014,
351 0x0c14, 0x0c14, 0x0c14, 0x0c14,
352 0x0c14, 0x0c14, 0x0c14, 0x0c14,
353 0x0023, 0x0023, 0x0023, 0x0023,
354 0x0023, 0x0023, 0x0023, 0x0023,
355 0x0023, 0x0023, 0x0023, 0x0023,
356 0x0023, 0x0023, 0x0023, 0x0023,
357 0x0813, 0x0813, 0x0813, 0x0813,
358 0x0813, 0x0813, 0x0813, 0x0813,
359 0x0813, 0x0813, 0x0813, 0x0813,
360 0x0813, 0x0813, 0x0813, 0x0813,
361 0x0412, 0x0412, 0x0412, 0x0412,
362 0x0412, 0x0412, 0x0412, 0x0412,
363 0x0412, 0x0412, 0x0412, 0x0412,
364 0x0412, 0x0412, 0x0412, 0x0412,
365 0x0412, 0x0412, 0x0412, 0x0412,
366 0x0412, 0x0412, 0x0412, 0x0412,
367 0x0412, 0x0412, 0x0412, 0x0412,
368 0x0412, 0x0412, 0x0412, 0x0412,
369 0x0010, 0x0010, 0x0010, 0x0010,
370 0x0010, 0x0010, 0x0010, 0x0010,
371 0x0010, 0x0010, 0x0010, 0x0010,
372 0x0010, 0x0010, 0x0010, 0x0010,
373 0x0010, 0x0010, 0x0010, 0x0010,
374 0x0010, 0x0010, 0x0010, 0x0010,
375 0x0010, 0x0010, 0x0010, 0x0010,
376 0x0010, 0x0010, 0x0010, 0x0010,
377 0x0010, 0x0010, 0x0010, 0x0010,
378 0x0010, 0x0010, 0x0010, 0x0010,
379 0x0010, 0x0010, 0x0010, 0x0010,
380 0x0010, 0x0010, 0x0010, 0x0010,
381 0x0010, 0x0010, 0x0010, 0x0010,
382 0x0010, 0x0010, 0x0010, 0x0010,
383 0x0010, 0x0010, 0x0010, 0x0010,
384 0x0010, 0x0010, 0x0010, 0x0010,
385 0x0010, 0x0010, 0x0010, 0x0010,
386 0x0010, 0x0010, 0x0010, 0x0010,
387 0x0010, 0x0010, 0x0010, 0x0010,
388 0x0010, 0x0010, 0x0010, 0x0010,
389 0x0010, 0x0010, 0x0010, 0x0010,
390 0x0010, 0x0010, 0x0010, 0x0010,
391 0x0010, 0x0010, 0x0010, 0x0010,
392 0x0010, 0x0010, 0x0010, 0x0010,
393 0x0010, 0x0010, 0x0010, 0x0010,
394 0x0010, 0x0010, 0x0010, 0x0010,
395 0x0010, 0x0010, 0x0010, 0x0010,
396 0x0010, 0x0010, 0x0010, 0x0010,
397 0x0010, 0x0010, 0x0010, 0x0010,
398 0x0010, 0x0010, 0x0010, 0x0010,
399 0x0010, 0x0010, 0x0010, 0x0010,
400 0x0010, 0x0010, 0x0010, 0x0010,
403 /* Macro for filling up the decoding table for mb_addr_inc */
404 #define ASSIGN1( start, end, step, val, num ) \
405 for( i = start ; i < end ; i+= step ) \
407 for( j = 0 ; j < step ; j++ ) \
409 mb_addr_inc[ i + j ] . value = val; \
410 mb_addr_inc[ i + j ] . num_bits = num; \
413 val--; \
419 *--------------------------------------------------------------
421 * init_mb_addr_inc --
423 * Initialize the VLC decoding table for macro_block_address_increment
425 * Results:
426 * The decoding table for macro_block_address_increment will
427 * be filled; illegal values will be filled as ERROR.
429 * Side effects:
430 * The global array mb_addr_inc will be filled.
432 *--------------------------------------------------------------
436 static
437 void init_mb_addr_inc( void )
439 int i, j, val;
441 for( i = 0 ; i < 8 ; i++ )
443 mb_addr_inc[ i ] . value = ERROR;
444 mb_addr_inc[ i ] . num_bits = 0;
447 mb_addr_inc[ 8 ] . value = MACRO_BLOCK_ESCAPE;
448 mb_addr_inc[ 8 ] . num_bits = 11;
450 for( i = 9 ; i < 15 ; i++ )
452 mb_addr_inc[ i ] . value = ERROR;
453 mb_addr_inc[ i ] . num_bits = 0;
456 mb_addr_inc[ 15 ] . value = MACRO_BLOCK_STUFFING;
457 mb_addr_inc[ 15 ] . num_bits = 11;
459 for( i = 16 ; i < 24 ; i++ )
461 mb_addr_inc[ i ] . value = ERROR;
462 mb_addr_inc[ i ] . num_bits = 0;
465 val = 33;
467 ASSIGN1( 24, 36, 1, val, 11 )
468 ASSIGN1( 36, 48, 2, val, 10 )
469 ASSIGN1( 48, 96, 8, val, 8 )
470 ASSIGN1( 96, 128, 16, val, 7 )
471 ASSIGN1( 128, 256, 64, val, 5 )
472 ASSIGN1( 256, 512, 128, val, 4 )
473 ASSIGN1( 512, 1024, 256, val, 3 )
474 ASSIGN1( 1024, 2048, 1024, val, 1 )
478 /* Macro for filling up the decoding table for mb_type */
479 #define ASSIGN2( start, end, quant, motion_forward, motion_backward, pattern, intra, num, mb_type ) \
480 for( i = start ; i < end ; i ++ ) \
482 mb_type[ i ] . mb_quant = quant; \
483 mb_type[ i ] . mb_motion_forward = motion_forward; \
484 mb_type[ i ] . mb_motion_backward = motion_backward; \
485 mb_type[ i ] . mb_pattern = pattern; \
486 mb_type[ i ] . mb_intra = intra; \
487 mb_type[ i ] . num_bits = num; \
493 *--------------------------------------------------------------
495 * init_mb_type_P --
497 * Initialize the VLC decoding table for macro_block_type in
498 * predictive-coded pictures.
500 * Results:
501 * The decoding table for macro_block_type in predictive-coded
502 * pictures will be filled; illegal values will be filled as ERROR.
504 * Side effects:
505 * The global array mb_type_P will be filled.
507 *--------------------------------------------------------------
511 static
512 void init_mb_type_P( void )
514 int i;
516 mb_type_P[ 0 ] . mb_quant =
517 mb_type_P[ 0 ] . mb_motion_forward =
518 mb_type_P[ 0 ] . mb_motion_backward =
519 mb_type_P[ 0 ] . mb_pattern =
520 mb_type_P[ 0 ] . mb_intra = ERROR;
521 mb_type_P[ 0 ] . num_bits = 0;
523 ASSIGN2( 1, 2, 1, 0, 0, 0, 1, 6, mb_type_P )
524 ASSIGN2( 2, 4, 1, 0, 0, 1, 0, 5, mb_type_P )
525 ASSIGN2( 4, 6, 1, 1, 0, 1, 0, 5, mb_type_P )
526 ASSIGN2( 6, 8, 0, 0, 0, 0, 1, 5, mb_type_P )
527 ASSIGN2( 8, 16, 0, 1, 0, 0, 0, 3, mb_type_P )
528 ASSIGN2( 16, 32, 0, 0, 0, 1, 0, 2, mb_type_P )
529 ASSIGN2( 32, 64, 0, 1, 0, 1, 0, 1, mb_type_P )
534 *--------------------------------------------------------------
536 * init_mb_type_B --
538 * Initialize the VLC decoding table for macro_block_type in
539 * bidirectionally-coded pictures.
541 * Results:
542 * The decoding table for macro_block_type in bidirectionally-coded
543 * pictures will be filled; illegal values will be filled as ERROR.
545 * Side effects:
546 * The global array mb_type_B will be filled.
548 *--------------------------------------------------------------
552 static
553 void init_mb_type_B( void )
555 int i;
557 mb_type_B[ 0 ] . mb_quant =
558 mb_type_B[ 0 ] . mb_motion_forward =
559 mb_type_B[ 0 ] . mb_motion_backward =
560 mb_type_B[ 0 ] . mb_pattern =
561 mb_type_B[ 0 ] . mb_intra = ERROR;
562 mb_type_B[ 0 ] . num_bits = 0;
564 ASSIGN2( 1, 2, 1, 0, 0, 0, 1, 6, mb_type_B );
565 ASSIGN2( 2, 3, 1, 0, 1, 1, 0, 6, mb_type_B );
566 ASSIGN2( 3, 4, 1, 1, 0, 1, 0, 6, mb_type_B );
567 ASSIGN2( 4, 6, 1, 1, 1, 1, 0, 5, mb_type_B );
568 ASSIGN2( 6, 8, 0, 0, 0, 0, 1, 5, mb_type_B );
569 ASSIGN2( 8, 12, 0, 1, 0, 0, 0, 4, mb_type_B );
570 ASSIGN2( 12, 16, 0, 1, 0, 1, 0, 4, mb_type_B );
571 ASSIGN2( 16, 24, 0, 0, 1, 0, 0, 3, mb_type_B );
572 ASSIGN2( 24, 32, 0, 0, 1, 1, 0, 3, mb_type_B );
573 ASSIGN2( 32, 48, 0, 1, 1, 0, 0, 2, mb_type_B );
574 ASSIGN2( 48, 64, 0, 1, 1, 1, 0, 2, mb_type_B );
578 /* Macro for filling up the decoding tables for motion_vectors */
579 #define ASSIGN3( start, end, step, val, num ) \
580 for( i = start; i < end; i+= step ) \
582 for( j = 0 ; j < step / 2 ; j++ ) \
584 motion_vectors[ i +j ] . code = val; \
585 motion_vectors[ i +j ] . num_bits = num; \
588 for( j = step / 2 ; j < step ; j++ ) \
590 motion_vectors[ i + j ] . code = -val; \
591 motion_vectors[ i + j ] . num_bits = num; \
594 val--; \
600 *--------------------------------------------------------------
602 * init_motion_vectors --
604 * Initialize the VLC decoding table for the various motion
605 * vectors, including motion_horizontal_forward_code,
606 * motion_vertical_forward_code, motion_horizontal_backward_code,
607 * and motion_vertical_backward_code.
609 * Results:
610 * The decoding table for the motion vectors will be filled;
611 * illegal values will be filled as ERROR.
613 * Side effects:
614 * The global array motion_vector will be filled.
616 *--------------------------------------------------------------
620 static
621 void init_motion_vectors( void )
623 int i, j, val = 16;
625 for( i = 0 ; i < 24 ; i++ )
627 motion_vectors[ i ] . code = ERROR;
628 motion_vectors[ i ] . num_bits = 0;
631 ASSIGN3( 24, 36, 2, val, 11 );
632 ASSIGN3( 36, 48, 4, val, 10 );
633 ASSIGN3( 48, 96, 16, val, 8 );
634 ASSIGN3( 96, 128, 32, val, 7 );
635 ASSIGN3( 128, 256, 128, val, 5 );
636 ASSIGN3( 256, 512, 256, val, 4 );
637 ASSIGN3( 512, 1024, 512, val, 3 );
638 ASSIGN3( 1024, 2048, 1024, val, 1 );
643 *--------------------------------------------------------------
645 * init_tables --
647 * Initialize all the tables for VLC decoding; this must be
648 * called when the system is set up before any decoding can
649 * take place.
651 * Results:
652 * All the decoding tables will be filled accordingly.
654 * Side effects:
655 * The corresponding global array for each decoding table
656 * will be filled.
658 *--------------------------------------------------------------
662 void init_tables( void )
664 init_mb_addr_inc();
665 init_mb_type_P();
666 init_mb_type_B();
667 init_motion_vectors();
669 #ifdef FLOATDCT
670 init_float_idct();
671 #endif
672 init_pre_idct();
677 *--------------------------------------------------------------
679 * DecodeDCTDCSizeLum --
681 * Huffman Decoder for dct_dc_size_luminance; location where
682 * the result of decoding will be placed is passed as argument.
683 * The decoded values are obtained by doing a table lookup on
684 * dct_dc_size_luminance.
686 * Results:
687 * The decoded value for dct_dc_size_luminance or ERROR for
688 * unbound values will be placed in the location specified.
690 * Side effects:
691 * Bit stream is irreversibly parsed.
693 *--------------------------------------------------------------
697 void decodeDCTDCSizeLum( struct MPEGVideoInstData *mvid, unsigned int *value )
699 unsigned int index;
701 show_bits7( index );
703 *value = dct_dc_size_luminance[ index ] . value;
705 flush_bits( dct_dc_size_luminance[ index ] . num_bits );
710 *--------------------------------------------------------------
712 * DecodeDCTDCSizeChrom --
714 * Huffman Decoder for dct_dc_size_chrominance; location where
715 * the result of decoding will be placed is passed as argument.
716 * The decoded values are obtained by doing a table lookup on
717 * dct_dc_size_chrominance.
719 * Results:
720 * The decoded value for dct_dc_size_chrominance or ERROR for
721 * unbound values will be placed in the location specified.
723 * Side effects:
724 * Bit stream is irreversibly parsed.
726 *--------------------------------------------------------------
730 void decodeDCTDCSizeChrom( struct MPEGVideoInstData *mvid, unsigned int *value )
732 unsigned int index;
734 show_bits8( index );
736 *value = dct_dc_size_chrominance[ index ] . value;
738 flush_bits( dct_dc_size_chrominance[ index ] . num_bits );
743 *--------------------------------------------------------------
745 * decodeDCTCoeff --
747 * Huffman Decoder for dct_coeff_first and dct_coeff_next;
748 * locations where the results of decoding: run and level, are to
749 * be placed and also the type of DCT coefficients, either
750 * dct_coeff_first or dct_coeff_next, are being passed as argument.
752 * The decoder first examines the next 8 bits in the input stream,
753 * and perform according to the following cases:
755 * '0000 0000' - examine 8 more bits (i.e. 16 bits total) and
756 * perform a table lookup on dct_coeff_tbl_0.
757 * One more bit is then examined to determine the sign
758 * of level.
760 * '0000 0001' - examine 4 more bits (i.e. 12 bits total) and
761 * perform a table lookup on dct_coeff_tbl_1.
762 * One more bit is then examined to determine the sign
763 * of level.
765 * '0000 0010' - examine 2 more bits (i.e. 10 bits total) and
766 * perform a table lookup on dct_coeff_tbl_2.
767 * One more bit is then examined to determine the sign
768 * of level.
770 * '0000 0011' - examine 2 more bits (i.e. 10 bits total) and
771 * perform a table lookup on dct_coeff_tbl_3.
772 * One more bit is then examined to determine the sign
773 * of level.
775 * otherwise - perform a table lookup on dct_coeff_tbl. If the
776 * value of run is not ESCAPE, extract one more bit
777 * to determine the sign of level; otherwise 6 more
778 * bits will be extracted to obtain the actual value
779 * of run , and then 8 or 16 bits to get the value of level.
783 * Results:
784 * The decoded values of run and level or ERROR for unbound values
785 * are placed in the locations specified.
787 * Side effects:
788 * Bit stream is irreversibly parsed.
790 *--------------------------------------------------------------
794 void decodeDCTCoeff( struct MPEGVideoInstData *mvid, const UWORD *dct_coeff_tbl, unsigned int *run, int *level )
796 DecodeDCTCoeff( dct_coeff_tbl, (*run), (*level) );
801 *--------------------------------------------------------------
803 * decodeDCTCoeffFirst --
805 * Huffman Decoder for dct_coeff_first. Locations for the
806 * decoded results: run and level, are being passed as
807 * arguments. Actual work is being done by calling DecodeDCTCoeff,
808 * with the table dct_coeff_first.
810 * Results:
811 * The decoded values of run and level for dct_coeff_first or
812 * ERROR for unbound values are placed in the locations given.
814 * Side effects:
815 * Bit stream is irreversibly parsed.
817 *--------------------------------------------------------------
821 void decodeDCTCoeffFirst( struct MPEGVideoInstData *mvid, unsigned int *run, int *level )
823 decodeDCTCoeff( mvid, dct_coeff_first, run, level );
828 *--------------------------------------------------------------
830 * decodeDCTCoeffNext --
832 * Huffman Decoder for dct_coeff_first. Locations for the
833 * decoded results: run and level, are being passed as
834 * arguments. Actual work is being done by calling DecodeDCTCoeff,
835 * with the table dct_coeff_next.
837 * Results:
838 * The decoded values of run and level for dct_coeff_next or
839 * ERROR for unbound values are placed in the locations given.
841 * Side effects:
842 * Bit stream is irreversibly parsed.
844 *--------------------------------------------------------------
848 void decodeDCTCoeffNext( struct MPEGVideoInstData *mvid, unsigned int *run, int *level )
850 decodeDCTCoeff( mvid, dct_coeff_next, run, level );