📄 macroblock.c
字号:
jj1 = max (0, min (img->height_cr/scale-1, (jj+f2)>>s1));
if1 = (ii&f2); if0 = f1-if1;
jf1 = (jj&f2); jf0 = f1-jf1;
*mpred++ = (if0 * jf0 * refimage[jj0][ii0] +
if1 * jf0 * refimage[jj0][ii1] +
if0 * jf1 * refimage[jj1][ii0] +
if1 * jf1 * refimage[jj1][ii1] + f4) / f3;
}
}
/*
*************************************************************************
* Function:Predict one component of a chroma 4x4 block
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void
OneComponentChromaPrediction4x4_dir (int* mpred, // --> array to store prediction values
int pix_c_x, // <-- horizontal pixel coordinate of 4x4 block
int pix_c_y, // <-- vertical pixel coordinate of 4x4 block
int***** mv, // <-- motion vector array
int ref, // <-- reference frame parameter (0.../ -1: backward)
int blocktype, // <-- block type
int uv,
int refframe
)
{
int i, j, ii, jj, ii0, jj0, ii1, jj1, if0, if1, jf0, jf1;
int incr;
int* mvb;
//int refframe = (ref<0 ? 0 : ref);
pel_t** refimage;
int je = pix_c_y + 4;
int ie = pix_c_x + 4;
int f1 = 8 , f2=f1-1, f3=f1*f1, f4=f3>>1;
int s1 = 3;
int img_pic_c_y = img->pix_c_y;
int scale = 1;
int field_mode;
incr = 1;
if(img->type==B_IMG && !img->picture_structure)
incr = 2;
ref = (img->type==B_IMG) ? ref+incr : ref;
field_mode = (!img->picture_structure);
refimage = mcef [ref][uv];
for (j=pix_c_y; j<je; j++)
for (i=pix_c_x; i<ie; i++)
{
//xyji 11.27
//sw 9.30
mvb = mv [(i-img->pix_c_x)>>2][(j-img_pic_c_y)>>2][refframe][blocktype];
{
int delta_P,TRp,DistanceIndexFw,DistanceIndexBw,delta_PB;
delta_P = 2*(img->imgtr_next_P_frm - img->imgtr_last_P_frm);
if(img->picture_structure)
TRp = (refframe+1)*delta_P; //the lates backward reference
else
{
TRp = delta_P;//refframe == 0 ? delta_P-1 : delta_P+1;
}
delta_PB = 2*(picture_distance - img->imgtr_last_P_frm); // Tsinghua 200701
if(!img->picture_structure)
{
if(img->current_mb_nr_fld < img->total_number_mb) //top field
DistanceIndexFw = refframe == 0 ? delta_PB-1:delta_PB;
else
DistanceIndexFw = refframe == 0 ? delta_PB:delta_PB+1;
}
else
DistanceIndexFw = delta_PB;
//DistanceIndexBw = TRp - DistanceIndexFw;
DistanceIndexBw = (TRp - DistanceIndexFw+512)%512; // Added by Zhijie Yang, 20070419, Broadcom
ii = (i<<s1) - ((mvb[0]*DistanceIndexBw*(512/DistanceIndexFw)+256)>>9);
jj = (j<<s1) - ((mvb[1]*DistanceIndexBw*(512/DistanceIndexFw)+256)>>9);
}
ii0 = max (0, min (img->width_cr -1, ii>>s1 ));
jj0 = max (0, min (img->height_cr/scale-1, jj>>s1 )); // For MB level field/frame -- scale chroma height by 2
ii1 = max (0, min (img->width_cr -1, (ii+f2)>>s1));
jj1 = max (0, min (img->height_cr/scale-1, (jj+f2)>>s1));
if1 = (ii&f2); if0 = f1-if1;
jf1 = (jj&f2); jf0 = f1-jf1;
*mpred++ = (if0 * jf0 * refimage[jj0][ii0] +
if1 * jf0 * refimage[jj0][ii1] +
if0 * jf1 * refimage[jj1][ii0] +
if1 * jf1 * refimage[jj1][ii1] + f4) / f3;
}
}
/*
*************************************************************************
* Function:Predict an intra chroma 4x4 block
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void IntraChromaPrediction4x4 (int uv, // <-- colour component
int block_x, // <-- relative horizontal block coordinate of 4x4 block
int block_y) // <-- relative vertical block coordinate of 4x4 block
{
int mode = img->mb_data[img->current_mb_nr].c_ipred_mode;
int i, j;
//===== prediction =====
for (j=block_y; j<block_y+4; j++)
for (i=block_x; i<block_x+4; i++)
{
img->mpr[i][j] = img->mprr_c[uv][mode][i][j];
}
}
/*
*************************************************************************
* Function:Predict one chroma 4x4 block
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void
ChromaPrediction4x4 (int uv, // <-- colour component
int block_x, // <-- relative horizontal block coordinate of 4x4 block
int block_y, // <-- relative vertical block coordinate of 4x4 block
int fw_mode, // <-- forward prediction mode (1-7, 0=DIRECT if bw_mode=0)
int bw_mode, // <-- backward prediction mode (1-7, 0=DIRECT if fw_mode=0)
int fw_ref_frame, // <-- reference frame for forward prediction (if (<0) -> intra prediction)
int bw_ref_frame) // <-- reference frame for backward prediction
{
static int fw_pred[16];
static int bw_pred[16];
int i, j;
int block_x4 = block_x+4;
int block_y4 = block_y+4;
int pic_pix_x = img->pix_c_x + block_x;
int pic_pix_y = img->pix_c_y + block_y;
int* fpred = fw_pred;
int* bpred = bw_pred;
int by = block_y >>2;
int bx = block_x >>2;
int direct = (fw_mode == 0 && bw_mode == 0 && (img->type==B_IMG));
int skipped = (fw_mode == 0 && bw_mode == 0 && (img->type!=B_IMG));
int *****fmv_array = (fw_mode && bw_mode)?img->all_omv:img->all_mv; // For MB level frame/field coding
int***** bmv_array = img->all_bmv;
int fw_ref_idx, bw_ref_idx;
int scale_frame;
int directforward = (img->type==B_IMG && fw_mode==0);
int fw_scale , fw_shift ;
int bw_scale , bw_shift ;
int bw_ref_num ;
int fw_ref_num ;
direct_mode = direct;
//===== INTRA PREDICTION =====
if (fw_ref_frame < 0)
{
IntraChromaPrediction4x4 (uv, block_x, block_y);
return;
}
if (direct)
{
fw_ref_frame= 0;//max(refFrArr[ipdirect_y][ipdirect_x],0);
bw_ref_frame= 0;//min(refFrArr[ipdirect_y][ipdirect_x],0);
if(!img->picture_structure)
{
scale_frame = refFrArr[img->block8_y + by][img->block8_x+bx];
bw_ref_frame = 0;//-1; xyji 11.25
if (img->current_mb_nr_fld < img->total_number_mb)
{
fw_ref_frame = scale_frame >= 1 ? 1 : 0;
bw_ref_frame = scale_frame >= 0 ? 1 : 0;
}
else
{
fw_ref_frame = (scale_frame == 1 || scale_frame < 0)? 0 : 1;
bw_ref_frame = 0;
}
if(scale_frame < 0)
bw_ref_frame = 1;
}
}
fw_ref_idx = fw_ref_frame;
bw_ref_idx = bw_ref_frame;
//===== INTER PREDICTION =====
if (fw_mode || (direct && (fw_ref_frame!=-1)) || skipped)
{
if(!img->picture_structure)
OneComponentChromaPrediction4x4 (fw_pred, pic_pix_x, pic_pix_y, fmv_array , fw_ref_frame, fw_mode, uv, (directforward ?1 :0));
else
OneComponentChromaPrediction4x4 (fw_pred, pic_pix_x, pic_pix_y, fmv_array , (directforward ?0 :fw_ref_frame), fw_mode, uv, (directforward ?1 :0));
}
if (bw_mode || (direct && (bw_ref_frame!=-1)) ||(direct && !img->picture_structure && (bw_ref_frame ==-1)))
{
//OneComponentChromaPrediction4x4 (bw_pred, pic_pix_x, pic_pix_y, bmv_array, -1, bw_mode, uv, 0 );
if(fw_mode && bw_mode)
OneComponentChromaPrediction4x4_dir (bw_pred, pic_pix_x, pic_pix_y, fmv_array,
(!img->picture_structure) ? -2+bw_ref_frame : -1, bw_mode, uv,fw_ref_frame);
else
OneComponentChromaPrediction4x4 (bw_pred, pic_pix_x, pic_pix_y, bmv_array,
(!img->picture_structure) ? -2+bw_ref_frame : -1, bw_mode, uv,0);
}
if (direct || (fw_mode && bw_mode))
{
if(!img->picture_structure)
bw_ref_frame=1-bw_ref_frame; //cjw used for bw reference buffer address changing 20060112 bw
fw_ref_num=(img->picture_structure)?(fw_ref_frame):(2*fw_ref_frame); //cjw 20060112 fw
bw_ref_num=(img->picture_structure)?(bw_ref_frame+1):(2*bw_ref_frame+1); //cjw 20060112 bw
fw_scale = img->chroma_scale[fw_ref_num];
fw_shift = img->chroma_shift[fw_ref_num];
bw_scale = img->chroma_scale[bw_ref_num];
bw_shift = img->chroma_shift[bw_ref_num];
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++){
img->mpr[i][j] = (*fpred + *bpred + 1) / 2;
if(img->LumVarFlag == 1) //cjw 20051219 Weighted Predition
img->mpr_weight[i][j] = (Clip1((((*fpred)*fw_scale+16)>>5) + fw_shift)
+ Clip1((((*bpred)*bw_scale+16)>>5) + bw_shift) + 1) / 2;
fpred++ ;
bpred++ ;
}
}
else if (fw_mode || skipped) //P fw and B one direction fw
{
if(img->type==B_IMG){
fw_ref_num=(img->picture_structure)?(fw_ref_frame):(2*fw_ref_frame); //cjw 20060112 B fw
fw_scale = img->chroma_scale[fw_ref_num];
fw_shift = img->chroma_shift[fw_ref_num];
}
else{ //P fw
fw_scale = img->chroma_scale[fw_ref_frame];
fw_shift = img->chroma_shift[fw_ref_frame];
}
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++){
img->mpr[i][j] = *fpred;
if((!skipped) &&(img->LumVarFlag == 1)) //cjw 20051219 Weighted Predition
img->mpr_weight[i][j] = Clip1(((((*fpred)*fw_scale+16)>>5) + fw_shift));
fpred++;
}
}
else //B bw
{
if(!img->picture_structure)
bw_ref_frame=1-bw_ref_frame;
bw_ref_num=(img->picture_structure)?(bw_ref_frame+1):(2*bw_ref_frame+1); //cjw 20060112 bw
bw_scale = img->chroma_scale[bw_ref_num];
bw_shift = img->chroma_shift[bw_ref_num];
for (j=block_y; j<block_y4; j++)
for (i=block_x; i<block_x4; i++){
img->mpr[i][j] = *bpred;
if(img->LumVarFlag == 1) //cjw 20051219 Weighted Predition
img->mpr_weight[i][j] = Clip1(((((*bpred)*bw_scale+16)>>5) + bw_shift));
bpred++;
}
}
}
/*
*************************************************************************
* Function:Chroma residual coding for an macroblock
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void ChromaResidualCoding (int* cr_cbp)
{
int uv, block8, block_y, block_x, j, i;
int fw_mode, bw_mode, refframe;
int skipped = (img->mb_data[img->current_mb_nr].mb_type == 0 && img->type == INTER_IMG);
int incr = 1, offset = 0; // For MB level field/frame coding
int incr_x = 1, offset_x = 0;
int bw_ref;
short tmp_block_88[8][8];
int tmp_cbp_blk;
int tmp_block[2][8][8];/*lgp*/
int tmp_mpr[2][8][8];/*lgp*/
int incr_y=1,off_y=0;/*lgp*/
int cbpc=0;/*lgp*/
int stage_block8x8_pos=0;/*lgp*/
//cjw 20051219
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
int IntraPrediction=IS_INTRA (currMB);
int direct;
for (*cr_cbp=0, uv=0; uv<2; uv++)
{
//===== prediction of chrominance blocks ===d==
block8 = 0;
for (block_y=/*0*/4*(stage_block8x8_pos/2)/*lgp*/; block_y<8; block_y+=4)
for (block_x=0; block_x<8; block_x+=4, block8++)
{
block8 = (block_y/4)*2 + block_x/4;/*lgp*/
SetModesAndRefframe (block8, &fw_mode, &bw_mode, &refframe, &bw_ref);
ChromaPrediction4x4 (uv, block_x, block_y, fw_mode, bw_mode, refframe, bw_ref);
direct = (fw_mode == 0 && bw_mode == 0 && (img->type==B_IMG));
// !! start shenyanfei
//if(((!IntraPrediction)&&/*cjw*/(!direct)&&(!skipped)&&(img->LumVarFlag == 1) && (img->mb_weighting_flag == 1)&&(img->weighting_prediction == 1))
//if(((!IntraPrediction)&&(!skipped)&&(!direct)&&(img->LumVarFlag == 1) && (img->mb_weighting_flag == 1)&&(img->weighting_prediction == 1)) //cjw 20051230
if(((!IntraPrediction)&& (!skipped) && (img->LumVarFlag == 1) && (img->mb_weighting_flag == 1)&&(img->weighting_prediction == 1)) //cjw 20060321
||((img->LumVarFlag == 1) && (img->mb_weighting_flag == 0))){
for (j=0; j<4; j++)
for (i=0; i<4; i++)
//cjw 20051219 Weighted Predition
//img->mpr[i+block_x][j+block_y] = img->mpr[i+block_x][j+block_y];
img->mpr[i+block_x][j+block_y] = img->mpr_weight[i+block_x][j+block_y];
}
// !! end shenyanfei
if (skipped||img->NoResidueDirect)
{
for (j=0; j<4; j++)
for (i=block_x; i<block_x+4; i++)
{
imgUV[uv][img->pix_c_y+block_y+incr_y*j+off_y][img->pix_c_x+i] = img->mpr[i][block_y+j];
}
}
else
for (j=0; j<4; j++)
for (i=block_x; i<block_x+4; i++)
{
tmp_mpr[uv][i][block_y+j] = img->mpr[i][block_y+j];
tmp_block[uv][block_y+j][i] = imgUV_org[uv][img->pix_c_y+block_y+incr_y*j+off_y][img->pix_c_x+i] - img->mpr[i][block_y+j];
img->m7[i][block_y+j] = imgUV_org[uv][img->pix_c_y+block_y+incr_y*j+off_y][img->pix_c_x+i] - img->mpr[i][block_y+j];
}
}
//===== DCT, Quantization, inverse Quantization, IDCT, and Reconstruction =====
//===== Call function for skip mode in SP frames to properly process frame ====
if ( !skipped&&!img->NoResidueDirect)
{
for (j=0;j<8; j++)
for (i=0;i<8; i++)
{
tmp_block_88[j][i] = img->m7[i][j];
}
transform_B8(tmp_block_88);
//Lou 1013 scanquant_B8 (QP_SCALE_CR[ img->qp+QP_OFS-MIN_QP],4,4+uv,tmp_block_88,0,cr_cbp,&tmp_cbp_blk);
scanquant_B8 (QP_SCALE_CR[ img->qp-MIN_QP], 4, 4+uv, tmp_block_88,0,cr_cbp,&tmp_cbp_blk);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -