📄 mpeg2_vld_intra_c.c
字号:
/* Function *//* ------------------------------------------------------------------------ */void mpeg2_vld_intra_cn( const short *restrict Wptr, // quantization matrix short *restrict outi, // IDCT coefficients output array IMG_mpeg2_vld *restrict Mpeg2v, // bitstream context structure int dc_pred[3], // DC prediction array 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 intra_vlc_format = Mpeg2v->intravlc; unsigned int qscl = Mpeg2v->quant_scale; int intra_dc_precision = Mpeg2v->dc_prec; 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 intra DC decoding *//* ------------------------------------------------------------------------ */ unsigned int cc, a_cc0, a_cc1, b, c, d, dc_size; int dc_diff, val, half_range; /* ------------------------------------------------------------------------ *//* 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 eob_err, fault, nrm; unsigned int test1, test2; /* ------------------------------------------------------------------------ *//* Variables for de-quantization *//* ------------------------------------------------------------------------ */ int neg, f1, f3, f5, qW, sum;#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) { intra_dc_precision -= 4; /* shift left DC by 4 */ 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 ltop0 *//* ------------------------------------------------------------------------ */ 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; 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 (DC coefficient) for INTRA block */ /* -------------------------------------------------------------------- */ top0 = (unsigned) (ltop0>>8); /* -------------------------------------------------------------------- */ /* Intra DC: decode dct_size and len (luminance and chrominance) */ /* -------------------------------------------------------------------- */ a_cc0 = a_cc1 = 0; b = _lmbd(0, top0); c = top0 >> 30; d = top0 >> 29; len = b + 1; if (cc==0) { dc_size = b + 2; a_cc0 = (b>=9); /* the last VLC doesn't have a final 0! */ b = b >> 1; d -= 4; } else { dc_size = b + 1; a_cc1 = (b>=10); /* the last VLC doesn't have a final 0! */ d = 1; /* anything !=0 */ } if (!b) len++; if (!c) dc_size--; if (!d) dc_size-=3; if (a_cc0) { len=9; dc_size=11; } if (a_cc1) { len=10; dc_size=11; } /* -------------------------------------------------------------------- */ /* Intra DC: obtain QFS[0] from dc_size and dc_differential */ /* -------------------------------------------------------------------- */ dc_diff=0; t1 = top0 << len; if (dc_size!=0) { half_range = 1 << (dc_size-1); dc_diff = t1 >> (32-dc_size); if (dc_diff < half_range) dc_diff = (dc_diff+1)-(2*half_range); } val = (dc_pred[cc]+= dc_diff); /* -------------------------------------------------------------------- */ /* Intra DC: de-quantization and store result */ /* -------------------------------------------------------------------- */ outi[block*64+0] = val << (3-intra_dc_precision); /* -------------------------------------------------------------------- */ /* Intra DC: mismatch control */ /* -------------------------------------------------------------------- */ sum += outi[block*64+0]; /* -------------------------------------------------------------------- */ /* Intra DC: now that we know the length of the current VL code we */ /* can advance bitstream to next one, i.e. by len+dc_size: */ /* -------------------------------------------------------------------- */ len+=dc_size; /* -------------------------------------------------------------------- */ /* from here it's the same code as used in the loop for the other */ /* coefficients */ /* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */ /* 1. update ltop0 from ltop0 and top1 */ /* -------------------------------------------------------------------- */ t5 = ltop0 << len; t7 = top1 >> (32-len); 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -