]> git.sesse.net Git - vlc/blob - src/video_parser/vpar_blocks.c
. D�placement de deux structures de lookup dans le parseur
[vlc] / src / video_parser / vpar_blocks.c
1 /*****************************************************************************
2  * vpar_blocks.c : blocks parsing
3  * (c)1999 VideoLAN
4  *****************************************************************************/
5
6 /*****************************************************************************
7  * Preamble
8  *****************************************************************************/
9 #include <errno.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <sys/uio.h>
15
16 #include "config.h"
17 #include "common.h"
18 #include "mtime.h"
19 #include "vlc_thread.h"
20
21 #include "intf_msg.h"
22 #include "debug.h"                    /* ?? temporaire, requis par netlist.h */
23
24 #include "input.h"
25 #include "input_netlist.h"
26 #include "decoder_fifo.h"
27 #include "video.h"
28 #include "video_output.h"
29
30 #include "vdec_idct.h"
31 #include "video_decoder.h"
32 #include "vdec_motion.h"
33
34 #include "vpar_blocks.h"
35 #include "vpar_headers.h"
36 #include "vpar_synchro.h"
37 #include "video_parser.h"
38 #include "video_fifo.h"
39
40 /*
41  * Welcome to vpar_blocks.c ! Here's where the heavy processor-critical parsing
42  * task is done. This file is divided in several parts :
43  *  - Initialization of the lookup tables
44  *  - Decoding of coded blocks
45  *  - Decoding of motion vectors
46  *  - Decoding of the other macroblock structures
47  *  - Picture data parsing management (slices and error handling)
48  * It's a pretty long file. Good luck and have a nice day.
49  */
50
51
52 /*
53  * Initialization tables
54  */
55
56     /* Table for coded_block_pattern resolution */
57 static lookup_t     pl_coded_pattern[512] = 
58     { {MB_ERROR, 0}, {0, 9}, {39, 9}, {27, 9}, {59, 9}, {55, 9}, {47, 9}, {31, 9},
59     {58, 8}, {58, 8}, {54, 8}, {54, 8}, {46, 8}, {46, 8}, {30, 8}, {30, 8},
60     {57, 8}, {57, 8}, {53, 8}, {53, 8}, {45, 8}, {45, 8}, {29, 8}, {29, 8},
61     {38, 8}, {38, 8}, {26, 8}, {26, 8}, {37, 8}, {37, 8}, {25, 8}, {25, 8},
62     {43, 8}, {43, 8}, {23, 8}, {23, 8}, {51, 8}, {51, 8}, {15, 8}, {15, 8},
63     {42, 8}, {42, 8}, {22, 8}, {22, 8}, {50, 8}, {50, 8}, {14, 8}, {14, 8},
64     {41, 8}, {41, 8}, {21, 8}, {21, 8}, {49, 8}, {49, 8}, {13, 8}, {13, 8},
65     {35, 8}, {35, 8}, {19, 8}, {19, 8}, {11, 8}, {11, 8}, {7, 8}, {7, 8},
66     {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
67     {10, 7}, {10, 7}, {10, 7}, {10, 7}, {6, 7}, {6, 7}, {6, 7}, {6, 7}, 
68     {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7}, 
69     {9, 7}, {9, 7}, {9, 7}, {9, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, 
70     {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, {63, 6}, 
71     {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6}, 
72     {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, {36, 6}, 
73     {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}, 
74     {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
75     {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5}, {62, 5},
76     {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, 
77     {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, {2, 5}, 
78     {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, 
79     {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, {61, 5}, 
80     {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, 
81     {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, {1, 5}, 
82     {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, 
83     {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, {56, 5}, 
84     {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, 
85     {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, {52, 5}, 
86     {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, 
87     {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, {44, 5}, 
88     {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, 
89     {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, {28, 5}, 
90     {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, 
91     {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, {40, 5}, 
92     {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, 
93     {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, {20, 5}, 
94     {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, 
95     {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, {48, 5}, 
96     {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, 
97     {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, {12, 5}, 
98     {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, 
99     {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, 
100     {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, 
101     {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, 
102     {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, 
103     {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, 
104     {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, 
105     {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, 
106     {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, 
107     {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, 
108     {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, 
109     {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4}, {8, 4},
110     {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
111     {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, 
112     {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, 
113     {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
114     {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
115     {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
116     {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
117     {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
118     {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
119     {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
120     {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, 
121     {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3}, {60, 3} };
122
123     /* Tables for dc DCT coefficients 
124      * Tables are cut in two parts to reduce memory occupation
125      */
126     
127     /* Table B-12, dct_dc_size_luminance, codes 00xxx ... 11110 */
128 static lookup_t     pl_dct_dc_lum_init_table_1[32] =
129     { {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
130       {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
131       {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
132       {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {MB_ERROR, 0}
133     };
134
135     /* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */
136 static lookup_t     pl_dct_dc_lum_init_table_2[32] =
137     { {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6},
138       {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10,9}, {11,9},
139       {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
140       {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
141       {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0},
142       {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}, {MB_ERROR, 0}
143     };
144
145     /* Table B-13, dct_dc_size_chrominance, codes 00xxx ... 11110 */
146 static lookup_t     pl_dct_dc_chrom_init_table_1[32] =
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       {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
150       {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {MB_ERROR, 0}
151     };
152
153     /* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */
154 static lookup_t     pl_dct_dc_chrom_init_table_2[32] =
155     { {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
156       {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
157       {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7},
158       {8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10,10}, {11,10}
159     };
160     
161
162     /* Tables for ac DCT coefficients. There are cut in many parts to save space */
163     /* Table B-14, DCT coefficients table zero,
164      * codes 0100 ... 1xxx (used for first (DC) coefficient)
165      */
166 static dct_lookup_t pl_DCT_tab_dc[12] =
167     {
168         {0,2,4}, {2,1,4}, {1,1,3}, {1,1,3},
169         {0,1,1}, {0,1,1}, {0,1,1}, {0,1,1},
170         {0,1,1}, {0,1,1}, {0,1,1}, {0,1,1}
171     };
172
173     /* Table B-14, DCT coefficients table zero,
174      * codes 0100 ... 1xxx (used for all other coefficients)
175      */
176 static dct_lookup_t pl_DCT_tab_ac[12] =
177     {
178         {0,2,4},  {2,1,4},  {1,1,3},  {1,1,3},
179         {DCT_EOB,0,2}, {DCT_EOB,0,2}, {DCT_EOB,0,2}, {DCT_EOB,0,2}, /* EOB */
180         {0,1,2},  {0,1,2},  {0,1,2},  {0,1,2}
181     };
182
183     /* Table B-14, DCT coefficients table zero,
184      * codes 000001xx ... 00111xxx
185      */
186 static dct_lookup_t pl_DCT_tab0[60] =
187     {
188         {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6}, {DCT_ESCAPE,0,6},
189         /* Escape */
190         {2,2,7}, {2,2,7}, {9,1,7}, {9,1,7},
191         {0,4,7}, {0,4,7}, {8,1,7}, {8,1,7},
192         {7,1,6}, {7,1,6}, {7,1,6}, {7,1,6},
193         {6,1,6}, {6,1,6}, {6,1,6}, {6,1,6},
194         {1,2,6}, {1,2,6}, {1,2,6}, {1,2,6},
195         {5,1,6}, {5,1,6}, {5,1,6}, {5,1,6},
196         {13,1,8}, {0,6,8}, {12,1,8}, {11,1,8},
197         {3,2,8}, {1,3,8}, {0,5,8}, {10,1,8},
198         {0,3,5}, {0,3,5}, {0,3,5}, {0,3,5},
199         {0,3,5}, {0,3,5}, {0,3,5}, {0,3,5},
200         {4,1,5}, {4,1,5}, {4,1,5}, {4,1,5},
201         {4,1,5}, {4,1,5}, {4,1,5}, {4,1,5},
202         {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
203         {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5}
204     };
205
206     /* Table B-15, DCT coefficients table one,
207      * codes 000001xx ... 11111111
208      */
209 static dct_lookup_t pl_DCT_tab0a[252] =
210     {
211         {65,0,6}, {65,0,6}, {65,0,6}, {65,0,6}, /* Escape */
212         {7,1,7}, {7,1,7}, {8,1,7}, {8,1,7},
213         {6,1,7}, {6,1,7}, {2,2,7}, {2,2,7},
214         {0,7,6}, {0,7,6}, {0,7,6}, {0,7,6},
215         {0,6,6}, {0,6,6}, {0,6,6}, {0,6,6},
216         {4,1,6}, {4,1,6}, {4,1,6}, {4,1,6},
217         {5,1,6}, {5,1,6}, {5,1,6}, {5,1,6},
218         {1,5,8}, {11,1,8}, {0,11,8}, {0,10,8},
219         {13,1,8}, {12,1,8}, {3,2,8}, {1,4,8},
220         {2,1,5}, {2,1,5}, {2,1,5}, {2,1,5},
221         {2,1,5}, {2,1,5}, {2,1,5}, {2,1,5},
222         {1,2,5}, {1,2,5}, {1,2,5}, {1,2,5},
223         {1,2,5}, {1,2,5}, {1,2,5}, {1,2,5},
224         {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
225         {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
226         {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
227         {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
228         {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
229         {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
230         {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
231         {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
232         {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
233         {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
234         {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4}, /* EOB */
235         {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
236         {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
237         {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
238         {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
239         {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
240         {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
241         {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
242         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
243         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
244         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
245         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
246         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
247         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
248         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
249         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
250         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
251         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
252         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
253         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
254         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
255         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
256         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
257         {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
258         {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
259         {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
260         {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
261         {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
262         {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
263         {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
264         {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
265         {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
266         {0,4,5}, {0,4,5}, {0,4,5}, {0,4,5},
267         {0,4,5}, {0,4,5}, {0,4,5}, {0,4,5},
268         {0,5,5}, {0,5,5}, {0,5,5}, {0,5,5},
269         {0,5,5}, {0,5,5}, {0,5,5}, {0,5,5},
270         {9,1,7}, {9,1,7}, {1,3,7}, {1,3,7},
271         {10,1,7}, {10,1,7}, {0,8,7}, {0,8,7},
272         {0,9,7}, {0,9,7}, {0,12,8}, {0,13,8},
273         {2,3,8}, {4,2,8}, {0,14,8}, {0,15,8}
274     };
275
276     /* Table B-14, DCT coefficients table zero,
277      * codes 0000001000 ... 0000001111
278      */
279 static dct_lookup_t pl_DCT_tab1[8] =
280     {
281         {16,1,10}, {5,2,10}, {0,7,10}, {2,3,10},
282         {1,4,10}, {15,1,10}, {14,1,10}, {4,2,10}
283     };
284
285     /* Table B-15, DCT coefficients table one,
286      * codes 000000100x ... 000000111x
287      */
288 static dct_lookup_t pl_DCT_tab1a[8] =
289     {
290         {5,2,9}, {5,2,9}, {14,1,9}, {14,1,9},
291         {2,4,10}, {16,1,10}, {15,1,9}, {15,1,9}
292     };
293
294     /* Table B-14/15, DCT coefficients table zero / one,
295      * codes 000000010000 ... 000000011111
296      */
297 static dct_lookup_t pl_DCT_tab2[16] =
298     {
299         {0,11,12}, {8,2,12}, {4,3,12}, {0,10,12},
300         {2,4,12}, {7,2,12}, {21,1,12}, {20,1,12},
301         {0,9,12}, {19,1,12}, {18,1,12}, {1,5,12},
302         {3,3,12}, {0,8,12}, {6,2,12}, {17,1,12}
303     };
304
305     /* Table B-14/15, DCT coefficients table zero / one,
306      * codes 0000000010000 ... 0000000011111
307      */
308 static dct_lookup_t pl_DCT_tab3[16] =
309     {
310         {10,2,13}, {9,2,13}, {5,3,13}, {3,4,13},
311         {2,5,13}, {1,7,13}, {1,6,13}, {0,15,13},
312         {0,14,13}, {0,13,13}, {0,12,13}, {26,1,13},
313         {25,1,13}, {24,1,13}, {23,1,13}, {22,1,13}
314     };
315
316     /* Table B-14/15, DCT coefficients table zero / one,
317      * codes 00000000010000 ... 00000000011111
318      */
319 static dct_lookup_t pl_DCT_tab4[16] =
320     {
321         {0,31,14}, {0,30,14}, {0,29,14}, {0,28,14},
322         {0,27,14}, {0,26,14}, {0,25,14}, {0,24,14},
323         {0,23,14}, {0,22,14}, {0,21,14}, {0,20,14},
324         {0,19,14}, {0,18,14}, {0,17,14}, {0,16,14}
325     };
326
327     /* Table B-14/15, DCT coefficients table zero / one,
328      *   codes 000000000010000 ... 000000000011111
329      */
330 static dct_lookup_t pl_DCT_tab5[16] =
331     {
332     {0,40,15}, {0,39,15}, {0,38,15}, {0,37,15},
333     {0,36,15}, {0,35,15}, {0,34,15}, {0,33,15},
334     {0,32,15}, {1,14,15}, {1,13,15}, {1,12,15},
335     {1,11,15}, {1,10,15}, {1,9,15}, {1,8,15}
336     };
337
338     /* Table B-14/15, DCT coefficients table zero / one,
339      * codes 0000000000010000 ... 0000000000011111
340      */
341 static dct_lookup_t pl_DCT_tab6[16] =
342     {
343         {1,18,16}, {1,17,16}, {1,16,16}, {1,15,16},
344         {6,3,16}, {16,2,16}, {15,2,16}, {14,2,16},
345         {13,2,16}, {12,2,16}, {11,2,16}, {31,1,16},
346         {30,1,16}, {29,1,16}, {28,1,16}, {27,1,16}
347     };
348
349
350 /*
351  * Initialization of lookup tables
352  */
353
354 /*****************************************************************************
355  * vpar_InitCrop : Initialize the crop table for saturation
356  *                 (ISO/IEC 13818-2 section 7.4.3)
357  *****************************************************************************/
358 #if defined(MPEG2_COMPLIANT) && !defined(VDEC_DFT)
359 void vpar_InitCrop( vpar_thread_t * p_vpar )
360 {
361     int i_dummy;
362
363     p_vpar->pi_crop = p_vpar->pi_crop_buf + 4096;
364
365     for( i_dummy = -4096; i_dummy < -2048; i_dummy++ )
366     {
367         p_vpar->pi_crop[i_dummy] = -2048;
368     }
369     for( ; i_dummy < 2047; i_dummy++ )
370     {
371         p_vpar->pi_crop[i_dummy] = i_dummy;
372     }
373     for( ; i_dummy < 4095; i_dummy++ )
374     {
375         p_vpar->pi_crop[i_dummy] = 2047;
376     }
377 }
378 #endif
379
380 /*****************************************************************************
381  * vpar_InitMbAddrInc : Initialize the lookup table for mb_addr_inc
382  *****************************************************************************/
383
384 /* Function for filling up the lookup table for mb_addr_inc */
385 static void __inline__ FillMbAddrIncTable( vpar_thread_t * p_vpar,
386                                     int i_start, int i_end, int i_step, 
387                                     int * pi_value, int i_length )
388 {
389     int i_pos, i_offset;
390     for( i_pos = i_start ; i_pos < i_end ; i_pos += i_step )
391     {
392         for( i_offset = 0 ; i_offset < i_step ; i_offset ++ )
393         {
394             p_vpar->pl_mb_addr_inc[i_pos + i_offset].i_value = * pi_value;
395             p_vpar->pl_mb_addr_inc[i_pos + i_offset].i_length = i_length;
396         }
397         (*pi_value)--;
398     }
399 }
400     
401 /* Function that initialize the table using the last one */
402 void vpar_InitMbAddrInc( vpar_thread_t * p_vpar )
403 {
404     int i_dummy;
405     int i_value;
406     
407     for( i_dummy = 0 ; i_dummy < 8 ; i_dummy++ )
408     {
409         p_vpar->pl_mb_addr_inc[i_dummy].i_value = MB_ERROR;
410         p_vpar->pl_mb_addr_inc[i_dummy].i_length = 0;
411     }
412
413     p_vpar->pl_mb_addr_inc[8].i_value = MB_ADDRINC_ESCAPE;
414     p_vpar->pl_mb_addr_inc[8].i_length = 11;
415
416     for( i_dummy = 9 ; i_dummy < 15 ; i_dummy ++ ) 
417     {
418         p_vpar->pl_mb_addr_inc[i_dummy].i_value =  MB_ERROR;
419         p_vpar->pl_mb_addr_inc[i_dummy].i_length = 0;
420     }
421
422     p_vpar->pl_mb_addr_inc[15].i_value = MB_ADDRINC_STUFFING;
423     p_vpar->pl_mb_addr_inc[15].i_length = 11;
424
425     for( i_dummy = 16; i_dummy < 24; i_dummy++ ) 
426     {
427         p_vpar->pl_mb_addr_inc[i_dummy].i_value =  MB_ERROR;
428         p_vpar->pl_mb_addr_inc[i_dummy].i_length = 0;
429     }
430     
431     i_value = 33;
432     
433     FillMbAddrIncTable( p_vpar, 24, 36, 1, &i_value, 11 );
434     FillMbAddrIncTable( p_vpar, 36, 48, 2, &i_value, 10 );
435     FillMbAddrIncTable( p_vpar, 48, 96, 8, &i_value, 8 );
436     FillMbAddrIncTable( p_vpar, 96, 128, 16, &i_value, 7 );
437     FillMbAddrIncTable( p_vpar, 128, 256, 64, &i_value, 5 );
438     FillMbAddrIncTable( p_vpar, 256, 512, 128, &i_value, 4 );
439     FillMbAddrIncTable( p_vpar, 512, 1024, 256, &i_value, 3 );
440     FillMbAddrIncTable( p_vpar, 1024, 2048, 1024, &i_value, 1 );
441 }
442
443 /*****************************************************************************
444  * vpar_Init*MBType : Initialize lookup table for the Macroblock type
445  *****************************************************************************/
446
447 /* Fonction for filling up the tables */
448 static void __inline__ FillMBType( vpar_thread_t * p_vpar,
449                                    int           i_mb_type,
450                                    int           i_start,
451                                    int           i_end,
452                                    int           i_value,
453                                    int           i_length )
454 {
455     int i_dummy;
456     
457     for( i_dummy = i_start ; i_dummy < i_end ; i_dummy++ )
458     {
459         p_vpar->ppl_mb_type[i_mb_type][i_dummy].i_value = i_value;
460         p_vpar->ppl_mb_type[i_mb_type][i_dummy].i_length = i_length;
461     }
462 }
463
464 /* Fonction that fills the table for P MB_Type */
465 void vpar_InitPMBType( vpar_thread_t * p_vpar )
466 {
467     FillMBType( p_vpar, 0, 32, 64, MB_MOTION_FORWARD|MB_PATTERN, 1 );
468     FillMBType( p_vpar, 0, 16, 32, MB_PATTERN, 2 );
469     FillMBType( p_vpar, 0, 8, 16, MB_MOTION_FORWARD, 3 );
470     FillMBType( p_vpar, 0, 6, 8, MB_INTRA, 5 );
471     FillMBType( p_vpar, 0, 4, 6, MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN, 5 );
472     FillMBType( p_vpar, 0, 2, 4, MB_QUANT|MB_PATTERN, 5 );
473     p_vpar->ppl_mb_type[0][1].i_value = MB_QUANT|MB_INTRA;
474     p_vpar->ppl_mb_type[0][1].i_length = 6;
475     p_vpar->ppl_mb_type[0][0].i_value = MB_ERROR;
476     p_vpar->ppl_mb_type[0][0].i_length = 0;
477 }
478
479 /* Fonction that fills the table for B MB_Type */
480 void vpar_InitBMBType( vpar_thread_t * p_vpar )
481 {
482     FillMBType( p_vpar, 1, 48, 64, MB_MOTION_FORWARD
483                                   |MB_MOTION_BACKWARD|MB_PATTERN, 2 );
484     FillMBType( p_vpar, 1, 32, 48, MB_MOTION_FORWARD|MB_MOTION_BACKWARD, 2 );
485     FillMBType( p_vpar, 1, 24, 32, MB_MOTION_BACKWARD|MB_PATTERN, 3 );
486     FillMBType( p_vpar, 1, 16, 24, MB_MOTION_BACKWARD, 3 );
487     FillMBType( p_vpar, 1, 12, 16, MB_MOTION_FORWARD|MB_PATTERN, 4 );
488     FillMBType( p_vpar, 1, 8, 12, MB_MOTION_FORWARD, 4 );
489     FillMBType( p_vpar, 1, 6, 8, MB_INTRA, 5 );
490     FillMBType( p_vpar, 1, 4, 6, MB_QUANT|MB_MOTION_FORWARD
491                                 |MB_MOTION_BACKWARD|MB_PATTERN, 5 );
492     p_vpar->ppl_mb_type[1][3].i_value = MB_QUANT|MB_MOTION_FORWARD|MB_PATTERN;
493     p_vpar->ppl_mb_type[1][3].i_length = 6;
494     p_vpar->ppl_mb_type[1][2].i_value = MB_QUANT|MB_MOTION_BACKWARD|MB_PATTERN;
495     p_vpar->ppl_mb_type[1][2].i_length = 6;
496     p_vpar->ppl_mb_type[1][1].i_value = MB_QUANT|MB_INTRA;
497     p_vpar->ppl_mb_type[1][1].i_length = 6;
498     p_vpar->ppl_mb_type[1][0].i_value =MB_ERROR;
499     p_vpar->ppl_mb_type[1][0].i_length = 0;
500 }
501
502
503 /*****************************************************************************
504  * vpar_InitDCTTables : Initialize tables giving the length of the dct
505  *                      coefficient from the vlc code
506  *****************************************************************************/
507
508 /* First fonction for filling the table */
509 static void __inline__ FillDCTTable( dct_lookup_t * p_tab_dest, dct_lookup_t * p_tab_src,
510                                      int i_step, int i_nb_elem, int i_offset )
511 {
512     int i_dummy, i_dummy2;
513
514     for( i_dummy=0 ; i_dummy < i_nb_elem ; i_dummy++ )
515     {
516         for( i_dummy2=0 ; i_dummy2 < i_step ; i_dummy2++ )
517         {
518             p_tab_dest[(i_dummy+i_offset)*i_step+i_dummy2] = p_tab_src[i_dummy];
519         }
520     }
521 }
522
523
524 /* Fonction that actually fills the table or create the pointers */
525 void vpar_InitDCTTables( vpar_thread_t * p_vpar )
526 {
527     /* Tables are cut in two parts to reduce memory occupation */    
528     p_vpar->pppl_dct_dc_size[0][0] = pl_dct_dc_lum_init_table_1;
529     p_vpar->pppl_dct_dc_size[0][1] = pl_dct_dc_lum_init_table_2;
530     p_vpar->pppl_dct_dc_size[1][0] = pl_dct_dc_chrom_init_table_1;
531     p_vpar->pppl_dct_dc_size[1][1] = pl_dct_dc_chrom_init_table_2;
532
533     memset( p_vpar->ppl_dct_coef[0], MB_ERROR, 16 );
534     memset( p_vpar->ppl_dct_coef[1], MB_ERROR, 16 );
535     
536     /* For table B14 & B15, we have a pointer to tables */
537     /* We fill the table thanks to the fonction defined above */
538     FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab0, 256, 60,  4 );
539     FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab1,  64,  8,  8 );
540     FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab2,  16, 16, 16 );
541     FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab3,   8, 16, 16 );
542     FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab4,   4, 16, 16 );
543     FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab5,   2, 16, 16 );
544     FillDCTTable( p_vpar->ppl_dct_coef[0], pl_DCT_tab6,   1, 16, 16 );
545
546     FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab0a, 256, 60, 4 );
547     FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab1a,  64,  8,  8 );
548     FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab2,   16, 16, 16 );
549     FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab3,    8, 16, 16 );
550     FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab4,    4, 16, 16 );
551     FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab5,    2, 16, 16 );
552     FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab6,    1, 16, 16 );
553 }
554
555
556 /*
557  * Block parsing
558  */
559
560 /*****************************************************************************
561  * DecodeMPEG1NonIntra : decode MPEG-1 non-intra blocks
562  *****************************************************************************/
563 static __inline__ void DecodeMPEG1NonIntra( vpar_thread_t * p_vpar,
564                                             macroblock_t * p_mb, int i_b,
565                                             int i_chroma_format )
566 {
567
568     if( p_vpar->picture.i_coding_type == D_CODING_TYPE )
569     {
570         /* Remove end_of_macroblock (always 1, prevents startcode emulation)
571          * ISO/IEC 11172-2 section 2.4.2.7 and 2.4.3.6 */
572         RemoveBits( &p_vpar->bit_stream, 1 );
573     }
574 }
575
576 /*****************************************************************************
577  * DecodeMPEG1Intra : decode MPEG-1 intra blocks
578  *****************************************************************************/
579 static __inline__ void DecodeMPEG1Intra( vpar_thread_t * p_vpar,
580                                          macroblock_t * p_mb, int i_b ,
581                                          int i_chroma_format )
582 {
583
584     if( p_vpar->picture.i_coding_type == D_CODING_TYPE )
585     {
586         /* Remove end_of_macroblock (always 1, prevents startcode emulation)
587          * ISO/IEC 11172-2 section 2.4.2.7 and 2.4.3.6 */
588         RemoveBits( &p_vpar->bit_stream, 1 );
589     }
590 }
591
592 /*****************************************************************************
593  * DecodeMPEG2NonIntra : decode MPEG-2 non-intra blocks
594  *****************************************************************************/
595 static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
596                                             macroblock_t * p_mb, int i_b,
597                                             int i_chroma_format )
598 {
599     int         i_parse;
600     int         i_nc;
601     int         i_cc;
602     int         i_coef;
603     int         i_type;
604     int         i_code;
605     int         i_length;
606     int         i_pos;
607     int         i_run;
608     int         i_level;
609     boolean_t   b_sign;
610     int *       pi_quant;
611     
612     /* Lookup Table for the chromatic component */
613     static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
614
615     i_cc = pi_cc_index[i_b];
616
617     /* Determine whether it is luminance or not (chrominance) */
618     i_type = ( i_cc + 1 ) >> 1;
619
620     /* Give a pointer to the quantization matrices for intra blocks */
621     if( (i_chroma_format == CHROMA_420) || (!i_type) )
622     {
623         pi_quant = p_vpar->sequence.nonintra_quant.pi_matrix;
624     }
625     else
626     {
627         pi_quant = p_vpar->sequence.chroma_nonintra_quant.pi_matrix;
628     }
629
630     /* Decoding of the AC coefficients */
631     
632     i_nc = 0;
633     i_coef = 0;
634     for( i_parse = 0; ; i_parse++ )
635     {
636         i_code = ShowBits( &p_vpar->bit_stream, 16 );
637         if( i_code >= 16384 )
638         {
639             if( i_parse == 0 )
640             {
641                 i_run =     pl_DCT_tab_dc[(i_code>>12)-4].i_run;
642                 i_level =   pl_DCT_tab_dc[(i_code>>12)-4].i_level;
643                 i_length =  pl_DCT_tab_dc[(i_code>>12)-4].i_length;
644             }
645             else
646             {
647                 i_run =     pl_DCT_tab_ac[(i_code>>12)-4].i_run;
648                 i_level =   pl_DCT_tab_ac[(i_code>>12)-4].i_level;
649                 i_length =  pl_DCT_tab_ac[(i_code>>12)-4].i_length;
650              }
651         }
652         else if( i_code >= 1024 )
653         {
654             i_run =     pl_DCT_tab0[(i_code>>8)-4].i_run;
655             i_length =  pl_DCT_tab0[(i_code>>8)-4].i_length;
656             i_level =   pl_DCT_tab0[(i_code>>8)-4].i_level;
657         }
658         else
659         {
660             i_run =     p_vpar->ppl_dct_coef[0][i_code].i_run;
661             i_length =  p_vpar->ppl_dct_coef[0][i_code].i_length;
662             i_level =   p_vpar->ppl_dct_coef[0][i_code].i_level;
663         }
664
665         
666         RemoveBits( &p_vpar->bit_stream, i_length );
667
668         switch( i_run )
669         {
670             case DCT_ESCAPE:
671                 i_run = GetBits( &p_vpar->bit_stream, 6 );
672                 i_level = GetBits( &p_vpar->bit_stream, 12 );
673                 i_level = (b_sign = ( i_level > 2047 )) ? 4096 - i_level
674                                                         : i_level;
675                 break;
676             case DCT_EOB:
677                 if( i_nc <= 1 )
678                 {
679                     p_mb->pf_idct[i_b] = vdec_SparseIDCT;
680                     p_mb->pi_sparse_pos[i_b] = i_coef;
681                 }
682                 else
683                 {
684                     p_mb->pf_idct[i_b] = vdec_IDCT;
685                 }
686                 return;
687
688                 break;
689             default:
690                 b_sign = GetBits( &p_vpar->bit_stream, 1 );
691         }
692         i_coef = i_parse;
693         i_parse += i_run;
694         i_nc ++;
695
696         if( i_parse >= 64 )
697         {
698             break;
699         }
700         
701         i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
702         i_level = ( ((i_level << 1) + 1) * p_vpar->mb.i_quantizer_scale 
703                     * pi_quant[i_pos] ) >> 5;
704         p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
705     }
706
707     intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds\n");
708     p_vpar->picture.b_error = 1;
709 }
710
711 /*****************************************************************************
712  * DecodeMPEG2Intra : decode MPEG-2 intra blocks
713  *****************************************************************************/
714 static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
715                                          macroblock_t * p_mb, int i_b,
716                                          int i_chroma_format )
717 {
718     int         i_parse;
719     int         i_nc;
720     int         i_cc;
721     int         i_coef;
722     int         i_type;
723     int         i_code;
724     int         i_length;
725     int         i_pos;
726     int         i_dct_dc_size;
727     int         i_dct_dc_diff;
728     int         i_run;
729     int         i_level;
730     boolean_t   b_vlc_intra;
731     boolean_t   b_sign;
732     int *       pi_quant;
733     
734     /* Lookup Table for the chromatic component */
735     static int pi_cc_index[12] = { 0, 0, 0, 0, 1, 2, 1, 2, 1, 2 };
736     i_cc = pi_cc_index[i_b];
737
738     /* Determine whether it is luminance or not (chrominance) */
739     i_type = ( i_cc + 1 ) >> 1;
740
741     /* Give a pointer to the quantization matrices for intra blocks */
742     if( (i_chroma_format == CHROMA_420) || (!i_type) )
743     {
744         pi_quant = p_vpar->sequence.intra_quant.pi_matrix;
745     }
746     else
747     {
748         pi_quant = p_vpar->sequence.chroma_intra_quant.pi_matrix;
749     }
750
751 #if 0    
752     /* Decoding of the DC intra coefficient */
753     /* The nb of bits to parse depends on i_type */
754     i_code = ShowBits( &p_vpar->bit_stream, 9 + i_type );
755     
756     /* To reduce memory occupation, there are two lookup tables
757      * See InitDCT above */
758     i_code5 = i_code >> (4+i_type);
759     
760     /* Shall we lookup in the first or in the second table ? */
761     i_select = ( i_code5 == 31 );
762     /* Offset value for looking in the second table */
763     i_offset = 0x1f0 + ( i_type * 0x1f0 );
764     i_pos = ( i_code5 * ( ! i_select ) ) + ( ( i_code - i_offset ) * i_select );
765     i_dct_dc_size = p_vpar->pppl_dct_dc_size[i_type][i_select][i_pos].i_value;
766 #endif
767     
768     if( !i_type/*i_b < 4*/ )
769     {
770         /* decode length */
771         i_code = ShowBits(&p_vpar->bit_stream, 5);
772         if (i_code<31)
773         {
774             i_dct_dc_size = pl_dct_dc_lum_init_table_1[i_code].i_value;
775             i_length = pl_dct_dc_lum_init_table_1[i_code].i_length;
776             RemoveBits( &p_vpar->bit_stream, i_length);
777         }
778         else
779         {
780             i_code = ShowBits(&p_vpar->bit_stream, 9) - 0x1f0;
781             i_dct_dc_size = pl_dct_dc_lum_init_table_2[i_code].i_value;
782             i_length = pl_dct_dc_lum_init_table_2[i_code].i_length;
783             RemoveBits( &p_vpar->bit_stream, i_length);
784         }
785     }
786     else
787     {
788         /* decode length */
789         i_code = ShowBits(&p_vpar->bit_stream, 5);
790
791         if (i_code<31)
792         {
793             i_dct_dc_size = pl_dct_dc_chrom_init_table_1[i_code].i_value;
794             i_length = pl_dct_dc_chrom_init_table_1[i_code].i_length;
795             RemoveBits(&p_vpar->bit_stream, i_length);
796         }
797         else
798         {
799             i_code = ShowBits(&p_vpar->bit_stream, 10) - 0x3e0;
800             i_dct_dc_size = pl_dct_dc_chrom_init_table_2[i_code].i_value;
801             i_length = pl_dct_dc_chrom_init_table_2[i_code].i_length;
802             RemoveBits( &p_vpar->bit_stream, i_length);
803         }
804     }
805     if (i_dct_dc_size==0)
806         i_dct_dc_diff = 0;
807     else
808     {
809         i_dct_dc_diff = GetBits( &p_vpar->bit_stream, i_dct_dc_size);
810         if ((i_dct_dc_diff & (1<<(i_dct_dc_size-1)))==0)
811             i_dct_dc_diff-= (1<<i_dct_dc_size) - 1;
812     }
813
814     /* Dump the variable length code */
815     //RemoveBits( &p_vpar->bit_stream, 
816     //          p_vpar->pppl_dct_dc_size[i_type][i_select][i_pos].i_length );
817     
818     /* Read the actual code with the good length */
819     p_vpar->mb.pi_dc_dct_pred[i_cc] += i_dct_dc_diff;
820
821     p_mb->ppi_blocks[i_b][0] = ( p_vpar->mb.pi_dc_dct_pred[i_cc] <<
822                                ( 3 - p_vpar->picture.i_intra_dc_precision ) );
823     i_nc = ( p_vpar->mb.pi_dc_dct_pred[i_cc] != 0 );
824
825     /* Decoding of the AC coefficients */
826     
827     i_coef = 0;
828     b_vlc_intra = p_vpar->picture.b_intra_vlc_format;
829     for( i_parse = 1; /*i_parse < 64*/; i_parse++ )
830     {
831         i_code = ShowBits( &p_vpar->bit_stream, 16 );
832         if( i_code >= 16384 )
833         {
834             if( b_vlc_intra )
835             {
836                 i_run =     pl_DCT_tab0a[(i_code>>8)-4].i_run;
837                 i_level =   pl_DCT_tab0a[(i_code>>8)-4].i_level;
838                 i_length =  pl_DCT_tab0a[(i_code>>8)-4].i_length;
839 //fprintf( stderr, "**********> %d, %d, %d *******\n", i_run, i_level, (i_code>>8)-4 );
840             }
841             else
842             {
843                 i_run =     pl_DCT_tab_ac[(i_code>>12)-4].i_run;
844                 i_level =   pl_DCT_tab_ac[(i_code>>12)-4].i_level;
845                 i_length =  pl_DCT_tab_ac[(i_code>>12)-4].i_length;
846              }
847         }
848         else
849         {
850             i_run =     p_vpar->ppl_dct_coef[b_vlc_intra][i_code].i_run;
851             i_length =  p_vpar->ppl_dct_coef[b_vlc_intra][i_code].i_length;
852             i_level =   p_vpar->ppl_dct_coef[b_vlc_intra][i_code].i_level;
853         }
854
855 #if 0
856         {
857             int code = i_code;
858             int intra_vlc_format = b_vlc_intra;
859             dct_lookup_t tab;
860             
861     if (code>=16384 && !intra_vlc_format)
862       tab = pl_DCT_tab_ac[(code>>12)-4];
863     else if (code>=1024)
864     {
865       if (intra_vlc_format)
866         tab = pl_DCT_tab0a[(code>>8)-4];
867       else
868         tab = pl_DCT_tab0[(code>>8)-4];
869     }
870     else if (code>=512)
871     {
872       if (intra_vlc_format)
873         tab = pl_DCT_tab1a[(code>>6)-8];
874       else
875         tab = pl_DCT_tab1[(code>>6)-8];
876     }
877     else if (code>=256)
878       tab = pl_DCT_tab2[(code>>4)-16];
879     else if (code>=128)
880       tab = pl_DCT_tab3[(code>>3)-16];
881     else if (code>=64)
882       tab = pl_DCT_tab4[(code>>2)-16];
883     else if (code>=32)
884       tab = pl_DCT_tab5[(code>>1)-16];
885     else if (code>=16)
886       tab = pl_DCT_tab6[code-16];
887     else
888     {
889        fprintf( stderr, "invalid Huffman code in Decode_MPEG2_Intra_Block()\n");
890     }
891
892     if( (i_run != tab.i_run) || (i_length != tab.i_length) || (i_level != tab.i_level) )
893     {
894         fprintf( stderr, "ET M....... !!!\n" );
895         exit(0);
896     }
897         }
898 #endif
899
900
901
902         
903         RemoveBits( &p_vpar->bit_stream, i_length );
904
905         switch( i_run )
906         {
907             case DCT_ESCAPE:
908                 i_run = GetBits( &p_vpar->bit_stream, 6 );
909                 i_level = GetBits( &p_vpar->bit_stream, 12 );
910                 /*p_mb->ppi_blocks[i_b][i_parse] = ( b_sign = ( i_level > 2047 ) ) 
911                                                           ? ( -4096 + i_level )
912                                                           : i_level;*/
913                 i_level = (b_sign = ( i_level > 2047 )) ? 4096 - i_level
914                                                         : i_level;
915                 break;
916             case DCT_EOB:
917                 if( i_nc <= 1 )
918                 {
919                     p_mb->pf_idct[i_b] = vdec_SparseIDCT;
920                     p_mb->pi_sparse_pos[i_b] = i_coef;
921                 }
922                 else
923                 {
924                     p_mb->pf_idct[i_b] = vdec_IDCT;
925                 }
926                 return;
927
928                 break;
929             default:
930                 b_sign = GetBits( &p_vpar->bit_stream, 1 );
931         }
932
933         i_coef = i_parse;
934         i_parse += i_run;
935         i_nc ++;
936  
937         if( i_parse >= 64 )
938         {
939             break;
940         }
941
942         i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
943         i_level = ( i_level *
944                     p_vpar->mb.i_quantizer_scale *
945                     pi_quant[i_pos] ) >> 4;
946         p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
947     }
948
949     intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds\n");
950     p_vpar->picture.b_error = 1;
951 }
952
953
954 /*
955  * Motion vectors
956  */
957
958 /****************************************************************************
959  * MotionCode : Parse the next motion code
960  ****************************************************************************/
961 static __inline__ int MotionCode( vpar_thread_t * p_vpar )
962 {
963     int i_code;
964     static lookup_t pl_mv_tab0[8] = 
965         { {-1,0}, {3,3}, {2,2}, {2,2}, {1,1}, {1,1}, {1,1}, {1,1} };
966     /* Table B-10, motion_code, codes 0000011 ... 000011x */
967     static lookup_t pl_mv_tab1[8] =
968         { {-1,0}, {-1,0}, {-1,0}, {7,6}, {6,6}, {5,6}, {4,5}, {4,5} };
969     /* Table B-10, motion_code, codes 0000001100 ... 000001011x */
970     static lookup_t pl_mv_tab2[12] = {
971         {16,9}, {15,9}, {14,9}, {13,9},
972         {12,9}, {11,9}, {10,8}, {10,8},
973         {9,8},  {9,8},  {8,8},  {8,8} };
974     
975     if( GetBits( &p_vpar->bit_stream, 1 ) )
976     {
977         return 0;
978     }
979     if( (i_code = ShowBits( &p_vpar->bit_stream, 9) ) >= 64 )
980     {
981         i_code >>= 6;
982         RemoveBits( &p_vpar->bit_stream, pl_mv_tab0[i_code].i_length );
983         return( GetBits( &p_vpar->bit_stream, 1 ) ?
984             -pl_mv_tab0[i_code].i_value : pl_mv_tab0[i_code].i_value );
985     }
986
987     if( i_code >= 24 )
988     {
989         i_code >>= 3;
990         RemoveBits( &p_vpar->bit_stream, pl_mv_tab1[i_code].i_length );
991         return( GetBits( &p_vpar->bit_stream, 1 ) ?
992             -pl_mv_tab1[i_code].i_value : pl_mv_tab1[i_code].i_value );
993     }
994
995     if( (i_code -= 12) < 0 )
996     {
997         p_vpar->picture.b_error = 1;
998         intf_DbgMsg( "vpar debug: Invalid motion_vector code\n" );
999         return 0;
1000     }
1001
1002     RemoveBits( &p_vpar->bit_stream, pl_mv_tab2[i_code].i_length );
1003     return( GetBits( &p_vpar->bit_stream, 1 ) ?
1004         -pl_mv_tab2[i_code].i_value : pl_mv_tab2[i_code].i_value );            
1005 }
1006
1007 /****************************************************************************
1008  * DecodeMotionVector : Decode a motion_vector
1009  ****************************************************************************/
1010 static __inline__ void DecodeMotionVector( int * pi_prediction, int i_r_size,
1011         int i_motion_code, int i_motion_residual, int i_full_pel )
1012 {
1013     int i_limit, i_vector;
1014
1015     /* ISO/IEC 13818-1 section 7.6.3.1 */
1016     i_limit = 16 << i_r_size;
1017     i_vector = *pi_prediction >> i_full_pel;
1018
1019     if( i_motion_code > 0 )
1020     {
1021         i_vector += ((i_motion_code-1) << i_r_size) + i_motion_residual + 1;
1022         if( i_vector >= i_limit )
1023             i_vector -= i_limit + i_limit;
1024     }
1025     else if( i_motion_code < 0 )
1026     {
1027         i_vector -= ((-i_motion_code-1) << i_r_size) + i_motion_residual + 1;
1028         if( i_vector < -i_limit )
1029             i_vector += i_limit + i_limit;
1030     }
1031     *pi_prediction = i_vector << i_full_pel;
1032 }
1033
1034 /****************************************************************************
1035  * MotionVector : Parse the next motion_vector field
1036  ****************************************************************************/
1037 static __inline__ void MotionVector( vpar_thread_t * p_vpar,
1038                                      macroblock_t * p_mb, int i_r,
1039                                      int i_s, int i_full_pel, int i_structure )
1040 {
1041     int i_motion_code, i_motion_residual;
1042     int i_r_size;
1043     int pi_dm_vector[2];
1044     
1045     i_r_size = p_vpar->picture.ppi_f_code[i_s][0] - 1;
1046     i_motion_code = MotionCode( p_vpar );
1047     i_motion_residual = (i_r_size != 0 && i_motion_code != 0) ?
1048                         GetBits( &p_vpar->bit_stream, i_r_size) : 0;
1049     DecodeMotionVector( &p_vpar->mb.pppi_pmv[i_r][i_s][0], i_r_size,
1050                         i_motion_code, i_motion_residual, i_full_pel );
1051     p_mb->pppi_motion_vectors[i_r][i_s][0] = p_vpar->mb.pppi_pmv[i_r][i_s][0];
1052
1053     if( p_vpar->mb.b_dmv )
1054     {
1055         if( GetBits(&p_vpar->bit_stream, 1) )
1056         {
1057             pi_dm_vector[0] = GetBits( &p_vpar->bit_stream, 1 ) ? -1 : 1;
1058         }
1059         else
1060         {
1061             pi_dm_vector[0] = 0;
1062         }
1063     }
1064     
1065     i_r_size = p_vpar->picture.ppi_f_code[i_s][1]-1;
1066     i_motion_code = MotionCode( p_vpar );
1067     i_motion_residual = (i_r_size != 0 && i_motion_code != 0) ?
1068                         GetBits( &p_vpar->bit_stream, i_r_size) : 0;
1069
1070    
1071     if( (p_vpar->mb.i_mv_format == MOTION_FIELD)
1072         && (i_structure == FRAME_STRUCTURE) )
1073     {
1074          p_vpar->mb.pppi_pmv[i_r][i_s][1] >>= 1;
1075     }
1076     
1077     DecodeMotionVector( &p_vpar->mb.pppi_pmv[i_r][i_s][1], i_r_size,
1078                         i_motion_code, i_motion_residual, i_full_pel );
1079
1080     if( (p_vpar->mb.i_mv_format == MOTION_FIELD)
1081         && (i_structure == FRAME_STRUCTURE) )
1082          p_vpar->mb.pppi_pmv[i_r][i_s][1] <<= 1;
1083      
1084     p_mb->pppi_motion_vectors[i_r][i_s][1] = p_vpar->mb.pppi_pmv[i_r][i_s][1];
1085
1086     if( p_vpar->mb.b_dmv )
1087     {
1088         if( GetBits(&p_vpar->bit_stream, 1) )
1089         {
1090             pi_dm_vector[1] = GetBits( &p_vpar->bit_stream, 1 ) ? -1 : 1;
1091         }
1092         else
1093         {
1094             pi_dm_vector[1] = 0;
1095         }
1096
1097         /* Dual Prime Arithmetic (ISO/IEC 13818-2 section 7.6.3.6). */
1098
1099 #define i_mv_x  p_mb->pppi_motion_vectors[0][0][0]
1100         if( i_structure == FRAME_STRUCTURE )
1101         {
1102 #define i_mv_y  (p_mb->pppi_motion_vectors[0][0][1] << 1)
1103             if( p_vpar->picture.b_top_field_first )
1104             {
1105                 /* vector for prediction of top field from bottom field */
1106                 p_mb->ppi_dmv[0][0] = ((i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1107                 p_mb->ppi_dmv[0][1] = ((i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1] - 1;
1108
1109                 /* vector for prediction of bottom field from top field */
1110                 p_mb->ppi_dmv[1][0] = ((3*i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1111                 p_mb->ppi_dmv[1][1] = ((3*i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1] + 1;
1112             }
1113             else
1114             {
1115                 /* vector for prediction of top field from bottom field */
1116                 p_mb->ppi_dmv[0][0] = ((3*i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1117                 p_mb->ppi_dmv[0][1] = ((3*i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1] - 1;
1118
1119                 /* vector for prediction of bottom field from top field */
1120                 p_mb->ppi_dmv[1][0] = ((i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1121                 p_mb->ppi_dmv[1][1] = ((i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1] + 1;
1122             }
1123 #undef i_mv_y
1124         }
1125         else
1126         {
1127 #define i_mv_y  p_mb->pppi_motion_vectors[0][0][1]
1128             /* vector for prediction from field of opposite 'parity' */
1129             p_mb->ppi_dmv[0][0] = ((i_mv_x + (i_mv_x > 0)) >> 1) + pi_dm_vector[0];
1130             p_mb->ppi_dmv[0][1] = ((i_mv_y + (i_mv_y > 0)) >> 1) + pi_dm_vector[1];
1131
1132             /* correct for vertical field shift */
1133             if( p_vpar->picture.i_structure == TOP_FIELD )
1134                 p_mb->ppi_dmv[0][1]--;
1135             else
1136                 p_mb->ppi_dmv[0][1]++;
1137 #undef i_mv_y
1138         }
1139 #undef i_mv_x
1140     }
1141 }
1142
1143 /*****************************************************************************
1144  * DecodeMVMPEG1 : Parse the next MPEG-1 motion vectors
1145  *****************************************************************************/
1146 static __inline__ void DecodeMVMPEG1( vpar_thread_t * p_vpar,
1147                             macroblock_t * p_mb, int i_s, int i_structure )
1148 {
1149     MotionVector( p_vpar, p_mb, 0, i_s,
1150                   p_vpar->picture.pb_full_pel_vector[i_s], i_structure );
1151 }
1152
1153 /*****************************************************************************
1154  * DecodeMVMPEG2 : Parse the next MPEG-2 motion_vectors field
1155  *****************************************************************************/
1156 static __inline__ void DecodeMVMPEG2( vpar_thread_t * p_vpar,
1157                             macroblock_t * p_mb, int i_s, int i_structure )
1158 {
1159     if( p_vpar->mb.i_mv_count == 1 )
1160     {
1161         if( p_vpar->mb.i_mv_format == MOTION_FIELD && !p_vpar->mb.b_dmv )
1162         {
1163             p_mb->ppi_field_select[0][i_s] = p_mb->ppi_field_select[1][i_s]
1164                                             = GetBits( &p_vpar->bit_stream, 1 );
1165         }
1166         MotionVector( p_vpar, p_mb, 0, i_s, 0, i_structure );
1167         p_vpar->mb.pppi_pmv[1][i_s][0] = p_vpar->mb.pppi_pmv[0][i_s][0];
1168         p_vpar->mb.pppi_pmv[1][i_s][1] = p_vpar->mb.pppi_pmv[0][i_s][1];
1169         p_mb->pppi_motion_vectors[1][i_s][0] = p_vpar->mb.pppi_pmv[0][i_s][0];
1170         p_mb->pppi_motion_vectors[1][i_s][1] = p_vpar->mb.pppi_pmv[0][i_s][1];
1171     }
1172     else
1173     {
1174         p_mb->ppi_field_select[0][i_s] = GetBits( &p_vpar->bit_stream, 1 );
1175         MotionVector( p_vpar, p_mb, 0, i_s, 0, i_structure );
1176         p_mb->ppi_field_select[1][i_s] = GetBits( &p_vpar->bit_stream, 1 );
1177         MotionVector( p_vpar, p_mb, 1, i_s, 0, i_structure );
1178     }
1179 }
1180
1181
1182 /*
1183  * Macroblock information structures
1184  */
1185
1186 /*****************************************************************************
1187  * MacroblockAddressIncrement : Get the macroblock_address_increment field
1188  *****************************************************************************/
1189 static __inline__ int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
1190 {
1191     int i_addr_inc = 0;
1192     /* Index in the lookup table mb_addr_inc */
1193     int    i_index = ShowBits( &p_vpar->bit_stream, 11 );
1194         
1195     /* Test the presence of the escape character */
1196     while( i_index == 8 )
1197     {
1198         RemoveBits( &p_vpar->bit_stream, 11 );
1199         i_addr_inc += 33;
1200         i_index = ShowBits( &p_vpar->bit_stream, 11 );
1201     }
1202      
1203     /* Affect the value from the lookup table */
1204     i_addr_inc += p_vpar->pl_mb_addr_inc[i_index].i_value;
1205     
1206     /* Dump the good number of bits */
1207     RemoveBits( &p_vpar->bit_stream, p_vpar->pl_mb_addr_inc[i_index].i_length );
1208     
1209     return i_addr_inc;
1210 }
1211
1212 /*****************************************************************************
1213  * IMBType : macroblock_type in I pictures
1214  *****************************************************************************/
1215 static __inline__ int IMBType( vpar_thread_t * p_vpar )
1216 {
1217     /* Take two bits for testing */
1218     int                 i_type = ShowBits( &p_vpar->bit_stream, 2 );
1219     
1220     /* Lookup table for macroblock_type */
1221     static lookup_t     pl_mb_Itype[4] = { {MB_ERROR, 0},
1222                                            {MB_QUANT|MB_INTRA, 2},
1223                                            {MB_INTRA, 1},
1224                                            {MB_INTRA, 1} };
1225     /* Dump the good number of bits */
1226     RemoveBits( &p_vpar->bit_stream, pl_mb_Itype[i_type].i_length );
1227     return pl_mb_Itype[i_type].i_value;
1228 }
1229
1230 /*****************************************************************************
1231  * PMBType : macroblock_type in P pictures
1232  *****************************************************************************/
1233 static __inline__ int PMBType( vpar_thread_t * p_vpar )
1234 {
1235     /* Testing on 6 bits */
1236     int                i_type = ShowBits( &p_vpar->bit_stream, 6 );
1237     
1238     /* Dump the good number of bits */
1239     RemoveBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[0][i_type].i_length );
1240     /* return the value from the lookup table for P type */
1241     return p_vpar->ppl_mb_type[0][i_type].i_value;
1242 }
1243
1244 /*****************************************************************************
1245  * BMBType : macroblock_type in B pictures
1246  *****************************************************************************/
1247 static __inline__ int BMBType( vpar_thread_t * p_vpar )
1248 {
1249      /* Testing on 6 bits */
1250     int                i_type = ShowBits( &p_vpar->bit_stream, 6 );
1251     
1252     /* Dump the good number of bits */
1253     RemoveBits( &p_vpar->bit_stream, p_vpar->ppl_mb_type[1][i_type].i_length );
1254     
1255     /* return the value from the lookup table for B type */
1256     return p_vpar->ppl_mb_type[1][i_type].i_value;
1257 }
1258
1259 /*****************************************************************************
1260  * DMBType : macroblock_type in D pictures
1261  *****************************************************************************/
1262 static __inline__ int DMBType( vpar_thread_t * p_vpar )
1263 {
1264     return GetBits( &p_vpar->bit_stream, 1 );
1265 }
1266
1267 /*****************************************************************************
1268  * CodedPattern420 : coded_block_pattern with 4:2:0 chroma
1269  *****************************************************************************/
1270 static __inline__ int CodedPattern420( vpar_thread_t * p_vpar )
1271 {
1272     /* Take the max 9 bits length vlc code for testing */
1273     int      i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
1274     
1275     /* Trash the good number of bits read in the lookup table */
1276     RemoveBits( &p_vpar->bit_stream, pl_coded_pattern[i_vlc].i_length );
1277     
1278     /* return the value from the vlc table */
1279     return pl_coded_pattern[i_vlc].i_value;
1280 }
1281
1282 /*****************************************************************************
1283  * CodedPattern422 : coded_block_pattern with 4:2:2 chroma
1284  *****************************************************************************/
1285 static __inline__ int CodedPattern422( vpar_thread_t * p_vpar )
1286 {
1287     int      i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
1288     
1289     RemoveBits( &p_vpar->bit_stream, pl_coded_pattern[i_vlc].i_length );
1290     
1291     /* Supplementary 2 bits long code for 4:2:2 format */
1292     return pl_coded_pattern[i_vlc].i_value |
1293            (GetBits( &p_vpar->bit_stream, 2 ) << 6);
1294 }
1295
1296 /*****************************************************************************
1297  * CodedPattern444 : coded_block_pattern with 4:4:4 chroma
1298  *****************************************************************************/
1299 static __inline__ int CodedPattern444( vpar_thread_t * p_vpar )
1300 {
1301     int      i_vlc = ShowBits( &p_vpar->bit_stream, 9 );
1302     
1303     RemoveBits( &p_vpar->bit_stream, pl_coded_pattern[i_vlc].i_length );
1304     
1305     return pl_coded_pattern[i_vlc].i_value |
1306            (GetBits( &p_vpar->bit_stream, 6 ) << 6);
1307 }
1308
1309 /*****************************************************************************
1310  * InitMacroblock : Initialize macroblock values
1311  *****************************************************************************/
1312 static __inline__ void InitMacroblock( vpar_thread_t * p_vpar,
1313                                        macroblock_t * p_mb, int i_coding_type,
1314                                        int i_chroma_format,
1315                                        int i_structure,
1316                                        boolean_t b_second_field )
1317 {
1318     p_mb->i_chroma_nb_blocks = 1 << i_chroma_format;
1319     p_mb->p_picture = p_vpar->picture.p_picture;
1320
1321     if( i_coding_type == B_CODING_TYPE )
1322         p_mb->p_backward = p_vpar->sequence.p_backward;
1323     else
1324         p_mb->p_backward = NULL;
1325     if( (i_coding_type == P_CODING_TYPE) || (i_coding_type == B_CODING_TYPE) )
1326         p_mb->p_forward = p_vpar->sequence.p_forward;
1327     else
1328         p_mb->p_forward = NULL;
1329
1330     p_mb->i_l_x = p_vpar->mb.i_l_x;
1331     p_mb->i_c_x = p_vpar->mb.i_c_x;
1332     p_mb->i_motion_l_y = p_vpar->mb.i_l_y;
1333     p_mb->i_motion_c_y = p_vpar->mb.i_c_y;
1334     if( (p_mb->b_motion_field = (i_structure == BOTTOM_FIELD)) )
1335     {
1336         p_mb->i_motion_l_y--;
1337         p_mb->i_motion_c_y--;
1338     }
1339     p_mb->i_addb_l_stride = (p_mb->i_l_stride = p_vpar->picture.i_l_stride) - 8;
1340     p_mb->i_addb_c_stride = (p_mb->i_c_stride = p_vpar->picture.i_c_stride) - 8;
1341     p_mb->b_P_second = ( b_second_field && i_coding_type == P_CODING_TYPE );
1342 }
1343
1344 /*****************************************************************************
1345  * UpdateContext : Update the p_vpar contextual values
1346  *****************************************************************************/
1347 static __inline__ void UpdateContext( vpar_thread_t * p_vpar, int i_structure )
1348 {
1349     /* Update macroblock real position. */
1350     p_vpar->mb.i_l_x += 16;
1351     p_vpar->mb.i_l_y += (p_vpar->mb.i_l_x / p_vpar->sequence.i_width)
1352                         * (2 - (i_structure == FRAME_STRUCTURE)) * 16;
1353     p_vpar->mb.i_l_x %= p_vpar->sequence.i_width;
1354
1355     p_vpar->mb.i_c_x += p_vpar->sequence.i_chroma_mb_width;
1356     p_vpar->mb.i_c_y += (p_vpar->mb.i_c_x / p_vpar->sequence.i_chroma_width)
1357                         * (2 - (i_structure == FRAME_STRUCTURE))
1358                         * p_vpar->sequence.i_chroma_mb_height;
1359     p_vpar->mb.i_c_x %= p_vpar->sequence.i_chroma_width;
1360 }
1361
1362 /*****************************************************************************
1363  * SkippedMacroblock : Generate a skipped macroblock with NULL motion vector
1364  *****************************************************************************/
1365 static __inline__ void SkippedMacroblock( vpar_thread_t * p_vpar, int i_mb,
1366                                           int i_mb_base, int i_coding_type,
1367                                           int i_chroma_format,
1368                                           int i_structure,
1369                                           boolean_t b_second_field )
1370 {
1371     macroblock_t *  p_mb;
1372
1373     static f_motion_t   pf_motion_skipped[4][4] =
1374     {
1375         {NULL, NULL, NULL, NULL},
1376         {NULL, vdec_MotionFieldField420, vdec_MotionFieldField420,
1377             vdec_MotionFrameFrame420},
1378         {NULL, vdec_MotionFieldField422, vdec_MotionFieldField422,
1379             vdec_MotionFrameFrame422},
1380         {NULL, vdec_MotionFieldField444, vdec_MotionFieldField444,
1381             vdec_MotionFrameFrame444},
1382     };
1383
1384     if( (p_mb = vpar_NewMacroblock( &p_vpar->vfifo )) == NULL )
1385     {
1386         /* b_die == 1 */
1387         return;
1388     }
1389 #ifdef VDEC_SMP
1390     p_vpar->picture.pp_mb[i_mb_base + i_mb] = p_mb;
1391 #endif
1392
1393     InitMacroblock( p_vpar, p_mb, i_coding_type, i_chroma_format,
1394                     i_structure, b_second_field );
1395    
1396     /* Motion type is picture structure. */
1397     p_mb->pf_motion = pf_motion_skipped[i_chroma_format]
1398                                        [i_structure];
1399     p_mb->i_mb_type = MB_MOTION_FORWARD;
1400     p_mb->i_coded_block_pattern = 0;
1401     memset( p_mb->pppi_motion_vectors, 0, 8*sizeof(int) );
1402
1403     /* Set the field we use for motion compensation */
1404     p_mb->ppi_field_select[0][0] = p_mb->ppi_field_select[0][1]
1405                                  = ( i_structure == BOTTOM_FIELD );
1406
1407     UpdateContext( p_vpar, i_structure );
1408
1409 #ifndef VDEC_SMP
1410     /* Decode the macroblock NOW ! */
1411     vdec_DecodeMacroblock( p_vpar->pp_vdec[0], p_mb );
1412 #endif
1413 }
1414
1415 /*****************************************************************************
1416  * MacroblockModes : Get the macroblock_modes structure
1417  *****************************************************************************/
1418 static __inline__ void MacroblockModes( vpar_thread_t * p_vpar,
1419                                         macroblock_t * p_mb,
1420                                         int i_chroma_format,
1421                                         int i_coding_type,
1422                                         int i_structure )
1423 {
1424     static int          ppi_mv_count[2][4] = { {0, 1, 2, 1}, {0, 2, 1, 1} };
1425     static int          ppi_mv_format[2][4] = { {0, 1, 1, 1}, {0, 1, 2, 1} };
1426
1427     /* Get macroblock_type. */
1428     switch( i_coding_type )
1429     {
1430     case P_CODING_TYPE:
1431         p_mb->i_mb_type = PMBType( p_vpar );
1432         break;
1433     case B_CODING_TYPE:
1434         p_mb->i_mb_type = BMBType( p_vpar );
1435         break;
1436     case I_CODING_TYPE:
1437         p_mb->i_mb_type = IMBType( p_vpar );
1438         break;
1439     case D_CODING_TYPE:
1440         p_mb->i_mb_type = DMBType( p_vpar );
1441     }
1442     
1443     /* SCALABILITY : warning, we don't know if spatial_temporal_weight_code
1444      * has to be dropped, take care if you use scalable streams. */
1445     /* RemoveBits( &p_vpar->bit_stream, 2 ); */
1446     
1447     if( (i_coding_type == P_CODING_TYPE || i_coding_type == B_CODING_TYPE)
1448         && (p_mb->i_mb_type & (MB_MOTION_FORWARD | MB_MOTION_BACKWARD)) )
1449     {
1450         if( !(i_structure == FRAME_STRUCTURE
1451                && p_vpar->picture.b_frame_pred_frame_dct) )
1452         {
1453             p_vpar->mb.i_motion_type = GetBits( &p_vpar->bit_stream, 2 );
1454         }
1455         else
1456         {
1457             p_vpar->mb.i_motion_type = MOTION_FRAME;
1458         }
1459
1460         /* ???? */
1461         p_vpar->mb.i_mv_count = ppi_mv_count[i_structure == FRAME_STRUCTURE]
1462                                             [p_vpar->mb.i_motion_type];
1463         p_vpar->mb.i_mv_format = ppi_mv_format[i_structure == FRAME_STRUCTURE]
1464                                               [p_vpar->mb.i_motion_type];
1465         p_vpar->mb.b_dmv = p_vpar->mb.i_motion_type == MOTION_DMV;
1466     }
1467
1468     p_vpar->mb.b_dct_type = 0;
1469     if( (i_structure == FRAME_STRUCTURE) &&
1470         (!p_vpar->picture.b_frame_pred_frame_dct) &&
1471         (p_mb->i_mb_type & (MB_PATTERN|MB_INTRA)) )
1472     {
1473         if( (p_vpar->mb.b_dct_type = GetBits( &p_vpar->bit_stream, 1 )) )
1474         {
1475             /* The DCT is coded on fields. Jump one line between each
1476              * sample. */
1477             p_mb->i_addb_l_stride <<= 1;
1478             p_mb->i_addb_l_stride += 8;
1479             /* With CHROMA_420, the DCT is necessarily frame-coded. */
1480             if( i_chroma_format != CHROMA_420 )
1481             {
1482                 p_mb->i_addb_c_stride <<= 1;
1483                 p_mb->i_addb_c_stride += 8;
1484             }
1485         }
1486     }
1487 }
1488
1489 /*****************************************************************************
1490  * ParseMacroblock : Parse the next macroblock
1491  *****************************************************************************/
1492 #define PARSEBLOCKS( MPEG1FUNC, MPEG2FUNC )                             \
1493 {                                                                       \
1494     i_mask = 1 << (3 + (1 << i_chroma_format));                         \
1495                                                                         \
1496     /* luminance */                                                     \
1497     p_data1 = p_mb->p_picture->p_y                                      \
1498         + p_mb->i_l_x + p_vpar->mb.i_l_y*(p_vpar->sequence.i_width);    \
1499                                                                         \
1500     for( i_b = 0 ; i_b < 4 ; i_b++, i_mask >>= 1 )                      \
1501     {                                                                   \
1502         if( p_mb->i_coded_block_pattern & i_mask )                      \
1503         {                                                               \
1504             memset( p_mb->ppi_blocks[i_b], 0, 64*sizeof(dctelem_t) );   \
1505             if( b_mpeg2 )                                               \
1506                 MPEG2FUNC( p_vpar, p_mb, i_b, i_chroma_format );        \
1507             else                                                        \
1508                 MPEG1FUNC( p_vpar, p_mb, i_b, i_chroma_format );        \
1509                                                                         \
1510             /* Calculate block coordinates. */                          \
1511             p_mb->p_data[i_b] = p_data1                                 \
1512                                 + pi_y[p_vpar->mb.b_dct_type][i_b]      \
1513                                 * p_vpar->sequence.i_width              \
1514                                 + pi_x[i_b];                            \
1515         }                                                               \
1516     }                                                                   \
1517                                                                         \
1518     if( p_vpar->picture.b_error )                                       \
1519     {                                                                   \
1520         /* Mark this block as skipped (better than green blocks), and   \
1521          * go to the next slice. */                                     \
1522         (*pi_mb_address)--;                                             \
1523         vpar_DestroyMacroblock( &p_vpar->vfifo, p_mb );                 \
1524         return;                                                         \
1525     }                                                                   \
1526                                                                         \
1527     /* chrominance */                                                   \
1528     p_data1 = p_mb->p_picture->p_u                                      \
1529               + p_mb->i_c_x                                             \
1530               + p_vpar->mb.i_c_y                                        \
1531                 * (p_vpar->sequence.i_chroma_width);                    \
1532     p_data2 = p_mb->p_picture->p_v                                      \
1533                + p_mb->i_c_x                                            \
1534                + p_vpar->mb.i_c_y                                       \
1535                 * (p_vpar->sequence.i_chroma_width);                    \
1536                                                                         \
1537     for( i_b = 4; i_b < 4 + (1 << i_chroma_format);                     \
1538          i_b++, i_mask >>= 1 )                                          \
1539     {                                                                   \
1540         yuv_data_t *    pp_data[2] = {p_data1, p_data2};                \
1541                                                                         \
1542         if( p_mb->i_coded_block_pattern & i_mask )                      \
1543         {                                                               \
1544             memset( p_mb->ppi_blocks[i_b], 0, 64*sizeof(dctelem_t) );   \
1545             if( b_mpeg2 )                                               \
1546                 MPEG2FUNC( p_vpar, p_mb, i_b, i_chroma_format );        \
1547             else                                                        \
1548                 MPEG1FUNC( p_vpar, p_mb, i_b, i_chroma_format );        \
1549                                                                         \
1550             /* Calculate block coordinates. */                          \
1551             p_mb->p_data[i_b] = pp_data[i_b & 1]                        \
1552                                  + pi_y[p_vpar->mb.b_dct_type][i_b]     \
1553                                    * p_vpar->sequence.i_chroma_width    \
1554                                  + pi_x[i_b];                           \
1555         }                                                               \
1556     }                                                                   \
1557 }
1558
1559 static __inline__ void ParseMacroblock(
1560                            vpar_thread_t * p_vpar,
1561                            int * pi_mb_address,     /* previous address to be
1562                                                      * used for mb_addr_incr */
1563                            int i_mb_previous,          /* actual previous mb */
1564                            int i_mb_base,     /* non-zero if field structure */
1565                            /* The following parameters are explicit in
1566                             * optimized routines : */
1567                            boolean_t b_mpeg2,             /* you know what ? */
1568                            int i_coding_type,                /* I, P, B or D */
1569                            int i_chroma_format,     /* 4:2:0, 4:2:2 or 4:4:4 */
1570                            int i_structure,    /* T(OP), B(OTTOM) or F(RAME) */
1571                            boolean_t b_second_field )     /* second field of a
1572                                                            * field picture   */
1573 {
1574     static f_motion_t   pppf_motion[4][2][4] =
1575       {
1576         { {NULL, NULL, NULL, NULL},
1577           {NULL, NULL, NULL, NULL}
1578         },
1579         { {NULL, vdec_MotionFieldField420, vdec_MotionField16x8420,
1580             vdec_MotionFieldDMV420},
1581           {NULL, vdec_MotionFrameField420, vdec_MotionFrameFrame420,
1582             vdec_MotionFrameDMV420}
1583         },
1584         { {NULL, vdec_MotionFieldField422, vdec_MotionField16x8422,
1585             vdec_MotionFieldDMV422},
1586           {NULL, vdec_MotionFrameField422, vdec_MotionFrameFrame422,
1587             vdec_MotionFrameDMV422}
1588         },
1589         { {NULL, vdec_MotionFieldField444, vdec_MotionField16x8444,
1590             vdec_MotionFieldDMV444},
1591           {NULL, vdec_MotionFrameField444, vdec_MotionFrameFrame444,
1592             vdec_MotionFrameDMV444}
1593         }
1594       };
1595     static int      pi_x[12] = {0,8,0,8,0,0,0,0,8,8,8,8};
1596     static int      pi_y[2][12] = { {0,0,8,8,0,0,8,8,0,0,8,8},
1597                                     {0,0,1,1,0,0,1,1,0,0,1,1} };
1598
1599     int             i_mb, i_b, i_mask;
1600     macroblock_t *  p_mb;
1601     yuv_data_t *    p_data1;
1602     yuv_data_t *    p_data2;
1603
1604     *pi_mb_address += MacroblockAddressIncrement( p_vpar );
1605
1606     if( *pi_mb_address - i_mb_previous - 1 )
1607     {
1608         /* Skipped macroblock (ISO/IEC 13818-2 7.6.6). */
1609
1610         /* Reset DC predictors (7.2.1). */
1611         p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
1612             = p_vpar->mb.pi_dc_dct_pred[2]
1613             = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
1614
1615         if( i_coding_type == P_CODING_TYPE )
1616         {
1617             /* Reset motion vector predictors (ISO/IEC 13818-2 7.6.3.4). */
1618             memset( p_vpar->mb.pppi_pmv, 0, 8*sizeof(int) );
1619         }
1620
1621         for( i_mb = i_mb_previous + 1; i_mb < *pi_mb_address; i_mb++ )
1622         {
1623             SkippedMacroblock( p_vpar, i_mb, i_mb_base, i_coding_type,
1624                                i_chroma_format, i_structure, b_second_field );
1625         }
1626     }
1627
1628     /* Get a macroblock structure. */
1629     if( (p_mb = vpar_NewMacroblock( &p_vpar->vfifo )) == NULL )
1630     {
1631         /* b_die == 1 */
1632         return;
1633     }
1634 #ifdef VDEC_SMP
1635     p_vpar->picture.pp_mb[i_mb_base + *pi_mb_address] = p_mb;
1636 #endif
1637
1638     InitMacroblock( p_vpar, p_mb, i_coding_type, i_chroma_format,
1639                     i_structure, b_second_field );
1640
1641     /* Parse off macroblock_modes structure. */
1642     MacroblockModes( p_vpar, p_mb, i_chroma_format, i_coding_type,
1643                      i_structure );
1644
1645     if( p_mb->i_mb_type & MB_QUANT )
1646     {
1647         LoadQuantizerScale( p_vpar );
1648     }
1649
1650     if( (i_coding_type == P_CODING_TYPE || i_coding_type == B_CODING_TYPE)
1651          && (p_mb->i_mb_type & MB_MOTION_FORWARD) )
1652     {
1653         if( b_mpeg2 )
1654             DecodeMVMPEG2( p_vpar, p_mb, 0, i_structure );
1655         else
1656             DecodeMVMPEG1( p_vpar, p_mb, 0, i_structure );
1657     }
1658
1659     if( (i_coding_type == B_CODING_TYPE)
1660          && (p_mb->i_mb_type & MB_MOTION_BACKWARD) )
1661     {
1662         if( b_mpeg2 )
1663             DecodeMVMPEG2( p_vpar, p_mb, 1, i_structure );
1664         else
1665             DecodeMVMPEG1( p_vpar, p_mb, 1, i_structure );
1666     }
1667
1668     if( i_coding_type == P_CODING_TYPE
1669          && !(p_mb->i_mb_type & (MB_MOTION_FORWARD|MB_INTRA)) )
1670     {
1671         /* Special No-MC macroblock in P pictures (7.6.3.5). */
1672         p_mb->i_mb_type |= MB_MOTION_FORWARD;
1673         memset( p_vpar->mb.pppi_pmv, 0, 8*sizeof(int) );
1674         memset( p_mb->pppi_motion_vectors, 0, 8*sizeof(int) );
1675         p_vpar->mb.i_motion_type = 1 + (i_structure == FRAME_STRUCTURE);
1676         p_mb->ppi_field_select[0][0] = (i_structure == BOTTOM_FIELD);
1677     }
1678
1679     if( (i_coding_type != I_CODING_TYPE) && !(p_mb->i_mb_type & MB_INTRA) )
1680     {
1681         /* Reset DC predictors (7.2.1). */
1682         p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
1683             = p_vpar->mb.pi_dc_dct_pred[2]
1684             = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
1685
1686         /* Motion function pointer. */
1687         p_mb->pf_motion = pppf_motion[i_chroma_format]
1688                                      [i_structure == FRAME_STRUCTURE]
1689                                      [p_vpar->mb.i_motion_type];
1690
1691         if( p_mb->i_mb_type & MB_PATTERN )
1692         {
1693             switch( i_chroma_format )
1694             {
1695             case CHROMA_420:
1696                 p_mb->i_coded_block_pattern = CodedPattern420( p_vpar );
1697                 break;
1698             case CHROMA_422:
1699                 p_mb->i_coded_block_pattern = CodedPattern422( p_vpar );
1700                 break;
1701             case CHROMA_444:
1702                 p_mb->i_coded_block_pattern = CodedPattern444( p_vpar );
1703             }
1704         }
1705         else
1706         {
1707             p_mb->i_coded_block_pattern = 0;
1708         }
1709
1710         /*
1711          * Effectively decode blocks.
1712          */
1713         PARSEBLOCKS( DecodeMPEG1NonIntra, DecodeMPEG2NonIntra )
1714     }
1715     else
1716     {
1717         if( !p_vpar->picture.b_concealment_mv )
1718         {
1719             /* Reset MV predictors. */
1720             memset( p_vpar->mb.pppi_pmv, 0, 8*sizeof(int) );
1721         }
1722         else
1723         {
1724             if( b_mpeg2 )
1725                 DecodeMVMPEG2( p_vpar, p_mb, 0, i_structure );
1726             else
1727                 DecodeMVMPEG1( p_vpar, p_mb, 0, i_structure );
1728             RemoveBits( &p_vpar->bit_stream, 1 );
1729         }
1730
1731         if( p_mb->i_mb_type & MB_PATTERN )
1732         {
1733             switch( i_chroma_format )
1734             {
1735             case CHROMA_420:
1736                 p_mb->i_coded_block_pattern = CodedPattern420( p_vpar );
1737                 break;
1738             case CHROMA_422:
1739                 p_mb->i_coded_block_pattern = CodedPattern422( p_vpar );
1740                 break;
1741             case CHROMA_444:
1742                 p_mb->i_coded_block_pattern = CodedPattern444( p_vpar );
1743             }
1744         }
1745         else
1746         {
1747             p_mb->i_coded_block_pattern =
1748                                 (1 << (4 + (1 << i_chroma_format))) - 1;
1749         }
1750
1751         /*
1752          * Effectively decode blocks.
1753          */
1754         PARSEBLOCKS( DecodeMPEG1Intra, DecodeMPEG2Intra )
1755     }
1756
1757     if( !p_vpar->picture.b_error )
1758     {
1759         UpdateContext( p_vpar, i_structure );
1760 #ifndef VDEC_SMP
1761         /* Decode the macroblock NOW ! */
1762         vdec_DecodeMacroblock( p_vpar->pp_vdec[0], p_mb );
1763 #endif
1764     }
1765     else
1766     {
1767         /* Mark this block as skipped (better than green blocks), and go
1768          * to the next slice. */
1769         (*pi_mb_address)--;
1770         vpar_DestroyMacroblock( &p_vpar->vfifo, p_mb );
1771     }
1772 }
1773
1774 /*
1775  * Picture data parsing management
1776  */
1777
1778 /*****************************************************************************
1779  * SliceHeader : Parse the next slice structure
1780  *****************************************************************************/
1781 static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
1782                                     int * pi_mb_address, int i_mb_base,
1783                                     u32 i_vert_code, boolean_t b_high,
1784                                     boolean_t b_dp_scalable,
1785                                     boolean_t b_mpeg2, int i_coding_type,
1786                                     int i_chroma_format, int i_structure,
1787                                     boolean_t b_second_field )
1788 {
1789     int                     i_mb_address_save = *pi_mb_address;
1790
1791     p_vpar->picture.b_error = 0;
1792
1793     if( b_high )
1794     {
1795         /* Picture with more than 2800 lines. */
1796         i_vert_code += GetBits( &p_vpar->bit_stream, 3 ) << 7;
1797     }
1798     if( b_dp_scalable )
1799     {
1800         /* DATA_PARTITIONING scalability. */
1801         RemoveBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
1802     }
1803
1804     LoadQuantizerScale( p_vpar );
1805
1806     if( GetBits( &p_vpar->bit_stream, 1 ) )
1807     {
1808         /* intra_slice, slice_id */
1809         RemoveBits( &p_vpar->bit_stream, 8 );
1810         /* extra_information_slice */
1811         while( GetBits( &p_vpar->bit_stream, 1 ) )
1812         {
1813             RemoveBits( &p_vpar->bit_stream, 8 );
1814         }
1815     }
1816     *pi_mb_address = (i_vert_code - 1)*p_vpar->sequence.i_mb_width;
1817     
1818     /* Reset DC coefficients predictors (ISO/IEC 13818-2 7.2.1). */
1819     p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
1820         = p_vpar->mb.pi_dc_dct_pred[2]
1821         = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
1822
1823     /* Reset motion vector predictors (ISO/IEC 13818-2 7.6.3.4). */
1824     memset( p_vpar->mb.pppi_pmv, 0, 8*sizeof(int) );
1825
1826     do
1827     {
1828         ParseMacroblock( p_vpar, pi_mb_address, i_mb_address_save,
1829                          i_mb_base, b_mpeg2, i_coding_type,
1830                          i_chroma_format, i_structure,
1831                          b_second_field );
1832         i_mb_address_save = *pi_mb_address;
1833     }
1834     while( ShowBits( &p_vpar->bit_stream, 23 ) && !p_vpar->picture.b_error
1835             && !p_vpar->b_die );
1836     NextStartCode( p_vpar );
1837 }
1838
1839 /*****************************************************************************
1840  * PictureData : Parse off all macroblocks (ISO/IEC 13818-2 6.2.3.7)
1841  *****************************************************************************/
1842 static __inline__ void PictureData( vpar_thread_t * p_vpar, int i_mb_base,
1843                                     boolean_t b_high, boolean_t b_dp_scalable,
1844                                     boolean_t b_mpeg2, int i_coding_type,
1845                                     int i_chroma_format, int i_structure,
1846                                     boolean_t b_second_field )
1847 {
1848     int         i_mb_address = 0;
1849     u32         i_dummy;
1850
1851     NextStartCode( p_vpar );
1852     while( (i_coding_type != I_CODING_TYPE || i_coding_type != D_CODING_TYPE
1853              || !p_vpar->picture.b_error)
1854            && i_mb_address+i_mb_base < p_vpar->sequence.i_mb_size
1855            && !p_vpar->b_die )
1856     {
1857         if( ((i_dummy = ShowBits( &p_vpar->bit_stream, 32 ))
1858                  < SLICE_START_CODE_MIN) ||
1859             (i_dummy > SLICE_START_CODE_MAX) )
1860         {
1861             intf_DbgMsg("vpar debug: premature end of picture\n");
1862             p_vpar->picture.b_error = 1;
1863             break;
1864         }
1865         RemoveBits32( &p_vpar->bit_stream );
1866         
1867         /* Decode slice data. */
1868         SliceHeader( p_vpar, &i_mb_address, i_mb_base, i_dummy & 255,
1869                      b_high, b_dp_scalable, b_mpeg2, i_coding_type,
1870                      i_chroma_format, i_structure, b_second_field );
1871     }
1872
1873     /* Try to recover from error. If we missed less than half the
1874      * number of macroblocks of the picture, mark the missed ones
1875      * as skipped. */
1876     if( (i_coding_type == P_CODING_TYPE || i_coding_type == B_CODING_TYPE)
1877         && p_vpar->picture.b_error &&
1878         ( (i_mb_address-i_mb_base) > (p_vpar->sequence.i_mb_size >> 1)
1879            || (i_structure != FRAME_STRUCTURE
1880                && (i_mb_address-i_mb_base) > (p_vpar->sequence.i_mb_size >> 2) ) ) )
1881     {
1882         int         i_mb;
1883
1884         p_vpar->picture.b_error = 0;
1885         for( i_mb = i_mb_address + 1;
1886              i_mb < (p_vpar->sequence.i_mb_size
1887                      << (i_structure != FRAME_STRUCTURE));
1888              i_mb++ )
1889         {
1890             SkippedMacroblock( p_vpar, i_mb, i_mb_base, i_coding_type,
1891                                i_chroma_format, i_structure, b_second_field );
1892         }
1893     }
1894 }
1895
1896 /*****************************************************************************
1897  * vpar_PictureDataVWXYZ : Parse the next macroblock ; specific functions
1898  *****************************************************************************
1899  * V = MPEG2 ?
1900  * W = coding type ?
1901  * X = chroma format ?
1902  * Y = structure ?
1903  * Z = second field ?
1904  *****************************************************************************/
1905 void vpar_PictureDataGENERIC( vpar_thread_t * p_vpar, int i_mb_base )
1906 {
1907     PictureData( p_vpar, i_mb_base, (p_vpar->sequence.i_height > 2800),
1908                  (p_vpar->sequence.i_scalable_mode == SC_DP),
1909                  p_vpar->sequence.b_mpeg2, p_vpar->picture.i_coding_type,
1910                  p_vpar->sequence.i_chroma_format,
1911                  p_vpar->picture.i_structure,
1912                  (p_vpar->picture.i_structure !=
1913                     p_vpar->picture.i_current_structure) );
1914 }
1915
1916 #if (VPAR_OPTIM_LEVEL > 0)
1917 /* Optimizations for frame pictures */
1918 void vpar_PictureData2I420F0( vpar_thread_t * p_vpar, int i_mb_base )
1919 {
1920     PictureData( p_vpar, 0, 0, 0, 1, I_CODING_TYPE, CHROMA_420,
1921                  FRAME_STRUCTURE, 0 );
1922 }
1923
1924 void vpar_PictureData2P420F0( vpar_thread_t * p_vpar, int i_mb_base )
1925 {
1926     PictureData( p_vpar, 0, 0, 0, 1, P_CODING_TYPE, CHROMA_420,
1927                  FRAME_STRUCTURE, 0 );
1928 }
1929
1930 void vpar_PictureData2B420F0( vpar_thread_t * p_vpar, int i_mb_base )
1931 {
1932     PictureData( p_vpar, 0, 0, 0, 1, B_CODING_TYPE, CHROMA_420,
1933                  FRAME_STRUCTURE, 0 );
1934 }
1935 #endif
1936
1937 #if (VPAR_OPTIM_LEVEL > 1)
1938 /* Optimizations for field pictures */
1939 void vpar_PictureData2I420TZ( vpar_thread_t * p_vpar, int i_mb_base )
1940 {
1941     PictureData( p_vpar, i_mb_base, 0, 0, 1, I_CODING_TYPE, CHROMA_420,
1942                  TOP_FIELD, (p_vpar->picture.i_structure !=
1943                                 p_vpar->picture.i_current_structure) );
1944 }
1945
1946 void vpar_PictureData2P420TZ( vpar_thread_t * p_vpar, int i_mb_base )
1947 {
1948     PictureData( p_vpar, i_mb_base, 0, 0, 1, P_CODING_TYPE, CHROMA_420,
1949                  TOP_FIELD, (p_vpar->picture.i_structure !=
1950                                 p_vpar->picture.i_current_structure) );
1951 }
1952
1953 void vpar_PictureData2B420TZ( vpar_thread_t * p_vpar, int i_mb_base )
1954 {
1955     PictureData( p_vpar, i_mb_base, 0, 0, 1, B_CODING_TYPE, CHROMA_420,
1956                  TOP_FIELD, (p_vpar->picture.i_structure !=
1957                                 p_vpar->picture.i_current_structure) );
1958 }
1959
1960 void vpar_PictureData2I420BZ( vpar_thread_t * p_vpar, int i_mb_base )
1961 {
1962     PictureData( p_vpar, i_mb_base, 0, 0, 1, I_CODING_TYPE, CHROMA_420,
1963                  BOTTOM_FIELD, (p_vpar->picture.i_structure !=
1964                                 p_vpar->picture.i_current_structure) );
1965 }
1966
1967 void vpar_PictureData2P420BZ( vpar_thread_t * p_vpar, int i_mb_base )
1968 {
1969     PictureData( p_vpar, i_mb_base, 0, 0, 1, P_CODING_TYPE, CHROMA_420,
1970                  BOTTOM_FIELD, (p_vpar->picture.i_structure !=
1971                                 p_vpar->picture.i_current_structure) );
1972 }
1973
1974 void vpar_PictureData2B420BZ( vpar_thread_t * p_vpar, int i_mb_base )
1975 {
1976     PictureData( p_vpar, i_mb_base, 0, 0, 1, B_CODING_TYPE, CHROMA_420,
1977                  BOTTOM_FIELD, (p_vpar->picture.i_structure !=
1978                                 p_vpar->picture.i_current_structure) );
1979 }
1980 #endif