--- branches/dev-api-4/xvidcore/src/encoder.c 2003/10/01 23:23:01 1161 +++ branches/dev-api-4/xvidcore/src/encoder.c 2003/11/09 20:49:21 1202 @@ -21,7 +21,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: encoder.c,v 1.95.2.42 2003-10-01 23:23:00 edgomez Exp $ + * $Id: encoder.c,v 1.95.2.49 2003-11-09 20:49:21 edgomez Exp $ * ****************************************************************************/ @@ -648,6 +648,8 @@ data.mb_height = pEnc->mbParam.mb_height; data.fincr = frame->fincr; data.fbase = pEnc->mbParam.fbase; + data.bquant_ratio = pEnc->mbParam.bquant_ratio; + data.bquant_offset = pEnc->mbParam.bquant_offset; for (i=0; i<3; i++) { data.min_quant[i] = pEnc->mbParam.min_quant[i]; @@ -994,7 +996,9 @@ SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); /* convert B-VOP to P-VOP */ - pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio; + pEnc->current->quant = 100*pEnc->current->quant - pEnc->mbParam.bquant_offset; + pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */ + pEnc->current->quant /= pEnc->mbParam.bquant_ratio; if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { image_copy(&pEnc->sOriginal, &pEnc->current->image, @@ -1082,7 +1086,7 @@ if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5, - "%i st:%i if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); + "%d st:%lld if:%d", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1161,7 +1165,9 @@ } /* convert B-VOP quant to P-VOP */ - pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio; + pEnc->current->quant = 100*pEnc->current->quant - pEnc->mbParam.bquant_offset; + pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */ + pEnc->current->quant /= pEnc->mbParam.bquant_ratio; type = P_VOP; } @@ -1406,6 +1412,9 @@ pEnc->fMvPrevSigma = -1; pEnc->mbParam.m_fcode = 2; + pEnc->current->is_edged = 0; /* not edged */ + pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ + return 1; /* intra */ } @@ -1448,10 +1457,13 @@ } - start_timer(); - image_setedges(pRef, pParam->edged_width, pParam->edged_height, - pParam->width, pParam->height); - stop_edges_timer(); + if (!reference->is_edged) { + start_timer(); + image_setedges(pRef, pParam->edged_width, pParam->edged_height, + pParam->width, pParam->height); + stop_edges_timer(); + reference->is_edged = 1; + } pParam->m_rounding_type = 1 - pParam->m_rounding_type; current->rounding_type = pParam->m_rounding_type; @@ -1463,13 +1475,16 @@ iLimit = mb_width * mb_height + 1; if ((current->vop_flags & XVID_VOP_HALFPEL)) { - start_timer(); - image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, - &pEnc->vInterHV, pParam->edged_width, - pParam->edged_height, - (pParam->vol_flags & XVID_VOL_QUARTERPEL), - current->rounding_type); - stop_inter_timer(); + if (reference->is_interpolated != current->rounding_type) { + start_timer(); + image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, + &pEnc->vInterHV, pParam->edged_width, + pParam->edged_height, + (pParam->vol_flags & XVID_VOL_QUARTERPEL), + current->rounding_type); + stop_inter_timer(); + reference->is_interpolated = current->rounding_type; + } } current->coding_type = P_VOP; @@ -1777,6 +1792,17 @@ memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height); } + pEnc->current->is_edged = 0; /* not edged */ + pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ + + /* what was this frame's interpolated reference will become + forward (past) reference in b-frame coding */ + + image_swap(&pEnc->vInterH, &pEnc->f_refh); + image_swap(&pEnc->vInterV, &pEnc->f_refv); + image_swap(&pEnc->vInterHV, &pEnc->f_refhv); + + /* XXX: debug { char s[100]; @@ -1828,24 +1854,38 @@ #endif /* forward */ - image_setedges(f_ref, pEnc->mbParam.edged_width, - pEnc->mbParam.edged_height, pEnc->mbParam.width, - pEnc->mbParam.height); - start_timer(); - image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, - pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, - (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); - stop_inter_timer(); + if (!pEnc->reference->is_edged) { + image_setedges(f_ref, pEnc->mbParam.edged_width, + pEnc->mbParam.edged_height, pEnc->mbParam.width, + pEnc->mbParam.height); + pEnc->current->is_edged = 1; + } + + if (pEnc->reference->is_interpolated != 0) { + start_timer(); + image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, + pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); + stop_inter_timer(); + pEnc->reference->is_interpolated = 0; + } /* backward */ - image_setedges(b_ref, pEnc->mbParam.edged_width, - pEnc->mbParam.edged_height, pEnc->mbParam.width, - pEnc->mbParam.height); - start_timer(); - image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, - pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, - (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); - stop_inter_timer(); + if (!pEnc->current->is_edged) { + image_setedges(b_ref, pEnc->mbParam.edged_width, + pEnc->mbParam.edged_height, pEnc->mbParam.width, + pEnc->mbParam.height); + pEnc->current->is_edged = 1; + } + + if (pEnc->current->is_interpolated != 0) { + start_timer(); + image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, + pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); + stop_inter_timer(); + pEnc->current->is_interpolated = 0; + } start_timer(); MotionEstimationBVOP(&pEnc->mbParam, frame, @@ -1872,11 +1912,14 @@ for (y = 0; y < pEnc->mbParam.mb_height; y++) { for (x = 0; x < pEnc->mbParam.mb_width; x++) { MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width]; - int direction = frame->vop_flags & XVID_VOP_ALTERNATESCAN ? 2 : 0; /* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ if (mb->mode == MODE_NOT_CODED) { - /* mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0; */ + if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) { + MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image, + NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0); + } + continue; } @@ -1906,8 +1949,8 @@ mb->cbp &= 0x3C; start_timer(); - MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs, - &frame->sStat, direction); + MBCodingBVOP(frame, mb, qcoeff, frame->fcode, frame->bcode, bs, + &frame->sStat); stop_coding_timer(); } }