--- trunk/xvidcore/src/bitstream/mbcoding.c 2002/03/09 15:29:26 15 +++ trunk/xvidcore/src/bitstream/mbcoding.c 2002/03/26 11:16:08 69 @@ -5,6 +5,8 @@ #include "../utils/mbfunctions.h" +#include /* malloc, free */ + #define ESCAPE 7167 #define ABS(X) (((X)>0)?(X):-(X)) #define CLIP(X,A) (X > A) ? (A) : (X) @@ -54,7 +56,8 @@ char *max_run_ptr = max_run[last + (intra << 1)]; for(l = 0; l < 64; l++) { // run - int32_t level = k, run = l; + int32_t level = k; + uint32_t run = l; if(abs(level) <= max_level_ptr[run] && run <= max_run_ptr[abs(level)]) { @@ -98,9 +101,9 @@ level += max_level_ptr[run]; else level -= max_level_ptr[run]; - + run -= max_run_ptr[abs(level)] + 1; - + if(abs(level) <= max_level_ptr[run] && run <= max_run_ptr[abs(level)]) { @@ -263,14 +266,17 @@ { uint32_t i, mcbpc, cbpy, bits; - mcbpc = pMB->cbp & 3; cbpy = pMB->cbp >> 2; // write mcbpc - if(pParam->coding_type == I_VOP) - BitstreamPutBits(bs, mcbpc_I[mcbpc].code, mcbpc_I[mcbpc].len); - else - BitstreamPutBits(bs, mcbpc_P_intra[mcbpc].code, mcbpc_P_intra[mcbpc].len); + if(pParam->coding_type == I_VOP) { + mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2); + BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code, mcbpc_intra_tab[mcbpc].len); + } + else { + mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3); + BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, mcbpc_inter_tab[mcbpc].len); + } // ac prediction flag if(pMB->acpred_directions[0]) @@ -285,6 +291,12 @@ if(pMB->mode == MODE_INTRA_Q) BitstreamPutBits(bs, pMB->dquant, 2); + // write interlacing + if (pParam->global_flags & XVID_INTERLACING) + { + BitstreamPutBit(bs, pMB->field_dct); + } + // code block coeffs for(i = 0; i < 6; i++) { @@ -314,14 +326,11 @@ int32_t i; uint32_t bits, mcbpc, cbpy; - mcbpc = pMB->cbp & 3; + mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3); cbpy = 15 - (pMB->cbp >> 2); // write mcbpc - if(pMB->mode == MODE_INTER4V) - BitstreamPutBits(bs, mcbpc_P_inter4v[mcbpc].code, mcbpc_P_inter4v[mcbpc].len); - else - BitstreamPutBits(bs, mcbpc_P_inter[mcbpc].code, mcbpc_P_inter[mcbpc].len); + BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, mcbpc_inter_tab[mcbpc].len); // write cbpy BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len); @@ -330,6 +339,27 @@ if(pMB->mode == MODE_INTER_Q) BitstreamPutBits(bs, pMB->dquant, 2); + // interlacing + if (pParam->global_flags & XVID_INTERLACING) + { + BitstreamPutBit(bs, pMB->field_dct); + DEBUG1("codep: field_dct: ", pMB->field_dct); + + // if inter block, write field ME flag + if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) + { + BitstreamPutBit(bs, pMB->field_pred); + DEBUG1("codep: field_pred: ", pMB->field_pred); + + // write field prediction references + if (pMB->field_pred) + { + BitstreamPutBit(bs, pMB->field_for_top); + BitstreamPutBit(bs, pMB->field_for_bot); + } + } + } + // code motion vector(s) for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {