📄 mpeg2_vld_inter_c.c
字号:
void mpeg2_vld_inter_cn( const short *restrict Wptr, // quantization matrix short *restrict outi, // IDCT coefficients output array IMG_mpeg2_vld *restrict Mpeg2v, // bitstream context structure int mode_12Q4, // if !=0 returns coeffs in 12Q4 format int num_blocks, // number of blocks in the MB int bsbuf_words // bitstream buffer size){ /* ------------------------------------------------------------------------ *//* get bitstream info *//* ------------------------------------------------------------------------ */ unsigned int *bsbuf = Mpeg2v->bsbuf; int next_wptr = Mpeg2v->next_wptr; int bptr = Mpeg2v->bptr; unsigned int word1 = Mpeg2v->word1; unsigned int word2 = Mpeg2v->word2; unsigned int top0 = Mpeg2v->top0; unsigned int top1 = Mpeg2v->top1; const unsigned char *zzptr = Mpeg2v->scan; unsigned int qscl = Mpeg2v->quant_scale; unsigned int cbp = Mpeg2v->cbp; unsigned int bptr_cmpl, top0_bk, word1_rw; unsigned long ltop0, t1, t5; /* 40-bit registers *//* ------------------------------------------------------------------------ *//* block number (0-3: lum, 4, 5: chrom) *//* ------------------------------------------------------------------------ */ int block; /* ------------------------------------------------------------------------ *//* Variables for length, run and level decoding *//* ------------------------------------------------------------------------ */ unsigned int t2, t4, t7, t8, t9; int rld_left, rld_index; unsigned short run_level; unsigned char run, len, len_c; const unsigned char *t3; short level; unsigned int fault, eob_err, nrm; unsigned int test1, test2; /* ------------------------------------------------------------------------ *//* Variables for de-quantization *//* ------------------------------------------------------------------------ */ int neg, pos, f1, f3, f5, qW, sum, cc;#ifdef _TMS320C6X int f4;#else _int64 f4;#endif const short *Wptr_origin=Wptr; const short *Wptr_end; short W; unsigned char cnum; /* ------------------------------------------------------------------------ *//* Variables for 12Q4 mode *//* ------------------------------------------------------------------------ */ int mask, shr, lsb; /* ------------------------------------------------------------------------ *//* In 12Q4 mode the returned DCT coefficients are left shifted by 4, *//* i.e. in 12Q4 format. *//* ------------------------------------------------------------------------ */ if (mode_12Q4) { mask = 0xFFF0; /* clear 4 LSBs of 12Q4 number */ shr = 16; /* shift right after saturate shift */ lsb = 16; /* LSB for mismatch control */ } else { mask = 0xFFFF; /* keep 4 LSBs */ shr = 20; /* shift right after saturate shift */ lsb = 1; /* LSB for mismatch control */ } /* ------------------------------------------------------------------------ *//* Advance bitsream by 8 bit to convert to 40-bit top0 *//* ------------------------------------------------------------------------ */ ltop0 = ((long)top0 << 8) + (top1 >> 24); bptr += 8; test2 = (bptr >= 32); if (test2) { word1_rw = word1; word1 = word2; word2 = bsbuf[next_wptr]; next_wptr += 1; next_wptr &= (bsbuf_words-1); } bptr = bptr & 31; bptr_cmpl = 32 - bptr; t8 = SHL(word1, bptr); t9 = SHR(word2, bptr_cmpl); /* unsigned shift */ top1 = t8 + t9; fault = 0;/* ------------------------------------------------------------------------ *//* block loop *//* ------------------------------------------------------------------------ */ for (block=0; block<num_blocks; block++) { /* -------------------------------------------------------------------- */ /* cbp: Bit 5 4 3 2 1 0 , if the corresponding bit is zero block no. */ /* (5-bit pos) is not coded */ /* -------------------------------------------------------------------- */ if (!(cbp & (1 << (num_blocks-block-1)))) continue; zzptr = Mpeg2v->scan; cc = (block<4) ? 0 : (block&1)+1; if (cc!=0 && num_blocks>6) Wptr=Wptr_origin + 64; /* weighting matrix for chrominance */ else Wptr=Wptr_origin; /* weighting matrix for luminance */ Wptr_end = Wptr + 64; sum = 0; eob_err = 0; /* -------------------------------------------------------------------- */ /* Decode first coefficient */ /* */ /* First code is special case: when the MSB of the first code is '1', */ /* we know it can only be VLC '1s' (because EOB cannot occur and the */ /* only other code is '11s' which is not valid for the first code.) */ /* If MSB=0 skip to normal AC loop, i.e. use NORM+4 extra bits as */ /* table index; if MSB=1 execute special case, do not use */ /* NORM because it may have overrun but set LEN=2, LEN_C=30. */ /* -------------------------------------------------------------------- */ if (ltop0>>39) { /* ---------------------------------------------------------------- */ /* Length computation, not required since we know LEN is 2. */ /* ---------------------------------------------------------------- */ len = 2; len_c = 30; /* ---------------------------------------------------------------- */ /* now that we know the length of the current VL code we can */ /* advance bitstream to next one: */ /* */ /* 1. update ltop0 from ltop0 and top1 */ /* ---------------------------------------------------------------- */ t5 = ltop0 << len; t7 = top1 >> len_c; top0_bk = (unsigned) (ltop0>>8); ltop0 = t5 + t7; /* ---------------------------------------------------------------- */ /* 2. update top1 from word1 and word2 after increasing bptr by */ /* len. if neccesary (i.e. if new bptr is greater than 32) */ /* update word1 and word2 from memory first. Don't forget that */ /* bptr is always relative to the next lower word boundary and */ /* therefore needs to be ANDed with 31 in case it become >=32. */ /* ---------------------------------------------------------------- */ bptr += len; test2 = (bptr >= 32); if (test2) { word1_rw = word1; word1 = word2; word2 = bsbuf[next_wptr]; next_wptr += 1; next_wptr &= (bsbuf_words-1); } bptr = bptr & 31; bptr_cmpl = 32 - bptr; t8 = SHL(word1, bptr); t9 = SHR(word2, bptr_cmpl); /* unsigned shift */ top1 = t8 + t9; /* ---------------------------------------------------------------- */ /* Run-Level Decode: run = 0, level = 1 */ /* ---------------------------------------------------------------- */ neg = _extu(top0_bk,1,31); /* ---------------------------------------------------------------- */ /* Run-lengh expansion and DQ */ /* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */ /* Dequantisation: *out_i = ((2*level + Sign(level)) * W * qscl) */ /* / 32. Sign(x)=-1 for x<0, 0 for x=0, +1 for x>0. Division '/': */ /* "Integer division with truncation of the result toward zero. */ /* For example, 7/4 and -7/-4 are truncated to 1 and -7/4 and */ /* 7/-4 are truncated to -1." (MPEG-2 Standard Text) */ /* ---------------------------------------------------------------- */ if (neg) f1=-3; /* 2*(-1)-1 */ else f1=3; /* 2*1+1 */ /* ---------------------------------------------------------------- */ /* find quantization matrix element at zigzag position and */ /* multiply f1 with W * qscl */ /* ---------------------------------------------------------------- */ W = *Wptr++; qW = qscl * W; f3 = f1 * qW; /* ---------------------------------------------------------------- */ /* for negative numbers we first need to add 31 before dividing */ /* by 32 to achieve truncation towards zero as required by the */ /* standard. */ /* ---------------------------------------------------------------- */ if (neg) f3 += 31; /* ---------------------------------------------------------------- */ /* saturate to signed 12 bit word (with /32 <-> >>5 incorporated) */ /* SSHL: shift left and saturate to 32 bits */ /* ---------------------------------------------------------------- */ f4 = _sshl(f3, 15); f5 = (int)(f4 >> shr); f5 &= mask; /* ---------------------------------------------------------------- */ /* mismatch control: determine if sum of coefficents is odd or */ /* even */ /* ---------------------------------------------------------------- */ sum += f5; /* ---------------------------------------------------------------- */ /* find un-zigzag position of DCT coefficient */ /* ---------------------------------------------------------------- */ zzptr++; /* always 0 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -