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