[svn] / trunk / xvidcore / src / prediction / mbprediction.h Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/src/prediction/mbprediction.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 248 - (view) (download)

1 : edgomez 149 /**************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - MB prediction header file -
5 :     *
6 :     * This program is an implementation of a part of one or more MPEG-4
7 :     * Video tools as specified in ISO/IEC 14496-2 standard. Those intending
8 :     * to use this software module in hardware or software products are
9 :     * advised that its use may infringe existing patents or copyrights, and
10 :     * any such use would be at such party's own risk. The original
11 :     * developer of this software module and his/her company, and subsequent
12 :     * editors and their companies, will have no liability for use of this
13 :     * software or modifications or derivatives thereof.
14 :     *
15 :     * This program is free software; you can redistribute it and/or modify
16 :     * it under the terms of the GNU General Public License as published by
17 :     * the xvid_free Software Foundation; either version 2 of the License, or
18 :     * (at your option) any later version.
19 :     *
20 :     * This program is distributed in the hope that it will be useful,
21 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 :     * GNU General Public License for more details.
24 :     *
25 :     * You should have received a copy of the GNU General Public License
26 :     * along with this program; if not, write to the xvid_free Software
27 :     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 :     *
29 : suxen_drol 248 * $Id: mbprediction.h,v 1.10 2002-06-28 15:14:40 suxen_drol Exp $
30 : edgomez 149 *
31 :     *************************************************************************/
32 :    
33 : suxen_drol 248 /******************************************************************************
34 :     * *
35 :     * Revision history: *
36 :     * *
37 :     * 29.06.2002 get_pmvdata() bounding *
38 :     * *
39 :     ******************************************************************************/
40 :    
41 :    
42 : Isibaar 3 #ifndef _MBPREDICTION_H_
43 :     #define _MBPREDICTION_H_
44 :    
45 :     #include "../portab.h"
46 :     #include "../decoder.h"
47 :     #include "../global.h"
48 :    
49 :     #define MIN(X, Y) ((X)<(Y)?(X):(Y))
50 :     #define MAX(X, Y) ((X)>(Y)?(X):(Y))
51 :    
52 : edgomez 149 /* very large value */
53 : Isibaar 3 #define MV_MAX_ERROR (4096 * 256)
54 :    
55 :     #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
56 :    
57 : edgomez 195 void MBPrediction(FRAMEINFO * frame, /* <-- The parameter for ACDC and MV prediction */
58 : Isibaar 3
59 : edgomez 195 uint32_t x_pos, /* <-- The x position of the MB to be searched */
60 : Isibaar 3
61 : edgomez 195 uint32_t y_pos, /* <-- The y position of the MB to be searched */
62 : Isibaar 3
63 : edgomez 195 uint32_t x_dim, /* <-- Number of macroblocks in a row */
64 : Isibaar 3
65 : edgomez 195 int16_t * qcoeff); /* <-> The quantized DCT coefficients */
66 :    
67 :     void add_acdc(MACROBLOCK * pMB,
68 :     uint32_t block,
69 :     int16_t dct_codes[64],
70 :     uint32_t iDcScaler,
71 :     int16_t predictors[8]);
72 :    
73 :    
74 :     void predict_acdc(MACROBLOCK * pMBs,
75 :     uint32_t x,
76 :     uint32_t y,
77 :     uint32_t mb_width,
78 :     uint32_t block,
79 :     int16_t qcoeff[64],
80 :     uint32_t current_quant,
81 :     int32_t iDcScaler,
82 : suxen_drol 248 int16_t predictors[8],
83 :     const unsigned int bound_x,
84 :     const unsigned int bound_y);
85 : edgomez 195
86 : suxen_drol 248
87 : chl 139 /* get_pmvdata returns the median predictor and nothing else */
88 :    
89 : edgomez 195 static __inline VECTOR
90 :     get_pmv(const MACROBLOCK * const pMBs,
91 :     const uint32_t x,
92 :     const uint32_t y,
93 :     const uint32_t x_dim,
94 :     const uint32_t block)
95 : chl 139 {
96 :    
97 : edgomez 149 int xin1, xin2, xin3;
98 :     int yin1, yin2, yin3;
99 :     int vec1, vec2, vec3;
100 : edgomez 195 VECTOR lneigh, tneigh, trneigh; /* left neighbour, top neighbour, topright neighbour */
101 : edgomez 149 VECTOR median;
102 : chl 139
103 : edgomez 195 static VECTOR zeroMV = { 0, 0 };
104 : edgomez 149 uint32_t index = x + y * x_dim;
105 : chl 139
106 : edgomez 149 /* first row (special case) */
107 : edgomez 195 if (y == 0 && (block == 0 || block == 1)) {
108 :     if ((x == 0) && (block == 0)) // first column, first block
109 :     {
110 : chl 139 return zeroMV;
111 :     }
112 : edgomez 195 if (block == 1) // second block; has only a left neighbour
113 : chl 139 {
114 :     return pMBs[index].mvs[0];
115 : edgomez 195 } else { /* block==0, but x!=0, so again, there is a left neighbour */
116 :    
117 :     return pMBs[index - 1].mvs[1];
118 : chl 139 }
119 : edgomez 149 }
120 : chl 139
121 :     /*
122 : edgomez 149 * MODE_INTER, vm18 page 48
123 :     * MODE_INTER4V vm18 page 51
124 :     *
125 :     * (x,y-1) (x+1,y-1)
126 :     * [ | ] [ | ]
127 :     * [ 2 | 3 ] [ 2 | ]
128 :     *
129 :     * (x-1,y) (x,y) (x+1,y)
130 :     * [ | 1 ] [ 0 | 1 ] [ 0 | ]
131 :     * [ | 3 ] [ 2 | 3 ] [ | ]
132 :     */
133 : chl 139
134 : edgomez 195 switch (block) {
135 : chl 139 case 0:
136 : edgomez 195 xin1 = x - 1;
137 :     yin1 = y;
138 :     vec1 = 1; /* left */
139 :     xin2 = x;
140 :     yin2 = y - 1;
141 :     vec2 = 2; /* top */
142 :     xin3 = x + 1;
143 :     yin3 = y - 1;
144 :     vec3 = 2; /* top right */
145 : chl 139 break;
146 :     case 1:
147 : edgomez 195 xin1 = x;
148 :     yin1 = y;
149 :     vec1 = 0;
150 :     xin2 = x;
151 :     yin2 = y - 1;
152 :     vec2 = 3;
153 :     xin3 = x + 1;
154 :     yin3 = y - 1;
155 :     vec3 = 2;
156 : edgomez 149 break;
157 : chl 139 case 2:
158 : edgomez 195 xin1 = x - 1;
159 :     yin1 = y;
160 :     vec1 = 3;
161 :     xin2 = x;
162 :     yin2 = y;
163 :     vec2 = 0;
164 :     xin3 = x;
165 :     yin3 = y;
166 :     vec3 = 1;
167 : edgomez 149 break;
168 : chl 139 default:
169 : edgomez 195 xin1 = x;
170 :     yin1 = y;
171 :     vec1 = 2;
172 :     xin2 = x;
173 :     yin2 = y;
174 :     vec2 = 0;
175 :     xin3 = x;
176 :     yin3 = y;
177 :     vec3 = 1;
178 : edgomez 149 }
179 : chl 139
180 :    
181 : edgomez 195 if (xin1 < 0 || /* yin1 < 0 || */ xin1 >= (int32_t) x_dim) {
182 :     lneigh = zeroMV;
183 :     } else {
184 :     lneigh = pMBs[xin1 + yin1 * x_dim].mvs[vec1];
185 : chl 139 }
186 :    
187 : edgomez 195 if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t) x_dim) {
188 : chl 139 tneigh = zeroMV;
189 : edgomez 195 } else {
190 :     tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2];
191 : chl 139 }
192 :    
193 : edgomez 195 if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t) x_dim) {
194 : chl 139 trneigh = zeroMV;
195 : edgomez 195 } else {
196 : chl 139 trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3];
197 :     }
198 :    
199 : edgomez 149 /* median,minimum */
200 : edgomez 195
201 :     median.x =
202 :     MIN(MAX(lneigh.x, tneigh.x),
203 :     MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x)));
204 :     median.y =
205 :     MIN(MAX(lneigh.y, tneigh.y),
206 :     MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y)));
207 : chl 139 return median;
208 :     }
209 :    
210 :    
211 : Isibaar 3 /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD
212 :     instead of only Median MV */
213 :    
214 : edgomez 195 static __inline int
215 :     get_pmvdata(const MACROBLOCK * const pMBs,
216 :     const uint32_t x,
217 :     const uint32_t y,
218 :     const uint32_t x_dim,
219 :     const uint32_t block,
220 :     VECTOR * const pmv,
221 : suxen_drol 248 int32_t * const psad,
222 :     const unsigned int bound_x,
223 :     const unsigned int bound_y)
224 : Isibaar 3 {
225 :    
226 : edgomez 149 /*
227 :     * pmv are filled with:
228 :     * [0]: Median (or whatever is correct in a special case)
229 :     * [1]: left neighbour
230 :     * [2]: top neighbour
231 :     * [3]: topright neighbour
232 :     * psad are filled with:
233 :     * [0]: minimum of [1] to [3]
234 :     * [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed)
235 :     * [2]: top neighbour's SAD
236 :     * [3]: topright neighbour's SAD
237 :     */
238 : Isibaar 3
239 : edgomez 149 int xin1, xin2, xin3;
240 :     int yin1, yin2, yin3;
241 :     int vec1, vec2, vec3;
242 : Isibaar 3
243 : edgomez 149 uint32_t index = x + y * x_dim;
244 : edgomez 195 const VECTOR zeroMV = { 0, 0 };
245 : edgomez 149
246 : chl 166 // first row of blocks (special case)
247 : suxen_drol 248 /* if (y == 0 && (block == 0 || block == 1)) { */
248 :     if (((y == bound_y && x >= bound_x) || (y == bound_y + 1 && x < bound_x))
249 :     && (block == 0 || block == 1)) {
250 :    
251 :     /* if ((x == 0) && (block == 0)) */ // first column, first block
252 :     if ((x == 0 || (y == bound_y && x == bound_x)) && (block == 0)) // first column, first block
253 : edgomez 195 {
254 : Isibaar 3 pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
255 : chl 166 psad[0] = 0;
256 :     psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;
257 : Isibaar 3 return 0;
258 :     }
259 : edgomez 195 if (block == 1) // second block; has only a left neighbour
260 : Isibaar 3 {
261 :     pmv[0] = pmv[1] = pMBs[index].mvs[0];
262 :     pmv[2] = pmv[3] = zeroMV;
263 :     psad[0] = psad[1] = pMBs[index].sad8[0];
264 : chl 166 psad[2] = psad[3] = MV_MAX_ERROR;
265 : Isibaar 3 return 0;
266 : edgomez 195 } else { /* block==0, but x!=0, so again, there is a left neighbour */
267 :    
268 :     pmv[0] = pmv[1] = pMBs[index - 1].mvs[1];
269 : Isibaar 3 pmv[2] = pmv[3] = zeroMV;
270 : edgomez 195 psad[0] = psad[1] = pMBs[index - 1].sad8[1];
271 : chl 166 psad[2] = psad[3] = MV_MAX_ERROR;
272 : Isibaar 3 return 0;
273 :     }
274 : edgomez 149 }
275 : Isibaar 3
276 :     /*
277 : edgomez 149 * MODE_INTER, vm18 page 48
278 :     * MODE_INTER4V vm18 page 51
279 :     *
280 :     * (x,y-1) (x+1,y-1)
281 :     * [ | ] [ | ]
282 :     * [ 2 | 3 ] [ 2 | ]
283 :     *
284 :     * (x-1,y) (x,y) (x+1,y)
285 :     * [ | 1 ] [ 0 | 1 ] [ 0 | ]
286 :     * [ | 3 ] [ 2 | 3 ] [ | ]
287 :     */
288 : Isibaar 3
289 : edgomez 195 switch (block) {
290 : Isibaar 3 case 0:
291 : edgomez 195 xin1 = x - 1;
292 :     yin1 = y;
293 :     vec1 = 1; /* left */
294 :     xin2 = x;
295 :     yin2 = y - 1;
296 :     vec2 = 2; /* top */
297 :     xin3 = x + 1;
298 :     yin3 = y - 1;
299 :     vec3 = 2; /* top right */
300 : Isibaar 3 break;
301 :     case 1:
302 : edgomez 195 xin1 = x;
303 :     yin1 = y;
304 :     vec1 = 0;
305 :     xin2 = x;
306 :     yin2 = y - 1;
307 :     vec2 = 3;
308 :     xin3 = x + 1;
309 :     yin3 = y - 1;
310 :     vec3 = 2;
311 : edgomez 149 break;
312 : Isibaar 3 case 2:
313 : edgomez 195 xin1 = x - 1;
314 :     yin1 = y;
315 :     vec1 = 3;
316 :     xin2 = x;
317 :     yin2 = y;
318 :     vec2 = 0;
319 :     xin3 = x;
320 :     yin3 = y;
321 :     vec3 = 1;
322 : edgomez 149 break;
323 : Isibaar 3 default:
324 : edgomez 195 xin1 = x;
325 :     yin1 = y;
326 :     vec1 = 2;
327 :     xin2 = x;
328 :     yin2 = y;
329 :     vec2 = 0;
330 :     xin3 = x;
331 :     yin3 = y;
332 :     vec3 = 1;
333 : edgomez 149 }
334 : Isibaar 3
335 :    
336 : edgomez 195 if (xin1 < 0 || xin1 >= (int32_t) x_dim) {
337 : chl 165 pmv[1] = zeroMV;
338 : Isibaar 3 psad[1] = MV_MAX_ERROR;
339 : edgomez 195 } else {
340 :     pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1];
341 :     psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1];
342 : Isibaar 3 }
343 :    
344 : edgomez 195 if (xin2 < 0 || xin2 >= (int32_t) x_dim) {
345 : Isibaar 3 pmv[2] = zeroMV;
346 :     psad[2] = MV_MAX_ERROR;
347 : edgomez 195 } else {
348 :     pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2];
349 :     psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2];
350 : Isibaar 3 }
351 :    
352 : edgomez 195 if (xin3 < 0 || xin3 >= (int32_t) x_dim) {
353 : Isibaar 3 pmv[3] = zeroMV;
354 :     psad[3] = MV_MAX_ERROR;
355 : edgomez 195 } else {
356 : Isibaar 3 pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];
357 : edgomez 195 psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3];
358 : Isibaar 3 }
359 :    
360 : edgomez 195 if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
361 :     pmv[0] = pmv[1];
362 :     psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
363 : chl 165 return 1;
364 : Isibaar 3 }
365 :    
366 : edgomez 149 /* median,minimum */
367 :    
368 : edgomez 195 pmv[0].x =
369 :     MIN(MAX(pmv[1].x, pmv[2].x),
370 :     MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
371 :     pmv[0].y =
372 :     MIN(MAX(pmv[1].y, pmv[2].y),
373 :     MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
374 :     psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
375 :    
376 : Isibaar 3 return 0;
377 :     }
378 :    
379 :    
380 : chl 139
381 : edgomez 195 #endif /* _MBPREDICTION_H_ */

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4