--- branches/dev-api-3/xvidcore/src/bitstream/mbcoding.c 2002/11/03 01:43:32 622 +++ branches/dev-api-3/xvidcore/src/bitstream/mbcoding.c 2003/01/11 14:59:24 769 @@ -41,7 +41,7 @@ * * * Revision history: * * * - * 28.10.2002 GMC support - gruel * + * 04.01.2003 GMC support - gruel * * 28.06.2002 added check_resync_marker() * * 14.04.2002 bframe encoding * * 08.03.2002 initial version; isibaar * @@ -49,9 +49,10 @@ ******************************************************************************/ - +#include #include #include "../portab.h" +#include "../global.h" #include "bitstream.h" #include "zigzag.h" #include "vlc_codes.h" @@ -59,11 +60,8 @@ #include "../utils/mbfunctions.h" -#define ABS(X) (((X)>0)?(X):-(X)) -#define CLIP(X,A) (X > A) ? (A) : (X) - -VLC intra_table[524032]; -VLC inter_table[524032]; +VLC intra_table[4*2048*64]; +VLC inter_table[4*2048*64]; VLC DCT3Dintra[4096]; VLC DCT3Dinter[4096]; @@ -83,6 +81,19 @@ if (len) BitstreamPutBits(bs, code, len); } +int bs_get_spritetrajectory(Bitstream * bs) +{ + int i; + for (i = 0; i < 12; i++) + { + if (BitstreamShowBits(bs, sprite_trajectory_len[i].len) == sprite_trajectory_len[i].code) + { + BitstreamSkip(bs, sprite_trajectory_len[i].len); + return i; + } + } + return -1; +} void init_vlc_tables(void) @@ -395,7 +406,6 @@ int32_t i; uint32_t bits, mcbpc, cbpy; - int mcsel=0; mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3); cbpy = 15 - (pMB->cbp >> 2); @@ -406,14 +416,8 @@ if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) ) { - if (frame->quarterpel) { - if ( (pMB->qmvs[0].x == frame->GMC_MV.x) && (pMB->qmvs[0].y == frame->GMC_MV.y) ) - mcsel=1; - } else { - if ( (pMB->mvs[0].x == frame->GMC_MV.x) && (pMB->mvs[0].y == frame->GMC_MV.y) ) - mcsel=1; - } - BitstreamPutBit(bs, mcsel); // mcsel: '0'=local motion, '1'=GMC + /* decision on GMC is done in encoder.c now */ + BitstreamPutBit(bs, pMB->mcsel); // mcsel: '0'=local motion, '1'=GMC } // write cbpy @@ -427,13 +431,13 @@ if (frame->global_flags & XVID_INTERLACING) { if (pMB->cbp) { BitstreamPutBit(bs, pMB->field_dct); - DEBUG1("codep: field_dct: ", pMB->field_dct); + DPRINTF(DPRINTF_MB,"codep: field_dct: %i", 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); + DPRINTF(DPRINTF_MB,"codep: field_pred: %i", pMB->field_pred); // write field prediction references if (pMB->field_pred) { @@ -443,7 +447,7 @@ } } // code motion vector(s) if motion is local - if (mcsel==0) + if (!pMB->mcsel) for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) { CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat); CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat); @@ -670,7 +674,7 @@ uint32_t index; - index = CLIP(BitstreamShowBits(bs, 9), 256); + index = MIN(BitstreamShowBits(bs, 9), 256); BitstreamSkip(bs, mcbpc_inter_table[index].len); @@ -818,7 +822,7 @@ do { level = get_coeff(bs, &run, &last, 1, 0); if (run == -1) { - DEBUG("fatal: invalid run"); + DPRINTF(DPRINTF_ERROR,"fatal: invalid run"); break; } coeff += run; @@ -827,8 +831,8 @@ DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level); //DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32)); - if (level < -127 || level > 127) { - DEBUG1("warning: intra_overflow", level); + if (level < -2047 || level > 2047) { + DPRINTF(DPRINTF_ERROR,"warning: intra_overflow %i", level); } coeff++; } while (!last); @@ -851,7 +855,7 @@ do { level = get_coeff(bs, &run, &last, 0, 0); if (run == -1) { - DEBUG("fatal: invalid run"); + DPRINTF(DPRINTF_ERROR,"fatal: invalid run"); break; } p += run; @@ -861,8 +865,8 @@ DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level); // DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32)); - if (level < -127 || level > 127) { - DEBUG1("warning: inter_overflow", level); + if (level < -2047 || level > 2047) { + DPRINTF(DPRINTF_ERROR,"warning: inter overflow %i", level); } p++; } while (!last);