31 |
#include <assert.h> |
#include <assert.h> |
32 |
#include <stdio.h> |
#include <stdio.h> |
33 |
#include <stdlib.h> |
#include <stdlib.h> |
34 |
|
#include <string.h> // memcpy |
35 |
|
|
36 |
#include "../encoder.h" |
#include "../encoder.h" |
37 |
#include "../utils/mbfunctions.h" |
#include "../utils/mbfunctions.h" |
53 |
(*CheckCandidate)((const int)(X),(const int)(Y), (D), &iDirection, data ); } |
(*CheckCandidate)((const int)(X),(const int)(Y), (D), &iDirection, data ); } |
54 |
|
|
55 |
static __inline int |
static __inline int |
56 |
d_mv_bits(int x, int y, const uint32_t iFcode, const int qpel, const int rrv) |
d_mv_bits(int x, int y, const VECTOR pred, const uint32_t iFcode, const int qpel, const int rrv) |
57 |
{ |
{ |
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; |
62 |
|
y = pred.y - y; |
63 |
|
|
64 |
if (x == 0) xb = 1; |
if (x == 0) xb = 1; |
65 |
else { |
else { |
248 |
current = data->currentMV; |
current = data->currentMV; |
249 |
xc = x; yc = y; |
xc = x; yc = y; |
250 |
} |
} |
251 |
t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode, data->qpel && !data->qpel_precision, 0); |
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel && !data->qpel_precision, 0); |
252 |
|
|
253 |
data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp + 1); |
data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp + 1); |
254 |
|
|
284 |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
285 |
|
|
286 |
Reference = GetReference(x, y, 0, data); |
Reference = GetReference(x, y, 0, data); |
287 |
t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode, 0, 1); |
t = d_mv_bits(x, y, data->predMV, data->iFcode, 0, 1); |
288 |
|
|
289 |
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); |
290 |
|
|
327 |
Reference = GetReference(x, y, 0, data); |
Reference = GetReference(x, y, 0, data); |
328 |
current = data->currentMV; |
current = data->currentMV; |
329 |
} |
} |
330 |
t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode, |
t = d_mv_bits(x, y, data->predMV, data->iFcode, |
331 |
data->qpel && !data->qpel_precision && !data->rrv, data->rrv); |
data->qpel && !data->qpel_precision && !data->rrv, data->rrv); |
332 |
|
|
333 |
sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096); |
sad = sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096); |
340 |
} |
} |
341 |
|
|
342 |
static void |
static void |
343 |
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) |
344 |
{ |
{ |
345 |
// maximum speed - for P/B/I decision |
// maximum speed - for P/B/I decision |
|
int32_t sad; |
|
346 |
|
|
347 |
if (( x > data->max_dx) || ( x < data->min_dx) |
if (( x > data->max_dx) || ( x < data->min_dx) |
348 |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
|| ( y > data->max_dy) || (y < data->min_dy)) return; |
349 |
|
|
350 |
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), |
351 |
data->iEdgedWidth, 256*4096); |
data->iEdgedWidth, data->temp+1); |
352 |
|
if (data->temp[0] < *(data->iMinSAD)) { |
353 |
if (sad < *(data->iMinSAD)) { |
*(data->iMinSAD) = data->temp[0]; |
|
*(data->iMinSAD) = sad; |
|
354 |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
355 |
*dir = Direction; } |
*dir = Direction; } |
356 |
|
if (data->temp[1] < data->iMinSAD[1]) { |
357 |
|
data->iMinSAD[1] = data->temp[1]; data->currentMV[1].x = x; data->currentMV[1].y = y; } |
358 |
|
if (data->temp[2] < data->iMinSAD[2]) { |
359 |
|
data->iMinSAD[2] = data->temp[2]; data->currentMV[2].x = x; data->currentMV[2].y = y; } |
360 |
|
if (data->temp[3] < data->iMinSAD[3]) { |
361 |
|
data->iMinSAD[3] = data->temp[3]; data->currentMV[3].x = x; data->currentMV[3].y = y; } |
362 |
|
if (data->temp[4] < data->iMinSAD[4]) { |
363 |
|
data->iMinSAD[4] = data->temp[4]; data->currentMV[4].x = x; data->currentMV[4].y = y; } |
364 |
|
|
365 |
} |
} |
366 |
|
|
367 |
|
|
388 |
current = data->currentMV; |
current = data->currentMV; |
389 |
} |
} |
390 |
|
|
391 |
t = d_mv_bits(xf - data->predMV.x, yf - data->predMV.y, data->iFcode, data->qpel && !data->qpel_precision, 0) |
t = d_mv_bits(xf, yf, data->predMV, data->iFcode, data->qpel && !data->qpel_precision, 0) |
392 |
+ d_mv_bits(xb - data->bpredMV.x, yb - data->bpredMV.y, data->iFcode, data->qpel && !data->qpel_precision, 0); |
+ d_mv_bits(xb, yb, data->bpredMV, data->iFcode, data->qpel && !data->qpel_precision, 0); |
393 |
|
|
394 |
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
395 |
sad += (data->lambda16 * t * sad)/1000; |
sad += (data->lambda16 * t * sad)/1000; |
408 |
const uint8_t *ReferenceF; |
const uint8_t *ReferenceF; |
409 |
const uint8_t *ReferenceB; |
const uint8_t *ReferenceB; |
410 |
VECTOR mvs, b_mvs; |
VECTOR mvs, b_mvs; |
411 |
|
const VECTOR zeroMV={0,0}; |
412 |
|
|
413 |
if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return; |
if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return; |
414 |
|
|
441 |
if (sad > *(data->iMinSAD)) return; |
if (sad > *(data->iMinSAD)) return; |
442 |
} |
} |
443 |
|
|
444 |
sad += (data->lambda16 * d_mv_bits(x, y, 1, 0, 0) * sad)/1000; |
sad += (data->lambda16 * d_mv_bits(x, y, zeroMV, 1, 0, 0) * sad)/1000; |
445 |
|
|
446 |
if (sad < *(data->iMinSAD)) { |
if (sad < *(data->iMinSAD)) { |
447 |
*(data->iMinSAD) = sad; |
*(data->iMinSAD) = sad; |
456 |
const uint8_t *ReferenceF; |
const uint8_t *ReferenceF; |
457 |
const uint8_t *ReferenceB; |
const uint8_t *ReferenceB; |
458 |
VECTOR mvs, b_mvs; |
VECTOR mvs, b_mvs; |
459 |
|
const VECTOR zeroMV = {0,0}; |
460 |
|
|
461 |
if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return; |
if (( x > 31) || ( x < -32) || ( y > 31) || (y < -32)) return; |
462 |
|
|
483 |
ReferenceB = Interpolate16x16qpel(b_mvs.x, b_mvs.y, 1, data); |
ReferenceB = Interpolate16x16qpel(b_mvs.x, b_mvs.y, 1, data); |
484 |
|
|
485 |
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
sad = sad16bi(data->Cur, ReferenceF, ReferenceB, data->iEdgedWidth); |
486 |
sad += (data->lambda16 * d_mv_bits(x, y, 1, 0, 0) * sad)/1000; |
sad += (data->lambda16 * d_mv_bits(x, y, zeroMV, 1, 0, 0) * sad)/1000; |
487 |
|
|
488 |
if (sad < *(data->iMinSAD)) { |
if (sad < *(data->iMinSAD)) { |
489 |
*(data->iMinSAD) = sad; |
*(data->iMinSAD) = sad; |
504 |
else Reference = GetReference(x, y, 0, data); |
else Reference = GetReference(x, y, 0, data); |
505 |
|
|
506 |
sad = sad8(data->Cur, Reference, data->iEdgedWidth); |
sad = sad8(data->Cur, Reference, data->iEdgedWidth); |
507 |
t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode, data->qpel && !data->qpel_precision, 0); |
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel && !data->qpel_precision, 0); |
508 |
|
|
509 |
sad += (data->lambda8 * t * (sad+NEIGH_8X8_BIAS))/100; |
sad += (data->lambda8 * t * (sad+NEIGH_8X8_BIAS))/100; |
510 |
|
|
1008 |
if (pParam->m_quarterpel) Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
if (pParam->m_quarterpel) Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0); |
1009 |
else Data->predMV = pmv[0]; |
else Data->predMV = pmv[0]; |
1010 |
|
|
1011 |
i = d_mv_bits(Data->predMV.x, Data->predMV.y, Data->iFcode, 0, 0); |
i = d_mv_bits(0, 0, Data->predMV, Data->iFcode, 0, 0); |
1012 |
Data->iMinSAD[0] = pMB->sad16 + (Data->lambda16 * i * pMB->sad16)/1000; |
Data->iMinSAD[0] = pMB->sad16 + (Data->lambda16 * i * pMB->sad16)/1000; |
1013 |
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; |
1014 |
Data->iMinSAD[2] = pMB->sad8[1]; |
Data->iMinSAD[2] = pMB->sad8[1]; |
1183 |
|
|
1184 |
if(pParam->m_quarterpel) { |
if(pParam->m_quarterpel) { |
1185 |
Data->predMV = 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); |
1186 |
if (block != 0) i = d_mv_bits( Data->currentQMV->x - Data->predMV.x, |
if (block != 0) i = d_mv_bits( Data->currentQMV->x, Data->currentQMV->y, |
1187 |
Data->currentQMV->y - Data->predMV.y, Data->iFcode, 0, 0); |
Data->predMV, Data->iFcode, 0, 0); |
1188 |
|
|
1189 |
} else { |
} else { |
1190 |
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); |
1191 |
if (block != 0) { |
if (block != 0) { |
1192 |
if (block != 0) i = d_mv_bits( Data->currentMV->x - Data->predMV.x, |
if (block != 0) i = d_mv_bits( Data->currentMV->x, Data->currentMV->y, |
1193 |
Data->currentMV->y - Data->predMV.y, Data->iFcode, 0, Data->rrv); |
Data->predMV, Data->iFcode, 0, Data->rrv); |
1194 |
} |
} |
1195 |
} |
} |
1196 |
|
|
1406 |
pMB->pmvs[0].x = Data->currentMV->x - predMV->x; |
pMB->pmvs[0].x = Data->currentMV->x - predMV->x; |
1407 |
pMB->pmvs[0].y = Data->currentMV->y - predMV->y; |
pMB->pmvs[0].y = Data->currentMV->y - predMV->y; |
1408 |
} |
} |
1409 |
if (mode_current == MODE_FORWARD) |
if (mode_current == MODE_FORWARD) pMB->mvs[0] = *Data->currentMV; |
1410 |
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 |
|
|
|
|
1411 |
} |
} |
1412 |
|
if (mode_current == MODE_FORWARD) *(Data->currentMV+2) = *Data->currentMV; |
1413 |
|
else *(Data->currentMV+1) = *Data->currentMV; //we store currmv for interpolate search |
1414 |
|
|
1415 |
} |
} |
1416 |
|
|
1545 |
} |
} |
1546 |
} |
} |
1547 |
|
|
|
|
|
1548 |
if (b_mb->mode == MODE_INTER4V) CheckCandidate = CheckCandidateDirect; |
if (b_mb->mode == MODE_INTER4V) CheckCandidate = CheckCandidateDirect; |
1549 |
else CheckCandidate = CheckCandidateDirectno4v; |
else CheckCandidate = CheckCandidateDirectno4v; |
1550 |
|
|
1571 |
|
|
1572 |
*best_sad = *Data->iMinSAD; |
*best_sad = *Data->iMinSAD; |
1573 |
|
|
1574 |
if (b_mb->mode == MODE_INTER4V) |
if (b_mb->mode == MODE_INTER4V) pMB->mode = MODE_DIRECT; |
|
pMB->mode = MODE_DIRECT; |
|
1575 |
else pMB->mode = MODE_DIRECT_NO4V; //for faster compensation |
else pMB->mode = MODE_DIRECT_NO4V; //for faster compensation |
1576 |
|
|
1577 |
pMB->pmvs[3] = *Data->currentMV; |
pMB->pmvs[3] = *Data->currentMV; |
1827 |
MODE_BACKWARD, &Data); |
MODE_BACKWARD, &Data); |
1828 |
|
|
1829 |
// 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 |
|
|
|
1830 |
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, |
1831 |
b_ref->y, b_refH->y, b_refV->y, b_refHV->y, |
b_ref->y, b_refH->y, b_refV->y, b_refHV->y, |
1832 |
&frame->image, |
&frame->image, |
1875 |
free(qimage); |
free(qimage); |
1876 |
} |
} |
1877 |
|
|
1878 |
static __inline int |
static __inline void |
1879 |
MEanalyzeMB ( const uint8_t * const pRef, |
MEanalyzeMB ( const uint8_t * const pRef, |
1880 |
const uint8_t * const pCur, |
const uint8_t * const pCur, |
1881 |
const int x, |
const int x, |
1882 |
const int y, |
const int y, |
1883 |
const MBParam * const pParam, |
const MBParam * const pParam, |
1884 |
const MACROBLOCK * const pMBs, |
MACROBLOCK * const pMBs, |
|
MACROBLOCK * const pMB, |
|
1885 |
SearchData * const Data) |
SearchData * const Data) |
1886 |
{ |
{ |
1887 |
|
|
1888 |
int i = 255, mask; |
int i, mask; |
1889 |
VECTOR pmv[3]; |
VECTOR pmv[3]; |
1890 |
*(Data->iMinSAD) = MV_MAX_ERROR; |
MACROBLOCK * pMB = &pMBs[x + y * pParam->mb_width]; |
1891 |
|
|
1892 |
|
for (i = 0; i < 5; i++) Data->iMinSAD[i] = MV_MAX_ERROR; |
1893 |
|
|
1894 |
//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 |
1895 |
if (x == 1 && y == 1) Data->predMV.x = Data->predMV.y = 0; |
if (x == 1 && y == 1) Data->predMV.x = Data->predMV.y = 0; |
1896 |
else |
else |
1897 |
if (x == 1) //left macroblock does not have any vector now |
if (x == 1) //left macroblock does not have any vector now |
1898 |
Data->predMV = (pMB - pParam->mb_width)->mvs[0]; // top instead of median |
Data->predMV = (pMB - pParam->mb_width)->mvs[0]; // top instead of median |
1899 |
else if (y == 1) // top macroblock don't have it's vector |
else if (y == 1) // top macroblock doesn't have it's vector |
1900 |
Data->predMV = (pMB - 1)->mvs[0]; // left instead of median |
Data->predMV = (pMB - 1)->mvs[0]; // left instead of median |
1901 |
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 |
1902 |
|
|
1903 |
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, |
1904 |
pParam->width, pParam->height, Data->iFcode - pParam->m_quarterpel, 0, 0); |
pParam->width, pParam->height, Data->iFcode - pParam->m_quarterpel, 0, Data->rrv); |
1905 |
|
|
1906 |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
1907 |
Data->Ref = pRef + (x + y * pParam->edged_width) * 16; |
Data->Ref = pRef + (x + y * pParam->edged_width) * 16; |
1912 |
pmv[2].y = EVEN(Data->predMV.y); |
pmv[2].y = EVEN(Data->predMV.y); |
1913 |
pmv[0].x = pmv[0].y = 0; |
pmv[0].x = pmv[0].y = 0; |
1914 |
|
|
1915 |
CheckCandidate16no4vI(0, 0, 255, &i, Data); |
CheckCandidate32I(0, 0, 255, &i, Data); |
1916 |
|
|
1917 |
//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; |
|
|
} |
|
1918 |
|
|
1919 |
if (!(mask = make_mask(pmv, 1))) |
if (!(mask = make_mask(pmv, 1))) |
1920 |
CheckCandidate16no4vI(pmv[1].x, pmv[1].y, mask, &i, Data); |
CheckCandidate32I(pmv[1].x, pmv[1].y, mask, &i, Data); |
1921 |
if (!(mask = make_mask(pmv, 2))) |
if (!(mask = make_mask(pmv, 2))) |
1922 |
CheckCandidate16no4vI(pmv[2].x, pmv[2].y, mask, &i, Data); |
CheckCandidate32I(pmv[2].x, pmv[2].y, mask, &i, Data); |
1923 |
|
|
1924 |
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 |
1925 |
DiamondSearch(Data->currentMV->x, Data->currentMV->y, Data, i); |
DiamondSearch(Data->currentMV->x, Data->currentMV->y, Data, i); |
1926 |
|
|
1927 |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0]; |
for (i = 0; i < 4; i++) { |
1928 |
pMB->mode = MODE_INTER; |
MACROBLOCK * MB = &pMBs[x + (i&1) + (y+(i>>1) * pParam->mb_width)]; |
1929 |
return *(Data->iMinSAD); |
MB->mvs[0] = MB->mvs[1] = MB->mvs[2] = MB->mvs[3] = Data->currentMV[i]; |
1930 |
|
MB->mode = MODE_INTER; |
1931 |
|
MB->sad16 = Data->iMinSAD[i+1]; |
1932 |
|
} |
1933 |
|
} |
1934 |
} |
} |
1935 |
|
|
1936 |
#define INTRA_THRESH 1350 |
#define INTRA_BIAS 2500 |
1937 |
#define INTER_THRESH 1200 |
#define INTRA_THRESH 1500 |
1938 |
|
#define INTER_THRESH 1400 |
1939 |
|
|
1940 |
|
|
1941 |
int |
int |
1951 |
MACROBLOCK * const pMBs = Current->mbs; |
MACROBLOCK * const pMBs = Current->mbs; |
1952 |
const IMAGE * const pCurrent = &Current->image; |
const IMAGE * const pCurrent = &Current->image; |
1953 |
int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH; |
int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH; |
1954 |
|
const VECTOR zeroMV = {0,0}; |
1955 |
|
|
1956 |
VECTOR currentMV; |
int32_t iMinSAD[5], temp[5]; |
1957 |
int32_t iMinSAD; |
VECTOR currentMV[5]; |
1958 |
SearchData Data; |
SearchData Data; |
1959 |
Data.iEdgedWidth = pParam->edged_width; |
Data.iEdgedWidth = pParam->edged_width; |
1960 |
Data.currentMV = ¤tMV; |
Data.currentMV = currentMV; |
1961 |
Data.iMinSAD = &iMinSAD; |
Data.iMinSAD = iMinSAD; |
1962 |
Data.iFcode = Current->fcode; |
Data.iFcode = Current->fcode; |
1963 |
CheckCandidate = CheckCandidate16no4vI; |
Data.rrv = Current->global_flags & XVID_REDUCED; |
1964 |
|
Data.temp = temp; |
1965 |
|
CheckCandidate = CheckCandidate32I; |
1966 |
|
|
1967 |
if (intraCount < 10) // we're right after an I frame |
if (intraCount < 10) // we're right after an I frame |
1968 |
IntraThresh += 4 * (intraCount - 10) * (intraCount - 10); |
IntraThresh += 4 * (intraCount - 10) * (intraCount - 10); |
1970 |
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 |
1971 |
IntraThresh -= (IntraThresh * (maxIntra - 5*(maxIntra - intraCount)))/maxIntra; |
IntraThresh -= (IntraThresh * (maxIntra - 5*(maxIntra - intraCount)))/maxIntra; |
1972 |
|
|
|
|
|
1973 |
InterThresh += 400 * (1 - bCount); |
InterThresh += 400 * (1 - bCount); |
1974 |
if (InterThresh < 200) InterThresh = 200; |
if (InterThresh < 300) InterThresh = 300; |
1975 |
|
|
1976 |
if (sadInit) (*sadInit) (); |
if (sadInit) (*sadInit) (); |
1977 |
|
|
1978 |
for (y = 1; y < pParam->mb_height-1; y++) { |
for (y = 1; y < pParam->mb_height-1; y+=2) { |
1979 |
for (x = 1; x < pParam->mb_width-1; x++) { |
for (x = 1; x < pParam->mb_width-1; x+=2) { |
1980 |
int sad, dev; |
int i; |
1981 |
MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width]; |
|
1982 |
|
if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV; |
1983 |
|
|
1984 |
sad = MEanalyzeMB(pRef->y, pCurrent->y, x, y, |
MEanalyzeMB(pRef->y, pCurrent->y, x, y, pParam, pMBs, &Data); |
|
pParam, pMBs, pMB, &Data); |
|
1985 |
|
|
1986 |
if (sad > IntraThresh) { |
for (i = 0; i < 4; i++) { |
1987 |
dev = dev16(pCurrent->y + (x + y * pParam->edged_width) * 16, |
int dev; |
1988 |
|
MACROBLOCK *pMB = &pMBs[x+(i&1) + y+(i>>1) * pParam->mb_width]; |
1989 |
|
if (pMB->sad16 > IntraThresh) { |
1990 |
|
dev = dev16(pCurrent->y + (x + (i&1) + (y + (i>>1))* pParam->edged_width) * 16, |
1991 |
pParam->edged_width); |
pParam->edged_width); |
1992 |
if (dev + IntraThresh < sad) { |
if (dev + IntraThresh < pMB->sad16) { |
1993 |
pMB->mode = MODE_INTRA; |
pMB->mode = MODE_INTRA; |
1994 |
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; |
1995 |
} |
} |
1996 |
} |
} |
1997 |
sSAD += sad; |
sSAD += pMB->sad16; |
1998 |
|
} |
1999 |
} |
} |
2000 |
} |
} |
2001 |
sSAD /= (pParam->mb_height-2)*(pParam->mb_width-2); |
sSAD /= (pParam->mb_height-2)*(pParam->mb_width-2); |
2002 |
|
if (sSAD > IntraThresh + INTRA_BIAS ) return I_VOP; |
2003 |
if (sSAD > InterThresh ) return P_VOP; |
if (sSAD > InterThresh ) return P_VOP; |
2004 |
emms(); |
emms(); |
2005 |
return B_VOP; |
return B_VOP; |
2031 |
} |
} |
2032 |
|
|
2033 |
|
|
2034 |
static __inline VECTOR |
static VECTOR |
2035 |
GlobalMotionEst(const MACROBLOCK * const pMBs, const MBParam * const pParam, const uint32_t iFcode) |
GlobalMotionEst(const MACROBLOCK * const pMBs, const MBParam * const pParam, const uint32_t iFcode) |
2036 |
{ |
{ |
2037 |
|
|