146 |
|
|
147 |
/* global flags */ |
/* global flags */ |
148 |
pEnc->mbParam.global_flags = create->global; |
pEnc->mbParam.global_flags = create->global; |
149 |
|
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED)) |
150 |
|
pEnc->mbParam.global_flags |= XVID_GLOBAL_DIVX5_USERDATA; |
151 |
|
|
152 |
/* width, height */ |
/* width, height */ |
153 |
pEnc->mbParam.width = create->width; |
pEnc->mbParam.width = create->width; |
1258 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
1259 |
|
|
1260 |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
1261 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP"); |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "CLOSED GOP BVOP->PVOP"); |
1262 |
} |
} |
1263 |
|
|
1264 |
/* convert B-VOP quant to P-VOP */ |
/* convert B-VOP quant to P-VOP */ |
1319 |
|
|
1320 |
/* prevent vol/vop misuse */ |
/* prevent vol/vop misuse */ |
1321 |
|
|
|
if (!(pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE)) |
|
|
pEnc->current->vop_flags &= ~XVID_VOP_REDUCED; |
|
|
|
|
1322 |
if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING)) |
if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING)) |
1323 |
pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN); |
pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN); |
1324 |
|
|
1446 |
|
|
1447 |
uint16_t x, y; |
uint16_t x, y; |
1448 |
|
|
|
if ((pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE)) |
|
|
{ |
|
|
mb_width = (pEnc->mbParam.width + 31) / 32; |
|
|
mb_height = (pEnc->mbParam.height + 31) / 32; |
|
|
|
|
|
/* 16x16->8x8 downsample requires 1 additional edge pixel*/ |
|
|
/* XXX: setedges is overkill */ |
|
|
start_timer(); |
|
|
image_setedges(&pEnc->current->image, |
|
|
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
|
|
pEnc->mbParam.width, pEnc->mbParam.height, 0); |
|
|
stop_edges_timer(); |
|
|
} |
|
|
|
|
1449 |
pEnc->mbParam.m_rounding_type = 1; |
pEnc->mbParam.m_rounding_type = 1; |
1450 |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
1451 |
pEnc->current->coding_type = I_VOP; |
pEnc->current->coding_type = I_VOP; |
1481 |
stop_prediction_timer(); |
stop_prediction_timer(); |
1482 |
|
|
1483 |
start_timer(); |
start_timer(); |
|
if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE) |
|
|
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
|
|
qcoeff[4*64+0]=0; /* zero, because for INTRA MBs DC value is saved */ |
|
|
qcoeff[5*64+0]=0; |
|
|
} |
|
1484 |
MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat); |
MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat); |
1485 |
stop_coding_timer(); |
stop_coding_timer(); |
1486 |
} |
} |
1487 |
|
|
|
if ((pEnc->current->vop_flags & XVID_VOP_REDUCED)) |
|
|
{ |
|
|
image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, |
|
|
pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width, |
|
|
16, 0); |
|
|
} |
|
1488 |
emms(); |
emms(); |
1489 |
|
|
1490 |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
1500 |
return 1; /* intra */ |
return 1; /* intra */ |
1501 |
} |
} |
1502 |
|
|
1503 |
|
static __inline void |
1504 |
|
updateFcode(Statistics * sStat, Encoder * pEnc) |
1505 |
|
{ |
1506 |
|
float fSigma; |
1507 |
|
int iSearchRange; |
1508 |
|
|
1509 |
#define INTRA_THRESHOLD 0.5 |
if (sStat->iMvCount == 0) |
1510 |
#define BFRAME_SKIP_THRESHHOLD 30 |
sStat->iMvCount = 1; |
1511 |
|
|
1512 |
|
fSigma = (float) sqrt((float) sStat->iMvSum / sStat->iMvCount); |
1513 |
|
|
1514 |
|
iSearchRange = 16 << pEnc->mbParam.m_fcode; |
1515 |
|
|
1516 |
|
if ((3.0 * fSigma > iSearchRange) && (pEnc->mbParam.m_fcode <= 5) ) |
1517 |
|
pEnc->mbParam.m_fcode++; |
1518 |
|
|
1519 |
|
else if ((5.0 * fSigma < iSearchRange) |
1520 |
|
&& (4.0 * pEnc->fMvPrevSigma < iSearchRange) |
1521 |
|
&& (pEnc->mbParam.m_fcode >= 2) ) |
1522 |
|
pEnc->mbParam.m_fcode--; |
1523 |
|
|
1524 |
|
pEnc->fMvPrevSigma = fSigma; |
1525 |
|
} |
1526 |
|
|
1527 |
|
#define BFRAME_SKIP_THRESHHOLD 30 |
1528 |
|
|
1529 |
/* FrameCodeP also handles S(GMC)-VOPs */ |
/* FrameCodeP also handles S(GMC)-VOPs */ |
1530 |
static int |
static int |
1531 |
FrameCodeP(Encoder * pEnc, |
FrameCodeP(Encoder * pEnc, |
1532 |
Bitstream * bs) |
Bitstream * bs) |
1533 |
{ |
{ |
|
float fSigma; |
|
1534 |
int bits = BitstreamPos(bs); |
int bits = BitstreamPos(bs); |
1535 |
|
|
1536 |
DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); |
1537 |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
1538 |
|
|
1539 |
int x, y, k; |
int x, y, k; |
|
int iSearchRange; |
|
|
int skip_possible; |
|
1540 |
FRAMEINFO *const current = pEnc->current; |
FRAMEINFO *const current = pEnc->current; |
1541 |
FRAMEINFO *const reference = pEnc->reference; |
FRAMEINFO *const reference = pEnc->reference; |
1542 |
MBParam * const pParam = &pEnc->mbParam; |
MBParam * const pParam = &pEnc->mbParam; |
1544 |
int mb_height = pParam->mb_height; |
int mb_height = pParam->mb_height; |
1545 |
int coded = 1; |
int coded = 1; |
1546 |
|
|
|
|
|
|
/* IMAGE *pCurrent = ¤t->image; */ |
|
1547 |
IMAGE *pRef = &reference->image; |
IMAGE *pRef = &reference->image; |
1548 |
|
|
|
if ((current->vop_flags & XVID_VOP_REDUCED)) |
|
|
{ |
|
|
mb_width = (pParam->width + 31) / 32; |
|
|
mb_height = (pParam->height + 31) / 32; |
|
|
} |
|
|
|
|
|
|
|
1549 |
if (!reference->is_edged) { |
if (!reference->is_edged) { |
1550 |
start_timer(); |
start_timer(); |
1551 |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
1571 |
} |
} |
1572 |
} |
} |
1573 |
|
|
1574 |
|
current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount = |
1575 |
|
current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0; |
1576 |
|
|
1577 |
current->coding_type = P_VOP; |
current->coding_type = P_VOP; |
1578 |
|
|
1579 |
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
1642 |
|
|
1643 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant); |
1644 |
|
|
|
current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount = |
|
|
current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0; |
|
|
|
|
|
|
|
1645 |
for (y = 0; y < mb_height; y++) { |
for (y = 0; y < mb_height; y++) { |
1646 |
for (x = 0; x < mb_width; x++) { |
for (x = 0; x < mb_width; x++) { |
1647 |
MACROBLOCK *pMB = |
MACROBLOCK *pMB = ¤t->mbs[x + y * pParam->mb_width]; |
1648 |
¤t->mbs[x + y * pParam->mb_width]; |
int skip_possible; |
|
|
|
|
int bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); |
|
1649 |
|
|
1650 |
if (bIntra) { |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) { |
1651 |
CodeIntraMB(pEnc, pMB); |
CodeIntraMB(pEnc, pMB); |
1652 |
MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y, |
MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y, |
1653 |
dct_codes, qcoeff); |
dct_codes, qcoeff); |
1658 |
|
|
1659 |
current->sStat.kblks++; |
current->sStat.kblks++; |
1660 |
|
|
|
if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE) |
|
|
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
|
|
qcoeff[4*64+0]=0; /* zero, because for INTRA MBs DC value is saved */ |
|
|
qcoeff[5*64+0]=0; |
|
|
} |
|
1661 |
MBCoding(current, pMB, qcoeff, bs, ¤t->sStat); |
MBCoding(current, pMB, qcoeff, bs, ¤t->sStat); |
1662 |
stop_coding_timer(); |
stop_coding_timer(); |
1663 |
continue; |
continue; |
1672 |
pParam->height, |
pParam->height, |
1673 |
pParam->edged_width, |
pParam->edged_width, |
1674 |
(current->vol_flags & XVID_VOL_QUARTERPEL), |
(current->vol_flags & XVID_VOL_QUARTERPEL), |
|
(current->vop_flags & XVID_VOP_REDUCED), |
|
1675 |
current->rounding_type); |
current->rounding_type); |
1676 |
|
|
1677 |
stop_comp_timer(); |
stop_comp_timer(); |
1678 |
|
|
1679 |
pMB->field_pred = 0; |
pMB->field_pred = 0; |
1680 |
|
|
1681 |
if (pMB->mode != MODE_NOT_CODED) |
if (pMB->cbp != 0) { |
1682 |
{ pMB->cbp = |
pMB->cbp = MBTransQuantInter(&pEnc->mbParam, current, pMB, x, y, |
|
MBTransQuantInter(&pEnc->mbParam, current, pMB, x, y, |
|
1683 |
dct_codes, qcoeff); |
dct_codes, qcoeff); |
1684 |
} |
} |
1685 |
|
|
1699 |
|
|
1700 |
/* Finished processing the MB, now check if to CODE or SKIP */ |
/* Finished processing the MB, now check if to CODE or SKIP */ |
1701 |
|
|
1702 |
skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER) && |
skip_possible = (pMB->cbp == 0) && (pMB->mode == MODE_INTER); |
|
(pMB->dquant == 0); |
|
1703 |
|
|
1704 |
if (current->coding_type == S_VOP) |
if (current->coding_type == S_VOP) |
1705 |
skip_possible &= (pMB->mcsel == 1); |
skip_possible &= (pMB->mcsel == 1); |
1706 |
else if (current->coding_type == P_VOP) { |
else { /* PVOP */ |
1707 |
if ((pParam->vol_flags & XVID_VOL_QUARTERPEL)) |
const VECTOR * const mv = (pParam->vol_flags & XVID_VOL_QUARTERPEL) ? |
1708 |
skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) ); |
pMB->qmvs : pMB->mvs; |
1709 |
else |
skip_possible &= ((mv->x|mv->y) == 0); |
|
skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) ); |
|
1710 |
} |
} |
1711 |
|
|
1712 |
if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) { |
if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) { |
|
|
|
1713 |
/* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */ |
/* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */ |
|
|
|
|
if (current->coding_type == P_VOP) /* special rule for P-VOP's SKIP */ |
|
|
{ |
|
1714 |
int bSkip = 1; |
int bSkip = 1; |
1715 |
|
|
1716 |
for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++) |
if (current->coding_type == P_VOP) { /* special rule for P-VOP's SKIP */ |
1717 |
{ |
|
1718 |
|
for (k = pEnc->bframenum_head; k < pEnc->bframenum_tail; k++) { |
1719 |
int iSAD; |
int iSAD; |
1720 |
iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x, |
iSAD = sad16(reference->image.y + 16*y*pParam->edged_width + 16*x, |
1721 |
pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x, |
pEnc->bframes[k]->image.y + 16*y*pParam->edged_width + 16*x, |
1722 |
pParam->edged_width,BFRAME_SKIP_THRESHHOLD); |
pParam->edged_width, BFRAME_SKIP_THRESHHOLD * pMB->quant); |
1723 |
if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant) |
if (iSAD >= BFRAME_SKIP_THRESHHOLD * pMB->quant) { |
1724 |
{ bSkip = 0; |
bSkip = 0; /* could not SKIP */ |
1725 |
break; |
if (pParam->vol_flags & XVID_VOL_QUARTERPEL) { |
|
} |
|
|
} |
|
|
|
|
|
if (!bSkip) { /* no SKIP, but trivial block */ |
|
|
if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) { |
|
1726 |
VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0); |
VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0); |
1727 |
pMB->pmvs[0].x = - predMV.x; |
pMB->pmvs[0].x = - predMV.x; |
1728 |
pMB->pmvs[0].y = - predMV.y; |
pMB->pmvs[0].y = - predMV.y; |
1729 |
} |
} else { |
|
else { |
|
1730 |
VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, 0); |
VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, 0); |
1731 |
pMB->pmvs[0].x = - predMV.x; |
pMB->pmvs[0].x = - predMV.x; |
1732 |
pMB->pmvs[0].y = - predMV.y; |
pMB->pmvs[0].y = - predMV.y; |
1733 |
} |
} |
1734 |
pMB->mode = MODE_INTER; |
pMB->mode = MODE_INTER; |
1735 |
pMB->cbp = 0; |
pMB->cbp = 0; |
1736 |
MBCoding(current, pMB, qcoeff, bs, ¤t->sStat); |
break; |
1737 |
stop_coding_timer(); |
} |
|
|
|
|
continue; /* next MB */ |
|
1738 |
} |
} |
1739 |
} |
} |
|
/* do SKIP */ |
|
1740 |
|
|
1741 |
|
if (bSkip) { |
1742 |
|
/* do SKIP */ |
1743 |
pMB->mode = MODE_NOT_CODED; |
pMB->mode = MODE_NOT_CODED; |
1744 |
MBSkip(bs); |
MBSkip(bs); |
1745 |
stop_coding_timer(); |
stop_coding_timer(); |
1746 |
continue; /* next MB */ |
continue; /* next MB */ |
1747 |
} |
} |
|
/* ordinary case: normal coded INTER/INTER4V block */ |
|
|
|
|
|
if ((current->vop_flags & XVID_VOP_GREYSCALE)) |
|
|
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
|
|
qcoeff[4*64+0]=0; /* zero, because DC for INTRA MBs DC value is saved */ |
|
|
qcoeff[5*64+0]=0; |
|
|
} |
|
|
|
|
|
if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) { |
|
|
VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0); |
|
|
pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; |
|
|
pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y; |
|
|
DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y); |
|
|
} else { |
|
|
VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, 0); |
|
|
pMB->pmvs[0].x = pMB->mvs[0].x - predMV.x; |
|
|
pMB->pmvs[0].y = pMB->mvs[0].y - predMV.y; |
|
|
DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y); |
|
|
} |
|
|
|
|
|
|
|
|
if (pMB->mode == MODE_INTER4V) |
|
|
{ int k; |
|
|
for (k=1;k<4;k++) |
|
|
{ |
|
|
if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) { |
|
|
VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, k); |
|
|
pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x; |
|
|
pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y; |
|
|
DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y); |
|
|
} else { |
|
|
VECTOR predMV = get_pmv2(current->mbs, pParam->mb_width, 0, x, y, k); |
|
|
pMB->pmvs[k].x = pMB->mvs[k].x - predMV.x; |
|
|
pMB->pmvs[k].y = pMB->mvs[k].y - predMV.y; |
|
|
DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y); |
|
|
} |
|
|
|
|
|
} |
|
1748 |
} |
} |
1749 |
|
|
1750 |
|
/* ordinary case: normal coded INTER/INTER4V block */ |
1751 |
MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat); |
MBCoding(current, pMB, qcoeff, bs, &pEnc->current->sStat); |
1752 |
stop_coding_timer(); |
stop_coding_timer(); |
|
|
|
1753 |
} |
} |
1754 |
} |
} |
1755 |
|
|
|
if ((current->vop_flags & XVID_VOP_REDUCED)) |
|
|
{ |
|
|
image_deblock_rrv(¤t->image, pParam->edged_width, |
|
|
current->mbs, mb_width, mb_height, pParam->mb_width, |
|
|
16, 0); |
|
|
} |
|
|
|
|
1756 |
emms(); |
emms(); |
1757 |
|
updateFcode(¤t->sStat, pEnc); |
|
if (current->sStat.iMvCount == 0) |
|
|
current->sStat.iMvCount = 1; |
|
|
|
|
|
fSigma = (float) sqrt((float) current->sStat.iMvSum / current->sStat.iMvCount); |
|
|
|
|
|
iSearchRange = 1 << (3 + pParam->m_fcode); |
|
|
|
|
|
if ((fSigma > iSearchRange / 3) |
|
|
&& (pParam->m_fcode <= (3 + (pParam->vol_flags & XVID_VOL_QUARTERPEL?1:0) ))) /* maximum search range 128 */ |
|
|
{ |
|
|
pParam->m_fcode++; |
|
|
iSearchRange *= 2; |
|
|
} else if ((fSigma < iSearchRange / 6) |
|
|
&& (pEnc->fMvPrevSigma >= 0) |
|
|
&& (pEnc->fMvPrevSigma < iSearchRange / 6) |
|
|
&& (pParam->m_fcode >= (2 + (pParam->vol_flags & XVID_VOL_QUARTERPEL?1:0) ))) /* minimum search range 16 */ |
|
|
{ |
|
|
pParam->m_fcode--; |
|
|
iSearchRange /= 2; |
|
|
} |
|
|
|
|
|
pEnc->fMvPrevSigma = fSigma; |
|
1758 |
|
|
1759 |
/* frame drop code */ |
/* frame drop code */ |
1760 |
#if 0 |
#if 0 |
1839 |
fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mode,mb->cbp); \ |
fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mode,mb->cbp); \ |
1840 |
} |
} |
1841 |
|
|
|
/* XXX: pEnc->current->global_flags &= ~XVID_VOP_REDUCED; reduced resoltion not yet supported */ |
|
|
|
|
1842 |
if (!first){ |
if (!first){ |
1843 |
fp=fopen("C:\\XVIDDBGE.TXT","w"); |
fp=fopen("C:\\XVIDDBGE.TXT","w"); |
1844 |
} |
} |
1909 |
if (mb->mode == MODE_NOT_CODED) { |
if (mb->mode == MODE_NOT_CODED) { |
1910 |
if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) { |
if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) { |
1911 |
MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image, |
MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image, |
1912 |
NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0); |
NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0); |
1913 |
} |
} |
|
|
|
1914 |
continue; |
continue; |
1915 |
} |
} |
1916 |
|
|
1917 |
if (mb->mode != MODE_DIRECT_NONE_MV || pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) { |
mb->quant = frame->quant; |
1918 |
|
|
1919 |
|
if (mb->cbp != 0 || pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) { |
1920 |
|
/* we have to motion-compensate, transfer etc, |
1921 |
|
because there might be blocks to code */ |
1922 |
|
|
1923 |
MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image, |
MBMotionCompensationBVOP(&pEnc->mbParam, mb, x, y, &frame->image, |
1924 |
f_ref, &pEnc->f_refh, &pEnc->f_refv, |
f_ref, &pEnc->f_refh, &pEnc->f_refv, |
1925 |
&pEnc->f_refhv, b_ref, &pEnc->vInterH, |
&pEnc->f_refhv, b_ref, &pEnc->vInterH, |
1926 |
&pEnc->vInterV, &pEnc->vInterHV, |
&pEnc->vInterV, &pEnc->vInterHV, |
1927 |
dct_codes); |
dct_codes); |
1928 |
|
|
|
if (mb->mode == MODE_DIRECT_NO4V) mb->mode = MODE_DIRECT; |
|
|
mb->quant = frame->quant; |
|
|
|
|
|
if (mb->mode != MODE_DIRECT_NONE_MV) |
|
1929 |
mb->cbp = MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, x, y, dct_codes, qcoeff); |
mb->cbp = MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, x, y, dct_codes, qcoeff); |
|
|
|
|
if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0) |
|
|
&& (mb->pmvs[3].x == 0) && (mb->pmvs[3].y == 0) ) { |
|
|
mb->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
|
|
} |
|
1930 |
} |
} |
1931 |
|
|
1932 |
/* keep only bits 5-2 -- Chroma blocks will just be skipped by the |
if (mb->mode == MODE_DIRECT_NO4V) |
1933 |
* coding function for BFrames, that's why we don't zero teh DC |
mb->mode = MODE_DIRECT; |
1934 |
* coeffs */ |
|
1935 |
if ((frame->vop_flags & XVID_VOP_GREYSCALE)) |
if (mb->mode == MODE_DIRECT && (mb->cbp | mb->pmvs[3].x | mb->pmvs[3].y) == 0) |
1936 |
|
mb->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
1937 |
|
else |
1938 |
|
if (frame->vop_flags & XVID_VOP_GREYSCALE) |
1939 |
|
/* keep only bits 5-2 -- Chroma blocks will just be skipped by MBCodingBVOP */ |
1940 |
mb->cbp &= 0x3C; |
mb->cbp &= 0x3C; |
1941 |
|
|
1942 |
start_timer(); |
start_timer(); |
1948 |
|
|
1949 |
emms(); |
emms(); |
1950 |
|
|
|
/* TODO: dynamic fcode/bcode ??? */ |
|
|
|
|
1951 |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
1952 |
frame->length = (BitstreamPos(bs) - bits) / 8; |
frame->length = (BitstreamPos(bs) - bits) / 8; |
1953 |
|
|