📄 getpic.c
字号:
else { if (plus_type && long_vectors) { mvx = getRVLC (); mvy = getRVLC (); /* flush start code emulation bit */ if (mvx == 1 && mvy == 1) flushbits(1); } else { mvx = getTMNMV (); mvy = getTMNMV (); } } pmv0 = find_pmv (xpos, ypos, k, 0); pmv1 = find_pmv (xpos, ypos, k, 1); if (plus_type && long_vectors && !syntax_arith_coding) { mvx += pmv0; mvy += pmv1; } else { mvx = motion_decode (mvx, pmv0); mvy = motion_decode (mvy, pmv1); } if (trace) { fprintf (trace_file, "mvx: %d\n", mvx); fprintf (trace_file, "mvy: %d\n", mvy); } /* store coded or not-coded */ coded_map[ypos + 1][xpos + 1] = 1; /* Check mv's to prevent seg.faults when error rate is high */ if (!mv_outside_frame) { bsize = k ? 8 : 16; offset = k ? (((k - 1) & 1) << 3) : 0; /* checking only integer component */ if ((xpos << 4) + (mvx / 2) + offset < 0 || (xpos << 4) + (mvx / 2) + offset > (mb_width << 4) - bsize) { if (!quiet) printf ("mvx out of range: searching for sync\n"); fault = 1; } offset = k ? (((k - 1) & 2) << 2) : 0; if ((ypos << 4) + (mvy / 2) + offset < 0 || (ypos << 4) + (mvy / 2) + offset > (mb_height << 4) - bsize) { if (!quiet) printf ("mvy out of range: searching for sync\n"); fault = 1; } } true_B_direct_mode_MV[0][k][ypos + 1][xpos + 1] = MV[0][k][ypos + 1][xpos + 1] = mvx; true_B_direct_mode_MV[1][k][ypos + 1][xpos + 1] = MV[1][k][ypos + 1][xpos + 1] = mvy; } /* PB frame delta vectors */ if (pb_frame) { if (((MODB == PBMODE_MVDB || MODB == PBMODE_CBPB_MVDB) && pb_frame == PB_FRAMES) || (pb_frame == IM_PB_FRAMES && (MODB == PBMODE_CBPB_FRW_PRED || MODB == PBMODE_FRW_PRED))) { if (syntax_arith_coding) { mvdbx_index = decode_a_symbol (cumf_MVD); mvdbx = mvdtab[mvdbx_index]; mvdby_index = decode_a_symbol (cumf_MVD); mvdby = mvdtab[mvdby_index]; } else { if (plus_type && long_vectors) { mvdbx = getRVLC (); mvdby = getRVLC (); /* flush start code emulation bit */ if (mvdbx == 1 && mvdby == 1) flushbits(1); } else { mvdbx = getTMNMV (); mvdby = getTMNMV (); } } long_vectors_bak = long_vectors; /* turn off long vectors when decoding forward motion vector * of im.pb frames */ pmv0 = 0; pmv1 = 0; if (pb_frame == IM_PB_FRAMES && (MODB == PBMODE_CBPB_FRW_PRED || MODB == PBMODE_FRW_PRED)) { long_vectors = 0; if (MBA % mb_width && (pMODB == PBMODE_CBPB_FRW_PRED || pMODB == PBMODE_FRW_PRED)) { /* MBA%mb_width : if not new gob */ pmv0 = pmvdbx; pmv1 = pmvdby; } } if (plus_type && long_vectors && !syntax_arith_coding) { mvdbx += pmv0; mvdby += pmv1; } else { mvdbx = motion_decode (mvdbx, pmv0); mvdby = motion_decode (mvdby, pmv1); } long_vectors = long_vectors_bak; /* This will not work if the PB deltas are so large they * require the second colums of the motion vector VLC table to * be used. To fix this it is necessary to calculate the MV * predictor for the PB delta: TRB*MV/TRD here, and use this * as the second parameter to motion_decode(). The B vector * itself will then be returned from motion_decode(). This * will have to be changed to the PB delta again, since it is * the PB delta which is used later */ if (trace) { fprintf (trace_file, "MVDB x: %d\n", mvdbx); fprintf (trace_file, "MVDB y: %d\n", mvdby); } } else { mvdbx = 0; mvdby = 0; } } } /* Intra. */ else { /* Set MVs to 0 for potential future use in true B direct mode * prediction. */ if (PCT_INTER == pict_type) { for (k=0; k<5; k++) { true_B_direct_mode_MV[0][k][ypos + 1][xpos + 1] = 0; true_B_direct_mode_MV[1][k][ypos + 1][xpos + 1] = 0; } } } if (fault) goto resync; } else { /* COD == 1 --> skipped MB */ if (MBA >= MBAmax) { /* all macroblocks decoded */ memcpy(anchorframemodemap,modemap,(sizeof(int)*(MBR+1)*(MBC+2)) ); return; } if (!syntax_arith_coding) if (PCT_INTER == pict_type || PCT_IPB == pict_type) flushbits (1); Mode = MODE_INTER; /* Reset CBP */ CBP = CBPB = 0; coded_map[ypos + 1][xpos + 1] = 0; /* reset motion vectors */ MV[0][0][ypos + 1][xpos + 1] = 0; MV[1][0][ypos + 1][xpos + 1] = 0; if (PCT_INTER == pict_type) { for (k=0; k<5; k++) { true_B_direct_mode_MV[0][k][ypos + 1][xpos + 1] = 0; true_B_direct_mode_MV[1][k][ypos + 1][xpos + 1] = 0; } } mvdbx = 0; mvdby = 0; } /* Store mode and prediction type */ modemap[ypos + 1][xpos + 1] = Mode; /* store defaults for advanced intra coding mode */ if (advanced_intra_coding) { for (i = 0; i < blk_cnt; i++) store_qcoeff[MBA * blk_cnt * 64 + i * 64] = 1024; } if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) { if (!pb_frame) { MV[0][0][ypos + 1][xpos + 1] = MV[1][0][ypos + 1][xpos + 1] = 0; } }reconstruct_mb: /* pixel coordinates of top left corner of current macroblock */ /* one delayed because of OBMC */ if (xpos > 0) { bx = 16 * (xpos - 1); by = 16 * ypos; } else { bx = coded_picture_width - 16; by = 16 * (ypos - 1); } if (MBA > 0 && !dont_reconstruct_next_mb) { Mode = modemap[by / 16 + 1][bx / 16 + 1]; /* forward motion compensation for B-frame */ if (pb_frame) { if (pCOD) { /* if the macroblock is not coded then it is bidir predicted */ pMODB = PBMODE_BIDIR_PRED; reconstruct (bx, by, 0, pmvdbx, pmvdby, PBMODE_BIDIR_PRED, pnewgob); } else { if (!(pb_frame == IM_PB_FRAMES && (pMODB == PBMODE_CBPB_BCKW_PRED || pMODB == PBMODE_BCKW_PRED))) reconstruct (bx, by, 0, pmvdbx, pmvdby, pMODB, pnewgob); } } /* motion compensation for P-frame */ if (Mode == MODE_INTER || Mode == MODE_INTER_Q || Mode == MODE_INTER4V || Mode == MODE_INTER4V_Q) { reconstruct (bx, by, 1, 0, 0, pMODB, pnewgob); } /* copy or add block data into P-picture */ for (comp = 0; comp < blk_cnt; comp++) { /* inverse DCT */ if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) { if (refidct) idctref (ld->block[comp]); else idct (ld->block[comp]); addblock (comp, bx, by, 0); } else if ((pCBP & (1 << (blk_cnt - 1 - comp)))) { /* No need to to do this for blocks with no coeffs */ if (refidct) idctref (ld->block[comp]); else idct (ld->block[comp]); addblock (comp, bx, by, 1); } } if (pb_frame) { if (pMODB == PBMODE_CBPB_BCKW_PRED || pMODB == PBMODE_BCKW_PRED) { reconstruct (bx, by, 0, 0, 0, pMODB, pnewgob); } /* add block data into B-picture */ for (comp = 6; comp < blk_cnt + 6; comp++) { if (!pCOD || adv_pred_mode) { if (pb_frame == IM_PB_FRAMES) { if (pMODB == PBMODE_CBPB_BIDIR_PRED || pMODB == PBMODE_BIDIR_PRED || pCOD) { reconblock_b (comp - 6, bx, by, Mode, 0, 0); } } else { reconblock_b (comp - 6, bx, by, Mode, pmvdbx, pmvdby); } } if ((pCBPB & (1 << (blk_cnt - 1 - comp % 6)))) { if (refidct) idctref (ld->block[comp]); else idct (ld->block[comp]); addblock (comp, bx, by, 1); } } } } /* end if (MBA > 0) */ if (!COD) { Mode = modemap[ypos + 1][xpos + 1]; /* decode blocks */ for (comp = 0; comp < blk_cnt; comp++) { clearblock (comp); if ((Mode == MODE_INTRA || Mode == MODE_INTRA_Q) && !(advanced_intra_coding)) { /* Intra (except in advanced intra coding mode) */ bp = ld->block[comp]; if (syntax_arith_coding) { INTRADC_index = decode_a_symbol (cumf_INTRADC); bp[0] = intradctab[INTRADC_index]; if (trace) fprintf (trace_file, "INTRADC Index: %d INTRADC: %d \n", INTRADC_index, bp[0]); } else { bp[0] = getbits (8); if (trace) { fprintf (trace_file, "DC[%d]: (", comp); printbits ((int) bp[0], 8, 8); fprintf (trace_file, "): %d\n", (int) bp[0]); } } if (bp[0] == 128) if (!quiet) fprintf (stderr, "Illegal DC-coeff: 1000000\n"); if (bp[0] == 255) /* Spec. in H.26P, not in TMN4 */ bp[0] = 128; bp[0] *= 8; /* Iquant */ if ((CBP & (1 << (blk_cnt - 1 - comp)))) { if (!syntax_arith_coding) getblock (comp, 0, 0, Mode); else get_sac_block (comp, 0, 0, Mode); } } else { /* Inter (or Intra in advanced intra coding mode) */ if ((CBP & (1 << (blk_cnt - 1 - comp)))) { if (!syntax_arith_coding) getblock (comp, 1, INTRA_AC_DC, Mode); else get_sac_block (comp, 1, INTRA_AC_DC, Mode); } } if ((advanced_intra_coding) && (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)) { Intra_AC_DC_Decode (store_qcoeff, INTRA_AC_DC, MBA, xpos, ypos, comp, newgob); memcpy ((void *) (store_qcoeff + MBA * blk_cnt * 64 + comp * 64), (void *) ld->block[comp], sizeof (short) * 64); } if (fault) goto resync; } /* Decode B blocks */ if (pb_frame) { for (comp = 6; comp < blk_cnt + 6; comp++) { clearblock (comp); if ((CBPB & (1 << (blk_cnt - 1 - comp % 6)))) { if (!syntax_arith_coding) getblock (comp, 1, 0, MODE_INTER); else get_sac_block (comp, 1, 0, MODE_INTER); } if (fault) goto resync; } } } conceal_gob: /* decode the last MB if data is missing */ if (decode_last_mb) { conceal_missing_gobs(start_mb_row_missing, number_of_mb_rows_missing); /* all macroblocks in the picture are done, return * if the first gob in the next frame is also missing, * we will also lose the secon gob of that next frame. * This can be dealt with, but we will live with that for now. */ if ( (number_of_mb_rows_missing + start_mb_row_missing) * mb_width >= MBAmax) return; ypos = gob; decode_last_mb = 0; dont_reconstruct_next_mb = 1; goto finish_gob; } else { /* advance to next macroblock */ MBA++; pCBP = CBP; pCBPB = CBPB; pCOD = COD; pMODB = MODB; quant_map[ypos + 1][xpos + 1] = quant; pmvdbx = mvdbx; pmvdby = mvdby; fflush (stdout); pnewgob = newgob; if (MBA >= MBAmax && !last_done) { COD = 1; xpos = 0; ypos++; last_done = 1; goto reconstruct_mb; } } }}/********************************************************************** * * Name: get_B_MBs * Description: decode MBs for one B picture
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -