26 |
* along with this program; if not, write to the xvid_free Software |
* along with this program; if not, write to the xvid_free Software |
27 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
28 |
* |
* |
29 |
* $Id: mbprediction.h,v 1.11 2002-06-30 10:46:29 suxen_drol Exp $ |
* $Id: mbprediction.h,v 1.15 2002-09-08 17:25:10 edgomez Exp $ |
30 |
* |
* |
31 |
*************************************************************************/ |
*************************************************************************/ |
32 |
|
|
|
/****************************************************************************** |
|
|
* * |
|
|
* Revision history: * |
|
|
* * |
|
|
* 29.06.2002 get_pmvdata() bounding * |
|
|
* * |
|
|
******************************************************************************/ |
|
|
|
|
|
|
|
33 |
#ifndef _MBPREDICTION_H_ |
#ifndef _MBPREDICTION_H_ |
34 |
#define _MBPREDICTION_H_ |
#define _MBPREDICTION_H_ |
35 |
|
|
45 |
|
|
46 |
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) ) |
47 |
|
|
48 |
|
/***************************************************************************** |
49 |
|
* Prototypes |
50 |
|
****************************************************************************/ |
51 |
|
|
52 |
void MBPrediction(FRAMEINFO * frame, /* <-- The parameter for ACDC and MV prediction */ |
void MBPrediction(FRAMEINFO * frame, /* <-- The parameter for ACDC and MV prediction */ |
53 |
|
|
54 |
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 */ |
78 |
const int bound); |
const int bound); |
79 |
|
|
80 |
|
|
81 |
/* get_pmvdata returns the median predictor and nothing else */ |
/***************************************************************************** |
82 |
|
* Inlined functions |
83 |
static __inline VECTOR |
****************************************************************************/ |
|
get_pmv(const MACROBLOCK * const pMBs, |
|
|
const uint32_t x, |
|
|
const uint32_t y, |
|
|
const uint32_t x_dim, |
|
|
const uint32_t block) |
|
|
{ |
|
|
|
|
|
int xin1, xin2, xin3; |
|
|
int yin1, yin2, yin3; |
|
|
int vec1, vec2, vec3; |
|
|
VECTOR lneigh, tneigh, trneigh; /* left neighbour, top neighbour, topright neighbour */ |
|
|
VECTOR median; |
|
|
|
|
|
static VECTOR zeroMV = { 0, 0 }; |
|
|
uint32_t index = x + y * x_dim; |
|
|
|
|
|
/* first row (special case) */ |
|
|
if (y == 0 && (block == 0 || block == 1)) { |
|
|
if ((x == 0) && (block == 0)) // first column, first block |
|
|
{ |
|
|
return zeroMV; |
|
|
} |
|
|
if (block == 1) // second block; has only a left neighbour |
|
|
{ |
|
|
return pMBs[index].mvs[0]; |
|
|
} else { /* block==0, but x!=0, so again, there is a left neighbour */ |
|
|
|
|
|
return pMBs[index - 1].mvs[1]; |
|
|
} |
|
|
} |
|
84 |
|
|
85 |
/* |
/* |
86 |
* MODE_INTER, vm18 page 48 |
* MODE_INTER, vm18 page 48 |
95 |
* [ | 3 ] [ 2 | 3 ] [ | ] |
* [ | 3 ] [ 2 | 3 ] [ | ] |
96 |
*/ |
*/ |
97 |
|
|
98 |
|
static __inline VECTOR |
99 |
|
get_pmv2(const MACROBLOCK * const mbs, |
100 |
|
const int mb_width, |
101 |
|
const int bound, |
102 |
|
const int x, |
103 |
|
const int y, |
104 |
|
const int block) |
105 |
|
{ |
106 |
|
static const VECTOR zeroMV = { 0, 0 }; |
107 |
|
|
108 |
|
int lx, ly, lz; /* left */ |
109 |
|
int tx, ty, tz; /* top */ |
110 |
|
int rx, ry, rz; /* top-right */ |
111 |
|
int lpos, tpos, rpos; |
112 |
|
int num_cand, last_cand; |
113 |
|
|
114 |
|
VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ |
115 |
|
|
116 |
switch (block) { |
switch (block) { |
117 |
case 0: |
case 0: |
118 |
xin1 = x - 1; |
lx = x - 1; ly = y; lz = 1; |
119 |
yin1 = y; |
tx = x; ty = y - 1; tz = 2; |
120 |
vec1 = 1; /* left */ |
rx = x + 1; ry = y - 1; rz = 2; |
|
xin2 = x; |
|
|
yin2 = y - 1; |
|
|
vec2 = 2; /* top */ |
|
|
xin3 = x + 1; |
|
|
yin3 = y - 1; |
|
|
vec3 = 2; /* top right */ |
|
121 |
break; |
break; |
122 |
case 1: |
case 1: |
123 |
xin1 = x; |
lx = x; ly = y; lz = 0; |
124 |
yin1 = y; |
tx = x; ty = y - 1; tz = 3; |
125 |
vec1 = 0; |
rx = x + 1; ry = y - 1; rz = 2; |
|
xin2 = x; |
|
|
yin2 = y - 1; |
|
|
vec2 = 3; |
|
|
xin3 = x + 1; |
|
|
yin3 = y - 1; |
|
|
vec3 = 2; |
|
126 |
break; |
break; |
127 |
case 2: |
case 2: |
128 |
xin1 = x - 1; |
lx = x - 1; ly = y; lz = 3; |
129 |
yin1 = y; |
tx = x; ty = y; tz = 0; |
130 |
vec1 = 3; |
rx = x; ry = y; rz = 1; |
|
xin2 = x; |
|
|
yin2 = y; |
|
|
vec2 = 0; |
|
|
xin3 = x; |
|
|
yin3 = y; |
|
|
vec3 = 1; |
|
131 |
break; |
break; |
132 |
default: |
default: |
133 |
xin1 = x; |
lx = x; ly = y; lz = 2; |
134 |
yin1 = y; |
tx = x; ty = y; tz = 0; |
135 |
vec1 = 2; |
rx = x; ry = y; rz = 1; |
|
xin2 = x; |
|
|
yin2 = y; |
|
|
vec2 = 0; |
|
|
xin3 = x; |
|
|
yin3 = y; |
|
|
vec3 = 1; |
|
136 |
} |
} |
137 |
|
|
138 |
|
lpos = lx + ly * mb_width; |
139 |
if (xin1 < 0 || /* yin1 < 0 || */ xin1 >= (int32_t) x_dim) { |
rpos = rx + ry * mb_width; |
140 |
lneigh = zeroMV; |
tpos = tx + ty * mb_width; |
141 |
|
last_cand = num_cand = 0; |
142 |
|
|
143 |
|
if (lpos >= bound && lx >= 0) { |
144 |
|
num_cand++; |
145 |
|
last_cand = 1; |
146 |
|
pmv[1] = mbs[lpos].mvs[lz]; |
147 |
} else { |
} else { |
148 |
lneigh = pMBs[xin1 + yin1 * x_dim].mvs[vec1]; |
pmv[1] = zeroMV; |
149 |
} |
} |
150 |
|
|
151 |
if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t) x_dim) { |
if (tpos >= bound) { |
152 |
tneigh = zeroMV; |
num_cand++; |
153 |
|
last_cand = 2; |
154 |
|
pmv[2] = mbs[tpos].mvs[tz]; |
155 |
} else { |
} else { |
156 |
tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2]; |
pmv[2] = zeroMV; |
157 |
} |
} |
158 |
|
|
159 |
if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t) x_dim) { |
if (rpos >= bound && rx < mb_width) { |
160 |
trneigh = zeroMV; |
num_cand++; |
161 |
|
last_cand = 3; |
162 |
|
pmv[3] = mbs[rpos].mvs[rz]; |
163 |
} else { |
} else { |
164 |
trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
pmv[3] = zeroMV; |
|
} |
|
|
|
|
|
/* median,minimum */ |
|
|
|
|
|
median.x = |
|
|
MIN(MAX(lneigh.x, tneigh.x), |
|
|
MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x))); |
|
|
median.y = |
|
|
MIN(MAX(lneigh.y, tneigh.y), |
|
|
MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y))); |
|
|
return median; |
|
165 |
} |
} |
166 |
|
|
167 |
|
/* |
168 |
|
* If there're more than one candidate, we return the median vector |
169 |
|
* edgomez : the special case "no candidates" is handled the same way |
170 |
|
* because all vectors are set to zero. So the median vector |
171 |
|
* is {0,0}, and this is exactly the vector we must return |
172 |
|
* according to the mpeg4 specs. |
173 |
|
*/ |
174 |
|
|
175 |
|
if (num_cand != 1) { |
176 |
|
/* set median */ |
177 |
|
|
178 |
int |
pmv[0].x = |
179 |
get_pmvdata2(const MACROBLOCK * const pMBs, |
MIN(MAX(pmv[1].x, pmv[2].x), |
180 |
const uint32_t x, |
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
181 |
const uint32_t y, |
pmv[0].y = |
182 |
const uint32_t x_dim, |
MIN(MAX(pmv[1].y, pmv[2].y), |
183 |
const uint32_t block, |
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
184 |
VECTOR * const pmv, |
return pmv[0]; |
185 |
int32_t * const psad, |
} |
|
const int bound); |
|
186 |
|
|
187 |
|
return pmv[last_cand]; /* no point calculating median mv */ |
188 |
|
} |
189 |
|
|
|
/* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD |
|
|
instead of only Median MV */ |
|
190 |
|
|
|
static __inline int |
|
|
get_pmvdata(const MACROBLOCK * const pMBs, |
|
|
const uint32_t x, |
|
|
const uint32_t y, |
|
|
const uint32_t x_dim, |
|
|
const uint32_t block, |
|
|
VECTOR * const pmv, |
|
|
int32_t * const psad) |
|
|
{ |
|
191 |
|
|
192 |
/* |
/* |
193 |
* pmv are filled with: |
* pmv are filled with: |
202 |
* [3]: topright neighbour's SAD |
* [3]: topright neighbour's SAD |
203 |
*/ |
*/ |
204 |
|
|
205 |
int xin1, xin2, xin3; |
static __inline int |
206 |
int yin1, yin2, yin3; |
get_pmvdata2(const MACROBLOCK * const mbs, |
207 |
int vec1, vec2, vec3; |
const int mb_width, |
208 |
|
const int bound, |
209 |
uint32_t index = x + y * x_dim; |
const int x, |
210 |
const VECTOR zeroMV = { 0, 0 }; |
const int y, |
211 |
|
const int block, |
212 |
// first row of blocks (special case) |
VECTOR * const pmv, |
213 |
if (y == 0 && (block == 0 || block == 1)) { |
int32_t * const psad) |
214 |
if ((x == 0) && (block == 0)) // first column, first block |
{ |
215 |
|
static const VECTOR zeroMV = { 0, 0 }; |
216 |
|
|
217 |
|
int lx, ly, lz; /* left */ |
218 |
|
int tx, ty, tz; /* top */ |
219 |
|
int rx, ry, rz; /* top-right */ |
220 |
|
int lpos, tpos, rpos; |
221 |
|
int num_cand, last_cand; |
222 |
|
|
223 |
|
switch (block) { |
224 |
|
case 0: |
225 |
|
lx = x - 1; ly = y; lz = 1; |
226 |
|
tx = x; ty = y - 1; tz = 2; |
227 |
|
rx = x + 1; ry = y - 1; rz = 2; |
228 |
|
break; |
229 |
|
case 1: |
230 |
|
lx = x; ly = y; lz = 0; |
231 |
|
tx = x; ty = y - 1; tz = 3; |
232 |
|
rx = x + 1; ry = y - 1; rz = 2; |
233 |
|
break; |
234 |
|
case 2: |
235 |
|
lx = x - 1; ly = y; lz = 3; |
236 |
|
tx = x; ty = y; tz = 0; |
237 |
|
rx = x; ry = y; rz = 1; |
238 |
|
break; |
239 |
|
default: |
240 |
|
lx = x; ly = y; lz = 2; |
241 |
|
tx = x; ty = y; tz = 0; |
242 |
|
rx = x; ry = y; rz = 1; |
243 |
|
} |
244 |
|
|
245 |
|
lpos = lx + ly * mb_width; |
246 |
|
rpos = rx + ry * mb_width; |
247 |
|
tpos = tx + ty * mb_width; |
248 |
|
last_cand = num_cand = 0; |
249 |
|
|
250 |
|
if (lpos >= bound && lx >= 0) { |
251 |
|
num_cand++; |
252 |
|
last_cand = 1; |
253 |
|
pmv[1] = mbs[lpos].mvs[lz]; |
254 |
|
psad[1] = mbs[lpos].sad8[lz]; |
255 |
|
} else { |
256 |
|
pmv[1] = zeroMV; |
257 |
|
psad[1] = MV_MAX_ERROR; |
258 |
|
} |
259 |
|
|
260 |
|
if (tpos >= bound) { |
261 |
|
num_cand++; |
262 |
|
last_cand = 2; |
263 |
|
pmv[2]= mbs[tpos].mvs[tz]; |
264 |
|
psad[2] = mbs[tpos].sad8[tz]; |
265 |
|
} else { |
266 |
|
pmv[2] = zeroMV; |
267 |
|
psad[2] = MV_MAX_ERROR; |
268 |
|
} |
269 |
|
|
270 |
|
if (rpos >= bound && rx < mb_width) { |
271 |
|
num_cand++; |
272 |
|
last_cand = 3; |
273 |
|
pmv[3] = mbs[rpos].mvs[rz]; |
274 |
|
psad[3] = mbs[rpos].sad8[rz]; |
275 |
|
} else { |
276 |
|
pmv[3] = zeroMV; |
277 |
|
psad[3] = MV_MAX_ERROR; |
278 |
|
} |
279 |
|
|
280 |
|
/* original pmvdata() compatibility hack */ |
281 |
|
if (x == 0 && y == 0 && block == 0) |
282 |
{ |
{ |
283 |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
284 |
psad[0] = 0; |
psad[0] = 0; |
285 |
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
286 |
return 0; |
return 0; |
287 |
} |
} |
|
if (block == 1) // second block; has only a left neighbour |
|
|
{ |
|
|
pmv[0] = pmv[1] = pMBs[index].mvs[0]; |
|
|
pmv[2] = pmv[3] = zeroMV; |
|
|
psad[0] = psad[1] = pMBs[index].sad8[0]; |
|
|
psad[2] = psad[3] = MV_MAX_ERROR; |
|
|
return 0; |
|
|
} else { /* block==0, but x!=0, so again, there is a left neighbour */ |
|
288 |
|
|
289 |
pmv[0] = pmv[1] = pMBs[index - 1].mvs[1]; |
/* if only one valid candidate preictor, the invalid candiates are set to the canidate */ |
290 |
pmv[2] = pmv[3] = zeroMV; |
if (num_cand == 1) { |
291 |
psad[0] = psad[1] = pMBs[index - 1].sad8[1]; |
pmv[0] = pmv[last_cand]; |
292 |
psad[2] = psad[3] = MV_MAX_ERROR; |
psad[0] = psad[last_cand]; |
293 |
return 0; |
// return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */ |
294 |
|
|
295 |
|
/* original pmvdata() compatibility hack */ |
296 |
|
return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); |
297 |
} |
} |
298 |
|
|
299 |
|
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
300 |
|
pmv[0] = pmv[1]; |
301 |
|
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
302 |
|
return 1; |
303 |
|
/* compatibility patch */ |
304 |
|
//return y==0 && block <= 1 ? 0 : 1; |
305 |
} |
} |
306 |
|
|
307 |
/* |
/* set median, minimum */ |
308 |
* MODE_INTER, vm18 page 48 |
|
309 |
* MODE_INTER4V vm18 page 51 |
pmv[0].x = |
310 |
* |
MIN(MAX(pmv[1].x, pmv[2].x), |
311 |
* (x,y-1) (x+1,y-1) |
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
312 |
* [ | ] [ | ] |
pmv[0].y = |
313 |
* [ 2 | 3 ] [ 2 | ] |
MIN(MAX(pmv[1].y, pmv[2].y), |
314 |
* |
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
315 |
* (x-1,y) (x,y) (x+1,y) |
|
316 |
* [ | 1 ] [ 0 | 1 ] [ 0 | ] |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
317 |
* [ | 3 ] [ 2 | 3 ] [ | ] |
|
318 |
*/ |
return 0; |
319 |
|
} |
320 |
|
|
321 |
|
/* copies of get_pmv and get_pmvdata for prediction from integer search */ |
322 |
|
|
323 |
|
static __inline VECTOR |
324 |
|
get_ipmv(const MACROBLOCK * const mbs, |
325 |
|
const int mb_width, |
326 |
|
const int bound, |
327 |
|
const int x, |
328 |
|
const int y, |
329 |
|
const int block) |
330 |
|
{ |
331 |
|
static const VECTOR zeroMV = { 0, 0 }; |
332 |
|
|
333 |
|
int lx, ly, lz; /* left */ |
334 |
|
int tx, ty, tz; /* top */ |
335 |
|
int rx, ry, rz; /* top-right */ |
336 |
|
int lpos, tpos, rpos; |
337 |
|
int num_cand, last_cand; |
338 |
|
|
339 |
|
VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ |
340 |
|
|
341 |
switch (block) { |
switch (block) { |
342 |
case 0: |
case 0: |
343 |
xin1 = x - 1; |
lx = x - 1; ly = y; lz = 1; |
344 |
yin1 = y; |
tx = x; ty = y - 1; tz = 2; |
345 |
vec1 = 1; /* left */ |
rx = x + 1; ry = y - 1; rz = 2; |
|
xin2 = x; |
|
|
yin2 = y - 1; |
|
|
vec2 = 2; /* top */ |
|
|
xin3 = x + 1; |
|
|
yin3 = y - 1; |
|
|
vec3 = 2; /* top right */ |
|
346 |
break; |
break; |
347 |
case 1: |
case 1: |
348 |
xin1 = x; |
lx = x; ly = y; lz = 0; |
349 |
yin1 = y; |
tx = x; ty = y - 1; tz = 3; |
350 |
vec1 = 0; |
rx = x + 1; ry = y - 1; rz = 2; |
|
xin2 = x; |
|
|
yin2 = y - 1; |
|
|
vec2 = 3; |
|
|
xin3 = x + 1; |
|
|
yin3 = y - 1; |
|
|
vec3 = 2; |
|
351 |
break; |
break; |
352 |
case 2: |
case 2: |
353 |
xin1 = x - 1; |
lx = x - 1; ly = y; lz = 3; |
354 |
yin1 = y; |
tx = x; ty = y; tz = 0; |
355 |
vec1 = 3; |
rx = x; ry = y; rz = 1; |
|
xin2 = x; |
|
|
yin2 = y; |
|
|
vec2 = 0; |
|
|
xin3 = x; |
|
|
yin3 = y; |
|
|
vec3 = 1; |
|
356 |
break; |
break; |
357 |
default: |
default: |
358 |
xin1 = x; |
lx = x; ly = y; lz = 2; |
359 |
yin1 = y; |
tx = x; ty = y; tz = 0; |
360 |
vec1 = 2; |
rx = x; ry = y; rz = 1; |
|
xin2 = x; |
|
|
yin2 = y; |
|
|
vec2 = 0; |
|
|
xin3 = x; |
|
|
yin3 = y; |
|
|
vec3 = 1; |
|
361 |
} |
} |
362 |
|
|
363 |
|
lpos = lx + ly * mb_width; |
364 |
|
rpos = rx + ry * mb_width; |
365 |
|
tpos = tx + ty * mb_width; |
366 |
|
last_cand = num_cand = 0; |
367 |
|
|
368 |
|
if (lpos >= bound && lx >= 0) { |
369 |
|
num_cand++; |
370 |
|
last_cand = 1; |
371 |
|
pmv[1] = mbs[lpos].i_mvs[lz]; |
372 |
|
} else { |
373 |
|
pmv[1] = zeroMV; |
374 |
|
} |
375 |
|
|
376 |
if (xin1 < 0 || xin1 >= (int32_t) x_dim) { |
if (tpos >= bound) { |
377 |
|
num_cand++; |
378 |
|
last_cand = 2; |
379 |
|
pmv[2] = mbs[tpos].i_mvs[tz]; |
380 |
|
} else { |
381 |
|
pmv[2] = zeroMV; |
382 |
|
} |
383 |
|
|
384 |
|
if (rpos >= bound && rx < mb_width) { |
385 |
|
num_cand++; |
386 |
|
last_cand = 3; |
387 |
|
pmv[3] = mbs[rpos].i_mvs[rz]; |
388 |
|
} else { |
389 |
|
pmv[3] = zeroMV; |
390 |
|
} |
391 |
|
|
392 |
|
/* if only one valid candidate predictor, the invalid candiates are set to the canidate */ |
393 |
|
if (num_cand != 1) { |
394 |
|
/* set median */ |
395 |
|
|
396 |
|
pmv[0].x = |
397 |
|
MIN(MAX(pmv[1].x, pmv[2].x), |
398 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
399 |
|
pmv[0].y = |
400 |
|
MIN(MAX(pmv[1].y, pmv[2].y), |
401 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
402 |
|
return pmv[0]; |
403 |
|
} |
404 |
|
|
405 |
|
return pmv[last_cand]; /* no point calculating median mv */ |
406 |
|
} |
407 |
|
|
408 |
|
static __inline int |
409 |
|
get_ipmvdata(const MACROBLOCK * const mbs, |
410 |
|
const int mb_width, |
411 |
|
const int bound, |
412 |
|
const int x, |
413 |
|
const int y, |
414 |
|
const int block, |
415 |
|
VECTOR * const pmv, |
416 |
|
int32_t * const psad) |
417 |
|
{ |
418 |
|
static const VECTOR zeroMV = { 0, 0 }; |
419 |
|
|
420 |
|
int lx, ly, lz; /* left */ |
421 |
|
int tx, ty, tz; /* top */ |
422 |
|
int rx, ry, rz; /* top-right */ |
423 |
|
int lpos, tpos, rpos; |
424 |
|
int num_cand, last_cand; |
425 |
|
|
426 |
|
switch (block) { |
427 |
|
case 0: |
428 |
|
lx = x - 1; ly = y; lz = 1; |
429 |
|
tx = x; ty = y - 1; tz = 2; |
430 |
|
rx = x + 1; ry = y - 1; rz = 2; |
431 |
|
break; |
432 |
|
case 1: |
433 |
|
lx = x; ly = y; lz = 0; |
434 |
|
tx = x; ty = y - 1; tz = 3; |
435 |
|
rx = x + 1; ry = y - 1; rz = 2; |
436 |
|
break; |
437 |
|
case 2: |
438 |
|
lx = x - 1; ly = y; lz = 3; |
439 |
|
tx = x; ty = y; tz = 0; |
440 |
|
rx = x; ry = y; rz = 1; |
441 |
|
break; |
442 |
|
default: |
443 |
|
lx = x; ly = y; lz = 2; |
444 |
|
tx = x; ty = y; tz = 0; |
445 |
|
rx = x; ry = y; rz = 1; |
446 |
|
} |
447 |
|
|
448 |
|
lpos = lx + ly * mb_width; |
449 |
|
rpos = rx + ry * mb_width; |
450 |
|
tpos = tx + ty * mb_width; |
451 |
|
last_cand = num_cand = 0; |
452 |
|
|
453 |
|
if (lpos >= bound && lx >= 0) { |
454 |
|
num_cand++; |
455 |
|
last_cand = 1; |
456 |
|
pmv[1] = mbs[lpos].i_mvs[lz]; |
457 |
|
psad[1] = mbs[lpos].i_sad8[lz]; |
458 |
|
} else { |
459 |
pmv[1] = zeroMV; |
pmv[1] = zeroMV; |
460 |
psad[1] = MV_MAX_ERROR; |
psad[1] = MV_MAX_ERROR; |
|
} else { |
|
|
pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1]; |
|
|
psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1]; |
|
461 |
} |
} |
462 |
|
|
463 |
if (xin2 < 0 || xin2 >= (int32_t) x_dim) { |
if (tpos >= bound) { |
464 |
|
num_cand++; |
465 |
|
last_cand = 2; |
466 |
|
pmv[2]= mbs[tpos].i_mvs[tz]; |
467 |
|
psad[2] = mbs[tpos].i_sad8[tz]; |
468 |
|
} else { |
469 |
pmv[2] = zeroMV; |
pmv[2] = zeroMV; |
470 |
psad[2] = MV_MAX_ERROR; |
psad[2] = MV_MAX_ERROR; |
|
} else { |
|
|
pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2]; |
|
|
psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2]; |
|
471 |
} |
} |
472 |
|
|
473 |
if (xin3 < 0 || xin3 >= (int32_t) x_dim) { |
if (rpos >= bound && rx < mb_width) { |
474 |
|
num_cand++; |
475 |
|
last_cand = 3; |
476 |
|
pmv[3] = mbs[rpos].i_mvs[rz]; |
477 |
|
psad[3] = mbs[rpos].i_sad8[rz]; |
478 |
|
} else { |
479 |
pmv[3] = zeroMV; |
pmv[3] = zeroMV; |
480 |
psad[3] = MV_MAX_ERROR; |
psad[3] = MV_MAX_ERROR; |
481 |
} else { |
} |
482 |
pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
|
483 |
psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3]; |
/* original pmvdata() compatibility hack */ |
484 |
|
if (x == 0 && y == 0 && block == 0) |
485 |
|
{ |
486 |
|
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
487 |
|
psad[0] = 0; |
488 |
|
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
489 |
|
return 0; |
490 |
|
} |
491 |
|
|
492 |
|
/* if only one valid candidate preictor, the invalid candiates are set to the canidate */ |
493 |
|
if (num_cand == 1) { |
494 |
|
pmv[0] = pmv[last_cand]; |
495 |
|
psad[0] = psad[last_cand]; |
496 |
|
// return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */ |
497 |
|
|
498 |
|
/* original pmvdata() compatibility hack */ |
499 |
|
return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); |
500 |
} |
} |
501 |
|
|
502 |
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
503 |
pmv[0] = pmv[1]; |
pmv[0] = pmv[1]; |
504 |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
505 |
return 1; |
return 1; |
506 |
|
/* compatibility patch */ |
507 |
|
//return y==0 && block <= 1 ? 0 : 1; |
508 |
} |
} |
509 |
|
|
510 |
/* median,minimum */ |
/* set median, minimum */ |
511 |
|
|
512 |
pmv[0].x = |
pmv[0].x = |
513 |
MIN(MAX(pmv[1].x, pmv[2].x), |
MIN(MAX(pmv[1].x, pmv[2].x), |
515 |
pmv[0].y = |
pmv[0].y = |
516 |
MIN(MAX(pmv[1].y, pmv[2].y), |
MIN(MAX(pmv[1].y, pmv[2].y), |
517 |
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
518 |
|
|
519 |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
520 |
|
|
521 |
return 0; |
return 0; |
522 |
} |
} |
523 |
|
|
524 |
|
|
|
|
|
525 |
#endif /* _MBPREDICTION_H_ */ |
#endif /* _MBPREDICTION_H_ */ |