📄 macroblock.c
字号:
for (hv=0; hv < 2; hv++)
{
if (!img->MbaffFrameFlag || hv==0)
{
mv_a = block_a.available ? tmp_mv[list][block_a.pos_x][block_a.pos_y][hv] : 0;
mv_b = block_b.available ? tmp_mv[list][block_b.pos_x][block_b.pos_y][hv] : 0;
mv_c = block_c.available ? tmp_mv[list][block_c.pos_x][block_c.pos_y][hv] : 0;
}
else
{
if (img->mb_data[img->current_mb_nr].mb_field)
{
mv_a = block_a.available ? img->mb_data[block_a.mb_addr].mb_field?
tmp_mv[list][block_a.pos_x][block_a.pos_y][hv]:
tmp_mv[list][block_a.pos_x][block_a.pos_y][hv] / 2:
0;
mv_b = block_b.available ? img->mb_data[block_b.mb_addr].mb_field?
tmp_mv[list][block_b.pos_x][block_b.pos_y][hv]:
tmp_mv[list][block_b.pos_x][block_b.pos_y][hv] / 2:
0;
mv_c = block_c.available ? img->mb_data[block_c.mb_addr].mb_field?
tmp_mv[list][block_c.pos_x][block_c.pos_y][hv]:
tmp_mv[list][block_c.pos_x][block_c.pos_y][hv] / 2:
0;
}
else
{
mv_a = block_a.available ? img->mb_data[block_a.mb_addr].mb_field?
tmp_mv[list][block_a.pos_x][block_a.pos_y][hv] * 2:
tmp_mv[list][block_a.pos_x][block_a.pos_y][hv]:
0;
mv_b = block_b.available ? img->mb_data[block_b.mb_addr].mb_field?
tmp_mv[list][block_b.pos_x][block_b.pos_y][hv] * 2:
tmp_mv[list][block_b.pos_x][block_b.pos_y][hv]:
0;
mv_c = block_c.available ? img->mb_data[block_c.mb_addr].mb_field?
tmp_mv[list][block_c.pos_x][block_c.pos_y][hv] * 2:
tmp_mv[list][block_c.pos_x][block_c.pos_y][hv]:
0;
}
}
switch (mvPredType)
{
case MVPRED_MEDIAN:
if(!(block_b.available || block_c.available))
pred_vec = mv_a;
else
pred_vec = mv_a+mv_b+mv_c-min(mv_a,min(mv_b,mv_c))-max(mv_a,max(mv_b,mv_c));
break;
case MVPRED_L:
pred_vec = mv_a;
break;
case MVPRED_U:
pred_vec = mv_b;
break;
case MVPRED_UR:
pred_vec = mv_c;
break;
default:
break;
}
if (hv==0) *pmv_x = pred_vec;
else *pmv_y = pred_vec;
}
}
/*!
************************************************************************
* \brief
* Set context for reference frames
************************************************************************
*/
int
BType2CtxRef (int btype)
{
if (btype<4) return 0;
else return 1;
}
/*!
************************************************************************
* \brief
* Read motion info
************************************************************************
*/
void readMotionInfoFromNAL (struct img_par *img, struct inp_par *inp)
{
int i,j,k;
int step_h,step_v;
int curr_mvd;
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
SyntaxElement currSE;
Slice *currSlice = img->currentSlice;
DataPartition *dP;
int *partMap = assignSE2partition[currSlice->dp_mode];
int bframe = (img->type==B_SLICE);
int partmode = (IS_P8x8(currMB)?4:currMB->mb_type);
int step_h0 = BLOCK_STEP [partmode][0];
int step_v0 = BLOCK_STEP [partmode][1];
int mv_mode, i0, j0, refframe;
int pmv[2];
int j4, i4, ii,jj;
int vec;
int iTRb,iTRp;
int mv_scale = 0;
int flag_mode;
if (bframe && IS_P8x8 (currMB))
{
if (img->direct_type)
{
//int pic_blocky = (img->mb_frame_field_flag && currMB->mb_field)? ((img->current_mb_nr%2)?img->block_y/2-BLOCK_SIZE / 2:img->block_y/2):img->block_y;
int imgblock_y= ((img->MbaffFrameFlag)&&(currMB->mb_field))? (img->current_mb_nr%2) ? (img->block_y-4)/2:img->block_y/2: img->block_y;
int list_offset = ((img->MbaffFrameFlag)&&(currMB->mb_field))? img->current_mb_nr%2 ? 4 : 2 : 0;
int fw_rFrameL, fw_rFrameU, fw_rFrameUL, fw_rFrameUR;
int bw_rFrameL, bw_rFrameU, bw_rFrameUL, bw_rFrameUR;
PixelPos mb_left, mb_up, mb_upleft, mb_upright;
int fw_rFrame,bw_rFrame;
int pmvfw[2]={0,0},pmvbw[2]={0,0};
getLuma4x4Neighbour(img->current_mb_nr, 0, 0, -1, 0, &mb_left);
getLuma4x4Neighbour(img->current_mb_nr, 0, 0, 0, -1, &mb_up);
getLuma4x4Neighbour(img->current_mb_nr, 0, 0, 16, -1, &mb_upright);
getLuma4x4Neighbour(img->current_mb_nr, 0, 0, -1, -1, &mb_upleft);
if (!img->MbaffFrameFlag)
{
fw_rFrameL = mb_left.available ? dec_picture->ref_idx[LIST_0][mb_left.pos_x][mb_left.pos_y] : -1;
fw_rFrameU = mb_up.available ? dec_picture->ref_idx[LIST_0][mb_up.pos_x][mb_up.pos_y] : -1;
fw_rFrameUL = mb_upleft.available ? dec_picture->ref_idx[LIST_0][mb_upleft.pos_x][mb_upleft.pos_y] : -1;
fw_rFrameUR = mb_upright.available ? dec_picture->ref_idx[LIST_0][mb_upright.pos_x][mb_upright.pos_y] : fw_rFrameUL;
bw_rFrameL = mb_left.available ? dec_picture->ref_idx[LIST_1][mb_left.pos_x][mb_left.pos_y] : -1;
bw_rFrameU = mb_up.available ? dec_picture->ref_idx[LIST_1][mb_up.pos_x][mb_up.pos_y] : -1;
bw_rFrameUL = mb_upleft.available ? dec_picture->ref_idx[LIST_1][mb_upleft.pos_x][mb_upleft.pos_y] : -1;
bw_rFrameUR = mb_upright.available ? dec_picture->ref_idx[LIST_1][mb_upright.pos_x][mb_upright.pos_y] : bw_rFrameUL;
}
else
{
if (img->mb_data[img->current_mb_nr].mb_field)
{
fw_rFrameL = mb_left.available ?
img->mb_data[mb_left.mb_addr].mb_field || dec_picture->ref_idx[LIST_0][mb_left.pos_x][mb_left.pos_y] < 0?
dec_picture->ref_idx[LIST_0][mb_left.pos_x][mb_left.pos_y] :
dec_picture->ref_idx[LIST_0][mb_left.pos_x][mb_left.pos_y] * 2: -1;
fw_rFrameU = mb_up.available ?
img->mb_data[mb_up.mb_addr].mb_field || dec_picture->ref_idx[LIST_0][mb_up.pos_x][mb_up.pos_y] < 0?
dec_picture->ref_idx[LIST_0][mb_up.pos_x][mb_up.pos_y] :
dec_picture->ref_idx[LIST_0][mb_up.pos_x][mb_up.pos_y] * 2: -1;
fw_rFrameUL = mb_upleft.available ?
img->mb_data[mb_upleft.mb_addr].mb_field || dec_picture->ref_idx[LIST_0][mb_upleft.pos_x][mb_upleft.pos_y] < 0?
dec_picture->ref_idx[LIST_0][mb_upleft.pos_x][mb_upleft.pos_y] :
dec_picture->ref_idx[LIST_0][mb_upleft.pos_x][mb_upleft.pos_y] *2: -1;
fw_rFrameUR = mb_upright.available ?
img->mb_data[mb_upright.mb_addr].mb_field || dec_picture->ref_idx[LIST_0][mb_upright.pos_x][mb_upright.pos_y] < 0 ?
dec_picture->ref_idx[LIST_0][mb_upright.pos_x][mb_upright.pos_y] :
dec_picture->ref_idx[LIST_0][mb_upright.pos_x][mb_upright.pos_y] * 2: fw_rFrameUL;
bw_rFrameL = mb_left.available ?
img->mb_data[mb_left.mb_addr].mb_field || dec_picture->ref_idx[LIST_1][mb_left.pos_x][mb_left.pos_y] < 0 ?
dec_picture->ref_idx[LIST_1][mb_left.pos_x][mb_left.pos_y] :
dec_picture->ref_idx[LIST_1][mb_left.pos_x][mb_left.pos_y] * 2: -1;
bw_rFrameU = mb_up.available ?
img->mb_data[mb_up.mb_addr].mb_field || dec_picture->ref_idx[LIST_1][mb_up.pos_x][mb_up.pos_y] < 0 ?
dec_picture->ref_idx[LIST_1][mb_up.pos_x][mb_up.pos_y] :
dec_picture->ref_idx[LIST_1][mb_up.pos_x][mb_up.pos_y] * 2: -1;
bw_rFrameUL = mb_upleft.available ?
img->mb_data[mb_upleft.mb_addr].mb_field || dec_picture->ref_idx[LIST_1][mb_upleft.pos_x][mb_upleft.pos_y] < 0 ?
dec_picture->ref_idx[LIST_1][mb_upleft.pos_x][mb_upleft.pos_y] :
dec_picture->ref_idx[LIST_1][mb_upleft.pos_x][mb_upleft.pos_y] *2: -1;
bw_rFrameUR = mb_upright.available ?
img->mb_data[mb_upright.mb_addr].mb_field || dec_picture->ref_idx[LIST_1][mb_upright.pos_x][mb_upright.pos_y] < 0 ?
dec_picture->ref_idx[LIST_1][mb_upright.pos_x][mb_upright.pos_y] :
dec_picture->ref_idx[LIST_1][mb_upright.pos_x][mb_upright.pos_y] * 2: bw_rFrameUL;
}
else
{
fw_rFrameL = mb_left.available ?
img->mb_data[mb_left.mb_addr].mb_field || dec_picture->ref_idx[LIST_0][mb_left.pos_x][mb_left.pos_y] < 0 ?
dec_picture->ref_idx[LIST_0][mb_left.pos_x][mb_left.pos_y] >> 1 :
dec_picture->ref_idx[LIST_0][mb_left.pos_x][mb_left.pos_y]: -1;
fw_rFrameU = mb_up.available ?
img->mb_data[mb_up.mb_addr].mb_field || dec_picture->ref_idx[LIST_0][mb_up.pos_x][mb_up.pos_y] < 0 ?
dec_picture->ref_idx[LIST_0][mb_up.pos_x][mb_up.pos_y] >> 1 :
dec_picture->ref_idx[LIST_0][mb_up.pos_x][mb_up.pos_y] : -1;
fw_rFrameUL = mb_upleft.available ?
img->mb_data[mb_upleft.mb_addr].mb_field || dec_picture->ref_idx[LIST_0][mb_upleft.pos_x][mb_upleft.pos_y] < 0 ?
dec_picture->ref_idx[LIST_0][mb_upleft.pos_x][mb_upleft.pos_y]>> 1 :
dec_picture->ref_idx[LIST_0][mb_upleft.pos_x][mb_upleft.pos_y] : -1;
fw_rFrameUR = mb_upright.available ?
img->mb_data[mb_upright.mb_addr].mb_field || dec_picture->ref_idx[LIST_0][mb_upright.pos_x][mb_upright.pos_y] < 0 ?
dec_picture->ref_idx[LIST_0][mb_upright.pos_x][mb_upright.pos_y] >> 1 :
dec_picture->ref_idx[LIST_0][mb_upright.pos_x][mb_upright.pos_y] : fw_rFrameUL;
bw_rFrameL = mb_left.available ?
img->mb_data[mb_left.mb_addr].mb_field || dec_picture->ref_idx[LIST_1][mb_left.pos_x][mb_left.pos_y] < 0 ?
dec_picture->ref_idx[LIST_1][mb_left.pos_x][mb_left.pos_y] >> 1 :
dec_picture->ref_idx[LIST_1][mb_left.pos_x][mb_left.pos_y] : -1;
bw_rFrameU = mb_up.available ?
img->mb_data[mb_up.mb_addr].mb_field || dec_picture->ref_idx[LIST_1][mb_up.pos_x][mb_up.pos_y] < 0 ?
dec_picture->ref_idx[LIST_1][mb_up.pos_x][mb_up.pos_y] >> 1 :
dec_picture->ref_idx[LIST_1][mb_up.pos_x][mb_up.pos_y] : -1;
bw_rFrameUL = mb_upleft.available ?
img->mb_data[mb_upleft.mb_addr].mb_field || dec_picture->ref_idx[LIST_1][mb_upleft.pos_x][mb_upleft.pos_y] < 0 ?
dec_picture->ref_idx[LIST_1][mb_upleft.pos_x][mb_upleft.pos_y] >> 1 :
dec_picture->ref_idx[LIST_1][mb_upleft.pos_x][mb_upleft.pos_y] : -1;
bw_rFrameUR = mb_upright.available ?
img->mb_data[mb_upright.mb_addr].mb_field || dec_picture->ref_idx[LIST_1][mb_upright.pos_x][mb_upright.pos_y] < 0 ?
dec_picture->ref_idx[LIST_1][mb_upright.pos_x][mb_upright.pos_y] >> 1:
dec_picture->ref_idx[LIST_1][mb_upright.pos_x][mb_upright.pos_y] : bw_rFrameUL;
}
}
fw_rFrame = (fw_rFrameL >= 0 && fw_rFrameU >= 0) ? min(fw_rFrameL,fw_rFrameU): max(fw_rFrameL,fw_rFrameU);
fw_rFrame = (fw_rFrame >= 0 && fw_rFrameUR >= 0) ? min(fw_rFrame,fw_rFrameUR): max(fw_rFrame,fw_rFrameUR);
bw_rFrame = (bw_rFrameL >= 0 && bw_rFrameU >= 0) ? min(bw_rFrameL,bw_rFrameU): max(bw_rFrameL,bw_rFrameU);
bw_rFrame = (bw_rFrame >= 0 && bw_rFrameUR >= 0) ? min(bw_rFrame,bw_rFrameUR): max(bw_rFrame,bw_rFrameUR);
if (fw_rFrame >=0)
SetMotionVectorPredictor (img, pmvfw, pmvfw+1, fw_rFrame, LIST_0, dec_picture->ref_idx, dec_picture->mv, 0, 0, 16, 16);
if (bw_rFrame >=0)
SetMotionVectorPredictor (img, pmvbw, pmvbw+1, bw_rFrame, LIST_1, dec_picture->ref_idx, dec_picture->mv, 0, 0, 16, 16);
for (i=0;i<4;i++)
{
if (currMB->b8mode[i] == 0)
for(j=2*(i/2);j<2*(i/2)+2;j++)
for(k=2*(i%2);k<2*(i%2)+2;k++)
{
int j6 = imgblock_y+j;
j4 = img->block_y+j;
i4 = img->block_x+k;
if (fw_rFrame >= 0)
{
if (!fw_rFrame && !listX[LIST_1 +list_offset][0]->moving_block[i4][j6])
{
dec_picture->mv [LIST_0][i4][j4][0] = 0;
dec_picture->mv [LIST_0][i4][j4][1] = 0;
dec_picture->ref_idx[LIST_0][i4][j4] = 0;
}
else
{
dec_picture->mv [LIST_0][i4][j4][0] = pmvfw[0];
dec_picture->mv [LIST_0][i4][j4][1] = pmvfw[1];
dec_picture->ref_idx[LIST_0][i4][j4] = fw_rFrame;
}
}
else
{
dec_picture->mv [LIST_0][i4][j4][0] = 0;
dec_picture->mv [LIST_0][i4][j4][1] = 0;
dec_picture->ref_idx[LIST_0][i4][j4] = -1;
}
if (bw_rFrame >= 0)
{
if (bw_rFrame==0 && !listX[LIST_1 +list_offset][0]->moving_block[i4][j6])
{
dec_picture->mv [LIST_1][i4][j4][0] = 0;
dec_picture->mv [LIST_1][i4][j4][1] = 0;
dec_picture->ref_idx[LIST_1][i4][j4] = 0;
}
else
{
dec_picture->mv [LIST_1][i4][j4][0] = pmvbw[0];
dec_picture->mv [LIST_1][i4][j4][1] = pmvbw[1];
dec_picture->ref_idx[LIST_1][i4][j4] = bw_rFrame;
}
}
else
{
dec_picture->mv [LIST_1][i4][j4][0] = 0;
dec_picture->mv [LIST_1][i4][j4][1] = 0;
dec_picture->ref_idx[LIST_1][i4][j4] = -1;
}
if (fw_rFrame <0 && bw_rFrame <0)
{
dec_picture->ref_idx[LIST_0][i4][j4] = 0;
dec_picture->ref_idx[LIST_1][i4][j4] = 0;
}
}
}
}
else
{
for (i=0;i<4;i++)
{
if (currMB->b8mode[i] == 0)
{
for(j=2*(i/2);j<2*(i/2)+2;j++)
{
for(k=2*(i%2);k<2*(i%2)+2;k++)
{
int ref_idx;
int list_offset = ((img->MbaffFrameFlag)&&(currMB->mb_field))? img->current_mb_nr%2 ? 4 : 2 : 0;
int imgblock_y= ((img->MbaffFrameFlag)&&(currMB->mb_field))? (img->current_mb_nr%2) ? (img->block_y-4)/2 : img->block_y/2 : img->block_y;
int refList = (listX[LIST_1 + list_offset][0]->ref_idx[LIST_0 ][img->block_x+k][imgblock_y+j]== -1 ? LIST_1 : LIST_0);
int mapped_idx, iref;
ref_idx= listX[LIST_1 + list_offset][0]->ref_idx[refList][img->block_x + k][imgblock_y + j];
if (ref_idx == -1)
{
dec_picture->ref_idx [LIST_0][img->block_x + k][img->block_y + j] = 0;
dec_picture->ref_idx [LIST_1][img->block_x + k][img->block_y + j] = 0;
}
else
{
if (dec_picture->ref_pic_num[LIST_0 + list_offset][ref_idx]==listX[LIST_1 + list_offset][0]->ref_pic_num[refList][ref_idx])
{
mapped_idx=ref_idx;
}
else
{
for (iref=0;iref<listXsize[refList + list_offset];iref++)
{
if (dec_picture->ref_pic_num[LIST_0 + list_offset][iref]==listX[LIST_1 + list_offset][0]->ref_pic_num[refList][ref_idx])
{
mapped_idx=iref;
break;
}
else //! invalid index. Default to zero even though this case should not happen
mapped_idx=0;
}
}
dec_picture->ref_idx [LIST_0][img->block_x + k][img->block_y + j] = mapped_idx;
dec_picture->ref_idx [LIST_1][img->block_x + k][img->block_y + j] = 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -