3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - MB prediction header file - |
* - MB prediction header file - |
5 |
* |
* |
6 |
* Copyright(C) 2002 Christoph Lampert <gruel@web.de> |
* This program is an implementation of a part of one or more MPEG-4 |
7 |
* 2002 Peter Ross <pross@xvid.org> |
* 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 file is part of XviD, a free MPEG-4 video encoder/decoder |
* 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 |
* XviD is free software; you can redistribute it and/or modify it |
* the xvid_free Software Foundation; either version 2 of the License, or |
|
* under the terms of the GNU General Public License as published by |
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
18 |
* (at your option) any later version. |
* (at your option) any later version. |
19 |
* |
* |
20 |
* This program is distributed in the hope that it will be useful, |
* This program is distributed in the hope that it will be useful, |
23 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
24 |
* |
* |
25 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
26 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the xvid_free Software |
27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
* |
|
|
* Under section 8 of the GNU General Public License, the copyright |
|
|
* holders of XVID explicitly forbid distribution in the following |
|
|
* countries: |
|
|
* |
|
|
* - Japan |
|
|
* - United States of America |
|
|
* |
|
|
* Linking XviD statically or dynamically with other modules is making a |
|
|
* combined work based on XviD. Thus, the terms and conditions of the |
|
|
* GNU General Public License cover the whole combination. |
|
|
* |
|
|
* As a special exception, the copyright holders of XviD give you |
|
|
* permission to link XviD with independent modules that communicate with |
|
|
* XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
|
|
* license terms of these independent modules, and to copy and distribute |
|
|
* the resulting combined work under terms of your choice, provided that |
|
|
* every copy of the combined work is accompanied by a complete copy of |
|
|
* the source code of XviD (the version of XviD used to produce the |
|
|
* combined work), being distributed under the terms of the GNU General |
|
|
* Public License plus this exception. An independent module is a module |
|
|
* which is not derived from or based on XviD. |
|
|
* |
|
|
* Note that people who make modified versions of XviD are not obligated |
|
|
* to grant this special exception for their modified versions; it is |
|
|
* their choice whether to do so. The GNU General Public License gives |
|
|
* permission to release a modified version without this exception; this |
|
|
* exception also makes it possible to release a modified version which |
|
|
* carries forward this exception. |
|
28 |
* |
* |
29 |
* $Id: mbprediction.h,v 1.18 2002-11-26 23:44:11 edgomez Exp $ |
* $Id: mbprediction.h,v 1.19 2003-02-15 15:22:19 edgomez Exp $ |
30 |
* |
* |
31 |
*************************************************************************/ |
*************************************************************************/ |
32 |
|
|
33 |
|
/****************************************************************************** |
34 |
|
* * |
35 |
|
* Revision history: * |
36 |
|
* * |
37 |
|
* 29.06.2002 get_pmvdata() bounding * |
38 |
|
* * |
39 |
|
******************************************************************************/ |
40 |
|
|
41 |
|
|
42 |
#ifndef _MBPREDICTION_H_ |
#ifndef _MBPREDICTION_H_ |
43 |
#define _MBPREDICTION_H_ |
#define _MBPREDICTION_H_ |
44 |
|
|
54 |
|
|
55 |
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
56 |
|
|
|
/***************************************************************************** |
|
|
* Prototypes |
|
|
****************************************************************************/ |
|
|
|
|
57 |
void MBPrediction(FRAMEINFO * frame, /* <-- The parameter for ACDC and MV prediction */ |
void MBPrediction(FRAMEINFO * frame, /* <-- The parameter for ACDC and MV prediction */ |
58 |
|
|
59 |
uint32_t x_pos, /* <-- The x position of the MB to be searched */ |
uint32_t x_pos, /* <-- The x position of the MB to be searched */ |
83 |
const int bound); |
const int bound); |
84 |
|
|
85 |
|
|
86 |
/***************************************************************************** |
#ifdef OLD_GETPMV |
87 |
* Inlined functions |
/* get_pmvdata returns the median predictor and nothing else */ |
88 |
****************************************************************************/ |
|
89 |
|
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 |
|
{ |
96 |
|
|
97 |
|
int xin1, xin2, xin3; |
98 |
|
int yin1, yin2, yin3; |
99 |
|
int vec1, vec2, vec3; |
100 |
|
VECTOR lneigh, tneigh, trneigh; /* left neighbour, top neighbour, topright neighbour */ |
101 |
|
VECTOR median; |
102 |
|
|
103 |
|
static VECTOR zeroMV = { 0, 0 }; |
104 |
|
uint32_t index = x + y * x_dim; |
105 |
|
|
106 |
|
/* first row (special case) */ |
107 |
|
if (y == 0 && (block == 0 || block == 1)) { |
108 |
|
if ((x == 0) && (block == 0)) // first column, first block |
109 |
|
{ |
110 |
|
return zeroMV; |
111 |
|
} |
112 |
|
if (block == 1) // second block; has only a left neighbour |
113 |
|
{ |
114 |
|
return pMBs[index].mvs[0]; |
115 |
|
} else { /* block==0, but x!=0, so again, there is a left neighbour */ |
116 |
|
|
117 |
|
return pMBs[index - 1].mvs[1]; |
118 |
|
} |
119 |
|
} |
120 |
|
|
121 |
|
/* |
122 |
|
* 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 |
|
|
134 |
|
switch (block) { |
135 |
|
case 0: |
136 |
|
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 |
|
break; |
146 |
|
case 1: |
147 |
|
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 |
|
break; |
157 |
|
case 2: |
158 |
|
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 |
|
break; |
168 |
|
default: |
169 |
|
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 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
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 |
|
} |
186 |
|
|
187 |
|
if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t) x_dim) { |
188 |
|
tneigh = zeroMV; |
189 |
|
} else { |
190 |
|
tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2]; |
191 |
|
} |
192 |
|
|
193 |
|
if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t) x_dim) { |
194 |
|
trneigh = zeroMV; |
195 |
|
} else { |
196 |
|
trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
197 |
|
} |
198 |
|
|
199 |
|
/* median,minimum */ |
200 |
|
|
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 |
|
return median; |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
static __inline VECTOR |
212 |
|
get_qpmv(const MACROBLOCK * const pMBs, |
213 |
|
const uint32_t x, |
214 |
|
const uint32_t y, |
215 |
|
const uint32_t x_dim, |
216 |
|
const uint32_t block) |
217 |
|
{ |
218 |
|
|
219 |
|
int xin1, xin2, xin3; |
220 |
|
int yin1, yin2, yin3; |
221 |
|
int vec1, vec2, vec3; |
222 |
|
VECTOR lneigh, tneigh, trneigh; /* left neighbour, top neighbour, topright neighbour */ |
223 |
|
VECTOR median; |
224 |
|
|
225 |
|
static VECTOR zeroMV = { 0, 0 }; |
226 |
|
uint32_t index = x + y * x_dim; |
227 |
|
|
228 |
|
/* first row (special case) */ |
229 |
|
if (y == 0 && (block == 0 || block == 1)) { |
230 |
|
if ((x == 0) && (block == 0)) // first column, first block |
231 |
|
{ |
232 |
|
return zeroMV; |
233 |
|
} |
234 |
|
if (block == 1) // second block; has only a left neighbour |
235 |
|
{ |
236 |
|
return pMBs[index].qmvs[0]; |
237 |
|
} else { /* block==0, but x!=0, so again, there is a left neighbour */ |
238 |
|
|
239 |
|
return pMBs[index - 1].qmvs[1]; |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
|
/* |
244 |
|
* MODE_INTER, vm18 page 48 |
245 |
|
* MODE_INTER4V vm18 page 51 |
246 |
|
* |
247 |
|
* (x,y-1) (x+1,y-1) |
248 |
|
* [ | ] [ | ] |
249 |
|
* [ 2 | 3 ] [ 2 | ] |
250 |
|
* |
251 |
|
* (x-1,y) (x,y) (x+1,y) |
252 |
|
* [ | 1 ] [ 0 | 1 ] [ 0 | ] |
253 |
|
* [ | 3 ] [ 2 | 3 ] [ | ] |
254 |
|
*/ |
255 |
|
|
256 |
|
switch (block) { |
257 |
|
case 0: |
258 |
|
xin1 = x - 1; |
259 |
|
yin1 = y; |
260 |
|
vec1 = 1; /* left */ |
261 |
|
xin2 = x; |
262 |
|
yin2 = y - 1; |
263 |
|
vec2 = 2; /* top */ |
264 |
|
xin3 = x + 1; |
265 |
|
yin3 = y - 1; |
266 |
|
vec3 = 2; /* top right */ |
267 |
|
break; |
268 |
|
case 1: |
269 |
|
xin1 = x; |
270 |
|
yin1 = y; |
271 |
|
vec1 = 0; |
272 |
|
xin2 = x; |
273 |
|
yin2 = y - 1; |
274 |
|
vec2 = 3; |
275 |
|
xin3 = x + 1; |
276 |
|
yin3 = y - 1; |
277 |
|
vec3 = 2; |
278 |
|
break; |
279 |
|
case 2: |
280 |
|
xin1 = x - 1; |
281 |
|
yin1 = y; |
282 |
|
vec1 = 3; |
283 |
|
xin2 = x; |
284 |
|
yin2 = y; |
285 |
|
vec2 = 0; |
286 |
|
xin3 = x; |
287 |
|
yin3 = y; |
288 |
|
vec3 = 1; |
289 |
|
break; |
290 |
|
default: |
291 |
|
xin1 = x; |
292 |
|
yin1 = y; |
293 |
|
vec1 = 2; |
294 |
|
xin2 = x; |
295 |
|
yin2 = y; |
296 |
|
vec2 = 0; |
297 |
|
xin3 = x; |
298 |
|
yin3 = y; |
299 |
|
vec3 = 1; |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
|
if (xin1 < 0 || /* yin1 < 0 || */ xin1 >= (int32_t) x_dim) { |
304 |
|
lneigh = zeroMV; |
305 |
|
} else { |
306 |
|
lneigh = pMBs[xin1 + yin1 * x_dim].qmvs[vec1]; |
307 |
|
} |
308 |
|
|
309 |
|
if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t) x_dim) { |
310 |
|
tneigh = zeroMV; |
311 |
|
} else { |
312 |
|
tneigh = pMBs[xin2 + yin2 * x_dim].qmvs[vec2]; |
313 |
|
} |
314 |
|
|
315 |
|
if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t) x_dim) { |
316 |
|
trneigh = zeroMV; |
317 |
|
} else { |
318 |
|
trneigh = pMBs[xin3 + yin3 * x_dim].qmvs[vec3]; |
319 |
|
} |
320 |
|
|
321 |
|
/* median,minimum */ |
322 |
|
|
323 |
|
median.x = |
324 |
|
MIN(MAX(lneigh.x, tneigh.x), |
325 |
|
MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x))); |
326 |
|
median.y = |
327 |
|
MIN(MAX(lneigh.y, tneigh.y), |
328 |
|
MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y))); |
329 |
|
return median; |
330 |
|
} |
331 |
|
|
332 |
|
/* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD |
333 |
|
instead of only Median MV */ |
334 |
|
|
335 |
|
static __inline int |
336 |
|
get_pmvdata(const MACROBLOCK * const pMBs, |
337 |
|
const uint32_t x, |
338 |
|
const uint32_t y, |
339 |
|
const uint32_t x_dim, |
340 |
|
const uint32_t block, |
341 |
|
VECTOR * const pmv, |
342 |
|
int32_t * const psad) |
343 |
|
{ |
344 |
|
|
345 |
|
/* |
346 |
|
* pmv are filled with: |
347 |
|
* [0]: Median (or whatever is correct in a special case) |
348 |
|
* [1]: left neighbour |
349 |
|
* [2]: top neighbour |
350 |
|
* [3]: topright neighbour |
351 |
|
* psad are filled with: |
352 |
|
* [0]: minimum of [1] to [3] |
353 |
|
* [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed) |
354 |
|
* [2]: top neighbour's SAD |
355 |
|
* [3]: topright neighbour's SAD |
356 |
|
*/ |
357 |
|
|
358 |
|
int xin1, xin2, xin3; |
359 |
|
int yin1, yin2, yin3; |
360 |
|
int vec1, vec2, vec3; |
361 |
|
|
362 |
|
uint32_t index = x + y * x_dim; |
363 |
|
const VECTOR zeroMV = { 0, 0 }; |
364 |
|
|
365 |
|
// first row of blocks (special case) |
366 |
|
if (y == 0 && (block == 0 || block == 1)) { |
367 |
|
if ((x == 0) && (block == 0)) // first column, first block |
368 |
|
{ |
369 |
|
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
370 |
|
psad[0] = 0; |
371 |
|
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
372 |
|
return 0; |
373 |
|
} |
374 |
|
if (block == 1) // second block; has only a left neighbour |
375 |
|
{ |
376 |
|
pmv[0] = pmv[1] = pMBs[index].mvs[0]; |
377 |
|
pmv[2] = pmv[3] = zeroMV; |
378 |
|
psad[0] = psad[1] = pMBs[index].sad8[0]; |
379 |
|
psad[2] = psad[3] = MV_MAX_ERROR; |
380 |
|
return 0; |
381 |
|
} else { /* block==0, but x!=0, so again, there is a left neighbour */ |
382 |
|
|
383 |
|
pmv[0] = pmv[1] = pMBs[index - 1].mvs[1]; |
384 |
|
pmv[2] = pmv[3] = zeroMV; |
385 |
|
psad[0] = psad[1] = pMBs[index - 1].sad8[1]; |
386 |
|
psad[2] = psad[3] = MV_MAX_ERROR; |
387 |
|
return 0; |
388 |
|
} |
389 |
|
} |
390 |
|
|
391 |
|
/* |
392 |
|
* MODE_INTER, vm18 page 48 |
393 |
|
* MODE_INTER4V vm18 page 51 |
394 |
|
* |
395 |
|
* (x,y-1) (x+1,y-1) |
396 |
|
* [ | ] [ | ] |
397 |
|
* [ 2 | 3 ] [ 2 | ] |
398 |
|
* |
399 |
|
* (x-1,y) (x,y) (x+1,y) |
400 |
|
* [ | 1 ] [ 0 | 1 ] [ 0 | ] |
401 |
|
* [ | 3 ] [ 2 | 3 ] [ | ] |
402 |
|
*/ |
403 |
|
|
404 |
|
switch (block) { |
405 |
|
case 0: |
406 |
|
xin1 = x - 1; |
407 |
|
yin1 = y; |
408 |
|
vec1 = 1; /* left */ |
409 |
|
xin2 = x; |
410 |
|
yin2 = y - 1; |
411 |
|
vec2 = 2; /* top */ |
412 |
|
xin3 = x + 1; |
413 |
|
yin3 = y - 1; |
414 |
|
vec3 = 2; /* top right */ |
415 |
|
break; |
416 |
|
case 1: |
417 |
|
xin1 = x; |
418 |
|
yin1 = y; |
419 |
|
vec1 = 0; |
420 |
|
xin2 = x; |
421 |
|
yin2 = y - 1; |
422 |
|
vec2 = 3; |
423 |
|
xin3 = x + 1; |
424 |
|
yin3 = y - 1; |
425 |
|
vec3 = 2; |
426 |
|
break; |
427 |
|
case 2: |
428 |
|
xin1 = x - 1; |
429 |
|
yin1 = y; |
430 |
|
vec1 = 3; |
431 |
|
xin2 = x; |
432 |
|
yin2 = y; |
433 |
|
vec2 = 0; |
434 |
|
xin3 = x; |
435 |
|
yin3 = y; |
436 |
|
vec3 = 1; |
437 |
|
break; |
438 |
|
default: |
439 |
|
xin1 = x; |
440 |
|
yin1 = y; |
441 |
|
vec1 = 2; |
442 |
|
xin2 = x; |
443 |
|
yin2 = y; |
444 |
|
vec2 = 0; |
445 |
|
xin3 = x; |
446 |
|
yin3 = y; |
447 |
|
vec3 = 1; |
448 |
|
} |
449 |
|
|
450 |
|
|
451 |
|
if (xin1 < 0 || xin1 >= (int32_t) x_dim) { |
452 |
|
pmv[1] = zeroMV; |
453 |
|
psad[1] = MV_MAX_ERROR; |
454 |
|
} else { |
455 |
|
pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1]; |
456 |
|
psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1]; |
457 |
|
} |
458 |
|
|
459 |
|
if (xin2 < 0 || xin2 >= (int32_t) x_dim) { |
460 |
|
pmv[2] = zeroMV; |
461 |
|
psad[2] = MV_MAX_ERROR; |
462 |
|
} else { |
463 |
|
pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2]; |
464 |
|
psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2]; |
465 |
|
} |
466 |
|
|
467 |
|
if (xin3 < 0 || xin3 >= (int32_t) x_dim) { |
468 |
|
pmv[3] = zeroMV; |
469 |
|
psad[3] = MV_MAX_ERROR; |
470 |
|
} else { |
471 |
|
pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
472 |
|
psad[3] = pMBs[xin3 + yin3 * x_dim].sad8[vec3]; |
473 |
|
} |
474 |
|
|
475 |
|
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
476 |
|
pmv[0] = pmv[1]; |
477 |
|
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
478 |
|
return 1; |
479 |
|
} |
480 |
|
|
481 |
|
/* median,minimum */ |
482 |
|
|
483 |
|
pmv[0].x = |
484 |
|
MIN(MAX(pmv[1].x, pmv[2].x), |
485 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
486 |
|
pmv[0].y = |
487 |
|
MIN(MAX(pmv[1].y, pmv[2].y), |
488 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
489 |
|
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
490 |
|
|
491 |
|
return 0; |
492 |
|
} |
493 |
|
|
494 |
|
#endif |
495 |
|
|
496 |
/* |
/* |
497 |
* MODE_INTER, vm18 page 48 |
* MODE_INTER, vm18 page 48 |
549 |
lpos = lx + ly * mb_width; |
lpos = lx + ly * mb_width; |
550 |
rpos = rx + ry * mb_width; |
rpos = rx + ry * mb_width; |
551 |
tpos = tx + ty * mb_width; |
tpos = tx + ty * mb_width; |
552 |
last_cand = num_cand = 0; |
num_cand = 0; |
553 |
|
|
554 |
if (lpos >= bound && lx >= 0) { |
if (lpos >= bound && lx >= 0) { |
555 |
num_cand++; |
num_cand++; |
575 |
pmv[3] = zeroMV; |
pmv[3] = zeroMV; |
576 |
} |
} |
577 |
|
|
578 |
|
/* if only one valid candidate predictor, the invalid candiates are set to the canidate */ |
579 |
|
if (num_cand != 1) { |
580 |
|
/* set median */ |
581 |
|
|
582 |
|
pmv[0].x = |
583 |
|
MIN(MAX(pmv[1].x, pmv[2].x), |
584 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
585 |
|
pmv[0].y = |
586 |
|
MIN(MAX(pmv[1].y, pmv[2].y), |
587 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
588 |
|
return pmv[0]; |
589 |
|
} |
590 |
|
|
591 |
|
return pmv[last_cand]; /* no point calculating median mv */ |
592 |
|
} |
593 |
|
|
594 |
|
|
595 |
|
|
596 |
/* |
/* |
597 |
* If there're more than one candidate, we return the median vector |
* MODE_INTER, vm18 page 48 |
598 |
* edgomez : the special case "no candidates" is handled the same way |
* MODE_INTER4V vm18 page 51 |
599 |
* because all vectors are set to zero. So the median vector |
* |
600 |
* is {0,0}, and this is exactly the vector we must return |
* (x,y-1) (x+1,y-1) |
601 |
* according to the mpeg4 specs. |
* [ | ] [ | ] |
602 |
|
* [ 2 | 3 ] [ 2 | ] |
603 |
|
* |
604 |
|
* (x-1,y) (x,y) (x+1,y) |
605 |
|
* [ | 1 ] [ 0 | 1 ] [ 0 | ] |
606 |
|
* [ | 3 ] [ 2 | 3 ] [ | ] |
607 |
*/ |
*/ |
608 |
|
|
609 |
|
static __inline VECTOR |
610 |
|
get_qpmv2(const MACROBLOCK * const mbs, |
611 |
|
const int mb_width, |
612 |
|
const int bound, |
613 |
|
const int x, |
614 |
|
const int y, |
615 |
|
const int block) |
616 |
|
{ |
617 |
|
static const VECTOR zeroMV = { 0, 0 }; |
618 |
|
|
619 |
|
int lx, ly, lz; /* left */ |
620 |
|
int tx, ty, tz; /* top */ |
621 |
|
int rx, ry, rz; /* top-right */ |
622 |
|
int lpos, tpos, rpos; |
623 |
|
int num_cand, last_cand; |
624 |
|
|
625 |
|
VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ |
626 |
|
|
627 |
|
switch (block) { |
628 |
|
case 0: |
629 |
|
lx = x - 1; ly = y; lz = 1; |
630 |
|
tx = x; ty = y - 1; tz = 2; |
631 |
|
rx = x + 1; ry = y - 1; rz = 2; |
632 |
|
break; |
633 |
|
case 1: |
634 |
|
lx = x; ly = y; lz = 0; |
635 |
|
tx = x; ty = y - 1; tz = 3; |
636 |
|
rx = x + 1; ry = y - 1; rz = 2; |
637 |
|
break; |
638 |
|
case 2: |
639 |
|
lx = x - 1; ly = y; lz = 3; |
640 |
|
tx = x; ty = y; tz = 0; |
641 |
|
rx = x; ry = y; rz = 1; |
642 |
|
break; |
643 |
|
default: |
644 |
|
lx = x; ly = y; lz = 2; |
645 |
|
tx = x; ty = y; tz = 0; |
646 |
|
rx = x; ry = y; rz = 1; |
647 |
|
} |
648 |
|
|
649 |
|
lpos = lx + ly * mb_width; |
650 |
|
rpos = rx + ry * mb_width; |
651 |
|
tpos = tx + ty * mb_width; |
652 |
|
num_cand = 0; |
653 |
|
|
654 |
|
if (lpos >= bound && lx >= 0) { |
655 |
|
num_cand++; |
656 |
|
last_cand = 1; |
657 |
|
pmv[1] = mbs[lpos].qmvs[lz]; |
658 |
|
} else { |
659 |
|
pmv[1] = zeroMV; |
660 |
|
} |
661 |
|
|
662 |
|
if (tpos >= bound) { |
663 |
|
num_cand++; |
664 |
|
last_cand = 2; |
665 |
|
pmv[2] = mbs[tpos].qmvs[tz]; |
666 |
|
} else { |
667 |
|
pmv[2] = zeroMV; |
668 |
|
} |
669 |
|
|
670 |
|
if (rpos >= bound && rx < mb_width) { |
671 |
|
num_cand++; |
672 |
|
last_cand = 3; |
673 |
|
pmv[3] = mbs[rpos].qmvs[rz]; |
674 |
|
} else { |
675 |
|
pmv[3] = zeroMV; |
676 |
|
} |
677 |
|
|
678 |
|
/* if only one valid candidate predictor, the invalid candiates are set to the canidate */ |
679 |
if (num_cand != 1) { |
if (num_cand != 1) { |
680 |
/* set median */ |
/* set median */ |
681 |
|
|
692 |
} |
} |
693 |
|
|
694 |
|
|
|
|
|
695 |
/* |
/* |
696 |
* pmv are filled with: |
* pmv are filled with: |
697 |
* [0]: Median (or whatever is correct in a special case) |
* [0]: Median (or whatever is correct in a special case) |
748 |
lpos = lx + ly * mb_width; |
lpos = lx + ly * mb_width; |
749 |
rpos = rx + ry * mb_width; |
rpos = rx + ry * mb_width; |
750 |
tpos = tx + ty * mb_width; |
tpos = tx + ty * mb_width; |
751 |
last_cand = num_cand = 0; |
num_cand = 0; |
752 |
|
|
753 |
if (lpos >= bound && lx >= 0) { |
if (lpos >= bound && lx >= 0) { |
754 |
num_cand++; |
num_cand++; |
793 |
if (num_cand == 1) { |
if (num_cand == 1) { |
794 |
pmv[0] = pmv[last_cand]; |
pmv[0] = pmv[last_cand]; |
795 |
psad[0] = psad[last_cand]; |
psad[0] = psad[last_cand]; |
796 |
/* return MVequal(pmv[0], zeroMV); no point calculating median mv and minimum sad */ |
// return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */ |
797 |
|
|
798 |
/* original pmvdata() compatibility hack */ |
/* original pmvdata() compatibility hack */ |
799 |
return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); |
return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); |
804 |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
805 |
return 1; |
return 1; |
806 |
/* compatibility patch */ |
/* compatibility patch */ |
807 |
/*return y==0 && block <= 1 ? 0 : 1; */ |
//return y==0 && block <= 1 ? 0 : 1; |
808 |
} |
} |
809 |
|
|
810 |
/* set median, minimum */ |
/* set median, minimum */ |
866 |
lpos = lx + ly * mb_width; |
lpos = lx + ly * mb_width; |
867 |
rpos = rx + ry * mb_width; |
rpos = rx + ry * mb_width; |
868 |
tpos = tx + ty * mb_width; |
tpos = tx + ty * mb_width; |
869 |
last_cand = num_cand = 0; |
num_cand = 0; |
870 |
|
|
871 |
if (lpos >= bound && lx >= 0) { |
if (lpos >= bound && lx >= 0) { |
872 |
num_cand++; |
num_cand++; |
951 |
lpos = lx + ly * mb_width; |
lpos = lx + ly * mb_width; |
952 |
rpos = rx + ry * mb_width; |
rpos = rx + ry * mb_width; |
953 |
tpos = tx + ty * mb_width; |
tpos = tx + ty * mb_width; |
954 |
last_cand = num_cand = 0; |
num_cand = 0; |
955 |
|
|
956 |
if (lpos >= bound && lx >= 0) { |
if (lpos >= bound && lx >= 0) { |
957 |
num_cand++; |
num_cand++; |
996 |
if (num_cand == 1) { |
if (num_cand == 1) { |
997 |
pmv[0] = pmv[last_cand]; |
pmv[0] = pmv[last_cand]; |
998 |
psad[0] = psad[last_cand]; |
psad[0] = psad[last_cand]; |
999 |
/* return MVequal(pmv[0], zeroMV); no point calculating median mv and minimum sad */ |
// return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */ |
1000 |
|
|
1001 |
/* original pmvdata() compatibility hack */ |
/* original pmvdata() compatibility hack */ |
1002 |
return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); |
return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); |
1007 |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
1008 |
return 1; |
return 1; |
1009 |
/* compatibility patch */ |
/* compatibility patch */ |
1010 |
/*return y==0 && block <= 1 ? 0 : 1; */ |
//return y==0 && block <= 1 ? 0 : 1; |
1011 |
} |
} |
1012 |
|
|
1013 |
/* set median, minimum */ |
/* set median, minimum */ |