📄 getpic.c
字号:
/* derive motion_type */ if (pict_struct==FRAME_PICTURE) motion_type = MC_FRAME; else { motion_type = MC_FIELD; /* predict from field of same parity */ mv_field_sel[0][0]=mv_field_sel[0][1] = (pict_struct==BOTTOM_FIELD); } /* skipped I are spatial-only predicted, */ /* skipped P and B are temporal-only predicted */ stwtype = (pict_type==I_TYPE) ? 8 : 0; /* clear MB_INTRA */ mb_type&= ~MB_INTRA; } if (twostreams && enhan.scalable_mode==SC_SNR) { ld = &enhan; if (SNRMBAinc==0) { if (!showbits(23)) /* startcode */ { startcode(); code = showbits(32); if (code<SLICE_MIN_START || code>SLICE_MAX_START) { /* only slice headers are allowed in picture_data */ if (!quiet) printf("Premature end of picture\n"); return; } flushbits(32); /* decode slice header (may change quant_scale) */ slice_vert_pos_ext = getslicehdr(); /* decode macroblock address increment */ SNRMBAinc = getMBA(); /* set current location */ SNRMBA = ((slice_vert_pos_ext<<7) + (code&255) - 1)*mb_width + SNRMBAinc - 1; SNRMBAinc = 1; /* first macroblock in slice: not skipped */ } else /* not startcode */ { if (SNRMBA>=MBAmax) { if (!quiet) printf("Too many macroblocks in picture\n"); return; } /* decode macroblock address increment */ SNRMBAinc = getMBA(); } } if (SNRMBA!=MBA) { /* streams out of sync */ if (!quiet) printf("Cant't synchronize streams\n"); return; } if (SNRMBAinc==1) /* not skipped */ { macroblock_modes(&SNRmb_type, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &SNRdct_type); if (SNRmb_type & MB_PATTERN) dct_type = SNRdct_type; if (SNRmb_type & MB_QUANT) { qs = getbits(5); ld->quant_scale = ld->qscale_type ? non_linear_mquant_table[qs] : qs<<1; } /* macroblock_pattern */ if (SNRmb_type & MB_PATTERN) { SNRcbp = getCBP(); if (chroma_format==CHROMA422) SNRcbp = (SNRcbp<<2) | getbits(2); /* coded_block_pattern_1 */ else if (chroma_format==CHROMA444) SNRcbp = (SNRcbp<<6) | getbits(6); /* coded_block_pattern_2 */ } else SNRcbp = 0; /* decode blocks */ for (comp=0; comp<blk_cnt; comp++) { clearblock(comp); if (SNRcbp & (1<<(blk_cnt-1-comp))) getmpg2interblock(comp); } } else /* SNRMBAinc!=1: skipped macroblock */ { for (comp=0; comp<blk_cnt; comp++) clearblock(comp); } ld = &base; } /* pixel coordinates of top left corner of current macroblock */ bx = 16*(MBA%mb_width); by = 16*(MBA/mb_width); /* motion compensation */ if (!(mb_type & MB_INTRA)) reconstruct(bx,by,mb_type,motion_type,PMV,mv_field_sel,dmvector, stwtype); if (base.scalable_mode==SC_DP) ld = &base; /* copy or add block data into picture */ for (comp=0; comp<blk_cnt; comp++) { if (twostreams && enhan.scalable_mode==SC_SNR) sumblock(comp); /* add SNR enhancement layer data to base layer */ /* MPEG-2 saturation and mismatch control */ if ((twostreams && enhan.scalable_mode==SC_SNR) || ld->mpeg2) saturate(ld->block[comp]); /* inverse DCT */ if (refidct) idctref(ld->block[comp]); else idct(ld->block[comp]); addblock(comp,bx,by,dct_type,(mb_type & MB_INTRA)==0); } /* advance to next macroblock */ MBA++; MBAinc--; if (twostreams && enhan.scalable_mode==SC_SNR) { SNRMBA++; SNRMBAinc--; } }}static void macroblock_modes(pmb_type,pstwtype,pstwclass, pmotion_type,pmv_count,pmv_format,pdmv,pmvscale,pdct_type) int *pmb_type, *pstwtype, *pstwclass; int *pmotion_type, *pmv_count, *pmv_format, *pdmv, *pmvscale; int *pdct_type;{ int mb_type; int stwtype, stwcode, stwclass; int motion_type, mv_count, mv_format, dmv, mvscale; int dct_type; static unsigned char stwc_table[3][4] = { {6,3,7,4}, {2,1,5,4}, {2,5,7,4} }; static unsigned char stwclass_table[9] = {0, 1, 2, 1, 1, 2, 3, 3, 4}; /* get macroblock_type */ mb_type = getMBtype(); if (fault) return; /* get spatial_temporal_weight_code */ if (mb_type & MB_WEIGHT) { if (stwc_table_index==0) stwtype = 4; else { stwcode = getbits(2); if (trace) { printf("spatial_temporal_weight_code ("); printbits(stwcode,2,2); printf("): %d\n",stwcode); } stwtype = stwc_table[stwc_table_index-1][stwcode]; } } else stwtype = (mb_type & MB_CLASS4) ? 8 : 0; /* derive spatial_temporal_weight_class (Table 7-18) */ stwclass = stwclass_table[stwtype]; /* get frame/field motion type */ if (mb_type & (MB_FORWARD|MB_BACKWARD)) { if (pict_struct==FRAME_PICTURE) /* frame_motion_type */ { motion_type = frame_pred_dct ? MC_FRAME : getbits(2); if (!frame_pred_dct && trace) { printf("frame_motion_type ("); printbits(motion_type,2,2); printf("): %s\n",motion_type==MC_FIELD?"Field": motion_type==MC_FRAME?"Frame": motion_type==MC_DMV?"Dual_Prime":"Invalid"); } } else /* field_motion_type */ { motion_type = getbits(2); if (trace) { printf("field_motion_type ("); printbits(motion_type,2,2); printf("): %s\n",motion_type==MC_FIELD?"Field": motion_type==MC_16X8?"16x8 MC": motion_type==MC_DMV?"Dual_Prime":"Invalid"); } } } else if ((mb_type & MB_INTRA) && conceal_mv) { /* concealment motion vectors */ motion_type = (pict_struct==FRAME_PICTURE) ? MC_FRAME : MC_FIELD; } /* derive mv_count, mv_format and dmv, (table 6-17, 6-18) */ if (pict_struct==FRAME_PICTURE) { mv_count = (motion_type==MC_FIELD && stwclass<2) ? 2 : 1; mv_format = (motion_type==MC_FRAME) ? MV_FRAME : MV_FIELD; } else { mv_count = (motion_type==MC_16X8) ? 2 : 1; mv_format = MV_FIELD; } dmv = (motion_type==MC_DMV); /* dual prime */ /* field mv predictions in frame pictures have to be scaled */ mvscale = ((mv_format==MV_FIELD) && (pict_struct==FRAME_PICTURE)); /* get dct_type (frame DCT / field DCT) */ dct_type = (pict_struct==FRAME_PICTURE) && (!frame_pred_dct) && (mb_type & (MB_PATTERN|MB_INTRA)) ? getbits(1) : 0; if (trace && (pict_struct==FRAME_PICTURE) && (!frame_pred_dct) && (mb_type & (MB_PATTERN|MB_INTRA))) printf("dct_type (%d): %s\n",dct_type,dct_type?"Field":"Frame"); /* return values */ *pmb_type = mb_type; *pstwtype = stwtype; *pstwclass = stwclass; *pmotion_type = motion_type; *pmv_count = mv_count; *pmv_format = mv_format; *pdmv = dmv; *pmvscale = mvscale; *pdct_type = dct_type;}/* set block to zero */static void clearblock(comp)int comp;{ short *bp; int i; bp = ld->block[comp]; for (i=0; i<64; i++) *bp++ = 0;}/* add SNR enhancement layer block data to base layer */static void sumblock(comp)int comp;{ short *bp1, *bp2; int i; bp1 = base.block[comp]; bp2 = enhan.block[comp]; for (i=0; i<64; i++) *bp1++ += *bp2++;}/* limit coefficients to -2048..2047 */static void saturate(bp)short *bp;{ int i, sum, val; sum = 0; /* saturation */ for (i=0; i<64; i++) { val = bp[i]; if (val>2047) val = 2047; else if (val<-2048) val = -2048; bp[i] = val; sum+= val; } /* mismatch control */ if ((sum&1)==0) bp[63]^= 1;}/* move/add 8x8-Block from block[comp] to refframe */static void addblock(comp,bx,by,dct_type,addflag)int comp,bx,by,dct_type,addflag;{ int cc,i, j, iincr; unsigned char *rfp; short *bp; cc = (comp<4) ? 0 : (comp&1)+1; /* color component index */ if (cc==0) { /* luminance */ if (pict_struct==FRAME_PICTURE) if (dct_type) { /* field DCT coding */ rfp = newframe[0] + coded_picture_width*(by+((comp&2)>>1)) + bx + ((comp&1)<<3); iincr = (coded_picture_width<<1) - 8; } else { /* frame DCT coding */ rfp = newframe[0] + coded_picture_width*(by+((comp&2)<<2)) + bx + ((comp&1)<<3); iincr = coded_picture_width - 8; } else { /* field picture */ rfp = newframe[0] + (coded_picture_width<<1)*(by+((comp&2)<<2)) + bx + ((comp&1)<<3); iincr = (coded_picture_width<<1) - 8; } } else { /* chrominance */ /* scale coordinates */ if (chroma_format!=CHROMA444) bx >>= 1; if (chroma_format==CHROMA420) by >>= 1; if (pict_struct==FRAME_PICTURE) { if (dct_type && (chroma_format!=CHROMA420)) { /* field DCT coding */ rfp = newframe[cc] + chrom_width*(by+((comp&2)>>1)) + bx + (comp&8); iincr = (chrom_width<<1) - 8; } else { /* frame DCT coding */ rfp = newframe[cc] + chrom_width*(by+((comp&2)<<2)) + bx + (comp&8); iincr = chrom_width - 8; } } else { /* field picture */ rfp = newframe[cc] + (chrom_width<<1)*(by+((comp&2)<<2)) + bx + (comp&8); iincr = (chrom_width<<1) - 8; } } bp = ld->block[comp]; if (addflag) { for (i=0; i<8; i++) { for (j=0; j<8; j++) { *rfp = clp[*bp++ + *rfp]; rfp++; } rfp+= iincr; } } else { for (i=0; i<8; i++) { for (j=0; j<8; j++) *rfp++ = clp[*bp++ + 128]; rfp+= iincr; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -