📄 getpic.cpp
字号:
CBPY = CBPY^15; /* needed in huffman coding only */
}
CBP = (CBPY << 2) | (MCBPC >> 4);
}
if (Mode == MODE_INTER4V && !adv_pred_mode)
if (!quiet)
fputs("8x8 vectors not allowed in normal prediction mode\n",dlog);
/* Could set fault-flag and resync */
if (Mode == MODE_INTER_Q || Mode == MODE_INTRA_Q) {
/* Read DQUANT if necessary */
if (syntax_arith_coding) {
DQUANT_index = decode_a_symbol(cumf_DQUANT);
DQUANT = dquanttab[DQUANT_index] - 2;
quant +=DQUANT;
//if (trace)
//printf("DQUANT Index: %d DQUANT %d \n",DQUANT_index, DQUANT);
}
else {
DQUANT = getbits(2);
quant += DQ_tab[DQUANT];
if (trace) {
fputs("DQUANT (",dlog);
printbits(DQUANT,2,2);
//printf("): %d = %d\n",DQUANT,DQ_tab[DQUANT]);
}
}
if (quant > 31 || quant < 1) {
if (!quiet)
fputs("Quantizer out of range: clipping\n",dlog);
quant = mmax(1,mmin(31,quant));
/* could set fault-flag and resync here */
}
}
/* motion vectors */
if (Mode == MODE_INTER || Mode == MODE_INTER_Q ||
Mode == MODE_INTER4V || pb_frame) {
if (Mode == MODE_INTER4V) { startmv = 1; stopmv = 4;}
else { startmv = 0; stopmv = 0;}
for (k = startmv; k <= stopmv; k++) {
if (syntax_arith_coding) {
mvx_index = decode_a_symbol(cumf_MVD);
mvx = mvdtab[mvx_index];
mvy_index = decode_a_symbol(cumf_MVD);
mvy = mvdtab[mvy_index];
//if (trace)
// printf("mvx_index: %d mvy_index: %d \n", mvy_index, mvx_index);
}
else {
mvx = getTMNMV();
mvy = getTMNMV();
}
pmv0 = find_pmv(xpos,ypos,k,0);
pmv1 = find_pmv(xpos,ypos,k,1);
mvx = motion_decode(mvx, pmv0);
mvy = motion_decode(mvy, pmv1);
/* if (trace) {
printf("mvx: %d\n", mvx);
printf("mvy: %d\n", mvy);
}
*/
/* 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)
fputs("mvx out of range: searching for sync\n",dlog);
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)
fputs("mvy out of range: searching for sync\n",dlog);
fault = 1;
}
}
MV[0][k][ypos+1][xpos+1] = mvx;
MV[1][k][ypos+1][xpos+1] = mvy;
}
/* PB frame delta vectors */
if (pb_frame) {
if (MODB == PBMODE_MVDB || MODB == PBMODE_CBPB_MVDB) {
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 {
mvdbx = getTMNMV();
mvdby = getTMNMV();
}
mvdbx = motion_decode(mvdbx, 0);
mvdby = motion_decode(mvdby, 0);
/* 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 in this program. I don't think PB
deltas outside the range mentioned above is useful, but
you never know... */
/*if (trace) {
printf("MVDB x: %d\n", mvdbx);
printf("MVDB y: %d\n", mvdby);
}
*/
}
else {
mvdbx = 0;
mvdby = 0;
}
}
}
if (fault) goto resync;
}
else { /* COD == 1 --> skipped MB */
if (MBA>=MBAmax)
return; /* all macroblocks decoded */
if (!syntax_arith_coding)
if (pict_type == PCT_INTER)
flushbits(1);
Mode = MODE_INTER;
/* Reset CBP */
CBP = CBPB = 0;
/* reset motion vectors */
MV[0][0][ypos+1][xpos+1] = 0;
MV[1][0][ypos+1][xpos+1] = 0;
mvdbx = 0;
mvdby = 0;
}
/* Store Mode*/
modemap[ypos+1][xpos+1] = Mode;
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) {
Mode = modemap[by/16+1][bx/16+1];
/* forward motion compensation for B-frame */
if (pb_frame)
reconstruct(bx,by,0,pmvdbx,pmvdby);
/* motion compensation for P-frame */
if (Mode == MODE_INTER || Mode == MODE_INTER_Q || Mode == MODE_INTER4V)
reconstruct(bx,by,1,0,0);
/* 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) {
/* add block data into B-picture */
for (comp = 6; comp<blk_cnt+6; comp++) {
if (!pCOD || adv_pred_mode)
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) { /* Intra */
bp = ld->block[comp];
if(syntax_arith_coding) {
INTRADC_index = decode_a_symbol(cumf_INTRADC);
bp[0] = intradctab[INTRADC_index];
//if (trace)
// printf("INTRADC Index: %d INTRADC: %d \n", INTRADC_index, bp[0]);
}
else {
bp[0] = getbits(8);
/*if (trace) {
printf("DC[%d]: (",comp);
printbits((int)bp[0],8,8);
printf("): %d\n",(int)bp[0]);
}
*/
}
if (bp[0] == 128)
if (!quiet)
fputs("Illegal DC-coeff: 1000000\n",dlog);
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);
else
get_sac_block(comp,0);
}
}
else { /* Inter */
if ( (CBP & (1<<(blk_cnt-1-comp))) ) {
if (!syntax_arith_coding)
getblock(comp,1);
else
get_sac_block(comp,1);
}
}
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);
else
get_sac_block(comp,1);
}
if (fault) goto resync;
}
}
}
/* advance to next macroblock */
MBA++;
pCBP = CBP; pCBPB = CBPB; pCOD = COD;
pmvdbx = mvdbx; pmvdby = mvdby;
fflush(stdout);
if (MBA >= MBAmax && !last_done) {
COD = 1;
xpos = 0;
ypos++;
last_done = 1;
goto reconstruct_mb;
}
}
}
/* set block to zero */
static void clearblock(int comp)
{
int *bp;
int i;
bp = (int *)ld->block[comp];
for (i=0; i<8; i++)
{
bp[0] = bp[1] = bp[2] = bp[3] = 0;
bp += 4;
}
}
/* move/add 8x8-Block from block[comp] to refframe or bframe */
static void addblock(int comp,int bx,int by,int addflag)
{
int cc,i, iincr, P = 1;
unsigned char *rfp;
short *bp;
bp = ld->block[comp];
if (comp >= 6) {
/* This is a component for B-frame forward prediction */
P = 0;
addflag = 1;
comp -= 6;
}
cc = (comp<4) ? 0 : (comp&1)+1; /* color component index */
if (cc==0) {
/* luminance */
/* frame DCT coding */
if (P)
rfp = newframe[0]
+ coded_picture_width*(by+((comp&2)<<2)) + bx + ((comp&1)<<3);
else
rfp = bframe[0]
+ coded_picture_width*(by+((comp&2)<<2)) + bx + ((comp&1)<<3);
iincr = coded_picture_width;
}
else {
/* chrominance */
/* scale coordinates */
bx >>= 1;
by >>= 1;
/* frame DCT coding */
if (P)
rfp = newframe[cc] + chrom_width*by + bx;
else
rfp = bframe[cc] + chrom_width*by + bx;
iincr = chrom_width;
}
if (addflag) {
for (i=0; i<8; i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -