📄 macroblock.c
字号:
if(listX[0][iref]->top_poc*2 == co_located_ref_id[refList][img->block_y_aff + j][img->block_x + k]
|| listX[0][iref]->bottom_poc*2 == co_located_ref_id[refList][img->block_y_aff + j][img->block_x + k])
{
mapped_idx=iref;
break;
}
else //! invalid index. Default to zero even though this case should not happen
mapped_idx=INVALIDINDEX;
continue;
}
if (dec_picture->ref_pic_num[img->current_slice_nr][LIST_0 + list_offset][iref]==co_located_ref_id[refList][img->block_y_aff + j][img->block_x + k])
{
mapped_idx=iref;
break;
}
else //! invalid index. Default to zero even though this case should not happen
mapped_idx=INVALIDINDEX;
}
if (INVALIDINDEX == mapped_idx)
{
error("temporal direct error\ncolocated block has ref that is unavailable",-1111);
}
dec_picture->ref_idx [LIST_0][img->block_y + j][img->block_x + k] = mapped_idx;
dec_picture->ref_idx [LIST_1][img->block_y + j][img->block_x + k] = 0;
}
}
}
}
}
}
}
// If multiple ref. frames, read reference frame for the MB *********************************
if(img->num_ref_idx_l0_active>1)
{
flag_mode = ( img->num_ref_idx_l0_active == 2 ? 1 : 0);
currSE.type = SE_REFFRAME;
dP = &(currSlice->partArr[partMap[SE_REFFRAME]]);
if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag) currSE.mapping = linfo_ue;
else currSE.reading = readRefFrame_CABAC;
for (j0=0; j0<4; j0+=step_v0)
{
for (i0=0; i0<4; i0+=step_h0)
{
k=2*(j0>>1)+(i0>>1);
if ((currMB->b8pdir[k]==0 || currMB->b8pdir[k]==2) && currMB->b8mode[k]!=0)
{
TRACE_STRING("ref_idx_l0");
img->subblock_x = i0;
img->subblock_y = j0;
if (!IS_P8x8 (currMB) || bframe || (!bframe && !img->allrefzero))
{
currSE.context = BType2CtxRef (currMB->b8mode[k]);
if( (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag) && flag_mode )
{
currSE.len = 1;
readSyntaxElement_FLC(&currSE, dP->bitstream);
currSE.value1 = 1 - currSE.value1;
}
else
{
currSE.value2 = LIST_0;
dP->readSyntaxElement (&currSE,img,dP);
}
refframe = currSE.value1;
}
else
{
refframe = 0;
}
for (j=img->block_y +j0; j<img->block_y +j0+step_v0;j++)
memset(&dec_picture->ref_idx[LIST_0][j][img->block_x + i0], refframe, step_h0 * sizeof(char));
}
}
}
}
else
{
for (j0=0; j0<4; j0+=step_v0)
{
for (i0=0; i0<4; i0+=step_h0)
{
k=2*(j0>>1)+(i0>>1);
if ((currMB->b8pdir[k]==0 || currMB->b8pdir[k]==2) && currMB->b8mode[k]!=0)
{
for (j=img->block_y + j0; j < img->block_y + j0+step_v0;j++)
memset(&dec_picture->ref_idx[LIST_0][j][img->block_x + i0], 0, step_h0 * sizeof(char));
}
}
}
}
// If backward multiple ref. frames, read backward reference frame for the MB *********************************
if(img->num_ref_idx_l1_active>1)
{
flag_mode = ( img->num_ref_idx_l1_active == 2 ? 1 : 0);
currSE.type = SE_REFFRAME;
dP = &(currSlice->partArr[partMap[SE_REFFRAME]]);
if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag)
currSE.mapping = linfo_ue;
else
currSE.reading = readRefFrame_CABAC;
for (j0=0; j0<4; j0+=step_v0)
{
for (i0=0; i0<4; i0+=step_h0)
{
k=2*(j0>>1)+(i0>>1);
if ((currMB->b8pdir[k]==1 || currMB->b8pdir[k]==2) && currMB->b8mode[k]!=0)
{
TRACE_STRING("ref_idx_l1");
img->subblock_x = i0;
img->subblock_y = j0;
currSE.context = BType2CtxRef (currMB->b8mode[k]);
if( (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag) && flag_mode )
{
currSE.len = 1;
readSyntaxElement_FLC(&currSE, dP->bitstream);
currSE.value1 = 1-currSE.value1;
}
else
{
currSE.value2 = LIST_1;
dP->readSyntaxElement (&currSE,img,dP);
}
refframe = currSE.value1;
for (j=img->block_y + j0; j<img->block_y + j0+step_v0;j++)
{
memset(&dec_picture->ref_idx[LIST_1][j][img->block_x + i0], refframe, step_h0 * sizeof(char));
}
}
}
}
}
else
{
for (j0=0; j0<4; j0+=step_v0)
{
for (i0=0; i0<4; i0+=step_h0)
{
k=2*(j0>>1)+(i0>>1);
if ((currMB->b8pdir[k]==1 || currMB->b8pdir[k]==2) && currMB->b8mode[k]!=0)
{
for (j=img->block_y + j0; j<img->block_y + j0+step_v0;j++)
memset(&dec_picture->ref_idx[LIST_1][ j][img->block_x + i0], 0, step_h0 * sizeof(char));
}
}
}
}
//===== READ FORWARD MOTION VECTORS =====
currSE.type = SE_MVD;
dP = &(currSlice->partArr[partMap[SE_MVD]]);
if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag) currSE.mapping = linfo_se;
else currSE.reading = readMVD_CABAC;
for (j0=0; j0<4; j0+=step_v0)
for (i0=0; i0<4; i0+=step_h0)
{
k=2*(j0>>1)+(i0>>1);
if ((currMB->b8pdir[k]==0 || currMB->b8pdir[k]==2) && (currMB->b8mode[k] !=0))//has forward vector
{
mv_mode = currMB->b8mode[k];
step_h = BLOCK_STEP [mv_mode][0];
step_v = BLOCK_STEP [mv_mode][1];
refframe = dec_picture->ref_idx[LIST_0][img->block_y+j0][img->block_x+i0];
for (j=j0; j<j0+step_v0; j+=step_v)
{
j4 = img->block_y+j;
for (i=i0; i<i0+step_h0; i+=step_h)
{
i4 = img->block_x+i;
// first make mv-prediction
SetMotionVectorPredictor (img, pmv, refframe, LIST_0, dec_picture->ref_idx, dec_picture->mv, i, j, 4*step_h, 4*step_v);
for (k=0; k < 2; k++)
{
TRACE_STRING("mvd_l0");
img->subblock_x = i; // position used for context determination
img->subblock_y = j; // position used for context determination
currSE.value2 = k<<1; // identifies the component; only used for context determination
dP->readSyntaxElement(&currSE,img,dP);
curr_mvd = currSE.value1;
vec=curr_mvd+pmv[k]; /* find motion vector */
for(jj=0;jj<step_v;jj++)
{
for(ii=0;ii<step_h;ii++)
{
dec_picture->mv [LIST_0][j4+jj][i4+ii][k] = vec;
currMB->mvd [LIST_0][j +jj][i +ii][k] = curr_mvd;
}
}
}
}
}
}
else if (currMB->b8mode[k=2*(j0>>1)+(i0>>1)]==0)
{
if (!img->direct_spatial_mv_pred_flag)
{
int list_offset = ((img->MbaffFrameFlag)&&(currMB->mb_field))? (mb_nr&0x01) ? 4 : 2 : 0;
int refList = (co_located_ref_idx[LIST_0 ][img->block_y_aff+j0][img->block_x+i0]== -1 ? LIST_1 : LIST_0);
int ref_idx = co_located_ref_idx[refList][img->block_y_aff+j0][img->block_x+i0];
if (ref_idx==-1)
{
for (j4=img->block_y+j0; j4<img->block_y+j0+step_v0; j4++)
{
for (i4=img->block_x+i0; i4<img->block_x+i0+step_h0; i4++)
{
dec_picture->ref_idx [LIST_1][j4][i4]=0;
dec_picture->ref_idx [LIST_0][j4][i4]=0;
for (ii=0; ii < 2; ii++)
{
dec_picture->mv [LIST_0][j4][i4][ii]=0;
dec_picture->mv [LIST_1][j4][i4][ii]=0;
}
}
}
}
else
{
int mapped_idx=-1, iref;
int j6;
for (iref = 0; iref < imin(img->num_ref_idx_l0_active, listXsize[LIST_0 + list_offset]); iref++)
{
int curr_mb_field = ((img->MbaffFrameFlag)&&(currMB->mb_field));
if(img->structure==0 && curr_mb_field==0)
{
// If the current MB is a frame MB and the colocated is from a field picture,
// then the co_located_ref_id may have been generated from the wrong value of
// frame_poc if it references it's complementary field, so test both POC values
if(listX[0][iref]->top_poc * 2 == co_located_ref_id[refList][img->block_y_aff + j0][img->block_x + i0]
|| listX[0][iref]->bottom_poc * 2 == co_located_ref_id[refList][img->block_y_aff + j0][img->block_x + i0])
{
mapped_idx=iref;
break;
}
else //! invalid index. Default to zero even though this case should not happen
mapped_idx=INVALIDINDEX;
continue;
}
if (dec_picture->ref_pic_num[img->current_slice_nr][LIST_0 + list_offset][iref]==co_located_ref_id[refList][img->block_y_aff+j0][img->block_x+i0])
{
mapped_idx=iref;
break;
}
else //! invalid index. Default to zero even though this case should not happen
mapped_idx=INVALIDINDEX;
}
if (INVALIDINDEX == mapped_idx)
{
error("temporal direct error\ncolocated block has ref that is unavailable",-1111);
}
for (j=j0; j<j0+step_v0; j++)
{
j4 = img->block_y+j;
j6 = img->block_y_aff + j;
for (i4=img->block_x+i0; i4<img->block_x+i0+step_h0; i4++)
{
mv_scale = img->mvscale[LIST_0 + list_offset][mapped_idx];
dec_picture->ref_idx [LIST_0][j4][i4] = mapped_idx;
dec_picture->ref_idx [LIST_1][j4][i4] = 0;
for (ii=0; ii < 2; ii++)
{
if (mv_scale == 9999 || listX[LIST_0+list_offset][mapped_idx]->is_long_term)
{
dec_picture->mv [LIST_0][j4][i4][ii] = co_located_mv[refList][j6][i4][ii];
dec_picture->mv [LIST_1][j4][i4][ii] = 0;
}
else
{
dec_picture->mv [LIST_0][j4][i4][ii] = (mv_scale * co_located_mv[refList][j6][i4][ii] + 128 ) >> 8;
dec_picture->mv [LIST_1][j4][i4][ii] = dec_picture->mv[LIST_0][j4][i4][ii] - co_located_mv[refList][j6][i4][ii];
}
}
}
}
}
}
}
}
//===== READ BACKWARD MOTION VECTORS =====
currSE.type = SE_MVD;
dP = &(currSlice->partArr[partMap[SE_MVD]]);
if (active_pps->entropy_coding_mode_flag == UVLC || dP->bitstream->ei_flag) currSE.mapping = linfo_se;
else currSE.reading = readMVD_CABAC;
for (j0=0; j0<4; j0+=step_v0)
{
for (i0=0; i0<4; i0+=step_h0)
{
k=2*(j0>>1)+(i0>>1);
if ((currMB->b8pdir[k]==1 || currMB->b8pdir[k]==2) && (currMB->b8mode[k]!=0))//has backward vector
{
mv_mode = currMB->b8mode[k];
step_h = BLOCK_STEP [mv_mode][0];
step_v = BLOCK_STEP [mv_mode][1];
refframe = dec_picture->ref_idx[LIST_1][img->block_y+j0][img->block_x+i0];
for (j=j0; j<j0+step_v0; j+=step_v)
{
j4 = img->block_y+j;
for (i=i0; i<i0+step_h0; i+=step_h)
{
i4 = img->block_x+i;
// first make mv-prediction
SetMotionVectorPredictor (img, pmv, refframe, LIST_1, dec_picture->ref_idx, dec_picture->mv, i, j, 4*step_h, 4*step_v);
for (k=0; k < 2; k++)
{
TRACE_STRING("mvd_l1");
img->subblock_x = i; // position used for context determination
img->subblock_y = j; // position used for context determination
currSE.value2 = (k<<1) +1; // identifies the component; only used for context determination
dP->readSyntaxElement(&currSE,img,dP);
curr_mvd = currSE.value1;
vec=curr_mvd+pmv[k]; /* find motion vector */
for(jj=0;jj<step_v;jj++)
{
for(ii=0;ii<step_h;ii++)
{
dec_picture->mv [LIST_1][j4+jj][i4+ii][k] = vec;
currMB->mvd [LIST_1][j+jj] [i+ii] [k] = curr_mvd;
}
}
}
}
}
}
}
}
// record reference picture Ids for deblocking decisions
for(j4=img->block_y;j4<(img->block_y+4);j4++)
{
for(i4=img->block_x;i4<(img->block_x+4);i4++)
{
if (dec_picture->ref_idx[LIST_0][j4][i4]>=0)
dec_picture->ref_pic_id[LIST_0][j4][i4] = dec_picture->ref_pic_num[img->current_slice_nr][LIST_0 + list_offset][(short)dec_picture->ref_idx[LIST_0][j4][i4]];
else
dec_picture->ref_pic_id[LIST_0][j4][i4] = INT64_MIN;
if (dec_picture->ref_idx[LIST_1][j4][i4]>=0)
dec_picture->ref_pic_id[LIST_1][j4][i4] = dec_picture->ref_pic_num[img->current_slice_nr][LIST_1 + list_offset][(short)dec_picture->ref_idx[LIST_1][j4][i4]];
else
dec_picture->ref_pic_id[LIST_1][j4][i4] = INT64_MIN;
}
}
}
/*!
************************************************************************
* \brief
* Get the Prediction from the Neighboring Blocks for Number of Nonzero Coefficients
*
* Luma Blocks
************************************************************************
*/
int predict_nnz(struct img_par *img, int i,int j)
{
PixelPos pix;
int pred_nnz = 0;
int cnt = 0;
int mb_nr = img->cur
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -