📄 macroblock.c
字号:
#endif
if(b8<4)
{
if( currMB->b8mode[b8]==IBLOCK )
{
IntraChromaPredModeFlag = 1;
//get from stream
readSyntaxElement_Intra8x8PredictionMode(&currSE);
//get from array and decode
bi = img->block_x + (b8&1);
bj = img->block_y + (b8/2);
upIntraPredMode = img->ipredmode[bi+1][bj];
leftIntraPredMode = img->ipredmode[bi][bj+1];
mostProbableIntraPredMode = (upIntraPredMode < 0 || leftIntraPredMode < 0) ? DC_PRED : upIntraPredMode < leftIntraPredMode ? upIntraPredMode : leftIntraPredMode;
dec = (currSE.value1 == -1) ? mostProbableIntraPredMode : currSE.value1 + (currSE.value1 >= mostProbableIntraPredMode);
//set
img->ipredmode[1+bi][1+bj]=dec;
j2 = bj;
}
}
else if( b8==4&&currMB->b8mode[b8-3]==IBLOCK)
{
currSE.type = SE_INTRAPREDMODE;
#if TRACE
strncpy(currSE.tracestring, "Chroma intra pred mode", TRACESTRING_SIZE);
#endif
currSE.mapping = linfo_ue;
readSyntaxElement_UVLC(&currSE,inp);
currMB->c_ipred_mode = currSE.value1;
if (currSE.value1 < DC_PRED_8 || currSE.value1 > PLANE_8)
{
printf("%d\n", img->current_mb_nr);
error("illegal chroma intra pred mode!\n", 600);
}
}
}
/*
*************************************************************************
* Function:Set context for reference frames
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
int BType2CtxRef (int btype)
{
if (btype<4)
return 0;
else
return 1;
}
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void readReferenceIndex(struct img_par *img, struct inp_par *inp)
{
int i,j,k;
// int mb_nr = img->current_mb_nr; //GB Falsch
Macroblock *currMB = &mb_data[img->current_mb_nr];
SyntaxElement currSE;
int bframe = (img->type==B_IMG);
int partmode = (IS_P8x8(currMB)?4:currMB->mb_type);
int step_h0 = BLOCK_STEP [partmode][0];
int step_v0 = BLOCK_STEP [partmode][1];
int i0, j0, refframe;
int **fwRefFrArr = img->fw_refFrArr;
int **bwRefFrArr = img->bw_refFrArr;
int ***fw_mv = img->fw_mv;
int ***bw_mv = img->bw_mv;
//int **moving_block_dir = moving_block;
int flag_mode;
// If multiple ref. frames, read reference frame for the MB *********************************
flag_mode = 0;
currSE.type = SE_REFFRAME;
currSE.mapping = linfo_ue;
if(currMB->mb_type!=I4MB)
{
step_h0 = (BLOCK_STEP[IS_P8x8(currMB) ? 4 : currMB->mb_type][0]);
step_v0 = (BLOCK_STEP[IS_P8x8(currMB) ? 4 : currMB->mb_type][1]);
}
// !! shenyanfei
for (j0=0; j0<2; )
{
if((currMB->mb_type==I4MB&&j0==0))
{ j0 += 1; continue;}
for (i0=0; i0<2; )
{
k=2*j0+i0;
if ((currMB->b8pdir[k]==0 || currMB->b8pdir[k]==2) && currMB->b8mode[k]!=0)
{
img->subblock_x = i0;
img->subblock_y = j0;
if ((!picture_reference_flag&&img->type==P_IMG && img->types!=I_IMG) || (!picture_reference_flag&&!img->picture_structure && img->types!=I_IMG))
{
#if TRACE
strncpy(currSE.tracestring, "Fwd ref frame no ", TRACESTRING_SIZE);
#endif
currSE.context = BType2CtxRef (currMB->b8mode[k]);
if(img->picture_structure || bframe)
currSE.len = 1;
else
currSE.len = 2;
readSyntaxElement_FLC(&currSE);
refframe = currSE.value1;
}
else
{
refframe = 0;
}
if (!bframe)
{
for (j=j0; j<j0+step_v0;j++)
for (i=i0; i<i0+step_h0;i++)
refFrArr[img->block_y+j][img->block_x+i] = refframe;
}
else // !! for B frame shenyanfei
{
for (j=j0; j<j0+step_v0;j++)
for (i=i0; i<i0+step_h0;i++)
img->fw_refFrArr[img->block_y+j][img->block_x+i] = refframe;
if (currMB->b8pdir[k]==2 && !img->picture_structure)
{
for (j=j0; j<j0+step_v0;j++)
for (i=i0; i<i0+step_h0;i++)
img->bw_refFrArr[img->block_y+j][img->block_x+i] = 1-refframe;
}
}
}
i0+=max(1,step_h0);
}
j0+=max(1,step_v0);
}
for (j0=0; j0<2; )
{
if((currMB->mb_type==I4MB&&j0==0))
{ j0 += 1; continue;}
for (i0=0; i0<2; )
{
k=2*j0+i0;
if ((currMB->b8pdir[k]==1) && currMB->b8mode[k]!=0)
{
img->subblock_x = i0;
img->subblock_y = j0;
if (img->type==B_IMG && !img->picture_structure&&!picture_reference_flag)
{
#if TRACE
strncpy(currSE.tracestring, "Bwd ref frame no ", TRACESTRING_SIZE);
#endif
currSE.context = BType2CtxRef (currMB->b8mode[k]);
if(img->picture_structure || bframe)
currSE.len = 1;
else
currSE.len = 2;
readSyntaxElement_FLC(&currSE);
refframe = currSE.value1;
}
else
{
refframe = 0;
}
for (j=j0; j<j0+step_v0;j++)
for (i=i0; i<i0+step_h0;i++)
img->bw_refFrArr[img->block_y+j][img->block_x+i] = refframe;
}
i0+=max(1,step_h0);
}
j0+=max(1,step_v0);
}
}
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void readMotionVector(struct img_par *img, struct inp_par *inp)
{
int i,j,k,l,m,n;
int step_h,step_v;
int curr_mvd;
// int mb_nr = img->current_mb_nr; //GB Falsch
Macroblock *currMB = &mb_data[img->current_mb_nr];
SyntaxElement currSE;
int bframe = (img->type==B_IMG);
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,iTRd;
int frame_no_next_P, frame_no_B, delta_P;
int ref;
int img_block_y;
int use_scaled_mv;
int fw_refframe,current_tr;
int **fwRefFrArr = img->fw_refFrArr;
int **bwRefFrArr = img->bw_refFrArr;
int ***fw_mv = img->fw_mv;
int ***bw_mv = img->bw_mv;
int scale_refframe,iTRp1,bw_ref;
if (bframe && IS_P8x8 (currMB))
{
for (i=0;i<4;i++)
{
if (currMB->b8mode[i] == 0)
{
for(j=i/2;j<i/2+1;j++)
{
for(k=(i%2);k<(i%2)+1;k++)
{
//sw
img->fw_refFrArr[img->block_y + j][img->block_x + k] = 0;
img->bw_refFrArr[img->block_y + j][img->block_x + k] = 0;
}
}
}
}
}
//===== READ FORWARD MOTION VECTORS =====
currSE.type = SE_MVD;
currSE.mapping = linfo_se;
for (j0=0; j0<2; )
{
if(currMB->mb_type!=I4MB)
{
step_h0 = (BLOCK_STEP[(currMB->mb_type==P8x8)? 4 : currMB->mb_type][0]);
step_v0 = (BLOCK_STEP[(currMB->mb_type==P8x8)? 4 : currMB->mb_type][1]);
}
if((currMB->mb_type==I4MB&&j0==0)) // for by jhzheng [2004/08/02]
{ j0 += 1; continue;}
//{break;}
for (i0=0; i0<2; )
{
k=2*j0+i0;
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];
if (!bframe) refframe = refFrArr [img->block_y+j0][img->block_x+i0];
else refframe = img->fw_refFrArr[img->block_y+j0][img->block_x+i0];
for (j=j0; j<j0+step_v0; j+=step_v)
for (i=i0; i<i0+step_h0; i+=step_h)
{
j4 = img->block_y+j;
i4 = img->block_x+i;
// first make mv-prediction
if (!bframe)
SetMotionVectorPredictor (img, pmv, pmv+1, refframe, refFrArr, img->mv, i, j, 8*step_h, 8*step_v, 0, 0);//Lou 1016
else
SetMotionVectorPredictor (img, pmv, pmv+1, refframe, img->fw_refFrArr, img->fw_mv, i, j, 8*step_h, 8*step_v, 0, 0);//Lou 1016
for (n=0; n < 2; n++)
{
#if TRACE
snprintf(currSE.tracestring, TRACESTRING_SIZE, "FMVD (pred %d)",pmv[n]);
#endif
img->subblock_x = i; // position used for context determination
img->subblock_y = j; // position used for context determination
currSE.value2 = (!bframe ? n : 2*n); // identifies the component; only used for context determination
readSyntaxElement_UVLC(&currSE,inp);
curr_mvd = currSE.value1;
vec=curr_mvd+pmv[n]; /* find motion vector */
// need B support
if (!bframe)
{
for(ii=0;ii<step_h;ii++)
for(jj=0;jj<step_v;jj++)
img->mv[i4+ii+BLOCK_SIZE][j4+jj][n]=vec;
}
else // B frame
{
for(ii=0;ii<step_h;ii++)
for(jj=0;jj<step_v;jj++)
img->fw_mv[i4+ii+BLOCK_SIZE][j4+jj][n]=vec;
}
/* store (oversampled) mvd */
for (l=0; l < step_v; l++)
for (m=0; m < step_h; m++)
currMB->mvd[0][j+l][i+m][n] = curr_mvd;
}
}
}
else if (currMB->b8mode[k=2*j0+i0]==0)
{// direct mode
// by Junhao Zheng 2004-08-04 22:00:51
//step_v0 = step_h0 = 1;
for (j=j0; j<j0+step_v0; j++)
for (i=i0; i<i0+step_h0; i++)
{
ref= refFrArr[img->block_y+j][img->block_x+i];
img_block_y = (img->current_mb_nr%2) ? (img->block_y-4)/2:img->block_y/2;
if(ref == -1)
{
//sw
img->fw_refFrArr[img->block_y+j][img->block_x+i]=0;
img->bw_refFrArr[img->block_y+j][img->block_x+i]=0;
j4 = img->block_y+j;
i4 = img->block_x+i;
for (ii=0; ii < 2; ii++)
{
img->fw_mv[i4+BLOCK_SIZE][j4][ii]=0;
img->bw_mv[i4+BLOCK_SIZE][j4][ii]=0;
}
SetMotionVectorPredictor(img,&(img->fw_mv[i4+BLOCK_SIZE][j4][0]),
&(img->fw_mv[i4+BLOCK_SIZE][j4][1]),0,img->fw_refFrArr,
img->fw_mv,0,0,16,16, 0, 1);
SetMotionVectorPredictor(img,&(img->bw_mv[i4+BLOCK_SIZE][j4][0]),
&(img->bw_mv[i4+BLOCK_SIZE][j4][1]),0,img->bw_refFrArr,
img->bw_mv,0,0,16,16, -1, 1);
}
else
{
frame_no_next_P =2*img->imgtr_next_P;
// frame_no_B = 2*img->tr;
frame_no_B = 2*img->pic_distance; // Added by Xiaozhen ZHENG, 2007.05.01
delta_P = 2* (img->imgtr_next_P - img->imgtr_last_P);
delta_P = (delta_P + 512)%512; // Added by Xiaozhen ZHENG, 2007.05.01
if(!img->picture_structure)
{
if (img->current_mb_nr_fld < img->PicSizeInMbs) //top field
scale_refframe = ref == 0 ? 0 : 1;
else
scale_refframe = ref == 1 ? 1 : 2;
}
else
scale_refframe = 0;
if(img->picture_structure)
{
iTRp = (ref+1)*delta_P;
iTRp1 = (scale_refframe+1)*delta_P;
}else
{
if (img->current_mb_nr_fld < img->PicSizeInMbs) //top field
{
iTRp = delta_P*(ref/2+1)-(ref+1)%2; //the lates backward reference
iTRp1 = delta_P*(scale_refframe/2+1)-(scale_refframe+1)%2; //the lates backward reference
bw_ref = 0;
}
else
{
iTRp = 1 + delta_P*((ref+1)/2)-ref%2;
iTRp1 = 1 + delta_P*((scale_refframe+1)/2)-scale_refframe%2;
bw_ref = 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -