52 |
#define CHECK_CANDIDATE(X,Y,D) { \ |
#define CHECK_CANDIDATE(X,Y,D) { \ |
53 |
(*CheckCandidate)((const int)(X),(const int)(Y), (D), &iDirection, data ); } |
(*CheckCandidate)((const int)(X),(const int)(Y), (D), &iDirection, data ); } |
54 |
|
|
|
#define GET_REFERENCE(X, Y, REF) { \ |
|
|
switch ( (((X)&1)<<1) + ((Y)&1) ) \ |
|
|
{ \ |
|
|
case 0 : REF = (uint8_t *)data->Ref + (X)/2 + ((Y)/2)*(data->iEdgedWidth); break; \ |
|
|
case 1 : REF = (uint8_t *)data->RefV + (X)/2 + (((Y)-1)/2)*(data->iEdgedWidth); break; \ |
|
|
case 2 : REF = (uint8_t *)data->RefH + ((X)-1)/2 + ((Y)/2)*(data->iEdgedWidth); break; \ |
|
|
default : REF = (uint8_t *)data->RefHV + ((X)-1)/2 + (((Y)-1)/2)*(data->iEdgedWidth); break; \ |
|
|
} \ |
|
|
} |
|
|
// I hate those macros :/ |
|
|
#define GET_REFERENCE2(X, Y, REF) { \ |
|
|
switch ( (((X)&1)<<1) + ((Y)&1) ) \ |
|
|
{ \ |
|
|
case 0 : REF = (uint8_t *)data->bRef + (X)/2 + ((Y)/2)*(data->iEdgedWidth); break; \ |
|
|
case 1 : REF = (uint8_t *)data->bRefV + (X)/2 + (((Y)-1)/2)*(data->iEdgedWidth); break; \ |
|
|
case 2 : REF = (uint8_t *)data->bRefH + ((X)-1)/2 + ((Y)/2)*(data->iEdgedWidth); break; \ |
|
|
default : REF = (uint8_t *)data->bRefHV + ((X)-1)/2 + (((Y)-1)/2)*(data->iEdgedWidth); break; \ |
|
|
} \ |
|
|
} |
|
|
|
|
|
|
|
55 |
#define iDiamondSize 2 |
#define iDiamondSize 2 |
56 |
|
|
57 |
static __inline int |
static __inline int |
116 |
return sad; |
return sad; |
117 |
} |
} |
118 |
|
|
119 |
|
static __inline const uint8_t * |
120 |
/* CHECK_CANDIATE FUNCTIONS START */ |
GetReference(const int x, const int y, const int dir, const SearchData * const data) |
|
|
|
|
|
|
|
static void |
|
|
CheckCandidate16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
|
121 |
{ |
{ |
122 |
int t; |
// dir : 0 = forward, 1 = backward |
123 |
const uint8_t * Reference; |
switch ( (dir << 2) | ((x&1)<<1) | (y&1) ) { |
124 |
|
case 0 : return data->Ref + x/2 + (y/2)*(data->iEdgedWidth); |
125 |
if (( x > data->max_dx) || ( x < data->min_dx) |
case 1 : return data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); |
126 |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
case 2 : return data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); |
127 |
|
case 3 : return data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); |
128 |
|
case 4 : return data->bRef + x/2 + (y/2)*(data->iEdgedWidth); |
129 |
|
case 5 : return data->bRefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); |
130 |
|
case 6 : return data->bRefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); |
131 |
|
default : return data->bRefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); |
132 |
|
|
|
switch ( ((x&1)<<1) + (y&1) ) { |
|
|
case 0 : Reference = data->Ref + x/2 + (y/2)*(data->iEdgedWidth); break; |
|
|
case 1 : Reference = data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
|
|
case 2 : Reference = data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); break; |
|
|
default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
|
133 |
} |
} |
|
|
|
|
data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp + 1); |
|
|
|
|
|
if (data->qpel) t = d_mv_bits(2*x - data->predQMV.x, 2*y - data->predQMV.y, data->iFcode); |
|
|
else t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode); |
|
|
|
|
|
data->temp[0] += (data->lambda16 * t * data->temp[0])/1000; |
|
|
data->temp[1] += (data->lambda8 * t * (data->temp[1] + NEIGH_8X8_BIAS))/100; |
|
|
|
|
|
if (data->chroma) data->temp[0] += ChromaSAD(x, y, data); |
|
|
|
|
|
if (data->temp[0] < data->iMinSAD[0]) { |
|
|
data->iMinSAD[0] = data->temp[0]; |
|
|
data->currentMV[0].x = x; data->currentMV[0].y = y; |
|
|
*dir = Direction; } |
|
|
|
|
|
if (data->temp[1] < data->iMinSAD[1]) { |
|
|
data->iMinSAD[1] = data->temp[1]; data->currentMV[1].x = x; data->currentMV[1].y = y; } |
|
|
if (data->temp[2] < data->iMinSAD[2]) { |
|
|
data->iMinSAD[2] = data->temp[2]; data->currentMV[2].x = x; data->currentMV[2].y = y; } |
|
|
if (data->temp[3] < data->iMinSAD[3]) { |
|
|
data->iMinSAD[3] = data->temp[3]; data->currentMV[3].x = x; data->currentMV[3].y = y; } |
|
|
if (data->temp[4] < data->iMinSAD[4]) { |
|
|
data->iMinSAD[4] = data->temp[4]; data->currentMV[4].x = x; data->currentMV[4].y = y; } |
|
|
|
|
134 |
} |
} |
135 |
|
|
136 |
static void |
static uint8_t * |
137 |
CheckCandidate16no4v(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
Interpolate8x8qpel(const int x, const int y, const int block, const int dir, const SearchData * const data) |
138 |
{ |
{ |
139 |
int32_t sad; |
// create or find a qpel-precision reference picture; return pointer to it |
140 |
const uint8_t * Reference; |
uint8_t * Reference = (uint8_t *)data->RefQ; |
141 |
|
const int32_t iEdgedWidth = data->iEdgedWidth; |
142 |
|
const uint32_t rounding = data->rounding; |
143 |
|
const int halfpel_x = x/2; |
144 |
|
const int halfpel_y = y/2; |
145 |
|
const uint8_t *ref1, *ref2, *ref3, *ref4; |
146 |
|
|
147 |
if (( x > data->max_dx) || ( x < data->min_dx) |
ref1 = GetReference(halfpel_x, halfpel_y, dir, data); // this reference is used in all cases |
148 |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
ref1 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
149 |
|
switch( ((x&1)<<1) + (y&1) ) { |
150 |
|
case 0: // pure halfpel position |
151 |
|
Reference = (uint8_t *) GetReference(halfpel_x, halfpel_y, dir, data); |
152 |
|
Reference += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
153 |
|
break; |
154 |
|
|
155 |
switch ( ((x&1)<<1) + (y&1) ) |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
156 |
{ |
ref2 = GetReference(halfpel_x, y - halfpel_y, dir, data); |
157 |
case 0 : Reference = data->Ref + x/2 + (y/2)*(data->iEdgedWidth); break; |
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
158 |
case 1 : Reference = data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding); |
159 |
case 2 : Reference = data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); break; |
break; |
|
default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
|
|
} |
|
160 |
|
|
161 |
sad = sad16(data->Cur, Reference, data->iEdgedWidth, MV_MAX_ERROR); |
case 2: // x qpel, y halfpel - left or right during qpel refinement |
162 |
if (data->qpel) //only to be used in b-frames' ME |
ref2 = GetReference(x - halfpel_x, halfpel_y, dir, data); |
163 |
sad += (data->lambda16 * d_mv_bits(2*x - data->predMV.x, 2*y - data->predMV.y, data->iFcode) * sad)/1000; |
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
164 |
else |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding); |
165 |
sad += (data->lambda16 * d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode) * sad)/1000; |
break; |
166 |
|
|
167 |
if (sad < *(data->iMinSAD)) { |
default: // x and y in qpel resolution - the "corners" (top left/right and |
168 |
*(data->iMinSAD) = sad; |
// bottom left/right) during qpel refinement |
169 |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
ref2 = GetReference(halfpel_x, y - halfpel_y, dir, data); |
170 |
*dir = Direction; } |
ref3 = GetReference(x - halfpel_x, halfpel_y, dir, data); |
171 |
|
ref4 = GetReference(x - halfpel_x, y - halfpel_y, dir, data); |
172 |
|
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
173 |
|
ref3 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
174 |
|
ref4 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
175 |
|
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
176 |
|
break; |
177 |
|
} |
178 |
|
return Reference; |
179 |
} |
} |
180 |
|
|
181 |
static void |
static uint8_t * |
182 |
CheckCandidate16_qpel(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
Interpolate16x16qpel(const int x, const int y, const int dir, const SearchData * const data) |
|
|
|
|
// CheckCandidate16 variant which expects x and y in quarter pixel resolution |
|
|
// Important: This is no general usable routine! x and y must be +/-1 (qpel resolution!) |
|
|
// around currentMV! |
|
183 |
{ |
{ |
184 |
int t; |
// create or find a qpel-precision reference picture; return pointer to it |
185 |
uint8_t * Reference = (uint8_t *)data->RefQ; |
uint8_t * Reference = (uint8_t *)data->RefQ; |
186 |
|
const int32_t iEdgedWidth = data->iEdgedWidth; |
187 |
|
const uint32_t rounding = data->rounding; |
188 |
|
const int halfpel_x = x/2; |
189 |
|
const int halfpel_y = y/2; |
190 |
const uint8_t *ref1, *ref2, *ref3, *ref4; |
const uint8_t *ref1, *ref2, *ref3, *ref4; |
|
VECTOR halfpelMV = *(data->currentMV); |
|
|
|
|
|
int32_t iEdgedWidth = data->iEdgedWidth; |
|
|
uint32_t rounding = data->rounding; |
|
|
|
|
|
if (( x > data->max_dx) || ( x < data->min_dx) |
|
|
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
|
|
|
|
|
GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1); // this refenrence is used in all cases |
|
|
switch( ((x&1)<<1) + (y&1) ) |
|
|
{ |
|
|
case 0: // pure halfpel position - shouldn't happen during a refinement step |
|
|
GET_REFERENCE(halfpelMV.x, halfpelMV.y, Reference); |
|
|
break; |
|
191 |
|
|
192 |
|
ref1 = GetReference(halfpel_x, halfpel_y, dir, data); // this reference is used in all cases |
193 |
|
switch( ((x&1)<<1) + (y&1) ) { |
194 |
|
case 0: // pure halfpel position |
195 |
|
return (uint8_t *) GetReference(halfpel_x, halfpel_y, dir, data); |
196 |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
197 |
GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2); |
ref2 = GetReference(halfpel_x, y - halfpel_y, dir, data); |
198 |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding); |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding); |
199 |
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding); |
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding); |
200 |
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding); |
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding); |
202 |
break; |
break; |
203 |
|
|
204 |
case 2: // x qpel, y halfpel - left or right during qpel refinement |
case 2: // x qpel, y halfpel - left or right during qpel refinement |
205 |
GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref2); |
ref2 = GetReference(x - halfpel_x, halfpel_y, dir, data); |
206 |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding); |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding); |
207 |
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding); |
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding); |
208 |
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding); |
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding); |
211 |
|
|
212 |
default: // x and y in qpel resolution - the "corners" (top left/right and |
default: // x and y in qpel resolution - the "corners" (top left/right and |
213 |
// bottom left/right) during qpel refinement |
// bottom left/right) during qpel refinement |
214 |
GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2); |
ref2 = GetReference(halfpel_x, y - halfpel_y, dir, data); |
215 |
GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref3); |
ref3 = GetReference(x - halfpel_x, halfpel_y, dir, data); |
216 |
GET_REFERENCE(x - halfpelMV.x, y - halfpelMV.y, ref4); |
ref4 = GetReference(x - halfpel_x, y - halfpel_y, dir, data); |
|
|
|
217 |
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
218 |
interpolate8x8_avg4(Reference+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, rounding); |
interpolate8x8_avg4(Reference+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, rounding); |
219 |
interpolate8x8_avg4(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, rounding); |
interpolate8x8_avg4(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, rounding); |
220 |
interpolate8x8_avg4(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, rounding); |
interpolate8x8_avg4(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, rounding); |
221 |
break; |
break; |
222 |
} |
} |
223 |
|
return Reference; |
224 |
|
} |
225 |
|
|
226 |
|
/* CHECK_CANDIATE FUNCTIONS START */ |
227 |
|
|
228 |
|
static void |
229 |
|
CheckCandidate16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
230 |
|
{ |
231 |
|
int t, xc, yc; |
232 |
|
const uint8_t * Reference; |
233 |
|
VECTOR * current; |
234 |
|
|
235 |
|
if (( x > data->max_dx) || ( x < data->min_dx) |
236 |
|
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
237 |
|
|
238 |
|
if (data->qpel_precision) { // x and y are in 1/4 precision |
239 |
|
Reference = Interpolate16x16qpel(x, y, 0, data); |
240 |
|
t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode); |
241 |
|
xc = x/2; yc = y/2; //for chroma sad |
242 |
|
current = data->currentQMV; |
243 |
|
} else { |
244 |
|
switch ( ((x&1)<<1) + (y&1) ) { |
245 |
|
case 0 : Reference = data->Ref + x/2 + (y/2)*(data->iEdgedWidth); break; |
246 |
|
case 1 : Reference = data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
247 |
|
case 2 : Reference = data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); break; |
248 |
|
default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
249 |
|
} |
250 |
|
if (data->qpel) t = d_mv_bits(2*x - data->predMV.x, 2*y - data->predMV.y, data->iFcode); |
251 |
|
else t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode); |
252 |
|
current = data->currentMV; |
253 |
|
xc = x; yc = y; |
254 |
|
} |
255 |
|
|
256 |
data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp+1); |
data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp+1); |
257 |
|
|
|
t = d_mv_bits(x - data->predQMV.x, y - data->predQMV.y, data->iFcode); |
|
258 |
data->temp[0] += (data->lambda16 * t * data->temp[0])/1000; |
data->temp[0] += (data->lambda16 * t * data->temp[0])/1000; |
259 |
data->temp[1] += (data->lambda8 * t * (data->temp[1] + NEIGH_8X8_BIAS))/100; |
data->temp[1] += (data->lambda8 * t * (data->temp[1] + NEIGH_8X8_BIAS))/100; |
260 |
|
|
261 |
if (data->chroma) |
if (data->chroma) data->temp[0] += ChromaSAD(xc, yc, data); |
|
data->temp[0] += ChromaSAD(x/2, y/2, data); |
|
262 |
|
|
263 |
if (data->temp[0] < data->iMinSAD[0]) { |
if (data->temp[0] < data->iMinSAD[0]) { |
264 |
data->iMinSAD[0] = data->temp[0]; |
data->iMinSAD[0] = data->temp[0]; |
265 |
data->currentQMV[0].x = x; data->currentQMV[0].y = y; |
current[0].x = x; current[0].y = y; |
266 |
/* *dir = Direction;*/ } |
*dir = Direction; } |
267 |
|
|
268 |
if (data->temp[1] < data->iMinSAD[1]) { |
if (data->temp[1] < data->iMinSAD[1]) { |
269 |
data->iMinSAD[1] = data->temp[1]; data->currentQMV[1].x = x; data->currentQMV[1].y = y; } |
data->iMinSAD[1] = data->temp[1]; current[1].x = x; current[1].y= y; } |
270 |
if (data->temp[2] < data->iMinSAD[2]) { |
if (data->temp[2] < data->iMinSAD[2]) { |
271 |
data->iMinSAD[2] = data->temp[2]; data->currentQMV[2].x = x; data->currentQMV[2].y = y; } |
data->iMinSAD[2] = data->temp[2]; current[2].x = x; current[2].y = y; } |
272 |
if (data->temp[3] < data->iMinSAD[3]) { |
if (data->temp[3] < data->iMinSAD[3]) { |
273 |
data->iMinSAD[3] = data->temp[3]; data->currentQMV[3].x = x; data->currentQMV[3].y = y; } |
data->iMinSAD[3] = data->temp[3]; current[3].x = x; current[3].y = y; } |
274 |
if (data->temp[4] < data->iMinSAD[4]) { |
if (data->temp[4] < data->iMinSAD[4]) { |
275 |
data->iMinSAD[4] = data->temp[4]; data->currentQMV[4].x = x; data->currentQMV[4].y = y; } |
data->iMinSAD[4] = data->temp[4]; current[4].x = x; current[4].y = y; } |
276 |
|
|
277 |
} |
} |
278 |
|
|
279 |
static void |
static void |
280 |
CheckCandidate16no4v_qpel(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidate16no4v(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
|
|
|
|
// CheckCandidate16no4v variant which expects x and y in quarter pixel resolution |
|
|
// Important: This is no general usable routine! x and y must be +/-1 (qpel resolution!) |
|
|
// around currentMV! |
|
|
// this function is for B-frames' search only |
|
281 |
{ |
{ |
|
uint8_t * Reference = (uint8_t *)data->RefQ; |
|
|
const uint8_t *ref1, *ref2, *ref3, *ref4; |
|
|
VECTOR halfpelMV = *(data->currentMV); |
|
|
|
|
|
int32_t iEdgedWidth = data->iEdgedWidth; |
|
282 |
int32_t sad; |
int32_t sad; |
283 |
|
const uint8_t * Reference; |
284 |
|
int t; |
285 |
|
VECTOR * current; |
286 |
|
|
287 |
if (( x > data->max_dx) || ( x < data->min_dx) |
if (( x > data->max_dx) || ( x < data->min_dx) |
288 |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
289 |
|
|
290 |
GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1); // this refenrence is used in all cases |
if (data->qpel_precision) { // x and y are in 1/4 precision |
291 |
switch( ((x&1)<<1) + (y&1) ) |
Reference = Interpolate16x16qpel(x, y, 0, data); |
292 |
{ |
t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode); |
293 |
case 0: // pure halfpel position - shouldn't happen during a refinement step |
current = data->currentQMV; |
294 |
GET_REFERENCE(halfpelMV.x, halfpelMV.y, Reference); |
} else { |
295 |
break; |
switch ( ((x&1)<<1) + (y&1) ) { |
296 |
|
case 0 : Reference = data->Ref + x/2 + (y/2)*(data->iEdgedWidth); break; |
297 |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
case 1 : Reference = data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
298 |
GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2); |
case 2 : Reference = data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); break; |
299 |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, 0); |
default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
300 |
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, 0); |
} |
301 |
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
if (data->qpel) t = d_mv_bits(2*x - data->predMV.x, 2*y - data->predMV.y, data->iFcode); |
302 |
interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
else t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode); |
303 |
break; |
current = data->currentMV; |
|
|
|
|
case 2: // x qpel, y halfpel - left or right during qpel refinement |
|
|
GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
default: // x and y in qpel resolution - the "corners" (top left/right and |
|
|
// bottom left/right) during qpel refinement |
|
|
GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2); |
|
|
GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref3); |
|
|
GET_REFERENCE(x - halfpelMV.x, y - halfpelMV.y, ref4); |
|
|
|
|
|
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(Reference+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
304 |
} |
} |
305 |
|
|
306 |
sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096); |
sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096); |
307 |
sad += (data->lambda16 * d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode) * sad)/1000; |
sad += (data->lambda16 * t * sad)/1000; |
308 |
|
|
309 |
if (sad < data->iMinSAD[0]) { |
if (sad < *(data->iMinSAD)) { |
310 |
data->iMinSAD[0] = sad; |
*(data->iMinSAD) = sad; |
311 |
data->currentQMV[0].x = x; data->currentQMV[0].y = y; |
current->x = x; current->y = y; |
312 |
/* *dir = Direction;*/ } |
*dir = Direction; } |
313 |
} |
} |
314 |
|
|
315 |
static void |
static void |
335 |
CheckCandidateInt(const int xf, const int yf, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidateInt(const int xf, const int yf, const int Direction, int * const dir, const SearchData * const data) |
336 |
{ |
{ |
337 |
int32_t sad; |
int32_t sad; |
338 |
const int xb = data->currentMV[1].x; |
int xb, yb, t; |
|
const int yb = data->currentMV[1].y; |
|
339 |
const uint8_t *ReferenceF, *ReferenceB; |
const uint8_t *ReferenceF, *ReferenceB; |
340 |
|
VECTOR *current; |
341 |
|
|
342 |
if (( xf > data->max_dx) || ( xf < data->min_dx) |
if (( xf > data->max_dx) || ( xf < data->min_dx) |
343 |
|| ( yf > data->max_dy) || (yf < data->min_dy)) return; |
|| ( yf > data->max_dy) || (yf < data->min_dy)) return; |
344 |
|
|
345 |
switch ( ((xf&1)<<1) + (yf&1) ) { |
if (data->qpel_precision) { |
346 |
case 0 : ReferenceF = data->Ref + xf/2 + (yf/2)*(data->iEdgedWidth); break; |
ReferenceF = Interpolate16x16qpel(xf, yf, 0, data); |
347 |
case 1 : ReferenceF = data->RefV + xf/2 + ((yf-1)/2)*(data->iEdgedWidth); break; |
xb = data->currentQMV[1].x; yb = data->currentQMV[1].y; |
348 |
case 2 : ReferenceF = data->RefH + (xf-1)/2 + (yf/2)*(data->iEdgedWidth); break; |
current = data->currentQMV; |
349 |
default : ReferenceF = data->RefHV + (xf-1)/2 + ((yf-1)/2)*(data->iEdgedWidth); break; |
ReferenceB = Interpolate16x16qpel(xb, yb, 1, data); |
350 |
} |
t = d_mv_bits(xf - data->predMV.x, yf - data->predMV.y, data->iFcode) |
351 |
|
+ d_mv_bits(xb - data->bpredMV.x, yb - data->bpredMV.y, data->iFcode); |
352 |
switch ( ((xb&1)<<1) + (yb&1) ) { |
} else { |
353 |
case 0 : ReferenceB = data->bRef + xb/2 + (yb/2)*(data->iEdgedWidth); break; |
ReferenceF = Interpolate16x16qpel(2*xf, 2*yf, 0, data); |
354 |
case 1 : ReferenceB = data->bRefV + xb/2 + ((yb-1)/2)*(data->iEdgedWidth); break; |
xb = data->currentMV[1].x; yb = data->currentMV[1].y; |
355 |
case 2 : ReferenceB = data->bRefH + (xb-1)/2 + (yb/2)*(data->iEdgedWidth); break; |
ReferenceB = Interpolate16x16qpel(2*xb, 2*yb, 1, data); |
356 |
default : ReferenceB = data->bRefHV + (xb-1)/2 + ((yb-1)/2)*(data->iEdgedWidth); break; |
current = data->currentMV; |
|
} |
|
|
|
|
|
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
|
|
|
|
357 |
if (data->qpel) |
if (data->qpel) |
358 |
sad += (data->lambda16 * |
t = d_mv_bits(2*xf - data->predMV.x, 2*yf - data->predMV.y, data->iFcode) |
359 |
( d_mv_bits(2*xf - data->predMV.x, 2*yf - data->predMV.y, data->iFcode) + |
+ d_mv_bits(2*xb - data->bpredMV.x, 2*yb - data->bpredMV.y, data->iFcode); |
|
d_mv_bits(2*xb - data->bpredMV.x, 2*yb - data->bpredMV.y, data->iFcode)) * sad)/1000; |
|
360 |
else |
else |
361 |
sad += (data->lambda16 * |
t = d_mv_bits(xf - data->predMV.x, yf - data->predMV.y, data->iFcode) |
362 |
( d_mv_bits(xf - data->predMV.x, yf - data->predMV.y, data->iFcode) + |
+ d_mv_bits(xb - data->bpredMV.x, yb - data->bpredMV.y, data->iFcode); |
|
d_mv_bits(xb - data->bpredMV.x, yb - data->bpredMV.y, data->iFcode)) * sad)/1000; |
|
|
|
|
|
if (sad < *(data->iMinSAD)) { |
|
|
*(data->iMinSAD) = sad; |
|
|
data->currentMV->x = xf; data->currentMV->y = yf; |
|
|
*dir = Direction; } |
|
|
} |
|
|
|
|
|
|
|
|
static void |
|
|
CheckCandidateInt_qpel(const int xf, const int yf, const int Direction, int * const dir, const SearchData * const data) |
|
|
{ |
|
|
// CheckCandidateInt variant which expects x and y in quarter pixel resolution |
|
|
|
|
|
int32_t sad; |
|
|
const int xb = data->currentQMV[1].x; |
|
|
const int yb = data->currentQMV[1].y; |
|
|
uint8_t * ReferenceF = (uint8_t *)data->RefQ; |
|
|
uint8_t * ReferenceB = (uint8_t *)data->RefQ + 16; |
|
|
const uint8_t *ref1, *ref2, *ref3, *ref4; |
|
|
VECTOR halfpelMV; |
|
|
const int32_t iEdgedWidth = data->iEdgedWidth; |
|
|
|
|
|
if (( xf > data->max_dx) || ( xf < data->min_dx) |
|
|
|| ( yf > data->max_dy) || (yf < data->min_dy)) return; |
|
|
|
|
|
halfpelMV.x = xf/2; //forward first |
|
|
halfpelMV.y = yf/2; |
|
|
GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1); // this reference is used in all cases |
|
|
switch( ((xf&1)<<1) + (yf&1) ) |
|
|
{ |
|
|
case 0: // pure halfpel position - shouldn't happen during a refinement step |
|
|
GET_REFERENCE(halfpelMV.x, halfpelMV.y, ReferenceF); |
|
|
break; |
|
|
|
|
|
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
|
|
GET_REFERENCE(halfpelMV.x, yf - halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceF, ref1, ref2, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8, ref1+8, ref2+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
case 2: // x qpel, y halfpel - left or right during qpel refinement |
|
|
GET_REFERENCE(xf - halfpelMV.x, halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceF, ref1, ref2, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8, ref1+8, ref2+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
default: // x and y in qpel resolution - the "corners" (top left/right and |
|
|
// bottom left/right) during qpel refinement |
|
|
GET_REFERENCE(halfpelMV.x, yf - halfpelMV.y, ref2); |
|
|
GET_REFERENCE(xf - halfpelMV.x, halfpelMV.y, ref3); |
|
|
GET_REFERENCE(xf - halfpelMV.x, yf - halfpelMV.y, ref4); |
|
|
|
|
|
interpolate8x8_avg4(ReferenceF, ref1, ref2, ref3, ref4, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceF+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceF+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceF+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
} |
|
|
|
|
|
halfpelMV.x = xb/2; //backward |
|
|
halfpelMV.y = yb/2; |
|
|
GET_REFERENCE2(halfpelMV.x, halfpelMV.y, ref1); // this reference is used in all cases |
|
|
switch( ((xb&1)<<1) + (yb&1) ) |
|
|
{ |
|
|
case 0: // pure halfpel position - shouldn't happen during a refinement step |
|
|
GET_REFERENCE2(halfpelMV.x, halfpelMV.y, ReferenceB); |
|
|
break; |
|
|
|
|
|
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
|
|
GET_REFERENCE2(halfpelMV.x, yb - halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceB, ref1, ref2, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8, ref1+8, ref2+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
case 2: // x qpel, y halfpel - left or right during qpel refinement |
|
|
GET_REFERENCE2(xb - halfpelMV.x, halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceB, ref1, ref2, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8, ref1+8, ref2+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
default: // x and y in qpel resolution - the "corners" (top left/right and |
|
|
// bottom left/right) during qpel refinement |
|
|
GET_REFERENCE2(halfpelMV.x, yb - halfpelMV.y, ref2); |
|
|
GET_REFERENCE2(xb - halfpelMV.x, halfpelMV.y, ref3); |
|
|
GET_REFERENCE2(xb - halfpelMV.x, yb - halfpelMV.y, ref4); |
|
|
|
|
|
interpolate8x8_avg4(ReferenceB, ref1, ref2, ref3, ref4, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceB+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceB+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceB+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
363 |
} |
} |
364 |
|
|
365 |
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
366 |
|
sad += (data->lambda16 * t * sad)/1000; |
|
sad += (data->lambda16 * |
|
|
( d_mv_bits(xf - data->predMV.x, yf - data->predMV.y, data->iFcode) + |
|
|
d_mv_bits(xb - data->bpredMV.x, yb - data->bpredMV.y, data->iFcode)) * sad)/1000; |
|
367 |
|
|
368 |
if (sad < *(data->iMinSAD)) { |
if (sad < *(data->iMinSAD)) { |
369 |
*(data->iMinSAD) = sad; |
*(data->iMinSAD) = sad; |
370 |
data->currentQMV->x = xf; data->currentQMV->y = yf; |
current->x = xf; current->y = yf; |
371 |
*dir = Direction; } |
*dir = Direction; } |
372 |
} |
} |
373 |
|
|
398 |
|| ( b_mvs.x > data->max_dx ) || ( b_mvs.x < data->min_dx ) |
|| ( b_mvs.x > data->max_dx ) || ( b_mvs.x < data->min_dx ) |
399 |
|| ( b_mvs.y > data->max_dy ) || ( b_mvs.y < data->min_dy )) return; |
|| ( b_mvs.y > data->max_dy ) || ( b_mvs.y < data->min_dy )) return; |
400 |
|
|
401 |
switch ( ((mvs.x&1)<<1) + (mvs.y&1) ) { |
if (!data->qpel) { |
402 |
case 0 : ReferenceF = data->Ref + mvs.x/2 + (mvs.y/2)*(data->iEdgedWidth); break; |
mvs.x *= 2; mvs.y *= 2; |
403 |
case 1 : ReferenceF = data->RefV + mvs.x/2 + ((mvs.y-1)/2)*(data->iEdgedWidth); break; |
b_mvs.x *= 2; b_mvs.y *= 2; //we move to qpel precision anyway |
|
case 2 : ReferenceF = data->RefH + (mvs.x-1)/2 + (mvs.y/2)*(data->iEdgedWidth); break; |
|
|
default : ReferenceF = data->RefHV + (mvs.x-1)/2 + ((mvs.y-1)/2)*(data->iEdgedWidth); break; |
|
|
} |
|
|
|
|
|
switch ( ((b_mvs.x&1)<<1) + (b_mvs.y&1) ) { |
|
|
case 0 : ReferenceB = data->bRef + b_mvs.x/2 + (b_mvs.y/2)*(data->iEdgedWidth); break; |
|
|
case 1 : ReferenceB = data->bRefV + b_mvs.x/2 + ((b_mvs.y-1)/2)*(data->iEdgedWidth); break; |
|
|
case 2 : ReferenceB = data->bRefH + (b_mvs.x-1)/2 + (b_mvs.y/2)*(data->iEdgedWidth); break; |
|
|
default : ReferenceB = data->bRefHV + (b_mvs.x-1)/2 + ((b_mvs.y-1)/2)*(data->iEdgedWidth); break; |
|
404 |
} |
} |
405 |
|
ReferenceF = Interpolate8x8qpel(mvs.x, mvs.y, k, 0, data); |
406 |
|
ReferenceB = Interpolate8x8qpel(b_mvs.x, b_mvs.y, k, 1, data); |
407 |
|
|
408 |
sad += sad8bi(data->Cur + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
sad += sad8bi(data->Cur + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
409 |
ReferenceF + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
ReferenceF, ReferenceB, |
|
ReferenceB + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
410 |
data->iEdgedWidth); |
data->iEdgedWidth); |
411 |
if (sad > *(data->iMinSAD)) return; |
if (sad > *(data->iMinSAD)) return; |
412 |
} |
} |
419 |
*dir = Direction; } |
*dir = Direction; } |
420 |
} |
} |
421 |
|
|
|
|
|
|
static void |
|
|
CheckCandidateDirect_qpel(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
|
|
{ |
|
|
int32_t sad = 0; |
|
|
int k; |
|
|
VECTOR mvs, b_mvs, halfpelMV; |
|
|
const uint8_t *ref1, *ref2, *ref3, *ref4; |
|
|
uint8_t *ReferenceF, *ReferenceB; |
|
|
const uint32_t iEdgedWidth = data->iEdgedWidth; |
|
|
|
|
|
if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return; |
|
|
|
|
|
for (k = 0; k < 4; k++) { |
|
|
ReferenceF = (uint8_t *)data->RefQ; |
|
|
ReferenceB = (uint8_t *)data->RefQ + 64; |
|
|
|
|
|
mvs.x = data->directmvF[k].x + x; |
|
|
b_mvs.x = ((x == 0) ? |
|
|
data->directmvB[k].x |
|
|
: mvs.x - data->referencemv[k].x); |
|
|
|
|
|
mvs.y = data->directmvF[k].y + y; |
|
|
b_mvs.y = ((y == 0) ? |
|
|
data->directmvB[k].y |
|
|
: mvs.y - data->referencemv[k].y); |
|
|
|
|
|
if (( mvs.x > data->max_dx ) || ( mvs.x < data->min_dx ) |
|
|
|| ( mvs.y > data->max_dy ) || ( mvs.y < data->min_dy ) |
|
|
|| ( b_mvs.x > data->max_dx ) || ( b_mvs.x < data->min_dx ) |
|
|
|| ( b_mvs.y > data->max_dy ) || ( b_mvs.y < data->min_dy )) return; |
|
|
|
|
|
halfpelMV.x = mvs.x/2; //forward first |
|
|
halfpelMV.y = mvs.y/2; |
|
|
GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1); // this reference is used in all cases |
|
|
switch( ((mvs.x&1)<<1) + (mvs.y&1) ) { |
|
|
case 0: // pure halfpel position |
|
|
GET_REFERENCE(halfpelMV.x + 16*(k&1), halfpelMV.y + 16*(k>>1), ReferenceF); |
|
|
break; |
|
|
|
|
|
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
|
|
GET_REFERENCE(halfpelMV.x, mvs.y - halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceF, ref1+8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref2+ 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
case 2: // x qpel, y halfpel - left or right during qpel refinement |
|
|
GET_REFERENCE(mvs.x - halfpelMV.x, halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceF, ref1 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref2 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
default: // x and y in qpel resolution - the "corners" (top left/right and |
|
|
// bottom left/right) during qpel refinement |
|
|
GET_REFERENCE(halfpelMV.x, mvs.y - halfpelMV.y, ref2); |
|
|
GET_REFERENCE(mvs.x - halfpelMV.x, halfpelMV.y, ref3); |
|
|
GET_REFERENCE(mvs.x - halfpelMV.x, mvs.y - halfpelMV.y, ref4); |
|
|
interpolate8x8_avg4(ReferenceF, ref1 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref2 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref3 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref4 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), iEdgedWidth, 0); |
|
|
break; |
|
|
} |
|
|
|
|
|
halfpelMV.x = b_mvs.x/2; |
|
|
halfpelMV.y = b_mvs.y/2; |
|
|
GET_REFERENCE2(halfpelMV.x, halfpelMV.y, ref1); // this reference is used in most cases |
|
|
switch( ((b_mvs.x&1)<<1) + (b_mvs.y&1) ) { |
|
|
case 0: // pure halfpel position |
|
|
GET_REFERENCE2(halfpelMV.x + 16*(k&1), halfpelMV.y + 16*(k>>1), ReferenceB); |
|
|
break; |
|
|
|
|
|
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
|
|
GET_REFERENCE2(halfpelMV.x, b_mvs.y - halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceB, ref1+8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref2+ 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
case 2: // x qpel, y halfpel - left or right during qpel refinement |
|
|
GET_REFERENCE2(b_mvs.x - halfpelMV.x, halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceB, ref1 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref2 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
default: // x and y in qpel resolution - the "corners" (top left/right and |
|
|
// bottom left/right) during qpel refinement |
|
|
GET_REFERENCE2(halfpelMV.x, b_mvs.y - halfpelMV.y, ref2); |
|
|
GET_REFERENCE2(b_mvs.x - halfpelMV.x, halfpelMV.y, ref3); |
|
|
GET_REFERENCE2(b_mvs.x - halfpelMV.x, b_mvs.y - halfpelMV.y, ref4); |
|
|
interpolate8x8_avg4(ReferenceB, ref1 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref2 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref3 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ref4 + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), iEdgedWidth, 0); |
|
|
break; |
|
|
} |
|
|
|
|
|
sad += sad8bi(data->Cur + 8*(k&1) + 8*(k>>1)*(data->iEdgedWidth), |
|
|
ReferenceF, |
|
|
ReferenceB, |
|
|
data->iEdgedWidth); |
|
|
if (sad > *(data->iMinSAD)) return; |
|
|
} |
|
|
|
|
|
sad += (data->lambda16 * d_mv_bits(x, y, 1) * sad)/1000; |
|
|
|
|
|
if (sad < *(data->iMinSAD)) { |
|
|
*(data->iMinSAD) = sad; |
|
|
data->currentMV->x = x; data->currentMV->y = y; |
|
|
*dir = Direction; } |
|
|
} |
|
|
|
|
|
static void |
|
|
CheckCandidateDirectno4v_qpel(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
|
|
{ |
|
|
int32_t sad = 0; |
|
|
VECTOR mvs, b_mvs, halfpelMV; |
|
|
const uint8_t *ref1, *ref2, *ref3, *ref4; |
|
|
const uint32_t iEdgedWidth = data->iEdgedWidth; |
|
|
uint8_t * ReferenceF = (uint8_t *)data->RefQ; |
|
|
uint8_t * ReferenceB = (uint8_t *)data->RefQ + 64; |
|
|
|
|
|
if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return; |
|
|
|
|
|
mvs.x = data->directmvF[0].x + x; |
|
|
b_mvs.x = ((x == 0) ? |
|
|
data->directmvB[0].x |
|
|
: mvs.x - data->referencemv[0].x); |
|
|
|
|
|
mvs.y = data->directmvF[0].y + y; |
|
|
b_mvs.y = ((y == 0) ? |
|
|
data->directmvB[0].y |
|
|
: mvs.y - data->referencemv[0].y); |
|
|
|
|
|
if (( mvs.x > data->max_dx ) || ( mvs.x < data->min_dx ) |
|
|
|| ( mvs.y > data->max_dy ) || ( mvs.y < data->min_dy ) |
|
|
|| ( b_mvs.x > data->max_dx ) || ( b_mvs.x < data->min_dx ) |
|
|
|| ( b_mvs.y > data->max_dy ) || ( b_mvs.y < data->min_dy )) return; |
|
|
|
|
|
halfpelMV.x = mvs.x/2; //forward first |
|
|
halfpelMV.y = mvs.y/2; |
|
|
GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1); // this reference is used in all cases |
|
|
switch( ((mvs.x&1)<<1) + (mvs.y&1) ) { |
|
|
case 0: // pure halfpel position |
|
|
GET_REFERENCE(halfpelMV.x, halfpelMV.y, ReferenceF); |
|
|
break; |
|
|
|
|
|
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
|
|
GET_REFERENCE(halfpelMV.x, mvs.y - halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceF, ref1, ref2, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8, ref1+8, ref2+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
case 2: // x qpel, y halfpel - left or right during qpel refinement |
|
|
GET_REFERENCE(mvs.x - halfpelMV.x, halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceF, ref1, ref2, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8, ref1+8, ref2+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceF+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
default: // x and y in qpel resolution |
|
|
GET_REFERENCE(halfpelMV.x, mvs.y - halfpelMV.y, ref2); |
|
|
GET_REFERENCE(mvs.x - halfpelMV.x, halfpelMV.y, ref3); |
|
|
GET_REFERENCE(mvs.x - halfpelMV.x, mvs.y - halfpelMV.y, ref4); |
|
|
|
|
|
interpolate8x8_avg4(ReferenceF, ref1, ref2, ref3, ref4, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceF+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceF+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceF+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
} |
|
|
|
|
|
halfpelMV.x = b_mvs.x/2; //backward |
|
|
halfpelMV.y = b_mvs.y/2; |
|
|
GET_REFERENCE2(halfpelMV.x, halfpelMV.y, ref1); |
|
|
switch( ((b_mvs.x&1)<<1) + (b_mvs.y&1) ) |
|
|
{ |
|
|
case 0: // pure halfpel position |
|
|
GET_REFERENCE2(halfpelMV.x, halfpelMV.y, ReferenceB); |
|
|
break; |
|
|
|
|
|
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
|
|
GET_REFERENCE2(halfpelMV.x, b_mvs.y - halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceB, ref1, ref2, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8, ref1+8, ref2+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
case 2: // x qpel, y halfpel - left or right during qpel refinement |
|
|
GET_REFERENCE2(b_mvs.x - halfpelMV.x, halfpelMV.y, ref2); |
|
|
interpolate8x8_avg2(ReferenceB, ref1, ref2, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8, ref1+8, ref2+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg2(ReferenceB+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
|
|
|
default: // x and y in qpel resolution - the "corners" (top left/right and |
|
|
// bottom left/right) during qpel refinement |
|
|
GET_REFERENCE2(halfpelMV.x, b_mvs.y - halfpelMV.y, ref2); |
|
|
GET_REFERENCE2(b_mvs.x - halfpelMV.x, halfpelMV.y, ref3); |
|
|
GET_REFERENCE2(b_mvs.x - halfpelMV.x, b_mvs.y - halfpelMV.y, ref4); |
|
|
|
|
|
interpolate8x8_avg4(ReferenceB, ref1, ref2, ref3, ref4, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceB+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceB+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, 0); |
|
|
interpolate8x8_avg4(ReferenceB+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, 0); |
|
|
break; |
|
|
} |
|
|
|
|
|
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
|
|
sad += (data->lambda16 * d_mv_bits(x, y, 1) * sad)/1000; |
|
|
|
|
|
if (sad < *(data->iMinSAD)) { |
|
|
*(data->iMinSAD) = sad; |
|
|
data->currentMV->x = x; data->currentMV->y = y; |
|
|
*dir = Direction; } |
|
|
} |
|
|
|
|
|
|
|
422 |
static void |
static void |
423 |
CheckCandidateDirectno4v(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidateDirectno4v(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
424 |
{ |
{ |
444 |
|| ( b_mvs.x > data->max_dx ) || ( b_mvs.x < data->min_dx ) |
|| ( b_mvs.x > data->max_dx ) || ( b_mvs.x < data->min_dx ) |
445 |
|| ( b_mvs.y > data->max_dy ) || ( b_mvs.y < data->min_dy )) return; |
|| ( b_mvs.y > data->max_dy ) || ( b_mvs.y < data->min_dy )) return; |
446 |
|
|
447 |
switch ( ((mvs.x&1)<<1) + (mvs.y&1) ) { |
if (!data->qpel) { |
448 |
case 0 : ReferenceF = data->Ref + mvs.x/2 + (mvs.y/2)*(data->iEdgedWidth); break; |
mvs.x *= 2; mvs.y *= 2; |
449 |
case 1 : ReferenceF = data->RefV + mvs.x/2 + ((mvs.y-1)/2)*(data->iEdgedWidth); break; |
b_mvs.x *= 2; b_mvs.y *= 2; //we move to qpel precision anyway |
|
case 2 : ReferenceF = data->RefH + (mvs.x-1)/2 + (mvs.y/2)*(data->iEdgedWidth); break; |
|
|
default : ReferenceF = data->RefHV + (mvs.x-1)/2 + ((mvs.y-1)/2)*(data->iEdgedWidth); break; |
|
|
} |
|
|
|
|
|
switch ( ((b_mvs.x&1)<<1) + (b_mvs.y&1) ) { |
|
|
case 0 : ReferenceB = data->bRef + b_mvs.x/2 + (b_mvs.y/2)*(data->iEdgedWidth); break; |
|
|
case 1 : ReferenceB = data->bRefV + b_mvs.x/2 + ((b_mvs.y-1)/2)*(data->iEdgedWidth); break; |
|
|
case 2 : ReferenceB = data->bRefH + (b_mvs.x-1)/2 + (b_mvs.y/2)*(data->iEdgedWidth); break; |
|
|
default : ReferenceB = data->bRefHV + (b_mvs.x-1)/2 + ((b_mvs.y-1)/2)*(data->iEdgedWidth); break; |
|
450 |
} |
} |
451 |
|
ReferenceF = Interpolate16x16qpel(mvs.x, mvs.y, 0, data); |
452 |
|
ReferenceB = Interpolate16x16qpel(b_mvs.x, b_mvs.y, 1, data); |
453 |
|
|
454 |
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
455 |
sad += (data->lambda16 * d_mv_bits(x, y, 1) * sad)/1000; |
sad += (data->lambda16 * d_mv_bits(x, y, 1) * sad)/1000; |
469 |
if (( x > data->max_dx) || ( x < data->min_dx) |
if (( x > data->max_dx) || ( x < data->min_dx) |
470 |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
471 |
|
|
472 |
switch ( ((x&1)<<1) + (y&1) ) |
if (data->qpel) Reference = Interpolate16x16qpel(x, y, 0, data); |
473 |
{ |
else Reference = Interpolate16x16qpel(2*x, 2*y, 0, data); |
|
case 0 : Reference = data->Ref + x/2 + (y/2)*(data->iEdgedWidth); break; |
|
|
case 1 : Reference = data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
|
|
case 2 : Reference = data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); break; |
|
|
default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break; |
|
|
} |
|
474 |
|
|
475 |
sad = sad8(data->Cur, Reference, data->iEdgedWidth); |
sad = sad8(data->Cur, Reference, data->iEdgedWidth); |
476 |
if (data->qpel) t = d_mv_bits(2 * x - data->predQMV.x, 2 * y - data->predQMV.y, data->iFcode); |
if (data->qpel) t = d_mv_bits(2 * x - data->predMV.x, 2 * y - data->predMV.y, data->iFcode); |
477 |
else t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode); |
else t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode); |
478 |
|
|
479 |
sad += (data->lambda8 * t * (sad+NEIGH_8X8_BIAS))/100; |
sad += (data->lambda8 * t * (sad+NEIGH_8X8_BIAS))/100; |
484 |
*dir = Direction; } |
*dir = Direction; } |
485 |
} |
} |
486 |
|
|
|
static void |
|
|
CheckCandidate8_qpel(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
|
|
// CheckCandidate8 variant which expects x and y in quarter pixel resolution |
|
|
// Important: This is no general usable routine! x and y must be +/-1 (qpel resolution!) |
|
|
// around currentMV! |
|
|
|
|
|
{ |
|
|
int32_t sad; |
|
|
uint8_t *Reference = (uint8_t *) data->RefQ; |
|
|
const uint8_t *ref1, *ref2, *ref3, *ref4; |
|
|
VECTOR halfpelMV = *(data->currentMV); |
|
|
|
|
|
int32_t iEdgedWidth = data->iEdgedWidth; |
|
|
uint32_t rounding = data->rounding; |
|
|
|
|
|
if (( x > data->max_dx) || ( x < data->min_dx) |
|
|
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
|
|
|
|
|
GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1); |
|
|
switch( ((x&1)<<1) + (y&1) ) |
|
|
{ |
|
|
case 0: // pure halfpel position - shouldn't happen during a refinement step |
|
|
GET_REFERENCE(halfpelMV.x, halfpelMV.y, Reference); |
|
|
break; |
|
|
|
|
|
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
|
|
GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2); |
|
|
|
|
|
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding); |
|
|
break; |
|
|
|
|
|
case 2: // x qpel, y halfpel - left or right during qpel refinement |
|
|
GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref2); |
|
|
|
|
|
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding); |
|
|
break; |
|
|
|
|
|
default: // x and y in qpel resolution - the "corners" (top left/right and |
|
|
// bottom left/right) during qpel refinement |
|
|
GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2); |
|
|
GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref3); |
|
|
GET_REFERENCE(x - halfpelMV.x, y - halfpelMV.y, ref4); |
|
|
|
|
|
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
|
|
break; |
|
|
} |
|
|
|
|
|
sad = sad8(data->Cur, Reference, data->iEdgedWidth); |
|
|
sad += (data->lambda8 * d_mv_bits(x - data->predQMV.x, y - data->predQMV.y, data->iFcode) * (sad+NEIGH_8X8_BIAS))/100; |
|
|
|
|
|
if (sad < *(data->iMinSAD)) { |
|
|
*(data->iMinSAD) = sad; |
|
|
data->currentQMV->x = x; data->currentQMV->y = y; |
|
|
*dir = Direction; } |
|
|
} |
|
|
|
|
487 |
/* CHECK_CANDIATE FUNCTIONS END */ |
/* CHECK_CANDIATE FUNCTIONS END */ |
488 |
|
|
489 |
/* MAINSEARCH FUNCTIONS START */ |
/* MAINSEARCH FUNCTIONS START */ |
633 |
/* HALFPELREFINE COULD BE A MAINSEARCH FUNCTION, BUT THERE IS NO NEED FOR IT */ |
/* HALFPELREFINE COULD BE A MAINSEARCH FUNCTION, BUT THERE IS NO NEED FOR IT */ |
634 |
|
|
635 |
static void |
static void |
636 |
HalfpelRefine(const SearchData * const data) |
SubpelRefine(const SearchData * const data) |
637 |
{ |
{ |
638 |
/* Do a half-pel refinement (or rather a "smallest possible amount" refinement) */ |
/* Do a half-pel or q-pel refinement */ |
639 |
|
VECTOR backupMV; |
|
VECTOR backupMV = *(data->currentMV); |
|
640 |
int iDirection; //not needed |
int iDirection; //not needed |
641 |
|
|
642 |
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y - 1, 0); |
if (data->qpel_precision) |
643 |
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y - 1, 0); |
backupMV = *(data->currentQMV); |
644 |
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y + 1, 0); |
else backupMV = *(data->currentMV); |
|
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y + 1, 0); |
|
|
|
|
|
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y, 0); |
|
|
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y, 0); |
|
|
|
|
|
CHECK_CANDIDATE(backupMV.x, backupMV.y + 1, 0); |
|
|
CHECK_CANDIDATE(backupMV.x, backupMV.y - 1, 0); |
|
|
} |
|
|
|
|
|
|
|
|
static void |
|
|
QuarterpelRefine(const SearchData * const data) |
|
|
{ |
|
|
/* Perform quarter pixel refinement*/ |
|
|
|
|
|
VECTOR backupMV = *(data->currentQMV); |
|
|
int iDirection; //not needed |
|
645 |
|
|
646 |
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y - 1, 0); |
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y - 1, 0); |
647 |
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y - 1, 0); |
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y - 1, 0); |
653 |
|
|
654 |
CHECK_CANDIDATE(backupMV.x, backupMV.y + 1, 0); |
CHECK_CANDIDATE(backupMV.x, backupMV.y + 1, 0); |
655 |
CHECK_CANDIDATE(backupMV.x, backupMV.y - 1, 0); |
CHECK_CANDIDATE(backupMV.x, backupMV.y - 1, 0); |
|
|
|
656 |
} |
} |
657 |
|
|
658 |
static __inline int |
static __inline int |
904 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
905 |
pParam->width, pParam->height, Data->iFcode, pParam->m_quarterpel); |
pParam->width, pParam->height, Data->iFcode, pParam->m_quarterpel); |
906 |
|
|
|
Data->predMV = pmv[0]; |
|
|
|
|
907 |
Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16; |
Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16; |
908 |
Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8; |
Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8; |
909 |
Data->CurU = pCur->u + (x + y * (Data->iEdgedWidth/2)) * 8; |
Data->CurU = pCur->u + (x + y * (Data->iEdgedWidth/2)) * 8; |
917 |
|
|
918 |
Data->lambda16 = lambda_vec16[iQuant]; |
Data->lambda16 = lambda_vec16[iQuant]; |
919 |
Data->lambda8 = lambda_vec8[iQuant]; |
Data->lambda8 = lambda_vec8[iQuant]; |
920 |
|
Data->qpel_precision = 0; |
921 |
|
|
922 |
if (!(MotionFlags & PMV_HALFPEL16)) { |
if (!(MotionFlags & PMV_HALFPEL16)) { |
923 |
Data->min_dx = EVEN(Data->min_dx); |
Data->min_dx = EVEN(Data->min_dx); |
930 |
for(i = 0; i < 5; i++) |
for(i = 0; i < 5; i++) |
931 |
Data->currentMV[i].x = Data->currentMV[i].y = 0; |
Data->currentMV[i].x = Data->currentMV[i].y = 0; |
932 |
|
|
933 |
if (pParam->m_quarterpel) { |
if (pParam->m_quarterpel) Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
934 |
Data->predQMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
else Data->predMV = pmv[0]; |
|
i = d_mv_bits(Data->predQMV.x, Data->predQMV.y, Data->iFcode); |
|
|
} else i = d_mv_bits(Data->predMV.x, Data->predMV.y, Data->iFcode); |
|
935 |
|
|
936 |
|
i = d_mv_bits(Data->predMV.x, Data->predMV.y, Data->iFcode); |
937 |
Data->iMinSAD[0] = pMB->sad16 + (Data->lambda16 * i * pMB->sad16)/1000; |
Data->iMinSAD[0] = pMB->sad16 + (Data->lambda16 * i * pMB->sad16)/1000; |
938 |
Data->iMinSAD[1] = pMB->sad8[0] + (Data->lambda8 * i * (pMB->sad8[0]+NEIGH_8X8_BIAS))/100; |
Data->iMinSAD[1] = pMB->sad8[0] + (Data->lambda8 * i * (pMB->sad8[0]+NEIGH_8X8_BIAS))/100; |
939 |
Data->iMinSAD[2] = pMB->sad8[1]; |
Data->iMinSAD[2] = pMB->sad8[1]; |
949 |
PreparePredictionsP(pmv, x, y, pParam->mb_width, pParam->mb_height, |
PreparePredictionsP(pmv, x, y, pParam->mb_width, pParam->mb_height, |
950 |
prevMBs + x + y * pParam->mb_width); |
prevMBs + x + y * pParam->mb_width); |
951 |
|
|
952 |
if (inter4v || pParam->m_quarterpel || Data->chroma) CheckCandidate = CheckCandidate16; |
if (inter4v || Data->chroma) CheckCandidate = CheckCandidate16; |
953 |
else CheckCandidate = CheckCandidate16no4v; |
else CheckCandidate = CheckCandidate16no4v; //for extra speed |
954 |
|
|
955 |
/* main loop. checking all predictions */ |
/* main loop. checking all predictions */ |
956 |
|
|
1007 |
} |
} |
1008 |
} |
} |
1009 |
|
|
1010 |
if (MotionFlags & PMV_HALFPELREFINE16) HalfpelRefine(Data); |
if (MotionFlags & PMV_HALFPELREFINE16) SubpelRefine(Data); |
1011 |
|
|
1012 |
for(i = 0; i < 5; i++) { |
for(i = 0; i < 5; i++) { |
1013 |
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // initialize qpel vectors |
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // initialize qpel vectors |
1016 |
|
|
1017 |
if((pParam->m_quarterpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) { |
if((pParam->m_quarterpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) { |
1018 |
|
|
1019 |
CheckCandidate = CheckCandidate16_qpel; |
Data->qpel_precision = 1; |
1020 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
1021 |
pParam->width, pParam->height, Data->iFcode, 0); |
pParam->width, pParam->height, Data->iFcode, 0); |
1022 |
|
|
1023 |
QuarterpelRefine(Data); |
SubpelRefine(Data); |
1024 |
} |
} |
1025 |
|
|
1026 |
if (Data->iMinSAD[0] < (int32_t)iQuant * 30 ) inter4v = 0; |
if (Data->iMinSAD[0] < (int32_t)iQuant * 30 ) inter4v = 0; |
1037 |
Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8); |
Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8); |
1038 |
|
|
1039 |
if (Data->chroma) { |
if (Data->chroma) { |
1040 |
int sum, dx, dy; |
int sumx, sumy, dx, dy; |
1041 |
|
|
1042 |
if(pParam->m_quarterpel) { |
if(pParam->m_quarterpel) { |
1043 |
sum = pMB->qmvs[0].y/2 + pMB->qmvs[1].y/2 + pMB->qmvs[2].y/2 + pMB->qmvs[3].y/2; |
sumx= pMB->qmvs[0].x/2 + pMB->qmvs[1].x/2 + pMB->qmvs[2].x/2 + pMB->qmvs[3].x/2; |
1044 |
} else sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
sumy = pMB->qmvs[0].y/2 + pMB->qmvs[1].y/2 + pMB->qmvs[2].y/2 + pMB->qmvs[3].y/2; |
1045 |
dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
} else { |
1046 |
|
sumx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
1047 |
if(pParam->m_quarterpel) { |
sumy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
1048 |
sum = pMB->qmvs[0].x/2 + pMB->qmvs[1].x/2 + pMB->qmvs[2].x/2 + pMB->qmvs[3].x/2; |
} |
1049 |
} else sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
1050 |
dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
1051 |
|
|
1052 |
Data->iMinSAD[1] += ChromaSAD(dx, dy, Data); |
Data->iMinSAD[1] += ChromaSAD(dx, dy, Data); |
1053 |
} |
} |
1061 |
pMB->mvs[0] = pMB->mvs[1] |
pMB->mvs[0] = pMB->mvs[1] |
1062 |
= pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0]; |
= pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0]; |
1063 |
|
|
|
pMB->qmvs[0] = pMB->qmvs[1] |
|
|
= pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0]; |
|
|
|
|
1064 |
pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = |
pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = |
1065 |
pMB->sad8[2] = pMB->sad8[3] = Data->iMinSAD[0]; |
pMB->sad8[2] = pMB->sad8[3] = Data->iMinSAD[0]; |
1066 |
|
|
1067 |
if(pParam->m_quarterpel) { |
if(pParam->m_quarterpel) { |
1068 |
pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predQMV.x; |
pMB->qmvs[0] = pMB->qmvs[1] |
1069 |
pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predQMV.y; |
= pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0]; |
1070 |
|
pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x; |
1071 |
|
pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y; |
1072 |
} else { |
} else { |
1073 |
pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x; |
pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x; |
1074 |
pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y; |
pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y; |
1096 |
Data->currentQMV = OldData->currentQMV + 1 + block; |
Data->currentQMV = OldData->currentQMV + 1 + block; |
1097 |
|
|
1098 |
if(pParam->m_quarterpel) { |
if(pParam->m_quarterpel) { |
1099 |
Data->predQMV = get_qpmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block); |
Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block); |
1100 |
if (block != 0) *(Data->iMinSAD) += (Data->lambda8 * |
if (block != 0) *(Data->iMinSAD) += (Data->lambda8 * |
1101 |
d_mv_bits( Data->currentQMV->x - Data->predQMV.x, |
d_mv_bits( Data->currentQMV->x - Data->predMV.x, |
1102 |
Data->currentQMV->y - Data->predQMV.y, |
Data->currentQMV->y - Data->predMV.y, |
1103 |
Data->iFcode) * (*Data->iMinSAD + NEIGH_8X8_BIAS))/100; |
Data->iFcode) * (*Data->iMinSAD + NEIGH_8X8_BIAS))/100; |
1104 |
} else { |
} else { |
1105 |
Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block); |
Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block); |
1117 |
Data->RefHV = OldData->RefHV + 8 * ((block&1) + pParam->edged_width*(block>>1)); |
Data->RefHV = OldData->RefHV + 8 * ((block&1) + pParam->edged_width*(block>>1)); |
1118 |
|
|
1119 |
Data->Cur = OldData->Cur + 8 * ((block&1) + pParam->edged_width*(block>>1)); |
Data->Cur = OldData->Cur + 8 * ((block&1) + pParam->edged_width*(block>>1)); |
1120 |
|
Data->qpel_precision = 0; |
1121 |
|
|
1122 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8, |
1123 |
pParam->width, pParam->height, OldData->iFcode, pParam->m_quarterpel); |
pParam->width, pParam->height, OldData->iFcode, pParam->m_quarterpel); |
1142 |
if (MotionFlags & PMV_HALFPELREFINE8) { |
if (MotionFlags & PMV_HALFPELREFINE8) { |
1143 |
int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD |
int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD |
1144 |
|
|
1145 |
HalfpelRefine(Data); // perform halfpel refine of current best vector |
SubpelRefine(Data); // perform halfpel refine of current best vector |
1146 |
|
|
1147 |
if(*(Data->iMinSAD) < temp_sad) { // we have found a better match |
if(*(Data->iMinSAD) < temp_sad) { // we have found a better match |
1148 |
Data->currentQMV->x = 2 * Data->currentMV->x; // update our qpel vector |
Data->currentQMV->x = 2 * Data->currentMV->x; // update our qpel vector |
1153 |
if(pParam->m_quarterpel) { |
if(pParam->m_quarterpel) { |
1154 |
if((!(Data->currentQMV->x & 1)) && (!(Data->currentQMV->y & 1)) && |
if((!(Data->currentQMV->x & 1)) && (!(Data->currentQMV->y & 1)) && |
1155 |
(MotionFlags & PMV_QUARTERPELREFINE8)) { |
(MotionFlags & PMV_QUARTERPELREFINE8)) { |
1156 |
CheckCandidate = CheckCandidate8_qpel; |
Data->qpel_precision = 1; |
1157 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8, |
1158 |
pParam->width, pParam->height, OldData->iFcode, pParam->m_quarterpel); |
pParam->width, pParam->height, OldData->iFcode, 0); |
1159 |
QuarterpelRefine(Data); |
SubpelRefine(Data); |
1160 |
} |
} |
1161 |
} |
} |
1162 |
} |
} |
1163 |
|
|
1164 |
if(pParam->m_quarterpel) { |
if(pParam->m_quarterpel) { |
1165 |
pMB->pmvs[block].x = Data->currentQMV->x - Data->predQMV.x; |
pMB->pmvs[block].x = Data->currentQMV->x - Data->predMV.x; |
1166 |
pMB->pmvs[block].y = Data->currentQMV->y - Data->predQMV.y; |
pMB->pmvs[block].y = Data->currentQMV->y - Data->predMV.y; |
1167 |
|
pMB->qmvs[block] = *(Data->currentQMV); |
1168 |
} |
} |
1169 |
else { |
else { |
1170 |
pMB->pmvs[block].x = Data->currentMV->x - Data->predMV.x; |
pMB->pmvs[block].x = Data->currentMV->x - Data->predMV.x; |
1172 |
} |
} |
1173 |
|
|
1174 |
pMB->mvs[block] = *(Data->currentMV); |
pMB->mvs[block] = *(Data->currentMV); |
|
pMB->qmvs[block] = *(Data->currentQMV); |
|
|
|
|
1175 |
pMB->sad8[block] = 4 * (*Data->iMinSAD); |
pMB->sad8[block] = 4 * (*Data->iMinSAD); |
1176 |
} |
} |
1177 |
|
|
1249 |
MainSearchFunc *MainSearchPtr; |
MainSearchFunc *MainSearchPtr; |
1250 |
*Data->iMinSAD = MV_MAX_ERROR; |
*Data->iMinSAD = MV_MAX_ERROR; |
1251 |
Data->iFcode = iFcode; |
Data->iFcode = iFcode; |
1252 |
|
Data->qpel_precision = 0; |
1253 |
|
|
1254 |
Data->Ref = pRef + (x + y * iEdgedWidth) * 16; |
Data->Ref = pRef + (x + y * iEdgedWidth) * 16; |
1255 |
Data->RefH = pRefH + (x + y * iEdgedWidth) * 16; |
Data->RefH = pRefH + (x + y * iEdgedWidth) * 16; |
1266 |
PreparePredictionsBF(pmv, x, y, pParam->mb_width, pMB, mode_current); |
PreparePredictionsBF(pmv, x, y, pParam->mb_width, pMB, mode_current); |
1267 |
|
|
1268 |
Data->currentMV->x = Data->currentMV->y = 0; |
Data->currentMV->x = Data->currentMV->y = 0; |
|
|
|
1269 |
CheckCandidate = CheckCandidate16no4v; |
CheckCandidate = CheckCandidate16no4v; |
1270 |
|
|
1271 |
// main loop. checking all predictions |
// main loop. checking all predictions |
1282 |
|
|
1283 |
(*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255); |
(*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255); |
1284 |
|
|
1285 |
HalfpelRefine(Data); |
SubpelRefine(Data); |
1286 |
|
|
1287 |
if (Data->qpel) { |
if (Data->qpel) { |
1288 |
Data->currentQMV->x = 2*Data->currentMV->x; |
Data->currentQMV->x = 2*Data->currentMV->x; |
1289 |
Data->currentQMV->y = 2*Data->currentMV->y; |
Data->currentQMV->y = 2*Data->currentMV->y; |
1290 |
CheckCandidate = CheckCandidate16no4v_qpel; |
Data->qpel_precision = 1; |
1291 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
1292 |
pParam->width, pParam->height, iFcode, pParam->m_quarterpel); |
pParam->width, pParam->height, iFcode, 0); |
1293 |
QuarterpelRefine(Data); |
SubpelRefine(Data); |
1294 |
} |
} |
1295 |
|
|
1296 |
// three bits are needed to code backward mode. four for forward |
// three bits are needed to code backward mode. four for forward |
1368 |
Data->min_dy *= 2; |
Data->min_dy *= 2; |
1369 |
Data->referencemv = b_mb->qmvs; |
Data->referencemv = b_mb->qmvs; |
1370 |
} else Data->referencemv = b_mb->mvs; |
} else Data->referencemv = b_mb->mvs; |
1371 |
|
Data->qpel_precision = 0; // it'm a trick. it's 1 not 0, but we need 0 here |
1372 |
|
|
1373 |
for (k = 0; k < 4; k++) { |
for (k = 0; k < 4; k++) { |
1374 |
pMB->mvs[k].x = Data->directmvF[k].x = ((TRB * Data->referencemv[k].x) / TRD); |
pMB->mvs[k].x = Data->directmvF[k].x = ((TRB * Data->referencemv[k].x) / TRD); |
1393 |
} |
} |
1394 |
} |
} |
1395 |
|
|
1396 |
if (Data->qpel) { |
|
|
if (b_mb->mode == MODE_INTER4V) |
|
|
CheckCandidate = CheckCandidateDirect_qpel; |
|
|
else CheckCandidate = CheckCandidateDirectno4v_qpel; |
|
|
} else { |
|
1397 |
if (b_mb->mode == MODE_INTER4V) CheckCandidate = CheckCandidateDirect; |
if (b_mb->mode == MODE_INTER4V) CheckCandidate = CheckCandidateDirect; |
1398 |
else CheckCandidate = CheckCandidateDirectno4v; |
else CheckCandidate = CheckCandidateDirectno4v; |
|
} |
|
1399 |
|
|
1400 |
(*CheckCandidate)(0, 0, 255, &k, Data); |
(*CheckCandidate)(0, 0, 255, &k, Data); |
1401 |
|
|
1453 |
|
|
1454 |
(*MainSearchPtr)(0, 0, Data, 255); |
(*MainSearchPtr)(0, 0, Data, 255); |
1455 |
|
|
1456 |
HalfpelRefine(Data); //or qpel refine, if we're in qpel mode |
SubpelRefine(Data); |
1457 |
|
|
1458 |
*Data->iMinSAD += 1 * Data->lambda16; // one bit is needed to code direct mode |
*Data->iMinSAD += 1 * Data->lambda16; // one bit is needed to code direct mode |
1459 |
*best_sad = *Data->iMinSAD; |
*best_sad = *Data->iMinSAD; |
1460 |
|
|
1461 |
if (b_mb->mode == MODE_INTER4V) |
// if (b_mb->mode == MODE_INTER4V) |
1462 |
pMB->mode = MODE_DIRECT; |
pMB->mode = MODE_DIRECT; |
1463 |
else pMB->mode = MODE_DIRECT_NO4V; //for faster compensation |
// else pMB->mode = MODE_DIRECT_NO4V; //for faster compensation |
1464 |
|
|
1465 |
pMB->pmvs[3] = *Data->currentMV; |
pMB->pmvs[3] = *Data->currentMV; |
1466 |
|
|
1535 |
bData.RefV = fData->bRefV = b_RefV + (x + y * iEdgedWidth) * 16; |
bData.RefV = fData->bRefV = b_RefV + (x + y * iEdgedWidth) * 16; |
1536 |
bData.RefHV = fData->bRefHV = b_RefHV + (x + y * iEdgedWidth) * 16; |
bData.RefHV = fData->bRefHV = b_RefHV + (x + y * iEdgedWidth) * 16; |
1537 |
bData.RefQ = fData->RefQ; |
bData.RefQ = fData->RefQ; |
1538 |
|
fData->qpel_precision = bData.qpel_precision = 0; |
1539 |
|
bData.rounding = 0; |
1540 |
|
|
1541 |
bData.bpredMV = fData->predMV = *f_predMV; |
bData.bpredMV = fData->predMV = *f_predMV; |
1542 |
fData->bpredMV = bData.predMV = *b_predMV; |
fData->bpredMV = bData.predMV = *b_predMV; |
1582 |
*fData->iMinSAD += 2 * fData->lambda16; // two bits are needed to code interpolate mode. |
*fData->iMinSAD += 2 * fData->lambda16; // two bits are needed to code interpolate mode. |
1583 |
|
|
1584 |
if (fData->qpel) { |
if (fData->qpel) { |
1585 |
CheckCandidate = CheckCandidateInt_qpel; |
fData->qpel_precision = bData.qpel_precision = 1; |
1586 |
get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 16, pParam->width, pParam->height, fcode, 0); |
get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 16, pParam->width, pParam->height, fcode, 0); |
1587 |
get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 16, pParam->width, pParam->height, bcode, 0); |
get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 16, pParam->width, pParam->height, bcode, 0); |
1588 |
fData->currentQMV[2].x = fData->currentQMV[0].x = 2 * fData->currentMV[0].x; |
fData->currentQMV[2].x = fData->currentQMV[0].x = 2 * fData->currentMV[0].x; |
1589 |
fData->currentQMV[2].y = fData->currentQMV[0].y = 2 * fData->currentMV[0].y; |
fData->currentQMV[2].y = fData->currentQMV[0].y = 2 * fData->currentMV[0].y; |
1590 |
fData->currentQMV[1].x = 2 * fData->currentMV[1].x; |
fData->currentQMV[1].x = 2 * fData->currentMV[1].x; |
1591 |
fData->currentQMV[1].y = 2 * fData->currentMV[1].y; |
fData->currentQMV[1].y = 2 * fData->currentMV[1].y; |
1592 |
// QuarterpelRefine(fData); |
SubpelRefine(fData); |
1593 |
fData->currentQMV[2] = fData->currentQMV[0]; |
fData->currentQMV[2] = fData->currentQMV[0]; |
1594 |
// QuarterpelRefine(&bData); |
SubpelRefine(&bData); |
1595 |
} |
} |
1596 |
|
|
1597 |
if (*fData->iMinSAD < *best_sad) { |
if (*fData->iMinSAD < *best_sad) { |
1656 |
Data.iMinSAD = &iMinSAD; |
Data.iMinSAD = &iMinSAD; |
1657 |
Data.lambda16 = lambda_vec16[frame->quant]; |
Data.lambda16 = lambda_vec16[frame->quant]; |
1658 |
Data.qpel = pParam->m_quarterpel; |
Data.qpel = pParam->m_quarterpel; |
1659 |
|
Data.rounding = 0; |
1660 |
|
|
1661 |
if((qimage = (uint8_t *) malloc(32 * pParam->edged_width)) == NULL) |
if((qimage = (uint8_t *) malloc(32 * pParam->edged_width)) == NULL) |
1662 |
return; // allocate some mem for qpel interpolated blocks |
return; // allocate some mem for qpel interpolated blocks |
1782 |
int i, t; |
int i, t; |
1783 |
MainSearchFunc * MainSearchPtr; |
MainSearchFunc * MainSearchPtr; |
1784 |
|
|
|
Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
|
|
Data->predQMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
|
1785 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
1786 |
pParam->width, pParam->height, Data->iFcode, pParam->m_quarterpel); |
pParam->width, pParam->height, Data->iFcode, pParam->m_quarterpel); |
1787 |
|
|
1795 |
Data->RefHV = pRefHV + (x + Data->iEdgedWidth*y) * 16; |
Data->RefHV = pRefHV + (x + Data->iEdgedWidth*y) * 16; |
1796 |
Data->RefCV = pRef->v + (x + y * (Data->iEdgedWidth/2)) * 8; |
Data->RefCV = pRef->v + (x + y * (Data->iEdgedWidth/2)) * 8; |
1797 |
Data->RefCU = pRef->u + (x + y * (Data->iEdgedWidth/2)) * 8; |
Data->RefCU = pRef->u + (x + y * (Data->iEdgedWidth/2)) * 8; |
1798 |
|
Data->qpel_precision = 0; |
1799 |
|
|
1800 |
if (!(MotionFlags & PMV_HALFPEL16)) { |
if (!(MotionFlags & PMV_HALFPEL16)) { |
1801 |
Data->min_dx = EVEN(Data->min_dx); |
Data->min_dx = EVEN(Data->min_dx); |
1803 |
Data->min_dy = EVEN(Data->min_dy); |
Data->min_dy = EVEN(Data->min_dy); |
1804 |
Data->max_dy = EVEN(Data->max_dy); |
Data->max_dy = EVEN(Data->max_dy); |
1805 |
} |
} |
1806 |
|
if (pParam->m_quarterpel) Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
1807 |
|
else Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
1808 |
|
|
1809 |
for(i = 0; i < 5; i++) Data->iMinSAD[i] = MV_MAX_ERROR; |
for(i = 0; i < 5; i++) Data->iMinSAD[i] = MV_MAX_ERROR; |
1810 |
|
|
1811 |
if (pMB->dquant != NO_CHANGE) inter4v = 0; |
if (pMB->dquant != NO_CHANGE) inter4v = 0; |
1812 |
|
|
1813 |
if (inter4v || pParam->m_quarterpel || Data->chroma) CheckCandidate = CheckCandidate16; |
if (inter4v || Data->chroma) CheckCandidate = CheckCandidate16; |
1814 |
else CheckCandidate = CheckCandidate16no4v; |
else CheckCandidate = CheckCandidate16no4v; |
1815 |
|
|
1816 |
pMB->mvs[0].x = EVEN(pMB->mvs[0].x); |
pMB->mvs[0].x = EVEN(pMB->mvs[0].x); |
1838 |
|
|
1839 |
(*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255); |
(*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255); |
1840 |
|
|
1841 |
if (MotionFlags & PMV_HALFPELREFINE16) HalfpelRefine(Data); |
if (MotionFlags & PMV_HALFPELREFINE16) SubpelRefine(Data); |
1842 |
|
|
1843 |
for(i = 0; i < 5; i++) { |
for(i = 0; i < 5; i++) { |
1844 |
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // initialize qpel vectors |
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // initialize qpel vectors |
1848 |
if((pParam->m_quarterpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) { |
if((pParam->m_quarterpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) { |
1849 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
1850 |
pParam->width, pParam->height, Data->iFcode, 0); |
pParam->width, pParam->height, Data->iFcode, 0); |
1851 |
CheckCandidate = CheckCandidate16_qpel; |
Data->qpel_precision = 1; |
1852 |
QuarterpelRefine(Data); |
SubpelRefine(Data); |
1853 |
} |
} |
1854 |
|
|
1855 |
if (inter4v) { |
if (inter4v) { |
1865 |
Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8); |
Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8); |
1866 |
|
|
1867 |
if (Data->chroma) { |
if (Data->chroma) { |
1868 |
int sum, dx, dy; |
int sumx, sumy, dx, dy; |
1869 |
|
|
1870 |
|
if(pParam->m_quarterpel) { |
1871 |
|
sumx= pMB->qmvs[0].x/2 + pMB->qmvs[1].x/2 + pMB->qmvs[2].x/2 + pMB->qmvs[3].x/2; |
1872 |
|
sumy = pMB->qmvs[0].y/2 + pMB->qmvs[1].y/2 + pMB->qmvs[2].y/2 + pMB->qmvs[3].y/2; |
1873 |
|
} else { |
1874 |
|
sumx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
1875 |
|
sumy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
1876 |
|
} |
1877 |
|
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
1878 |
|
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
1879 |
|
|
|
if(pParam->m_quarterpel) |
|
|
sum = (pMB->qmvs[0].y/2 + pMB->qmvs[1].y/2 + pMB->qmvs[2].y/2 + pMB->qmvs[3].y/2); |
|
|
else sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
|
|
dy = (sum ? SIGN(sum) * |
|
|
(roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
|
|
|
|
|
if(pParam->m_quarterpel) |
|
|
sum = (pMB->qmvs[0].x/2 + pMB->qmvs[1].x/2 + pMB->qmvs[2].x/2 + pMB->qmvs[3].x/2); |
|
|
else sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
|
|
dx = (sum ? SIGN(sum) * |
|
|
(roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) : 0); |
|
1880 |
Data->iMinSAD[1] += ChromaSAD(dx, dy, Data); |
Data->iMinSAD[1] += ChromaSAD(dx, dy, Data); |
1881 |
} |
} |
1882 |
} |
} |
1896 |
pMB->sad8[2] = pMB->sad8[3] = Data->iMinSAD[0]; |
pMB->sad8[2] = pMB->sad8[3] = Data->iMinSAD[0]; |
1897 |
|
|
1898 |
if(pParam->m_quarterpel) { |
if(pParam->m_quarterpel) { |
1899 |
pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predQMV.x; |
pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x; |
1900 |
pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predQMV.y; |
pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y; |
1901 |
} else { |
} else { |
1902 |
pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x; |
pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x; |
1903 |
pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y; |
pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y; |