📄 macroblock.c
字号:
{
currMB->cbp=NCBP[currMB->mb_type-5][0]; // qhg //modefy by xfwang 2004.7.29
currMB->mb_type = I4MB;
for (i=0;i<4;i++)
{
currMB->b8mode[i] = IBLOCK;
currMB->b8pdir[i] = -1;
}
}
else
{
currMB->mb_type = I16MB;
for (i=0;i<4;i++) {currMB->b8mode[i]=0; currMB->b8pdir[i]=-1; }
currMB->cbp= ICBPTAB[(I16OFFSET)>>2];
}
}
/*
*************************************************************************
* Function:Interpret the mb mode for I-Frames
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void interpret_mb_mode_I(struct img_par *img)
{
int i;
const int ICBPTAB[6] = {0,16,32,15,31,47};
Macroblock *currMB = &mb_data[img->current_mb_nr];
int num =4;
currMB->mb_type = I4MB;
for (i=0;i<4;i++)
{
currMB->b8mode[i]=IBLOCK;
currMB->b8pdir[i]=-1;
}
for (i=num;i<4;i++)
{
currMB->b8mode[i]=currMB->mb_type_2==P8x8? 4 : currMB->mb_type_2; currMB->b8pdir[i]=0;
}
}
/*
*************************************************************************
* Function:Interpret the mb mode for B-Frames
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void interpret_mb_mode_B(struct img_par *img)
{
static const int offset2pdir16x16[12] = {0, 0, 1, 2, 0,0,0,0,0,0,0,0};
static const int offset2pdir16x8[22][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{1,1},{0,0},{0,1},{0,0},{1,0},
{0,0},{0,2},{0,0},{1,2},{0,0},{2,0},{0,0},{2,1},{0,0},{2,2},{0,0}};
static const int offset2pdir8x16[22][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{1,1},{0,0},{0,1},{0,0},
{1,0},{0,0},{0,2},{0,0},{1,2},{0,0},{2,0},{0,0},{2,1},{0,0},{2,2}};
const int ICBPTAB[6] = {0,16,32,15,31,47};
Macroblock *currMB = &mb_data[img->current_mb_nr];//GB current_mb_nr];
int i, mbmode;
int mbtype = currMB->mb_type;
int *b8mode = currMB->b8mode;
int *b8pdir = currMB->b8pdir;
//--- set mbtype, b8type, and b8pdir ---
if (mbtype==0) // direct
{
mbmode=0; for(i=0;i<4;i++) {b8mode[i]=0; b8pdir[i]=2; }
}
else if (/*mbtype==23 qhg */ mbtype>=23) // intra4x4
{
currMB->cbp=NCBP[mbtype-23][0]; // qhg
mbmode=I4MB; for(i=0;i<4;i++) {b8mode[i]=IBLOCK; b8pdir[i]=-1; }
}
else if (mbtype==22) // 8x8(+split)
{
mbmode=P8x8; // b8mode and pdir is transmitted in additional codewords
}
else if (mbtype<4) // 16x16
{
mbmode=1;
for(i=0;i<4;i++) {b8mode[i]=1; b8pdir[i]=offset2pdir16x16[mbtype]; }
}
else if (mbtype%2==0) // 16x8
{
mbmode=2;
for(i=0;i<4;i++) {b8mode[i]=2; b8pdir[i]=offset2pdir16x8 [mbtype][i/2]; }
}
else
{
mbmode=3;
for(i=0;i<4;i++) {b8mode[i]=3; b8pdir[i]=offset2pdir8x16 [mbtype][i%2]; }
}
currMB->mb_type = mbmode;
}
/*
*************************************************************************
* Function:init macroblock I and P frames
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void init_macroblock(struct img_par *img)
{
int i,j;
Macroblock *currMB = &mb_data[img->current_mb_nr];//GB current_mb_nr];
img->mv[img->block_x+4][img->block_y][2]=img->number;
for (i=0;i<2;i++)
{ // reset vectors and pred. modes
for(j=0;j<2;j++)
{
img->mv[img->block_x+i+4][img->block_y+j][0] = 0;
img->mv[img->block_x+i+4][img->block_y+j][1] = 0;
}
}
for (i=0;i<2;i++)
{ // reset vectors and pred. modes
for(j=0;j<2;j++)
{
img->ipredmode[img->block_x+i+1][img->block_y+j+1] = -1; //by oliver 0512
}
}
// Set the reference frame information for motion vector prediction
if (IS_INTRA (currMB))
{
for (j=0; j<2; j++)
for (i=0; i<2; i++)
{
refFrArr[img->block_y+j][img->block_x+i] = -1;
}
}
else if (!IS_P8x8 (currMB))
{
for (j=0; j<2; j++)
for (i=0; i<2; i++)
{
refFrArr[img->block_y+j][img->block_x+i] = 0;
}
}
else
{
for (j=0; j<2; j++)
for (i=0; i<2; i++)
{
refFrArr[img->block_y+j][img->block_x+i] = (currMB->b8mode[2*j+i]==IBLOCK ? -1 : 0);
}
}
}
/*
*************************************************************************
* Function:Sets mode for 8x8 block
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void SetB8Mode (struct img_par* img, Macroblock* currMB, int value, int i)
{
static const int p_v2b8 [ 5] = {4, 5, 6, 7, IBLOCK};
static const int p_v2pd [ 5] = {0, 0, 0, 0, -1};
static const int b_v2b8 [14] = {0, 4, 4, 4, 5, 6, 5, 6, 5, 6, 7, 7, 7, IBLOCK};
static const int b_v2pd [14] = {2, 0, 1, 2, 0, 0, 1, 1, 2, 2, 0, 1, 2, -1};
if (img->type==B_IMG)
{
currMB->b8mode[i] = b_v2b8[value];
currMB->b8pdir[i] = b_v2pd[value];
}
else
{
currMB->b8mode[i] = p_v2b8[value];
currMB->b8pdir[i] = p_v2pd[value];
}
}
/*
*************************************************************************
* Function:Get the syntax elements from the NAL
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
int read_one_macroblock(struct img_par *img,struct inp_par *inp)
{
int i,j;
SyntaxElement currSE;
Macroblock *currMB = &mb_data[img->current_mb_nr];//GB current_mb_nr];
int img_block_y;
int real_mb_type;
int fixqp; //add by wuzhongmou 200612
fixqp = (fixed_picture_qp|| fixed_slice_qp); //add by wuzhongmou 200612
//img->allrefzero = 0; //delete by xfwang 2004.7.29
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{
img->m8[0][i][j]=0;
img->m8[1][i][j]=0;
}
currMB->qp = img->qp ;
currSE.type = SE_MBTYPE;
currSE.mapping = linfo_ue;
currMB->mb_type_2= 0;
if(img->type == I_IMG)
{
currMB->mb_type = 0;
}
else if(skip_mode_flag)
{
if(img->cod_counter == -1)
{
#if TRACE
strncpy(currSE.tracestring, "MB runlength", TRACESTRING_SIZE);
#endif
readSyntaxElement_UVLC(&currSE,inp);
img->cod_counter = currSE.value1;
}
if (img->cod_counter==0)
{
#if TRACE
strncpy(currSE.tracestring, "MB Type", TRACESTRING_SIZE);
#endif
readSyntaxElement_UVLC(&currSE,inp);
if(img->type == P_IMG)
currSE.value1++;
currMB->mb_type = currSE.value1;
img->cod_counter--;
}
else
{
img->cod_counter--;
currMB->mb_type = 0; // !! skip mode shenyanfei
}
}
else
{
#if TRACE
strncpy(currSE.tracestring, "MB Type", TRACESTRING_SIZE);
#endif
readSyntaxElement_UVLC(&currSE,inp);
if(img->type == P_IMG)
currSE.value1++;
currSE.value1--;
real_mb_type = currSE.value1;
if(currSE.value1<0)
currSE.value1 = 0;
currMB->mb_type = currSE.value1;
img->cod_counter--;
}
if ((img->type==P_IMG )) // inter frame
interpret_mb_mode_P(img);
else if (img->type==I_IMG) // intra frame
interpret_mb_mode_I(img);
else if ((img->type==B_IMG)) // B frame
interpret_mb_mode_B(img);
//====== READ 8x8 SUB-PARTITION MODES (modes of 8x8 blocks) and Intra VBST block modes ======
if (IS_P8x8 (currMB))
{
currSE.type = SE_MBTYPE;
if(img->type!=P_IMG)
{
for (i=0; i<4; i++)
{
currSE.mapping = linfo_ue;
#if TRACE
strncpy(currSE.tracestring, "8x8 mode", TRACESTRING_SIZE);
#endif
//mb_part_type is fix length coding(fix length equal 2)!! jlzheng 7.22
assert (currStream->streamBuffer != NULL);
currSE.len = 2;
readSyntaxElement_FLC (&currSE);
// END
SetB8Mode (img, currMB, currSE.value1, i);
}
}
else
{
currSE.value1 = 0;
for (i=0; i<4; i++)
{
SetB8Mode (img, currMB, currSE.value1, i);
}
}
}
//! TO for Error Concelament
//! If we have an INTRA Macroblock and we lost the partition
//! which contains the intra coefficients Copy MB would be better
//! than just a grey block.
//! Seems to be a bit at the wrong place to do this right here, but for this case
//! up to now there is no other way.//Lou
//--- init macroblock data ---
if (img->type==B_IMG)
init_macroblock_Bframe(img);
else
init_macroblock (img);
if (IS_INTRA(currMB))
{
for (i=0;i<5;i++)
read_ipred_block_modes(img,inp,i);
}
if (skip_mode_flag)
{
if (IS_DIRECT (currMB) && img->cod_counter >= 0)
{
int i, j, iii, jjj;
currMB->cbp = 0;
for (i=0;i<BLOCK_SIZE;i++)
{ // reset luma coeffs
for (j=0;j<BLOCK_SIZE;j++)
for(iii=0;iii<BLOCK_SIZE;iii++)
for(jjj=0;jjj<BLOCK_SIZE;jjj++)
img->cof[i][j][iii][jjj]=0;
}
for (j=4;j<6;j++)
{ // reset chroma coeffs
for (i=0;i<4;i++)
for (iii=0;iii<4;iii++)
for (jjj=0;jjj<4;jjj++)
img->cof[i][j][iii][jjj]=0;
}
return DECODE_MB;
}
}
else
{
if (img->type==B_IMG&& real_mb_type<0)
{
int i, j, iii, jjj;
currMB->cbp = 0;
for (i=0;i<BLOCK_SIZE;i++)
{ // reset luma coeffs
for (j=0;j<BLOCK_SIZE;j++)
for(iii=0;iii<BLOCK_SIZE;iii++)
for(jjj=0;jjj<BLOCK_SIZE;jjj++)
img->cof[i][j][iii][jjj]=0;
}
for (j=4;j<6;j++)
{ // reset chroma coeffs
for (i=0;i<4;i++)
for (iii=0;iii<4;iii++)
for (jjj=0;jjj<4;jjj++)
img->cof[i][j][iii][jjj]=0;
}
return DECODE_MB;
}
}
if (IS_COPY (currMB)) //keep last macroblock
{
int i, j, iii, jjj, pmv[2];
int ***tmp_mv = img->mv;
int mb_available_up = (img->mb_y == 0) ? 0 : (currMB->slice_nr == mb_data[img->current_mb_nr-img->width/16].slice_nr);
int mb_available_left = (img->mb_x == 0) ? 0 : (currMB->slice_nr == mb_data[img->current_mb_nr-1].slice_nr);
int zeroMotionAbove = !mb_available_up ? 1 : refFrArr[img->block_y-1][img->block_x] == 0 && tmp_mv[4+img->block_x ][img->block_y-1][0] == 0 && tmp_mv[4+img->block_x ][img->block_y-1][1] == 0 ? 1 : 0;
int zeroMotionLeft = !mb_available_left? 1 : refFrArr[img->block_y][img->block_x-1] == 0 && tmp_mv[4+img->block_x-1][img->block_y ][0] == 0 && tmp_mv[4+img->block_x-1][img->block_y ][1] == 0 ? 1 : 0;
currMB->cbp = 0;
for (i=0;i<BLOCK_SIZE;i++)
{ // reset luma coeffs
for (j=0;j<BLOCK_SIZE;j++)
for(iii=0;iii<BLOCK_SIZE;iii++)
for(jjj=0;jjj<BLOCK_SIZE;jjj++)
img->cof[i][j][iii][jjj]=0;
}
for (j=4;j<6;j++)
{ // reset chroma coeffs
for (i=0;i<4;i++)
for (iii=0;iii<4;iii++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -