58 |
int xb, yb; |
int xb, yb; |
59 |
if (qpel) { x *= 2; y *= 2;} |
if (qpel) { x *= 2; y *= 2;} |
60 |
else if (rrv) { x = RRV_MV_SCALEDOWN(x); y = RRV_MV_SCALEDOWN(y); } |
else if (rrv) { x = RRV_MV_SCALEDOWN(x); y = RRV_MV_SCALEDOWN(y); } |
61 |
x = pred.x - x; |
x -= pred.x; |
62 |
y = pred.y - y; |
y -= pred.y; |
63 |
|
|
64 |
if (x == 0) xb = 1; |
if (x) { |
|
else { |
|
65 |
if (x < 0) x = -x; |
if (x < 0) x = -x; |
66 |
x += (1 << (iFcode - 1)) - 1; |
x += (1 << (iFcode - 1)) - 1; |
67 |
x >>= (iFcode - 1); |
x >>= (iFcode - 1); |
68 |
if (x > 32) x = 32; |
if (x > 32) x = 32; |
69 |
xb = mvtab[x] + iFcode; |
xb = mvtab[x] + iFcode; |
70 |
} |
} else xb = 1; |
71 |
|
|
72 |
if (y == 0) yb = 1; |
if (y) { |
|
else { |
|
73 |
if (y < 0) y = -y; |
if (y < 0) y = -y; |
74 |
y += (1 << (iFcode - 1)) - 1; |
y += (1 << (iFcode - 1)) - 1; |
75 |
y >>= (iFcode - 1); |
y >>= (iFcode - 1); |
76 |
if (y > 32) y = 32; |
if (y > 32) y = 32; |
77 |
yb = mvtab[y] + iFcode; |
yb = mvtab[y] + iFcode; |
78 |
} |
} else yb = 1; |
79 |
return xb + yb; |
return xb + yb; |
80 |
} |
} |
81 |
|
|
83 |
ChromaSAD(int dx, int dy, const SearchData * const data) |
ChromaSAD(int dx, int dy, const SearchData * const data) |
84 |
{ |
{ |
85 |
int sad; |
int sad; |
86 |
dx = (dx >> 1) + roundtab_79[dx & 0x3]; |
const uint32_t stride = data->iEdgedWidth/2; |
|
dy = (dy >> 1) + roundtab_79[dy & 0x3]; |
|
87 |
|
|
88 |
if (dx == data->temp[5] && dy == data->temp[6]) return data->temp[7]; //it has been checked recently |
if (dx == data->temp[5] && dy == data->temp[6]) return data->temp[7]; //it has been checked recently |
89 |
|
data->temp[5] = dx; data->temp[6] = dy; // backup |
90 |
|
|
91 |
switch (((dx & 1) << 1) | (dy & 1)) { |
switch (((dx & 1) << 1) | (dy & 1)) { |
92 |
case 0: |
case 0: |
93 |
sad = sad8(data->CurU, data->RefCU + (dy/2) * (data->iEdgedWidth/2) + dx/2, data->iEdgedWidth/2); |
dx = dx / 2; dy = dy / 2; |
94 |
sad += sad8(data->CurV, data->RefCV + (dy/2) * (data->iEdgedWidth/2) + dx/2, data->iEdgedWidth/2); |
sad = sad8(data->CurU, data->RefCU + dy * stride + dx, stride); |
95 |
|
sad += sad8(data->CurV, data->RefCV + dy * stride + dx, stride); |
96 |
break; |
break; |
97 |
case 1: |
case 1: |
98 |
dx = dx / 2; dy = (dy - 1) / 2; |
dx = dx / 2; dy = (dy - 1) / 2; |
99 |
sad = sad8bi(data->CurU, data->RefCU + dy * (data->iEdgedWidth/2) + dx, data->RefCU + (dy+1) * (data->iEdgedWidth/2) + dx, data->iEdgedWidth/2); |
sad = sad8bi(data->CurU, data->RefCU + dy * stride + dx, data->RefCU + (dy+1) * stride + dx, stride); |
100 |
sad += sad8bi(data->CurV, data->RefCV + dy * (data->iEdgedWidth/2) + dx, data->RefCV + (dy+1) * (data->iEdgedWidth/2) + dx, data->iEdgedWidth/2); |
sad += sad8bi(data->CurV, data->RefCV + dy * stride + dx, data->RefCV + (dy+1) * stride + dx, stride); |
101 |
break; |
break; |
102 |
case 2: |
case 2: |
103 |
dx = (dx - 1) / 2; dy = dy / 2; |
dx = (dx - 1) / 2; dy = dy / 2; |
104 |
sad = sad8bi(data->CurU, data->RefCU + dy * (data->iEdgedWidth/2) + dx, data->RefCU + dy * (data->iEdgedWidth/2) + dx+1, data->iEdgedWidth/2); |
sad = sad8bi(data->CurU, data->RefCU + dy * stride + dx, data->RefCU + dy * stride + dx+1, stride); |
105 |
sad += sad8bi(data->CurV, data->RefCV + dy * (data->iEdgedWidth/2) + dx, data->RefCV + dy * (data->iEdgedWidth/2) + dx+1, data->iEdgedWidth/2); |
sad += sad8bi(data->CurV, data->RefCV + dy * stride + dx, data->RefCV + dy * stride + dx+1, stride); |
106 |
break; |
break; |
107 |
default: |
default: |
108 |
dx = (dx - 1) / 2; dy = (dy - 1) / 2; |
dx = (dx - 1) / 2; dy = (dy - 1) / 2; |
109 |
interpolate8x8_halfpel_hv(data->RefQ, |
interpolate8x8_halfpel_hv(data->RefQ, data->RefCU + dy * stride + dx, stride, data->rounding); |
110 |
data->RefCU + dy * (data->iEdgedWidth/2) + dx, data->iEdgedWidth/2, |
sad = sad8(data->CurU, data->RefQ, stride); |
111 |
data->rounding); |
|
112 |
sad = sad8(data->CurU, data->RefQ, data->iEdgedWidth/2); |
interpolate8x8_halfpel_hv(data->RefQ, data->RefCV + dy * stride + dx, stride, data->rounding); |
113 |
interpolate8x8_halfpel_hv(data->RefQ, |
sad += sad8(data->CurV, data->RefQ, stride); |
|
data->RefCV + dy * (data->iEdgedWidth/2) + dx, data->iEdgedWidth/2, |
|
|
data->rounding); |
|
|
sad += sad8(data->CurV, data->RefQ, data->iEdgedWidth/2); |
|
114 |
break; |
break; |
115 |
} |
} |
116 |
data->temp[5] = dx; data->temp[6] = dy; data->temp[7] = sad; //backup |
data->temp[7] = sad; //backup, part 2 |
117 |
return sad; |
return sad; |
118 |
} |
} |
119 |
|
|
120 |
static __inline const uint8_t * |
static __inline const uint8_t * |
121 |
GetReference(const int x, const int y, const int dir, const SearchData * const data) |
GetReferenceB(const int x, const int y, const int dir, const SearchData * const data) |
122 |
{ |
{ |
123 |
// dir : 0 = forward, 1 = backward |
// dir : 0 = forward, 1 = backward |
124 |
switch ( (dir << 2) | ((x&1)<<1) | (y&1) ) { |
switch ( (dir << 2) | ((x&1)<<1) | (y&1) ) { |
133 |
} |
} |
134 |
} |
} |
135 |
|
|
136 |
|
// this is a simpler copy of GetReferenceB, but as it's __inline anyway, we can keep the two separate |
137 |
|
static __inline const uint8_t * |
138 |
|
GetReference(const int x, const int y, const SearchData * const data) |
139 |
|
{ |
140 |
|
switch ( ((x&1)<<1) | (y&1) ) { |
141 |
|
case 0 : return data->Ref + x/2 + (y/2)*(data->iEdgedWidth); |
142 |
|
case 1 : return data->RefV + x/2 + ((y-1)/2)*(data->iEdgedWidth); |
143 |
|
case 2 : return data->RefH + (x-1)/2 + (y/2)*(data->iEdgedWidth); |
144 |
|
default : return data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
static uint8_t * |
static uint8_t * |
149 |
Interpolate8x8qpel(const int x, const int y, const int block, const int dir, const SearchData * const data) |
Interpolate8x8qpel(const int x, const int y, const int block, const int dir, const SearchData * const data) |
150 |
{ |
{ |
156 |
const int halfpel_y = y/2; |
const int halfpel_y = y/2; |
157 |
const uint8_t *ref1, *ref2, *ref3, *ref4; |
const uint8_t *ref1, *ref2, *ref3, *ref4; |
158 |
|
|
159 |
ref1 = GetReference(halfpel_x, halfpel_y, dir, data); // this reference is used in all cases |
ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data); |
160 |
ref1 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
ref1 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
161 |
switch( ((x&1)<<1) + (y&1) ) { |
switch( ((x&1)<<1) + (y&1) ) { |
162 |
case 0: // pure halfpel position |
case 0: // pure halfpel position |
163 |
Reference = (uint8_t *) GetReference(halfpel_x, halfpel_y, dir, data); |
return (uint8_t *) ref1; |
|
Reference += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
|
164 |
break; |
break; |
165 |
|
|
166 |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
167 |
ref2 = GetReference(halfpel_x, y - halfpel_y, dir, data); |
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
168 |
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
169 |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
170 |
break; |
break; |
171 |
|
|
172 |
case 2: // x qpel, y halfpel - left or right during qpel refinement |
case 2: // x qpel, y halfpel - left or right during qpel refinement |
173 |
ref2 = GetReference(x - halfpel_x, halfpel_y, dir, data); |
ref2 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data); |
174 |
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
175 |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
176 |
break; |
break; |
177 |
|
|
178 |
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 |
179 |
// bottom left/right) during qpel refinement |
// bottom left/right) during qpel refinement |
180 |
ref2 = GetReference(halfpel_x, y - halfpel_y, dir, data); |
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
181 |
ref3 = GetReference(x - halfpel_x, halfpel_y, dir, data); |
ref3 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data); |
182 |
ref4 = GetReference(x - halfpel_x, y - halfpel_y, dir, data); |
ref4 = GetReferenceB(x - halfpel_x, y - halfpel_y, dir, data); |
183 |
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
ref2 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
184 |
ref3 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
ref3 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
185 |
ref4 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
ref4 += 8 * (block&1) + 8 * (block>>1) * iEdgedWidth; |
200 |
const int halfpel_y = y/2; |
const int halfpel_y = y/2; |
201 |
const uint8_t *ref1, *ref2, *ref3, *ref4; |
const uint8_t *ref1, *ref2, *ref3, *ref4; |
202 |
|
|
203 |
ref1 = GetReference(halfpel_x, halfpel_y, dir, data); // this reference is used in all cases |
ref1 = GetReferenceB(halfpel_x, halfpel_y, dir, data); |
204 |
switch( ((x&1)<<1) + (y&1) ) { |
switch( ((x&1)<<1) + (y&1) ) { |
205 |
case 0: // pure halfpel position |
case 0: // pure halfpel position |
206 |
return (uint8_t *) GetReference(halfpel_x, halfpel_y, dir, data); |
return (uint8_t *) ref1; |
207 |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
case 1: // x halfpel, y qpel - top or bottom during qpel refinement |
208 |
ref2 = GetReference(halfpel_x, y - halfpel_y, dir, data); |
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
209 |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
210 |
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding, 8); |
211 |
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding, 8); |
213 |
break; |
break; |
214 |
|
|
215 |
case 2: // x qpel, y halfpel - left or right during qpel refinement |
case 2: // x qpel, y halfpel - left or right during qpel refinement |
216 |
ref2 = GetReference(x - halfpel_x, halfpel_y, dir, data); |
ref2 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data); |
217 |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding, 8); |
218 |
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding, 8); |
219 |
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding, 8); |
interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding, 8); |
222 |
|
|
223 |
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 |
224 |
// bottom left/right) during qpel refinement |
// bottom left/right) during qpel refinement |
225 |
ref2 = GetReference(halfpel_x, y - halfpel_y, dir, data); |
ref2 = GetReferenceB(halfpel_x, y - halfpel_y, dir, data); |
226 |
ref3 = GetReference(x - halfpel_x, halfpel_y, dir, data); |
ref3 = GetReferenceB(x - halfpel_x, halfpel_y, dir, data); |
227 |
ref4 = GetReference(x - halfpel_x, y - halfpel_y, dir, data); |
ref4 = GetReferenceB(x - halfpel_x, y - halfpel_y, dir, data); |
228 |
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding); |
229 |
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); |
230 |
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); |
251 |
xc = x/2; yc = y/2; //for chroma sad |
xc = x/2; yc = y/2; //for chroma sad |
252 |
current = data->currentQMV; |
current = data->currentQMV; |
253 |
} else { |
} else { |
254 |
Reference = GetReference(x, y, 0, data); |
Reference = GetReference(x, y, data); |
255 |
current = data->currentMV; |
current = data->currentMV; |
256 |
xc = x; yc = y; |
xc = x; yc = y; |
257 |
} |
} |
262 |
data->temp[0] += (data->lambda16 * t * data->temp[0])/1000; |
data->temp[0] += (data->lambda16 * t * data->temp[0])/1000; |
263 |
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; |
264 |
|
|
265 |
if (data->chroma) data->temp[0] += ChromaSAD(xc, yc, data); |
if (data->chroma) data->temp[0] += ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3], |
266 |
|
(yc >> 1) + roundtab_79[yc & 0x3], data); |
267 |
|
|
268 |
if (data->temp[0] < data->iMinSAD[0]) { |
if (data->temp[0] < data->iMinSAD[0]) { |
269 |
data->iMinSAD[0] = data->temp[0]; |
data->iMinSAD[0] = data->temp[0]; |
291 |
( x > data->max_dx) || ( x < data->min_dx) |
( x > data->max_dx) || ( x < data->min_dx) |
292 |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
293 |
|
|
294 |
Reference = GetReference(x, y, 0, data); |
Reference = GetReference(x, y, data); |
295 |
t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 1); |
t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 1); |
296 |
|
|
297 |
data->temp[0] = sad32v_c(data->Cur, Reference, data->iEdgedWidth, data->temp + 1); |
data->temp[0] = sad32v_c(data->Cur, Reference, data->iEdgedWidth, data->temp + 1); |
332 |
Reference = Interpolate16x16qpel(x, y, 0, data); |
Reference = Interpolate16x16qpel(x, y, 0, data); |
333 |
current = data->currentQMV; |
current = data->currentQMV; |
334 |
} else { |
} else { |
335 |
Reference = GetReference(x, y, 0, data); |
Reference = GetReference(x, y, data); |
336 |
current = data->currentMV; |
current = data->currentMV; |
337 |
} |
} |
338 |
t = d_mv_bits(x, y, data->predMV, data->iFcode, |
t = d_mv_bits(x, y, data->predMV, data->iFcode, |
339 |
data->qpel && !data->qpel_precision && !data->rrv, data->rrv); |
data->qpel && !data->qpel_precision, data->rrv); |
340 |
|
|
341 |
sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096); |
sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096); |
342 |
sad += (data->lambda16 * t * sad)/1000; |
sad += (data->lambda16 * t * sad)/1000; |
348 |
} |
} |
349 |
|
|
350 |
static void |
static void |
351 |
CheckCandidate16no4vI(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
CheckCandidate32I(const int x, const int y, const int Direction, int * const dir, const SearchData * const data) |
352 |
{ |
{ |
353 |
// maximum speed - for P/B/I decision |
// maximum speed - for P/B/I decision |
|
int32_t sad; |
|
354 |
|
|
355 |
if (( x > data->max_dx) || ( x < data->min_dx) |
if (( x > data->max_dx) || ( x < data->min_dx) |
356 |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
357 |
|
|
358 |
sad = sad16(data->Cur, data->Ref + x/2 + (y/2)*(data->iEdgedWidth), |
data->temp[0] = sad32v_c(data->Cur, data->Ref + x/2 + (y/2)*(data->iEdgedWidth), |
359 |
data->iEdgedWidth, 256*4096); |
data->iEdgedWidth, data->temp+1); |
360 |
|
if (data->temp[0] < *(data->iMinSAD)) { |
361 |
if (sad < *(data->iMinSAD)) { |
*(data->iMinSAD) = data->temp[0]; |
|
*(data->iMinSAD) = sad; |
|
362 |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
363 |
*dir = Direction; } |
*dir = Direction; } |
364 |
} |
if (data->temp[1] < data->iMinSAD[1]) { |
365 |
|
data->iMinSAD[1] = data->temp[1]; data->currentMV[1].x = x; data->currentMV[1].y = y; } |
366 |
|
if (data->temp[2] < data->iMinSAD[2]) { |
367 |
|
data->iMinSAD[2] = data->temp[2]; data->currentMV[2].x = x; data->currentMV[2].y = y; } |
368 |
|
if (data->temp[3] < data->iMinSAD[3]) { |
369 |
|
data->iMinSAD[3] = data->temp[3]; data->currentMV[3].x = x; data->currentMV[3].y = y; } |
370 |
|
if (data->temp[4] < data->iMinSAD[4]) { |
371 |
|
data->iMinSAD[4] = data->temp[4]; data->currentMV[4].x = x; data->currentMV[4].y = y; } |
372 |
|
|
373 |
|
} |
374 |
|
|
375 |
static void |
static void |
376 |
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) |
389 |
current = data->currentQMV; |
current = data->currentQMV; |
390 |
ReferenceB = Interpolate16x16qpel(xb, yb, 1, data); |
ReferenceB = Interpolate16x16qpel(xb, yb, 1, data); |
391 |
} else { |
} else { |
392 |
ReferenceF = GetReference(xf, yf, 0, data); |
ReferenceF = GetReference(xf, yf, data); |
393 |
xb = data->currentMV[1].x; yb = data->currentMV[1].y; |
xb = data->currentMV[1].x; yb = data->currentMV[1].y; |
394 |
ReferenceB = GetReference(xb, yb, 1, data); |
ReferenceB = GetReferenceB(xb, yb, 1, data); |
395 |
current = data->currentMV; |
current = data->currentMV; |
396 |
} |
} |
397 |
|
|
508 |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
509 |
|
|
510 |
if (data->qpel) Reference = Interpolate16x16qpel(x, y, 0, data); |
if (data->qpel) Reference = Interpolate16x16qpel(x, y, 0, data); |
511 |
else Reference = GetReference(x, y, 0, data); |
else Reference = GetReference(x, y, data); |
512 |
|
|
513 |
sad = sad8(data->Cur, Reference, data->iEdgedWidth); |
sad = sad8(data->Cur, Reference, data->iEdgedWidth); |
514 |
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel && !data->qpel_precision, 0); |
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel && !data->qpel_precision, 0); |
681 |
backupMV = *(data->currentQMV); |
backupMV = *(data->currentQMV); |
682 |
else backupMV = *(data->currentMV); |
else backupMV = *(data->currentMV); |
683 |
|
|
684 |
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y - 1, 0); |
CHECK_CANDIDATE(backupMV.x, backupMV.y - 1, 0); |
685 |
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y - 1, 0); |
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y - 1, 0); |
|
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y + 1, 0); |
|
|
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y + 1, 0); |
|
|
|
|
|
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y, 0); |
|
686 |
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y, 0); |
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y, 0); |
687 |
|
CHECK_CANDIDATE(backupMV.x + 1, backupMV.y + 1, 0); |
688 |
CHECK_CANDIDATE(backupMV.x, backupMV.y + 1, 0); |
CHECK_CANDIDATE(backupMV.x, backupMV.y + 1, 0); |
689 |
CHECK_CANDIDATE(backupMV.x, backupMV.y - 1, 0); |
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y + 1, 0); |
690 |
|
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y, 0); |
691 |
|
CHECK_CANDIDATE(backupMV.x - 1, backupMV.y - 1, 0); |
692 |
} |
} |
693 |
|
|
694 |
static __inline int |
static __inline int |
1099 |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
Data->currentQMV[i].y = 2 * Data->currentMV[i].y; |
1100 |
} |
} |
1101 |
|
|
1102 |
if((!Data->rrv) && (pParam->m_quarterpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) { |
if((Data->qpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) { |
1103 |
|
|
1104 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1105 |
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, |
1123 |
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); |
1124 |
|
|
1125 |
if (Data->chroma) { |
if (Data->chroma) { |
1126 |
int sumx, sumy, dx, dy; |
int sumx, sumy; |
1127 |
|
|
1128 |
if(pParam->m_quarterpel) { |
if(pParam->m_quarterpel) { |
1129 |
sumx= pMB->qmvs[0].x/2 + pMB->qmvs[1].x/2 + pMB->qmvs[2].x/2 + pMB->qmvs[3].x/2; |
sumx= pMB->qmvs[0].x/2 + pMB->qmvs[1].x/2 + pMB->qmvs[2].x/2 + pMB->qmvs[3].x/2; |
1132 |
sumx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
sumx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
1133 |
sumy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
sumy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
1134 |
} |
} |
|
dx = (sumx >> 3) + roundtab_76[sumx & 0xf]; |
|
|
dy = (sumy >> 3) + roundtab_76[sumy & 0xf]; |
|
1135 |
|
|
1136 |
Data->iMinSAD[1] += ChromaSAD(dx, dy, Data); |
Data->iMinSAD[1] += ChromaSAD( (sumx >> 3) + roundtab_76[sumx & 0xf], |
1137 |
|
(sumy >> 3) + roundtab_76[sumy & 0xf], Data); |
1138 |
} |
} |
1139 |
} |
} |
1140 |
|
|
1142 |
Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x); |
Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x); |
1143 |
Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y); |
Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y); |
1144 |
} |
} |
1145 |
|
|
1146 |
if (!(inter4v) || |
if (!(inter4v) || |
1147 |
(Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + |
(Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + |
1148 |
Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant )) { |
Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant )) { |
1245 |
} |
} |
1246 |
} |
} |
1247 |
|
|
1248 |
if(!Data->rrv && Data->qpel) { |
if(Data->qpel) { |
1249 |
if((!(Data->currentQMV->x & 1)) && (!(Data->currentQMV->y & 1)) && |
if((!(Data->currentQMV->x & 1)) && (!(Data->currentQMV->y & 1)) && |
1250 |
(MotionFlags & PMV_QUARTERPELREFINE8)) { |
(MotionFlags & PMV_QUARTERPELREFINE8)) { |
1251 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1343 |
|
|
1344 |
const int32_t iEdgedWidth = pParam->edged_width; |
const int32_t iEdgedWidth = pParam->edged_width; |
1345 |
|
|
1346 |
int i, iDirection, mask; |
int i, iDirection = 255, mask; |
1347 |
VECTOR pmv[7]; |
VECTOR pmv[7]; |
1348 |
MainSearchFunc *MainSearchPtr; |
MainSearchFunc *MainSearchPtr; |
1349 |
*Data->iMinSAD = MV_MAX_ERROR; |
*Data->iMinSAD = MV_MAX_ERROR; |
1368 |
CheckCandidate = CheckCandidate16no4v; |
CheckCandidate = CheckCandidate16no4v; |
1369 |
|
|
1370 |
// main loop. checking all predictions |
// main loop. checking all predictions |
1371 |
for (i = 0; i < 8; i++) { |
for (i = 0; i < 7; i++) { |
1372 |
if (!(mask = make_mask(pmv, i)) ) continue; |
if (!(mask = make_mask(pmv, i)) ) continue; |
1373 |
CheckCandidate16no4v(pmv[i].x, pmv[i].y, mask, &iDirection, Data); |
CheckCandidate16no4v(pmv[i].x, pmv[i].y, mask, &iDirection, Data); |
1374 |
} |
} |
1379 |
MainSearchPtr = AdvDiamondSearch; |
MainSearchPtr = AdvDiamondSearch; |
1380 |
else MainSearchPtr = DiamondSearch; |
else MainSearchPtr = DiamondSearch; |
1381 |
|
|
1382 |
(*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255); |
(*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, iDirection); |
1383 |
|
|
1384 |
SubpelRefine(Data); |
SubpelRefine(Data); |
1385 |
|
|
1386 |
if (Data->qpel) { |
if (Data->qpel && *Data->iMinSAD < *best_sad + 300) { |
1387 |
Data->currentQMV->x = 2*Data->currentMV->x; |
Data->currentQMV->x = 2*Data->currentMV->x; |
1388 |
Data->currentQMV->y = 2*Data->currentMV->y; |
Data->currentQMV->y = 2*Data->currentMV->y; |
1389 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1393 |
} |
} |
1394 |
|
|
1395 |
// three bits are needed to code backward mode. four for forward |
// three bits are needed to code backward mode. four for forward |
1396 |
// we treat the bits just like they were vector's |
|
1397 |
if (mode_current == MODE_FORWARD) *Data->iMinSAD += 4 * Data->lambda16; |
if (mode_current == MODE_FORWARD) *Data->iMinSAD += 4 * Data->lambda16; |
1398 |
else *Data->iMinSAD += 3 * Data->lambda16; |
else *Data->iMinSAD += 3 * Data->lambda16; |
1399 |
|
|
1411 |
pMB->pmvs[0].x = Data->currentMV->x - predMV->x; |
pMB->pmvs[0].x = Data->currentMV->x - predMV->x; |
1412 |
pMB->pmvs[0].y = Data->currentMV->y - predMV->y; |
pMB->pmvs[0].y = Data->currentMV->y - predMV->y; |
1413 |
} |
} |
1414 |
if (mode_current == MODE_FORWARD) |
if (mode_current == MODE_FORWARD) pMB->mvs[0] = *Data->currentMV; |
1415 |
pMB->mvs[0] = *(Data->currentMV+2) = *Data->currentMV; |
else pMB->b_mvs[0] = *Data->currentMV; |
|
else |
|
|
pMB->b_mvs[0] = *(Data->currentMV+1) = *Data->currentMV; //we store currmv for interpolate search |
|
|
|
|
1416 |
} |
} |
1417 |
|
if (mode_current == MODE_FORWARD) *(Data->currentMV+2) = *Data->currentMV; |
1418 |
|
else *(Data->currentMV+1) = *Data->currentMV; //we store currmv for interpolate search |
1419 |
|
|
1420 |
} |
} |
1421 |
|
|
1550 |
} |
} |
1551 |
} |
} |
1552 |
|
|
|
|
|
1553 |
if (b_mb->mode == MODE_INTER4V) CheckCandidate = CheckCandidateDirect; |
if (b_mb->mode == MODE_INTER4V) CheckCandidate = CheckCandidateDirect; |
1554 |
else CheckCandidate = CheckCandidateDirectno4v; |
else CheckCandidate = CheckCandidateDirectno4v; |
1555 |
|
|
1576 |
|
|
1577 |
*best_sad = *Data->iMinSAD; |
*best_sad = *Data->iMinSAD; |
1578 |
|
|
1579 |
if (b_mb->mode == MODE_INTER4V) |
if (b_mb->mode == MODE_INTER4V || Data->qpel) pMB->mode = MODE_DIRECT; |
|
pMB->mode = MODE_DIRECT; |
|
1580 |
else pMB->mode = MODE_DIRECT_NO4V; //for faster compensation |
else pMB->mode = MODE_DIRECT_NO4V; //for faster compensation |
1581 |
|
|
1582 |
pMB->pmvs[3] = *Data->currentMV; |
pMB->pmvs[3] = *Data->currentMV; |
1693 |
} while (!(iDirection)); |
} while (!(iDirection)); |
1694 |
|
|
1695 |
if (fData->qpel) { |
if (fData->qpel) { |
1696 |
|
if (*fData->iMinSAD > *best_sad + 500) return; |
1697 |
CheckCandidate = CheckCandidateInt; |
CheckCandidate = CheckCandidateInt; |
1698 |
fData->qpel_precision = bData.qpel_precision = 1; |
fData->qpel_precision = bData.qpel_precision = 1; |
1699 |
get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 16, pParam->width, pParam->height, fcode, 1, 0); |
get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 16, pParam->width, pParam->height, fcode, 1, 0); |
1703 |
fData->currentQMV[1].x = 2 * fData->currentMV[1].x; |
fData->currentQMV[1].x = 2 * fData->currentMV[1].x; |
1704 |
fData->currentQMV[1].y = 2 * fData->currentMV[1].y; |
fData->currentQMV[1].y = 2 * fData->currentMV[1].y; |
1705 |
SubpelRefine(fData); |
SubpelRefine(fData); |
1706 |
|
if (*fData->iMinSAD > *best_sad + 300) return; |
1707 |
fData->currentQMV[2] = fData->currentQMV[0]; |
fData->currentQMV[2] = fData->currentQMV[0]; |
1708 |
SubpelRefine(&bData); |
SubpelRefine(&bData); |
1709 |
} |
} |
1710 |
|
|
1711 |
*fData->iMinSAD += (2+2) * fData->lambda16; // two bits are needed to code interpolate mode. |
*fData->iMinSAD += (2+3) * fData->lambda16; // two bits are needed to code interpolate mode. |
1712 |
|
|
1713 |
if (*fData->iMinSAD < *best_sad) { |
if (*fData->iMinSAD < *best_sad) { |
1714 |
*best_sad = *fData->iMinSAD; |
*best_sad = *fData->iMinSAD; |
1834 |
MODE_BACKWARD, &Data); |
MODE_BACKWARD, &Data); |
1835 |
|
|
1836 |
// interpolate search comes last, because it uses data from forward and backward as prediction |
// interpolate search comes last, because it uses data from forward and backward as prediction |
|
|
|
1837 |
SearchInterpolate(f_ref->y, f_refH->y, f_refV->y, f_refHV->y, |
SearchInterpolate(f_ref->y, f_refH->y, f_refV->y, f_refHV->y, |
1838 |
b_ref->y, b_refH->y, b_refV->y, b_refHV->y, |
b_ref->y, b_refH->y, b_refV->y, b_refHV->y, |
1839 |
&frame->image, |
&frame->image, |
1882 |
free(qimage); |
free(qimage); |
1883 |
} |
} |
1884 |
|
|
1885 |
static __inline int |
static __inline void |
1886 |
MEanalyzeMB ( const uint8_t * const pRef, |
MEanalyzeMB ( const uint8_t * const pRef, |
1887 |
const uint8_t * const pCur, |
const uint8_t * const pCur, |
1888 |
const int x, |
const int x, |
1889 |
const int y, |
const int y, |
1890 |
const MBParam * const pParam, |
const MBParam * const pParam, |
1891 |
const MACROBLOCK * const pMBs, |
MACROBLOCK * const pMBs, |
|
MACROBLOCK * const pMB, |
|
1892 |
SearchData * const Data) |
SearchData * const Data) |
1893 |
{ |
{ |
1894 |
|
|
1895 |
int i = 255, mask; |
int i, mask; |
1896 |
VECTOR pmv[3]; |
VECTOR pmv[3]; |
1897 |
*(Data->iMinSAD) = MV_MAX_ERROR; |
MACROBLOCK * pMB = &pMBs[x + y * pParam->mb_width]; |
1898 |
|
|
1899 |
|
for (i = 0; i < 5; i++) Data->iMinSAD[i] = MV_MAX_ERROR; |
1900 |
|
|
1901 |
//median is only used as prediction. it doesn't have to be real |
//median is only used as prediction. it doesn't have to be real |
1902 |
if (x == 1 && y == 1) Data->predMV.x = Data->predMV.y = 0; |
if (x == 1 && y == 1) Data->predMV.x = Data->predMV.y = 0; |
1903 |
else |
else |
1904 |
if (x == 1) //left macroblock does not have any vector now |
if (x == 1) //left macroblock does not have any vector now |
1905 |
Data->predMV = (pMB - pParam->mb_width)->mvs[0]; // top instead of median |
Data->predMV = (pMB - pParam->mb_width)->mvs[0]; // top instead of median |
1906 |
else if (y == 1) // top macroblock don't have it's vector |
else if (y == 1) // top macroblock doesn't have it's vector |
1907 |
Data->predMV = (pMB - 1)->mvs[0]; // left instead of median |
Data->predMV = (pMB - 1)->mvs[0]; // left instead of median |
1908 |
else Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); //else median |
else Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); //else median |
1909 |
|
|
1910 |
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, |
1911 |
pParam->width, pParam->height, Data->iFcode - pParam->m_quarterpel, 0, 0); |
pParam->width, pParam->height, Data->iFcode - pParam->m_quarterpel, 0, Data->rrv); |
1912 |
|
|
1913 |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
1914 |
Data->Ref = pRef + (x + y * pParam->edged_width) * 16; |
Data->Ref = pRef + (x + y * pParam->edged_width) * 16; |
1919 |
pmv[2].y = EVEN(Data->predMV.y); |
pmv[2].y = EVEN(Data->predMV.y); |
1920 |
pmv[0].x = pmv[0].y = 0; |
pmv[0].x = pmv[0].y = 0; |
1921 |
|
|
1922 |
CheckCandidate16no4vI(0, 0, 255, &i, Data); |
CheckCandidate32I(0, 0, 255, &i, Data); |
1923 |
|
|
1924 |
//early skip for 0,0 |
if (*Data->iMinSAD > 4 * MAX_SAD00_FOR_SKIP * 4) { |
|
if (*Data->iMinSAD < MAX_SAD00_FOR_SKIP * 4) { |
|
|
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0]; |
|
|
pMB->mode = MODE_NOT_CODED; |
|
|
return 0; |
|
|
} |
|
1925 |
|
|
1926 |
if (!(mask = make_mask(pmv, 1))) |
if (!(mask = make_mask(pmv, 1))) |
1927 |
CheckCandidate16no4vI(pmv[1].x, pmv[1].y, mask, &i, Data); |
CheckCandidate32I(pmv[1].x, pmv[1].y, mask, &i, Data); |
1928 |
if (!(mask = make_mask(pmv, 2))) |
if (!(mask = make_mask(pmv, 2))) |
1929 |
CheckCandidate16no4vI(pmv[2].x, pmv[2].y, mask, &i, Data); |
CheckCandidate32I(pmv[2].x, pmv[2].y, mask, &i, Data); |
1930 |
|
|
1931 |
if (*Data->iMinSAD > MAX_SAD00_FOR_SKIP * 6) // diamond only if needed |
if (*Data->iMinSAD > 4 * MAX_SAD00_FOR_SKIP * 4) // diamond only if needed |
1932 |
DiamondSearch(Data->currentMV->x, Data->currentMV->y, Data, i); |
DiamondSearch(Data->currentMV->x, Data->currentMV->y, Data, i); |
1933 |
|
|
1934 |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0]; |
for (i = 0; i < 4; i++) { |
1935 |
pMB->mode = MODE_INTER; |
MACROBLOCK * MB = &pMBs[x + (i&1) + (y+(i>>1) * pParam->mb_width)]; |
1936 |
return *(Data->iMinSAD); |
MB->mvs[0] = MB->mvs[1] = MB->mvs[2] = MB->mvs[3] = Data->currentMV[i]; |
1937 |
|
MB->mode = MODE_INTER; |
1938 |
|
MB->sad16 = Data->iMinSAD[i+1]; |
1939 |
|
} |
1940 |
|
} |
1941 |
} |
} |
1942 |
|
|
1943 |
#define INTRA_THRESH 1350 |
#define INTRA_BIAS 2500 |
1944 |
#define INTER_THRESH 1200 |
#define INTRA_THRESH 1500 |
1945 |
|
#define INTER_THRESH 1400 |
1946 |
|
|
1947 |
|
|
1948 |
int |
int |
1958 |
MACROBLOCK * const pMBs = Current->mbs; |
MACROBLOCK * const pMBs = Current->mbs; |
1959 |
const IMAGE * const pCurrent = &Current->image; |
const IMAGE * const pCurrent = &Current->image; |
1960 |
int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH; |
int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH; |
1961 |
|
const VECTOR zeroMV = {0,0}; |
1962 |
|
|
1963 |
VECTOR currentMV; |
int32_t iMinSAD[5], temp[5]; |
1964 |
int32_t iMinSAD; |
VECTOR currentMV[5]; |
1965 |
SearchData Data; |
SearchData Data; |
1966 |
Data.iEdgedWidth = pParam->edged_width; |
Data.iEdgedWidth = pParam->edged_width; |
1967 |
Data.currentMV = ¤tMV; |
Data.currentMV = currentMV; |
1968 |
Data.iMinSAD = &iMinSAD; |
Data.iMinSAD = iMinSAD; |
1969 |
Data.iFcode = Current->fcode; |
Data.iFcode = Current->fcode; |
1970 |
CheckCandidate = CheckCandidate16no4vI; |
Data.rrv = Current->global_flags & XVID_REDUCED; |
1971 |
|
Data.temp = temp; |
1972 |
|
CheckCandidate = CheckCandidate32I; |
1973 |
|
|
1974 |
if (intraCount < 10) // we're right after an I frame |
if (intraCount < 10) // we're right after an I frame |
1975 |
IntraThresh += 4 * (intraCount - 10) * (intraCount - 10); |
IntraThresh += 4 * (intraCount - 10) * (intraCount - 10); |
1977 |
if ( 5*(maxIntra - intraCount) < maxIntra) // we're close to maximum. 2 sec when max is 10 sec |
if ( 5*(maxIntra - intraCount) < maxIntra) // we're close to maximum. 2 sec when max is 10 sec |
1978 |
IntraThresh -= (IntraThresh * (maxIntra - 5*(maxIntra - intraCount)))/maxIntra; |
IntraThresh -= (IntraThresh * (maxIntra - 5*(maxIntra - intraCount)))/maxIntra; |
1979 |
|
|
|
|
|
1980 |
InterThresh += 400 * (1 - bCount); |
InterThresh += 400 * (1 - bCount); |
1981 |
if (InterThresh < 200) InterThresh = 200; |
if (InterThresh < 300) InterThresh = 300; |
1982 |
|
|
1983 |
if (sadInit) (*sadInit) (); |
if (sadInit) (*sadInit) (); |
1984 |
|
|
1985 |
for (y = 1; y < pParam->mb_height-1; y++) { |
for (y = 1; y < pParam->mb_height-1; y+=2) { |
1986 |
for (x = 1; x < pParam->mb_width-1; x++) { |
for (x = 1; x < pParam->mb_width-1; x+=2) { |
1987 |
int sad, dev; |
int i; |
1988 |
MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width]; |
|
1989 |
|
if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV; |
1990 |
|
|
1991 |
sad = MEanalyzeMB(pRef->y, pCurrent->y, x, y, |
MEanalyzeMB(pRef->y, pCurrent->y, x, y, pParam, pMBs, &Data); |
|
pParam, pMBs, pMB, &Data); |
|
1992 |
|
|
1993 |
if (sad > IntraThresh) { |
for (i = 0; i < 4; i++) { |
1994 |
dev = dev16(pCurrent->y + (x + y * pParam->edged_width) * 16, |
int dev; |
1995 |
|
MACROBLOCK *pMB = &pMBs[x+(i&1) + y+(i>>1) * pParam->mb_width]; |
1996 |
|
if (pMB->sad16 > IntraThresh) { |
1997 |
|
dev = dev16(pCurrent->y + (x + (i&1) + (y + (i>>1))* pParam->edged_width) * 16, |
1998 |
pParam->edged_width); |
pParam->edged_width); |
1999 |
if (dev + IntraThresh < sad) { |
if (dev + IntraThresh < pMB->sad16) { |
2000 |
pMB->mode = MODE_INTRA; |
pMB->mode = MODE_INTRA; |
2001 |
if (++intra > (pParam->mb_height-2)*(pParam->mb_width-2)/2) return I_VOP; |
if (++intra > (pParam->mb_height-2)*(pParam->mb_width-2)/2) return I_VOP; |
2002 |
} |
} |
2003 |
} |
} |
2004 |
sSAD += sad; |
sSAD += pMB->sad16; |
2005 |
|
} |
2006 |
} |
} |
2007 |
} |
} |
2008 |
sSAD /= (pParam->mb_height-2)*(pParam->mb_width-2); |
sSAD /= (pParam->mb_height-2)*(pParam->mb_width-2); |
2009 |
|
if (sSAD > IntraThresh + INTRA_BIAS ) return I_VOP; |
2010 |
if (sSAD > InterThresh ) return P_VOP; |
if (sSAD > InterThresh ) return P_VOP; |
2011 |
emms(); |
emms(); |
2012 |
return B_VOP; |
return B_VOP; |
2077 |
max_x = gmc.x + step; |
max_x = gmc.x + step; |
2078 |
min_y = gmc.y - step; |
min_y = gmc.y - step; |
2079 |
max_y = gmc.y + step; |
max_y = gmc.y + step; |
|
|
|
2080 |
} |
} |
2081 |
|
|
2082 |
if (bestcount < (pParam->mb_height-2)*(pParam->mb_width-2)/10) |
if (bestcount < (pParam->mb_height-2)*(pParam->mb_width-2)/10) |
2083 |
gmc.x = gmc.y = 0; //no camara pan, no GMC |
gmc.x = gmc.y = 0; //no camara pan, no GMC |
2084 |
|
|
2085 |
// step2: let's refine camera panning using gradiend-descent approach. |
// step2: let's refine camera panning using gradiend-descent approach |
2086 |
// TODO: more warping points may be evaluated here (like in interpolate mode search - two vectors in one diamond) |
// TODO: more warping points may be evaluated here (like in interpolate mode search - two vectors in one diamond) |
2087 |
bestcount = 0; |
bestcount = 0; |
2088 |
CheckGMC(gmc.x, gmc.y, 255, &iDirection, pMBs, &bestcount, &gmc, pParam); |
CheckGMC(gmc.x, gmc.y, 255, &iDirection, pMBs, &bestcount, &gmc, pParam); |