--- encoder.c 2003/07/29 23:02:29 1.95.2.35 +++ encoder.c 2003/08/22 16:11:58 1.95.2.39 @@ -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.35 2003/07/29 23:02:29 edgomez Exp $ + * $Id: encoder.c,v 1.95.2.39 2003/08/22 16:11:58 edgomez Exp $ * ****************************************************************************/ @@ -115,9 +115,9 @@ enc_create(xvid_enc_create_t * create) { Encoder *pEnc; - int n; + int n; - if (XVID_MAJOR(create->version) != 1) /* v1.x.x */ + if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ return XVID_ERR_VERSION; if (create->width%2 || create->height%2) @@ -226,8 +226,7 @@ pEnc->mbParam.frame_drop_ratio = MAX(create->frame_drop_ratio, 0); /* max keyframe interval */ - pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <= 0 ? - (10 * pEnc->mbParam.fbase) / pEnc->mbParam.fincr : create->max_key_interval; + pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <= 0 ? (10 * (int)pEnc->mbParam.fbase) / (int)pEnc->mbParam.fincr : create->max_key_interval; /* allocate working frame-image memory */ @@ -741,7 +740,7 @@ for (j=0; jmbParam.mb_height; j++) for (i=0; imbParam.mb_width; i++) { - data.dquant[j*data.dquant_stride + i] = frame->mbs[j*pEnc->mbParam.mb_width + i].dquant;; + data.dquant[j*data.dquant_stride + i] = frame->mbs[j*pEnc->mbParam.mb_width + i].dquant; } } @@ -771,7 +770,7 @@ } /* call plugins */ - for (i=0; inum_plugins;i++) { + for (i=0; i<(unsigned int)pEnc->num_plugins;i++) { emms(); if (pEnc->plugins[i].func) { if (pEnc->plugins[i].func(pEnc->plugins[i].param, opt, &data, 0) < 0) { @@ -867,7 +866,7 @@ int type; Bitstream bs; - if (XVID_MAJOR(xFrame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1)) /* v1.x.x */ + if (XVID_VERSION_MAJOR(xFrame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)) /* v1.x.x */ return XVID_ERR_VERSION; xFrame->out_flags = 0; @@ -1253,7 +1252,7 @@ * on next enc_encode call we must flush bframes * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ -done_flush: +/*done_flush:*/ pEnc->flush_bframes = 1; @@ -1285,6 +1284,10 @@ { unsigned int i,j; int quant = frame->quant; + if (quant > 31) + frame->quant = quant = 31; + else if (quant < 1) + frame->quant = quant = 1; for (j=0; jmb_height; j++) for (i=0; imb_width; i++) { @@ -1292,7 +1295,7 @@ quant += pMB->dquant; if (quant > 31) quant = 31; - if (quant < 1) + else if (quant < 1) quant = 1; pMB->quant = quant; } @@ -1480,7 +1483,7 @@ current->warp = GlobalMotionEst( current->mbs, pParam, current, reference, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); - if (current->motion_flags & XVID_GME_REFINE) { + if (current->motion_flags & XVID_ME_GME_REFINE) { gmcval = GlobalMotionEstRefine(¤t->warp, current->mbs, pParam, current, reference, @@ -1565,6 +1568,11 @@ current->sStat.kblks++; + 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; + } MBCoding(current, pMB, qcoeff, bs, ¤t->sStat); stop_coding_timer(); continue; @@ -1891,9 +1899,12 @@ } } -#ifdef BFRAMES_DEC_DEBUG - BFRAME_DEBUG -#endif + /* keep only bits 5-2 -- Chroma blocks will just be skipped by the + * coding function for BFrames, that's why we don't zero teh DC + * coeffs */ + if ((frame->vop_flags & XVID_VOP_GREYSCALE)) + mb->cbp &= 0x3C; + start_timer(); MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs, &frame->sStat, direction);