--- branches/dev-api-4/xvidcore/src/encoder.c 2003/11/19 21:27:25 1220 +++ branches/dev-api-4/xvidcore/src/encoder.c 2003/11/20 12:07:19 1221 @@ -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.54 2003-11-19 15:42:38 syskin Exp $ + * $Id: encoder.c,v 1.95.2.55 2003-11-20 12:07:19 syskin Exp $ * ****************************************************************************/ @@ -776,15 +776,13 @@ frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; } } - frame->mbs[0].quant = data.quant; /* BEFORE2 will not affect the quant in stats */ + frame->mbs[0].quant = data.quant; /* FRAME will not affect the quant in stats */ } } - - static __inline void inc_frame_num(Encoder * pEnc) { pEnc->current->frame_num = pEnc->m_framenum; @@ -800,6 +798,34 @@ pEnc->m_framenum--; /* debug ticker */ } +static __inline void +MBSetDquant(MACROBLOCK * pMB, int x, int y, MBParam * mbParam) +{ + if (pMB->cbp == 0) { + /* we want to code dquant but the quantizer value will not be used yet + let's find out if we can postpone dquant to next MB + */ + if (x == mbParam->mb_width-1 && y == mbParam->mb_height-1) { + pMB->dquant = 0; /* it's the last MB of all, the easiest case */ + return; + } else { + MACROBLOCK * next = pMB + 1; + const MACROBLOCK * prev = pMB - 1; + if (next->mode != MODE_INTER4V && next->mode != MODE_NOT_CODED) + /* mode allows dquant change in the future */ + if (abs(next->quant - prev->quant) <= 2) { + /* quant change is not out of range */ + pMB->quant = prev->quant; + pMB->dquant = 0; + next->dquant = next->quant - prev->quant; + return; + } + } + } + /* couldn't skip this dquant */ + pMB->mode = MODE_INTER_Q; +} + static __inline void @@ -1603,10 +1629,6 @@ stop_comp_timer(); - if (pMB->dquant != 0) { - pMB->mode = MODE_INTER_Q; - } - pMB->field_pred = 0; if (pMB->mode != MODE_NOT_CODED) @@ -1615,6 +1637,10 @@ dct_codes, qcoeff); } + if (pMB->dquant != 0) + MBSetDquant(pMB, x, y, &pEnc->mbParam); + + if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y || pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x || pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) {