1 |
|
/************************************************************************** |
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 |
|
* $Id: mbprediction.h,v 1.14 2002-09-07 13:43:00 edgomez Exp $ |
30 |
|
* |
31 |
|
*************************************************************************/ |
32 |
|
|
33 |
#ifndef _MBPREDICTION_H_ |
#ifndef _MBPREDICTION_H_ |
34 |
#define _MBPREDICTION_H_ |
#define _MBPREDICTION_H_ |
35 |
|
|
40 |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
41 |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
42 |
|
|
43 |
// very large value |
/* very large value */ |
44 |
#define MV_MAX_ERROR (4096 * 256) |
#define MV_MAX_ERROR (4096 * 256) |
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 |
void MBPrediction(FRAMEINFO *frame, /* <-- the parameter for ACDC and MV prediction */ |
/***************************************************************************** |
49 |
|
* Prototypes |
50 |
|
****************************************************************************/ |
51 |
|
|
52 |
|
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 */ |
55 |
|
|
56 |
uint32_t y_pos, /* <-- The y position of the MB to be searched */ |
uint32_t y_pos, /* <-- The y position of the MB to be searched */ |
57 |
|
|
58 |
uint32_t x_dim, /* <-- Number of macroblocks in a row */ |
uint32_t x_dim, /* <-- Number of macroblocks in a row */ |
59 |
int16_t *qcoeff /* <-> The quantized DCT coefficients */ |
|
60 |
); |
int16_t * qcoeff); /* <-> The quantized DCT coefficients */ |
61 |
|
|
62 |
void add_acdc(MACROBLOCK *pMB, |
void add_acdc(MACROBLOCK *pMB, |
63 |
uint32_t block, |
uint32_t block, |
67 |
|
|
68 |
|
|
69 |
void predict_acdc(MACROBLOCK *pMBs, |
void predict_acdc(MACROBLOCK *pMBs, |
70 |
uint32_t x, uint32_t y, uint32_t mb_width, |
uint32_t x, |
71 |
|
uint32_t y, |
72 |
|
uint32_t mb_width, |
73 |
uint32_t block, |
uint32_t block, |
74 |
int16_t qcoeff[64], |
int16_t qcoeff[64], |
75 |
uint32_t current_quant, |
uint32_t current_quant, |
76 |
int32_t iDcScaler, |
int32_t iDcScaler, |
77 |
int16_t predictors[8]); |
int16_t predictors[8], |
78 |
|
const int bound); |
79 |
|
|
|
/* get_pmvdata returns the median predictor and nothing else */ |
|
80 |
|
|
81 |
static __inline VECTOR get_pmv(const MACROBLOCK * const pMBs, |
/***************************************************************************** |
82 |
const uint32_t x, const uint32_t y, |
* Inlined functions |
83 |
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; |
|
|
// zeroMV.x = zeroMV.y = 0; |
|
|
|
|
|
// 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 |
87 |
MODE_INTER4V vm18 page 51 |
* MODE_INTER4V vm18 page 51 |
88 |
|
* |
89 |
(x,y-1) (x+1,y-1) |
* (x,y-1) (x+1,y-1) |
90 |
[ | ] [ | ] |
* [ | ] [ | ] |
91 |
[ 2 | 3 ] [ 2 | ] |
* [ 2 | 3 ] [ 2 | ] |
92 |
|
* |
93 |
(x-1,y) (x,y) (x+1,y) |
* (x-1,y) (x,y) (x+1,y) |
94 |
[ | 1 ] [ 0 | 1 ] [ 0 | ] |
* [ | 1 ] [ 0 | 1 ] [ 0 | ] |
95 |
[ | 3 ] [ 2 | 3 ] [ | ] |
* [ | 3 ] [ 2 | 3 ] [ | ] |
96 |
*/ |
*/ |
97 |
|
|
98 |
switch (block) |
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) { |
117 |
case 0: |
case 0: |
118 |
xin1 = x - 1; yin1 = y; vec1 = 1; /* left */ |
lx = x - 1; ly = y; lz = 1; |
119 |
xin2 = x; yin2 = y - 1; vec2 = 2; /* top */ |
tx = x; ty = y - 1; tz = 2; |
120 |
xin3 = x + 1; yin3 = y - 1; vec3 = 2; /* top right */ |
rx = x + 1; ry = y - 1; rz = 2; |
121 |
break; |
break; |
122 |
case 1: |
case 1: |
123 |
xin1 = x; yin1 = y; vec1 = 0; |
lx = x; ly = y; lz = 0; |
124 |
xin2 = x; yin2 = y - 1; vec2 = 3; |
tx = x; ty = y - 1; tz = 3; |
125 |
xin3 = x + 1; yin3 = y - 1; vec3 = 2; |
rx = x + 1; ry = y - 1; rz = 2; |
126 |
break; |
break; |
127 |
case 2: |
case 2: |
128 |
xin1 = x - 1; yin1 = y; vec1 = 3; |
lx = x - 1; ly = y; lz = 3; |
129 |
xin2 = x; yin2 = y; vec2 = 0; |
tx = x; ty = y; tz = 0; |
130 |
xin3 = x; yin3 = y; vec3 = 1; |
rx = x; ry = y; rz = 1; |
131 |
break; |
break; |
132 |
default: |
default: |
133 |
xin1 = x; yin1 = y; vec1 = 2; |
lx = x; ly = y; lz = 2; |
134 |
xin2 = x; yin2 = y; vec2 = 0; |
tx = x; ty = y; tz = 0; |
135 |
xin3 = x; yin3 = y; vec3 = 1; |
rx = x; ry = y; rz = 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 |
{ |
tpos = tx + ty * mb_width; |
141 |
lneigh = zeroMV; |
num_cand = 0; |
142 |
} |
|
143 |
else |
if (lpos >= bound && lx >= 0) { |
144 |
{ |
num_cand++; |
145 |
lneigh = pMBs[xin1 + yin1 * x_dim].mvs[vec1]; |
last_cand = 1; |
146 |
|
pmv[1] = mbs[lpos].mvs[lz]; |
147 |
|
} else { |
148 |
|
pmv[1] = zeroMV; |
149 |
} |
} |
150 |
|
|
151 |
if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t)x_dim) |
if (tpos >= bound) { |
152 |
{ |
num_cand++; |
153 |
tneigh = zeroMV; |
last_cand = 2; |
154 |
} |
pmv[2] = mbs[tpos].mvs[tz]; |
155 |
else |
} else { |
156 |
{ |
pmv[2] = zeroMV; |
|
tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2]; |
|
157 |
} |
} |
158 |
|
|
159 |
if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t)x_dim) |
if (rpos >= bound && rx < mb_width) { |
160 |
{ |
num_cand++; |
161 |
trneigh = zeroMV; |
last_cand = 3; |
162 |
} |
pmv[3] = mbs[rpos].mvs[rz]; |
163 |
else |
} else { |
164 |
{ |
pmv[3] = zeroMV; |
|
trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
|
165 |
} |
} |
166 |
|
|
167 |
// median,minimum |
/* if only one valid candidate predictor, the invalid candiates are set to the canidate */ |
168 |
|
if (num_cand != 1) { |
169 |
|
/* set median */ |
170 |
|
|
171 |
|
pmv[0].x = |
172 |
|
MIN(MAX(pmv[1].x, pmv[2].x), |
173 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
174 |
|
pmv[0].y = |
175 |
|
MIN(MAX(pmv[1].y, pmv[2].y), |
176 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
177 |
|
return pmv[0]; |
178 |
|
} |
179 |
|
|
180 |
median.x = MIN(MAX(lneigh.x, tneigh.x), MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x))); |
return pmv[last_cand]; /* no point calculating median mv */ |
|
median.y = MIN(MAX(lneigh.y, tneigh.y), MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y))); |
|
|
return median; |
|
181 |
} |
} |
182 |
|
|
183 |
|
|
|
/* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD |
|
|
instead of only Median MV */ |
|
184 |
|
|
185 |
static __inline int get_pmvdata(const MACROBLOCK * const pMBs, |
/* |
186 |
const uint32_t x, const uint32_t y, |
* pmv are filled with: |
187 |
const uint32_t x_dim, |
* [0]: Median (or whatever is correct in a special case) |
188 |
const uint32_t block, |
* [1]: left neighbour |
189 |
|
* [2]: top neighbour |
190 |
|
* [3]: topright neighbour |
191 |
|
* psad are filled with: |
192 |
|
* [0]: minimum of [1] to [3] |
193 |
|
* [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed) |
194 |
|
* [2]: top neighbour's SAD |
195 |
|
* [3]: topright neighbour's SAD |
196 |
|
*/ |
197 |
|
|
198 |
|
static __inline int |
199 |
|
get_pmvdata2(const MACROBLOCK * const mbs, |
200 |
|
const int mb_width, |
201 |
|
const int bound, |
202 |
|
const int x, |
203 |
|
const int y, |
204 |
|
const int block, |
205 |
VECTOR * const pmv, |
VECTOR * const pmv, |
206 |
int32_t * const psad) |
int32_t * const psad) |
207 |
{ |
{ |
208 |
/* pmv are filled with: |
static const VECTOR zeroMV = { 0, 0 }; |
|
[0]: Median (or whatever is correct in a special case) |
|
|
[1]: left neighbour |
|
|
[2]: top neighbour, |
|
|
[3]: topright neighbour, |
|
|
psad are filled with: |
|
|
[0]: minimum of [1] to [3] |
|
|
[1]: left neighbour's SAD // [1] to [3] are actually not needed |
|
|
[2]: top neighbour's SAD, |
|
|
[3]: topright neighbour's SAD, |
|
|
*/ |
|
209 |
|
|
210 |
int xin1, xin2, xin3; |
int lx, ly, lz; /* left */ |
211 |
int yin1, yin2, yin3; |
int tx, ty, tz; /* top */ |
212 |
int vec1, vec2, vec3; |
int rx, ry, rz; /* top-right */ |
213 |
|
int lpos, tpos, rpos; |
214 |
static VECTOR zeroMV; |
int num_cand, last_cand; |
|
uint32_t index = x + y * x_dim; |
|
|
zeroMV.x = zeroMV.y = 0; |
|
215 |
|
|
216 |
// first row (special case) |
switch (block) { |
217 |
if (y == 0 && (block == 0 || block == 1)) |
case 0: |
218 |
{ |
lx = x - 1; ly = y; lz = 1; |
219 |
if ((x == 0) && (block == 0)) // first column, first block |
tx = x; ty = y - 1; tz = 2; |
220 |
|
rx = x + 1; ry = y - 1; rz = 2; |
221 |
|
break; |
222 |
|
case 1: |
223 |
|
lx = x; ly = y; lz = 0; |
224 |
|
tx = x; ty = y - 1; tz = 3; |
225 |
|
rx = x + 1; ry = y - 1; rz = 2; |
226 |
|
break; |
227 |
|
case 2: |
228 |
|
lx = x - 1; ly = y; lz = 3; |
229 |
|
tx = x; ty = y; tz = 0; |
230 |
|
rx = x; ry = y; rz = 1; |
231 |
|
break; |
232 |
|
default: |
233 |
|
lx = x; ly = y; lz = 2; |
234 |
|
tx = x; ty = y; tz = 0; |
235 |
|
rx = x; ry = y; rz = 1; |
236 |
|
} |
237 |
|
|
238 |
|
lpos = lx + ly * mb_width; |
239 |
|
rpos = rx + ry * mb_width; |
240 |
|
tpos = tx + ty * mb_width; |
241 |
|
num_cand = 0; |
242 |
|
|
243 |
|
if (lpos >= bound && lx >= 0) { |
244 |
|
num_cand++; |
245 |
|
last_cand = 1; |
246 |
|
pmv[1] = mbs[lpos].mvs[lz]; |
247 |
|
psad[1] = mbs[lpos].sad8[lz]; |
248 |
|
} else { |
249 |
|
pmv[1] = zeroMV; |
250 |
|
psad[1] = MV_MAX_ERROR; |
251 |
|
} |
252 |
|
|
253 |
|
if (tpos >= bound) { |
254 |
|
num_cand++; |
255 |
|
last_cand = 2; |
256 |
|
pmv[2]= mbs[tpos].mvs[tz]; |
257 |
|
psad[2] = mbs[tpos].sad8[tz]; |
258 |
|
} else { |
259 |
|
pmv[2] = zeroMV; |
260 |
|
psad[2] = MV_MAX_ERROR; |
261 |
|
} |
262 |
|
|
263 |
|
if (rpos >= bound && rx < mb_width) { |
264 |
|
num_cand++; |
265 |
|
last_cand = 3; |
266 |
|
pmv[3] = mbs[rpos].mvs[rz]; |
267 |
|
psad[3] = mbs[rpos].sad8[rz]; |
268 |
|
} else { |
269 |
|
pmv[3] = zeroMV; |
270 |
|
psad[3] = MV_MAX_ERROR; |
271 |
|
} |
272 |
|
|
273 |
|
/* original pmvdata() compatibility hack */ |
274 |
|
if (x == 0 && y == 0 && block == 0) |
275 |
{ |
{ |
276 |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
277 |
psad[0] = psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
psad[0] = 0; |
278 |
|
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
279 |
return 0; |
return 0; |
280 |
} |
} |
281 |
if (block == 1) // second block; has only a left neighbour |
|
282 |
{ |
/* if only one valid candidate preictor, the invalid candiates are set to the canidate */ |
283 |
pmv[0] = pmv[1] = pMBs[index].mvs[0]; |
if (num_cand == 1) { |
284 |
pmv[2] = pmv[3] = zeroMV; |
pmv[0] = pmv[last_cand]; |
285 |
psad[0] = psad[1] = pMBs[index].sad8[0]; |
psad[0] = psad[last_cand]; |
286 |
psad[2] = psad[3] = MV_MAX_ERROR; |
// return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */ |
287 |
return 0; |
|
288 |
|
/* original pmvdata() compatibility hack */ |
289 |
|
return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); |
290 |
} |
} |
291 |
else /* block==0, but x!=0, so again, there is a left neighbour*/ |
|
292 |
{ |
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
293 |
pmv[0] = pmv[1] = pMBs[index-1].mvs[1]; |
pmv[0] = pmv[1]; |
294 |
pmv[2] = pmv[3] = zeroMV; |
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
295 |
psad[0] = psad[1] = pMBs[index-1].sad8[1]; |
return 1; |
296 |
psad[2] = psad[3] = MV_MAX_ERROR; |
/* compatibility patch */ |
297 |
return 0; |
//return y==0 && block <= 1 ? 0 : 1; |
298 |
} |
} |
299 |
|
|
300 |
|
/* set median, minimum */ |
301 |
|
|
302 |
|
pmv[0].x = |
303 |
|
MIN(MAX(pmv[1].x, pmv[2].x), |
304 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
305 |
|
pmv[0].y = |
306 |
|
MIN(MAX(pmv[1].y, pmv[2].y), |
307 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
308 |
|
|
309 |
|
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
310 |
|
|
311 |
|
return 0; |
312 |
} |
} |
313 |
|
|
314 |
/* |
/* copies of get_pmv and get_pmvdata for prediction from integer search */ |
|
MODE_INTER, vm18 page 48 |
|
|
MODE_INTER4V vm18 page 51 |
|
315 |
|
|
316 |
(x,y-1) (x+1,y-1) |
static __inline VECTOR |
317 |
[ | ] [ | ] |
get_ipmv(const MACROBLOCK * const mbs, |
318 |
[ 2 | 3 ] [ 2 | ] |
const int mb_width, |
319 |
|
const int bound, |
320 |
(x-1,y) (x,y) (x+1,y) |
const int x, |
321 |
[ | 1 ] [ 0 | 1 ] [ 0 | ] |
const int y, |
322 |
[ | 3 ] [ 2 | 3 ] [ | ] |
const int block) |
323 |
*/ |
{ |
324 |
|
static const VECTOR zeroMV = { 0, 0 }; |
325 |
|
|
326 |
|
int lx, ly, lz; /* left */ |
327 |
|
int tx, ty, tz; /* top */ |
328 |
|
int rx, ry, rz; /* top-right */ |
329 |
|
int lpos, tpos, rpos; |
330 |
|
int num_cand, last_cand; |
331 |
|
|
332 |
switch (block) |
VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ |
333 |
{ |
|
334 |
|
switch (block) { |
335 |
case 0: |
case 0: |
336 |
xin1 = x - 1; yin1 = y; vec1 = 1; /* left */ |
lx = x - 1; ly = y; lz = 1; |
337 |
xin2 = x; yin2 = y - 1; vec2 = 2; /* top */ |
tx = x; ty = y - 1; tz = 2; |
338 |
xin3 = x + 1; yin3 = y - 1; vec3 = 2; /* top right */ |
rx = x + 1; ry = y - 1; rz = 2; |
339 |
break; |
break; |
340 |
case 1: |
case 1: |
341 |
xin1 = x; yin1 = y; vec1 = 0; |
lx = x; ly = y; lz = 0; |
342 |
xin2 = x; yin2 = y - 1; vec2 = 3; |
tx = x; ty = y - 1; tz = 3; |
343 |
xin3 = x + 1; yin3 = y - 1; vec3 = 2; |
rx = x + 1; ry = y - 1; rz = 2; |
344 |
break; |
break; |
345 |
case 2: |
case 2: |
346 |
xin1 = x - 1; yin1 = y; vec1 = 3; |
lx = x - 1; ly = y; lz = 3; |
347 |
xin2 = x; yin2 = y; vec2 = 0; |
tx = x; ty = y; tz = 0; |
348 |
xin3 = x; yin3 = y; vec3 = 1; |
rx = x; ry = y; rz = 1; |
349 |
break; |
break; |
350 |
default: |
default: |
351 |
xin1 = x; yin1 = y; vec1 = 2; |
lx = x; ly = y; lz = 2; |
352 |
xin2 = x; yin2 = y; vec2 = 0; |
tx = x; ty = y; tz = 0; |
353 |
xin3 = x; yin3 = y; vec3 = 1; |
rx = x; ry = y; rz = 1; |
354 |
} |
} |
355 |
|
|
356 |
|
lpos = lx + ly * mb_width; |
357 |
|
rpos = rx + ry * mb_width; |
358 |
|
tpos = tx + ty * mb_width; |
359 |
|
num_cand = 0; |
360 |
|
|
361 |
|
if (lpos >= bound && lx >= 0) { |
362 |
|
num_cand++; |
363 |
|
last_cand = 1; |
364 |
|
pmv[1] = mbs[lpos].i_mvs[lz]; |
365 |
|
} else { |
366 |
|
pmv[1] = zeroMV; |
367 |
|
} |
368 |
|
|
369 |
if (xin1 < 0 || /* yin1 < 0 || */ xin1 >= (int32_t)x_dim) |
if (tpos >= bound) { |
370 |
|
num_cand++; |
371 |
|
last_cand = 2; |
372 |
|
pmv[2] = mbs[tpos].i_mvs[tz]; |
373 |
|
} else { |
374 |
|
pmv[2] = zeroMV; |
375 |
|
} |
376 |
|
|
377 |
|
if (rpos >= bound && rx < mb_width) { |
378 |
|
num_cand++; |
379 |
|
last_cand = 3; |
380 |
|
pmv[3] = mbs[rpos].i_mvs[rz]; |
381 |
|
} else { |
382 |
|
pmv[3] = zeroMV; |
383 |
|
} |
384 |
|
|
385 |
|
/* if only one valid candidate predictor, the invalid candiates are set to the canidate */ |
386 |
|
if (num_cand != 1) { |
387 |
|
/* set median */ |
388 |
|
|
389 |
|
pmv[0].x = |
390 |
|
MIN(MAX(pmv[1].x, pmv[2].x), |
391 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
392 |
|
pmv[0].y = |
393 |
|
MIN(MAX(pmv[1].y, pmv[2].y), |
394 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
395 |
|
return pmv[0]; |
396 |
|
} |
397 |
|
|
398 |
|
return pmv[last_cand]; /* no point calculating median mv */ |
399 |
|
} |
400 |
|
|
401 |
|
static __inline int |
402 |
|
get_ipmvdata(const MACROBLOCK * const mbs, |
403 |
|
const int mb_width, |
404 |
|
const int bound, |
405 |
|
const int x, |
406 |
|
const int y, |
407 |
|
const int block, |
408 |
|
VECTOR * const pmv, |
409 |
|
int32_t * const psad) |
410 |
{ |
{ |
411 |
|
static const VECTOR zeroMV = { 0, 0 }; |
412 |
|
|
413 |
|
int lx, ly, lz; /* left */ |
414 |
|
int tx, ty, tz; /* top */ |
415 |
|
int rx, ry, rz; /* top-right */ |
416 |
|
int lpos, tpos, rpos; |
417 |
|
int num_cand, last_cand; |
418 |
|
|
419 |
|
switch (block) { |
420 |
|
case 0: |
421 |
|
lx = x - 1; ly = y; lz = 1; |
422 |
|
tx = x; ty = y - 1; tz = 2; |
423 |
|
rx = x + 1; ry = y - 1; rz = 2; |
424 |
|
break; |
425 |
|
case 1: |
426 |
|
lx = x; ly = y; lz = 0; |
427 |
|
tx = x; ty = y - 1; tz = 3; |
428 |
|
rx = x + 1; ry = y - 1; rz = 2; |
429 |
|
break; |
430 |
|
case 2: |
431 |
|
lx = x - 1; ly = y; lz = 3; |
432 |
|
tx = x; ty = y; tz = 0; |
433 |
|
rx = x; ry = y; rz = 1; |
434 |
|
break; |
435 |
|
default: |
436 |
|
lx = x; ly = y; lz = 2; |
437 |
|
tx = x; ty = y; tz = 0; |
438 |
|
rx = x; ry = y; rz = 1; |
439 |
|
} |
440 |
|
|
441 |
|
lpos = lx + ly * mb_width; |
442 |
|
rpos = rx + ry * mb_width; |
443 |
|
tpos = tx + ty * mb_width; |
444 |
|
num_cand = 0; |
445 |
|
|
446 |
|
if (lpos >= bound && lx >= 0) { |
447 |
|
num_cand++; |
448 |
|
last_cand = 1; |
449 |
|
pmv[1] = mbs[lpos].i_mvs[lz]; |
450 |
|
psad[1] = mbs[lpos].i_sad8[lz]; |
451 |
|
} else { |
452 |
pmv[1] = zeroMV; |
pmv[1] = zeroMV; |
453 |
psad[1] = MV_MAX_ERROR; |
psad[1] = MV_MAX_ERROR; |
454 |
} |
} |
|
else |
|
|
{ |
|
|
pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1]; |
|
|
psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1]; |
|
|
} |
|
455 |
|
|
456 |
if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t)x_dim) |
if (tpos >= bound) { |
457 |
{ |
num_cand++; |
458 |
|
last_cand = 2; |
459 |
|
pmv[2]= mbs[tpos].i_mvs[tz]; |
460 |
|
psad[2] = mbs[tpos].i_sad8[tz]; |
461 |
|
} else { |
462 |
pmv[2] = zeroMV; |
pmv[2] = zeroMV; |
463 |
psad[2] = MV_MAX_ERROR; |
psad[2] = MV_MAX_ERROR; |
464 |
} |
} |
|
else |
|
|
{ |
|
|
pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2]; |
|
|
psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2]; |
|
|
} |
|
465 |
|
|
466 |
if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t)x_dim) |
if (rpos >= bound && rx < mb_width) { |
467 |
{ |
num_cand++; |
468 |
|
last_cand = 3; |
469 |
|
pmv[3] = mbs[rpos].i_mvs[rz]; |
470 |
|
psad[3] = mbs[rpos].i_sad8[rz]; |
471 |
|
} else { |
472 |
pmv[3] = zeroMV; |
pmv[3] = zeroMV; |
473 |
psad[3] = MV_MAX_ERROR; |
psad[3] = MV_MAX_ERROR; |
474 |
} |
} |
475 |
else |
|
476 |
|
/* original pmvdata() compatibility hack */ |
477 |
|
if (x == 0 && y == 0 && block == 0) |
478 |
{ |
{ |
479 |
pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3]; |
pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV; |
480 |
psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3]; |
psad[0] = 0; |
481 |
|
psad[1] = psad[2] = psad[3] = MV_MAX_ERROR; |
482 |
|
return 0; |
483 |
} |
} |
484 |
|
|
485 |
if ( (MVequal(pmv[1],pmv[2])) && (MVequal(pmv[1],pmv[3])) ) |
/* if only one valid candidate preictor, the invalid candiates are set to the canidate */ |
486 |
{ pmv[0]=pmv[1]; |
if (num_cand == 1) { |
487 |
psad[0]=psad[1]; |
pmv[0] = pmv[last_cand]; |
488 |
|
psad[0] = psad[last_cand]; |
489 |
|
// return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */ |
490 |
|
|
491 |
|
/* original pmvdata() compatibility hack */ |
492 |
|
return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV); |
493 |
|
} |
494 |
|
|
495 |
|
if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) { |
496 |
|
pmv[0] = pmv[1]; |
497 |
|
psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]); |
498 |
return 1; |
return 1; |
499 |
|
/* compatibility patch */ |
500 |
|
//return y==0 && block <= 1 ? 0 : 1; |
501 |
} |
} |
502 |
|
|
503 |
// median,minimum |
/* set median, minimum */ |
504 |
|
|
505 |
|
pmv[0].x = |
506 |
|
MIN(MAX(pmv[1].x, pmv[2].x), |
507 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
508 |
|
pmv[0].y = |
509 |
|
MIN(MAX(pmv[1].y, pmv[2].y), |
510 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
511 |
|
|
|
pmv[0].x = MIN(MAX(pmv[1].x, pmv[2].x), MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
|
|
pmv[0].y = MIN(MAX(pmv[1].y, pmv[2].y), MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
|
512 |
psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]); |
psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]); |
513 |
|
|
514 |
return 0; |
return 0; |
515 |
} |
} |
516 |
|
|
517 |
|
|
|
|
|
518 |
#endif /* _MBPREDICTION_H_ */ |
#endif /* _MBPREDICTION_H_ */ |