26 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
* |
* |
29 |
* $Id: encoder.c,v 1.95.2.14 2003-03-26 11:01:03 suxen_drol Exp $ |
* $Id: encoder.c,v 1.95.2.15 2003-03-26 14:56:10 edgomez Exp $ |
30 |
* |
* |
31 |
****************************************************************************/ |
****************************************************************************/ |
32 |
|
|
181 |
} |
} |
182 |
} |
} |
183 |
|
|
184 |
if ((pEnc->mbParam.global_flags & XVID_EXTRASTATS_ENABLE) || |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_EXTRASTATS_ENABLE) || |
185 |
(pEnc->mbParam.plugin_flags & XVID_REQPSNR)) { |
(pEnc->mbParam.plugin_flags & XVID_REQPSNR)) { |
186 |
pEnc->mbParam.plugin_flags |= XVID_REQORIGINAL; /* psnr calculation requires the original */ |
pEnc->mbParam.plugin_flags |= XVID_REQORIGINAL; /* psnr calculation requires the original */ |
187 |
} |
} |
683 |
data.original.stride[2] = pEnc->mbParam.edged_width/2; |
data.original.stride[2] = pEnc->mbParam.edged_width/2; |
684 |
} |
} |
685 |
|
|
686 |
if ((frame->vol_flags & XVID_EXTRASTATS) || |
if ((frame->vol_flags & XVID_VOL_EXTRASTATS) || |
687 |
(pEnc->mbParam.plugin_flags & XVID_REQPSNR)) { |
(pEnc->mbParam.plugin_flags & XVID_REQPSNR)) { |
688 |
|
|
689 |
data.sse_y = |
data.sse_y = |
855 |
if (image_input |
if (image_input |
856 |
(&q->image, pEnc->mbParam.width, pEnc->mbParam.height, |
(&q->image, pEnc->mbParam.width, pEnc->mbParam.height, |
857 |
pEnc->mbParam.edged_width, (uint8_t**)xFrame->input.plane, xFrame->input.stride, |
pEnc->mbParam.edged_width, (uint8_t**)xFrame->input.plane, xFrame->input.stride, |
858 |
xFrame->input.csp, xFrame->vol_flags & XVID_INTERLACING)) |
xFrame->input.csp, xFrame->vol_flags & XVID_VOL_INTERLACING)) |
859 |
{ |
{ |
860 |
emms(); |
emms(); |
861 |
return XVID_ERR_FORMAT; |
return XVID_ERR_FORMAT; |
862 |
} |
} |
863 |
stop_conv_timer(); |
stop_conv_timer(); |
864 |
|
|
865 |
if ((xFrame->vop_flags & XVID_CHROMAOPT)) { |
if ((xFrame->vop_flags & XVID_VOP_CHROMAOPT)) { |
866 |
image_chroma_optimize(&q->image, |
image_chroma_optimize(&q->image, |
867 |
pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width); |
pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width); |
868 |
} |
} |
919 |
indentical to the future-referece frame. |
indentical to the future-referece frame. |
920 |
*/ |
*/ |
921 |
|
|
922 |
if ((pEnc->mbParam.global_flags & XVID_PACKED && pEnc->bframenum_tail > 0)) { |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED && pEnc->bframenum_tail > 0)) { |
923 |
int tmp; |
int tmp; |
924 |
int bits; |
int bits; |
925 |
|
|
961 |
if (xFrame->input.csp == XVID_CSP_NULL) /* no futher input */ |
if (xFrame->input.csp == XVID_CSP_NULL) /* no futher input */ |
962 |
{ |
{ |
963 |
|
|
964 |
if (!(pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->mbParam.max_bframes > 0) { |
if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0) { |
965 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
966 |
} |
} |
967 |
|
|
1015 |
pEnc->current->bcode = pEnc->mbParam.m_fcode; |
pEnc->current->bcode = pEnc->mbParam.m_fcode; |
1016 |
|
|
1017 |
|
|
1018 |
if ((xFrame->vop_flags & XVID_CHROMAOPT)) { |
if ((xFrame->vop_flags & XVID_VOP_CHROMAOPT)) { |
1019 |
image_chroma_optimize(&pEnc->current->image, |
image_chroma_optimize(&pEnc->current->image, |
1020 |
pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width); |
pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width); |
1021 |
} |
} |
1043 |
&pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, |
&pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, |
1044 |
pEnc->iFrameNum, pEnc->bframenum_tail); |
pEnc->iFrameNum, pEnc->bframenum_tail); |
1045 |
|
|
1046 |
if (type == B_VOP && !(pEnc->current->vop_flags & XVID_DYNAMIC_BFRAMES)) { |
if (type == B_VOP && !(pEnc->current->vop_flags & XVID_VOP_DYNAMIC_BFRAMES)) { |
1047 |
type = P_VOP; /* disable dynamic bframes */ |
type = P_VOP; /* disable dynamic bframes */ |
1048 |
} |
} |
1049 |
} |
} |
1060 |
|
|
1061 |
pEnc->iFrameNum++; |
pEnc->iFrameNum++; |
1062 |
|
|
1063 |
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
1064 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5, |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5, |
1065 |
"%i st:%i if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); |
"%i st:%i if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); |
1066 |
} |
} |
1070 |
* (we dont encode here, rather we store the frame in the bframes queue, to be encoded later) |
* (we dont encode here, rather we store the frame in the bframes queue, to be encoded later) |
1071 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1072 |
if (type == B_VOP) { |
if (type == B_VOP) { |
1073 |
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
1074 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP"); |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP"); |
1075 |
} |
} |
1076 |
|
|
1101 |
} |
} |
1102 |
|
|
1103 |
/* for unpacked bframes, output the stats for the last encoded frame */ |
/* for unpacked bframes, output the stats for the last encoded frame */ |
1104 |
if (!(pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) |
if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) |
1105 |
{ |
{ |
1106 |
if (pEnc->current->stamp > 0) { |
if (pEnc->current->stamp > 0) { |
1107 |
call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
1115 |
* if the frame prior to an iframe is scheduled as a bframe, we must change it to a pframe |
* if the frame prior to an iframe is scheduled as a bframe, we must change it to a pframe |
1116 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1117 |
|
|
1118 |
if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_CLOSED_GOP) && pEnc->bframenum_tail > 0) { |
if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP) && pEnc->bframenum_tail > 0) { |
1119 |
|
|
1120 |
// place this frame back on the encoding-queue (head) |
// place this frame back on the encoding-queue (head) |
1121 |
// we will deal with it next time |
// we will deal with it next time |
1131 |
pEnc->bframenum_tail--; |
pEnc->bframenum_tail--; |
1132 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
1133 |
|
|
1134 |
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
1135 |
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, "DX50 BVOP->PVOP"); |
1136 |
} |
} |
1137 |
|
|
1151 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
1152 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1153 |
|
|
1154 |
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
1155 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP"); |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP"); |
1156 |
} |
} |
1157 |
|
|
1159 |
/* ---- update vol flags at IVOP ----------- */ |
/* ---- update vol flags at IVOP ----------- */ |
1160 |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; |
1161 |
|
|
1162 |
if ((pEnc->mbParam.vol_flags & XVID_MPEGQUANT)) { |
if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { |
1163 |
if (frame->quant_intra_matrix != NULL) |
if (frame->quant_intra_matrix != NULL) |
1164 |
set_intra_matrix(frame->quant_intra_matrix); |
set_intra_matrix(frame->quant_intra_matrix); |
1165 |
if (frame->quant_inter_matrix != NULL) |
if (frame->quant_inter_matrix != NULL) |
1168 |
|
|
1169 |
/* prevent vol/vop misuse */ |
/* prevent vol/vop misuse */ |
1170 |
|
|
1171 |
if (!(pEnc->current->vol_flags & XVID_REDUCED_ENABLE)) |
if (!(pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE)) |
1172 |
pEnc->current->vop_flags &= ~XVID_REDUCED; |
pEnc->current->vop_flags &= ~XVID_VOP_REDUCED; |
1173 |
|
|
1174 |
if (!(pEnc->current->vol_flags & XVID_INTERLACING)) |
if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING)) |
1175 |
pEnc->current->vop_flags &= ~(XVID_TOPFIELDFIRST|XVID_ALTERNATESCAN); |
pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN); |
1176 |
|
|
1177 |
/* ^^^------------------------ */ |
/* ^^^------------------------ */ |
1178 |
|
|
1194 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
1195 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1196 |
|
|
1197 |
if ((pEnc->current->vop_flags & XVID_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
1198 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP"); |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP"); |
1199 |
} |
} |
1200 |
|
|
1216 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
1217 |
|
|
1218 |
/* packed & queued_bframes: dont bother outputting stats, we do so after the flush */ |
/* packed & queued_bframes: dont bother outputting stats, we do so after the flush */ |
1219 |
if ((pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) { |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) { |
1220 |
goto repeat; |
goto repeat; |
1221 |
} |
} |
1222 |
|
|
1223 |
/* packed or no-bframes: output stats */ |
/* packed or no-bframes: output stats */ |
1224 |
if ((pEnc->mbParam.global_flags & XVID_PACKED) || pEnc->mbParam.max_bframes == 0) { |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) || pEnc->mbParam.max_bframes == 0) { |
1225 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
1226 |
} |
} |
1227 |
|
|
1290 |
|
|
1291 |
uint16_t x, y; |
uint16_t x, y; |
1292 |
|
|
1293 |
if ((pEnc->current->vol_flags & XVID_REDUCED_ENABLE)) |
if ((pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE)) |
1294 |
{ |
{ |
1295 |
mb_width = (pEnc->mbParam.width + 31) / 32; |
mb_width = (pEnc->mbParam.width + 31) / 32; |
1296 |
mb_height = (pEnc->mbParam.height + 31) / 32; |
mb_height = (pEnc->mbParam.height + 31) / 32; |
1336 |
stop_prediction_timer(); |
stop_prediction_timer(); |
1337 |
|
|
1338 |
start_timer(); |
start_timer(); |
1339 |
if (pEnc->current->vop_flags & XVID_GREYSCALE) |
if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE) |
1340 |
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
1341 |
qcoeff[4*64+0]=0; /* zero, because for INTRA MBs DC value is saved */ |
qcoeff[4*64+0]=0; /* zero, because for INTRA MBs DC value is saved */ |
1342 |
qcoeff[5*64+0]=0; |
qcoeff[5*64+0]=0; |
1345 |
stop_coding_timer(); |
stop_coding_timer(); |
1346 |
} |
} |
1347 |
|
|
1348 |
if ((pEnc->current->vop_flags & XVID_REDUCED)) |
if ((pEnc->current->vop_flags & XVID_VOP_REDUCED)) |
1349 |
{ |
{ |
1350 |
image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, |
image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, |
1351 |
pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width, |
pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width, |
1354 |
emms(); |
emms(); |
1355 |
|
|
1356 |
/* for divx5 compatibility, we must always pad between the packed p and b frames */ |
/* for divx5 compatibility, we must always pad between the packed p and b frames */ |
1357 |
if ((pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) |
1358 |
BitstreamPadAlways(bs); |
BitstreamPadAlways(bs); |
1359 |
else |
else |
1360 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1400 |
/* IMAGE *pCurrent = &pEnc->current->image; */ |
/* IMAGE *pCurrent = &pEnc->current->image; */ |
1401 |
IMAGE *pRef = &pEnc->reference->image; |
IMAGE *pRef = &pEnc->reference->image; |
1402 |
|
|
1403 |
if ((pEnc->current->vop_flags & XVID_REDUCED)) |
if ((pEnc->current->vop_flags & XVID_VOP_REDUCED)) |
1404 |
{ |
{ |
1405 |
mb_width = (pEnc->mbParam.width + 31) / 32; |
mb_width = (pEnc->mbParam.width + 31) / 32; |
1406 |
mb_height = (pEnc->mbParam.height + 31) / 32; |
mb_height = (pEnc->mbParam.height + 31) / 32; |
1422 |
else |
else |
1423 |
iLimit = mb_width * mb_height + 1; |
iLimit = mb_width * mb_height + 1; |
1424 |
|
|
1425 |
if ((pEnc->current->vop_flags & XVID_HALFPEL)) { |
if ((pEnc->current->vop_flags & XVID_VOP_HALFPEL)) { |
1426 |
start_timer(); |
start_timer(); |
1427 |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
1428 |
&pEnc->vInterHV, pEnc->mbParam.edged_width, |
&pEnc->vInterHV, pEnc->mbParam.edged_width, |
1429 |
pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_height, |
1430 |
(pEnc->mbParam.vol_flags & XVID_QUARTERPEL), |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), |
1431 |
pEnc->current->rounding_type); |
pEnc->current->rounding_type); |
1432 |
stop_inter_timer(); |
stop_inter_timer(); |
1433 |
} |
} |
1450 |
|
|
1451 |
if (bIntra == 1) return FrameCodeI(pEnc, bs); |
if (bIntra == 1) return FrameCodeI(pEnc, bs); |
1452 |
|
|
1453 |
if ( ( pEnc->current->vol_flags & XVID_GMC ) |
if ( ( pEnc->current->vol_flags & XVID_VOL_GMC ) |
1454 |
&& ( (pEnc->current->warp.duv[1].x != 0) || (pEnc->current->warp.duv[1].y != 0) ) ) |
&& ( (pEnc->current->warp.duv[1].x != 0) || (pEnc->current->warp.duv[1].y != 0) ) ) |
1455 |
{ |
{ |
1456 |
pEnc->current->coding_type = S_VOP; |
pEnc->current->coding_type = S_VOP; |
1462 |
generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image, |
generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image, |
1463 |
pEnc->mbParam.mb_width, pEnc->mbParam.mb_height, |
pEnc->mbParam.mb_width, pEnc->mbParam.mb_height, |
1464 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2, |
1465 |
pEnc->mbParam.m_fcode, (pEnc->mbParam.vol_flags & XVID_QUARTERPEL), 0, |
pEnc->mbParam.m_fcode, (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0, |
1466 |
pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC); |
pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC); |
1467 |
|
|
1468 |
} |
} |
1511 |
pEnc->vGMC.y + 16*y*pEnc->mbParam.edged_width + 16*x, |
pEnc->vGMC.y + 16*y*pEnc->mbParam.edged_width + 16*x, |
1512 |
pEnc->mbParam.edged_width, 65536); |
pEnc->mbParam.edged_width, 65536); |
1513 |
|
|
1514 |
if (pEnc->current->motion_flags & PMV_CHROMA16) { |
if (pEnc->current->motion_flags & XVID_ME_CHROMA16) { |
1515 |
iSAD += sad8(pEnc->current->image.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, |
iSAD += sad8(pEnc->current->image.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, |
1516 |
pEnc->vGMC.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->mbParam.edged_width/2); |
pEnc->vGMC.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->mbParam.edged_width/2); |
1517 |
|
|
1521 |
|
|
1522 |
if (iSAD <= pMB->sad16) { /* mode decision GMC */ |
if (iSAD <= pMB->sad16) { /* mode decision GMC */ |
1523 |
|
|
1524 |
if ((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) |
if ((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) |
1525 |
pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv; |
pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv; |
1526 |
else |
else |
1527 |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
1544 |
dct_codes, pEnc->mbParam.width, |
dct_codes, pEnc->mbParam.width, |
1545 |
pEnc->mbParam.height, |
pEnc->mbParam.height, |
1546 |
pEnc->mbParam.edged_width, |
pEnc->mbParam.edged_width, |
1547 |
(pEnc->current->vol_flags & XVID_QUARTERPEL), |
(pEnc->current->vol_flags & XVID_VOL_QUARTERPEL), |
1548 |
(pEnc->current->vop_flags & XVID_REDUCED), |
(pEnc->current->vop_flags & XVID_VOP_REDUCED), |
1549 |
pEnc->current->rounding_type); |
pEnc->current->rounding_type); |
1550 |
|
|
1551 |
stop_comp_timer(); |
stop_comp_timer(); |
1580 |
if (pEnc->current->coding_type == S_VOP) |
if (pEnc->current->coding_type == S_VOP) |
1581 |
skip_possible &= (pMB->mcsel == 1); |
skip_possible &= (pMB->mcsel == 1); |
1582 |
else if (pEnc->current->coding_type == P_VOP) { |
else if (pEnc->current->coding_type == P_VOP) { |
1583 |
if ((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) |
if ((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) |
1584 |
skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) ); |
skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) ); |
1585 |
else |
else |
1586 |
skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) ); |
skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) ); |
1607 |
} |
} |
1608 |
|
|
1609 |
if (!bSkip) { /* no SKIP, but trivial block */ |
if (!bSkip) { /* no SKIP, but trivial block */ |
1610 |
if((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) { |
if((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) { |
1611 |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
1612 |
pMB->pmvs[0].x = - predMV.x; |
pMB->pmvs[0].x = - predMV.x; |
1613 |
pMB->pmvs[0].y = - predMV.y; |
pMB->pmvs[0].y = - predMV.y; |
1634 |
} |
} |
1635 |
/* ordinary case: normal coded INTER/INTER4V block */ |
/* ordinary case: normal coded INTER/INTER4V block */ |
1636 |
|
|
1637 |
if ((pEnc->current->vop_flags & XVID_GREYSCALE)) |
if ((pEnc->current->vop_flags & XVID_VOP_GREYSCALE)) |
1638 |
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
1639 |
qcoeff[4*64+0]=0; /* zero, because DC for INTRA MBs DC value is saved */ |
qcoeff[4*64+0]=0; /* zero, because DC for INTRA MBs DC value is saved */ |
1640 |
qcoeff[5*64+0]=0; |
qcoeff[5*64+0]=0; |
1641 |
} |
} |
1642 |
|
|
1643 |
if((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) { |
if((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) { |
1644 |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
1645 |
pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; |
pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; |
1646 |
pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y; |
pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y; |
1657 |
{ int k; |
{ int k; |
1658 |
for (k=1;k<4;k++) |
for (k=1;k<4;k++) |
1659 |
{ |
{ |
1660 |
if((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) { |
if((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) { |
1661 |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k); |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k); |
1662 |
pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x; |
pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x; |
1663 |
pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y; |
pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y; |
1678 |
} |
} |
1679 |
} |
} |
1680 |
|
|
1681 |
if ((pEnc->current->vop_flags & XVID_REDUCED)) |
if ((pEnc->current->vop_flags & XVID_VOP_REDUCED)) |
1682 |
{ |
{ |
1683 |
image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, |
image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, |
1684 |
pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width, |
pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width, |
1700 |
iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode); |
iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode); |
1701 |
|
|
1702 |
if ((fSigma > iSearchRange / 3) |
if ((fSigma > iSearchRange / 3) |
1703 |
&& (pEnc->mbParam.m_fcode <= (3 + (pEnc->mbParam.vol_flags & XVID_QUARTERPEL?1:0) ))) /* maximum search range 128 */ |
&& (pEnc->mbParam.m_fcode <= (3 + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL?1:0) ))) /* maximum search range 128 */ |
1704 |
{ |
{ |
1705 |
pEnc->mbParam.m_fcode++; |
pEnc->mbParam.m_fcode++; |
1706 |
iSearchRange *= 2; |
iSearchRange *= 2; |
1707 |
} else if ((fSigma < iSearchRange / 6) |
} else if ((fSigma < iSearchRange / 6) |
1708 |
&& (pEnc->fMvPrevSigma >= 0) |
&& (pEnc->fMvPrevSigma >= 0) |
1709 |
&& (pEnc->fMvPrevSigma < iSearchRange / 6) |
&& (pEnc->fMvPrevSigma < iSearchRange / 6) |
1710 |
&& (pEnc->mbParam.m_fcode >= (2 + (pEnc->mbParam.vol_flags & XVID_QUARTERPEL?1:0) ))) /* minimum search range 16 */ |
&& (pEnc->mbParam.m_fcode >= (2 + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL?1:0) ))) /* minimum search range 16 */ |
1711 |
{ |
{ |
1712 |
pEnc->mbParam.m_fcode--; |
pEnc->mbParam.m_fcode--; |
1713 |
iSearchRange /= 2; |
iSearchRange /= 2; |
1755 |
*/ |
*/ |
1756 |
|
|
1757 |
/* for divx5 compatibility, we must always pad between the packed p and b frames */ |
/* for divx5 compatibility, we must always pad between the packed p and b frames */ |
1758 |
if ((pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) |
1759 |
BitstreamPadAlways(bs); |
BitstreamPadAlways(bs); |
1760 |
else |
else |
1761 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1786 |
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); \ |
1787 |
} |
} |
1788 |
|
|
1789 |
/* XXX: pEnc->current->global_flags &= ~XVID_REDUCED; reduced resoltion not yet supported */ |
/* XXX: pEnc->current->global_flags &= ~XVID_VOP_REDUCED; reduced resoltion not yet supported */ |
1790 |
|
|
1791 |
if (!first){ |
if (!first){ |
1792 |
fp=fopen("C:\\XVIDDBGE.TXT","w"); |
fp=fopen("C:\\XVIDDBGE.TXT","w"); |
1802 |
start_timer(); |
start_timer(); |
1803 |
image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
1804 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1805 |
(pEnc->mbParam.vol_flags & XVID_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1806 |
stop_inter_timer(); |
stop_inter_timer(); |
1807 |
|
|
1808 |
/* backward */ |
/* backward */ |
1812 |
start_timer(); |
start_timer(); |
1813 |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1814 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1815 |
(pEnc->mbParam.vol_flags & XVID_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1816 |
stop_inter_timer(); |
stop_inter_timer(); |
1817 |
|
|
1818 |
start_timer(); |
start_timer(); |
1849 |
for (y = 0; y < pEnc->mbParam.mb_height; y++) { |
for (y = 0; y < pEnc->mbParam.mb_height; y++) { |
1850 |
for (x = 0; x < pEnc->mbParam.mb_width; x++) { |
for (x = 0; x < pEnc->mbParam.mb_width; x++) { |
1851 |
MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width]; |
MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width]; |
1852 |
int direction = frame->vop_flags & XVID_ALTERNATESCAN ? 2 : 0; |
int direction = frame->vop_flags & XVID_VOP_ALTERNATESCAN ? 2 : 0; |
1853 |
|
|
1854 |
/* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ |
/* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ |
1855 |
if (mb->mode == MODE_NOT_CODED) { |
if (mb->mode == MODE_NOT_CODED) { |