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