📄 me_umhex.c
字号:
flag_intra_SAD = ((flag_intra[(img->pix_x)>>4])||(flag_intra[((img->pix_x)>>4)-1])||(flag_intra[((img->pix_x)>>4)+1])) ;
}
}
return;
}
void UMHEX_skip_intrabk_SAD(int best_mode, int ref_max)
{
int i,j,k, ref;
if (img->number > 0)
flag_intra[(img->pix_x)>>4] = (best_mode == 9 || best_mode == 10) ? 1:0;
if (img->type != I_SLICE && (best_mode == 9 || best_mode == 10))
{
for (i=0; i < 4; i++)
{
for (j=0; j < 4; j++)
{
for (k=0; k < 9;k++)
{
fastme_l0_cost[k][j][i] = 0;
fastme_l1_cost[k][j][i] = 0;
for (ref=0; ref<ref_max;ref++)
{
fastme_ref_cost[ref][k][j][i] = 0;
}
}
}
}
}
return;
}
void UMHEX_setup(short ref, int list, int block_y, int block_x, int blocktype, short ******all_mv)
{
int N_Bframe=0;
int n_Bframe=0;
int temp_blocktype = 0;
int indication_blocktype[8]={0,0,1,1,2,4,4,5};
N_Bframe = params->successive_Bframe;
n_Bframe =(N_Bframe) ? (stats->frame_ctr[B_SLICE]%(N_Bframe+1)): 0;
/**************************** MV prediction **********************/
//MV uplayer prediction
if (blocktype>1)
{
temp_blocktype = indication_blocktype[blocktype];
pred_MV_uplayer[0] = all_mv[list][ref][temp_blocktype][block_y][block_x][0];
pred_MV_uplayer[1] = all_mv[list][ref][temp_blocktype][block_y][block_x][1];
}
//MV ref-frame prediction
pred_MV_ref_flag = 0;
if(list==0)
{
if (img->field_picture)
{
if ( ref > 1)
{
pred_MV_ref[0] = all_mv[0][ref-2][blocktype][block_y][block_x][0];
pred_MV_ref[0] = (int)(pred_MV_ref[0]*((ref>>1)+1)/(float)((ref>>1)));
pred_MV_ref[1] = all_mv[0][ref-2][blocktype][block_y][block_x][1];
pred_MV_ref[1] = (int)(pred_MV_ref[1]*((ref>>1)+1)/(float)((ref>>1)));
pred_MV_ref_flag = 1;
}
if (img->type == B_SLICE && (ref==0 || ref==1) )
{
pred_MV_ref[0] =(int) (all_mv[1][0][blocktype][block_y][block_x][0]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
pred_MV_ref[1] =(int) (all_mv[1][0][blocktype][block_y][block_x][1]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
pred_MV_ref_flag = 1;
}
}
else //frame case
{
if ( ref > 0)
{
pred_MV_ref[0] = all_mv[0][ref-1][blocktype][block_y][block_x][0];
pred_MV_ref[0] = (int)(pred_MV_ref[0]*(ref+1)/(float)(ref));
pred_MV_ref[1] = all_mv[0][ref-1][blocktype][block_y][block_x][1];
pred_MV_ref[1] = (int)(pred_MV_ref[1]*(ref+1)/(float)(ref));
pred_MV_ref_flag = 1;
}
if (img->type == B_SLICE && (ref==0)) //B frame forward prediction, first ref
{
pred_MV_ref[0] =(int) (all_mv[1][0][blocktype][block_y][block_x][0] * (-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
pred_MV_ref[1] =(int) (all_mv[1][0][blocktype][block_y][block_x][1] * (-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
pred_MV_ref_flag = 1;
}
}
}
/******************************SAD prediction**********************************/
if (list==0 && ref>0) //pred_SAD_ref
{
if (flag_intra_SAD) //add this for irregular motion
{
pred_SAD = 0;
}
else
{
if (img->field_picture)
{
if (ref > 1)
{
pred_SAD = fastme_ref_cost[ref-2][blocktype][block_y][block_x];
}
else
{
pred_SAD = fastme_ref_cost[0][blocktype][block_y][block_x];
}
}
else
{
pred_SAD = fastme_ref_cost[ref-1][blocktype][block_y][block_x];
}
}
}
else if (blocktype>1) // pred_SAD_uplayer
{
if (flag_intra_SAD)
{
pred_SAD = 0;
}
else
{
pred_SAD = (list==1) ? (fastme_l1_cost[temp_blocktype][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x]) : (fastme_l0_cost[temp_blocktype][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x]);
pred_SAD /= 2;
}
}
else pred_SAD = 0 ; // pred_SAD_space
}
/*!
************************************************************************
* \brief
* UMHEXBipredIntegerPelBlockMotionSearch: fast pixel block motion search for bipred mode
* this algrithm is called UMHexagonS(see JVT-D016),which includes
* four steps with different kinds of search patterns
* \author
* Main contributors: (see contributors.h for copyright, address and affiliation details)
* - Zhibo Chen <chenzhibo@tsinghua.org.cn>
* - JianFeng Xu <fenax@video.mdc.tsinghua.edu.cn>
* - Xiaozhong Xu <xxz@video.mdc.tsinghua.edu.cn>
* \date :
* 2006.1
************************************************************************
*/
int // ==> minimum motion cost after search
UMHEXBipredIntegerPelBlockMotionSearch (Macroblock *currMB, // <-- current Macroblock
imgpel* cur_pic, // <-- original pixel values for the AxB block
short ref, // <-- reference frame (0... or -1 (backward))
int list, // <-- current reference list
int list_offset, // <-- MBAFF list offset
char ***refPic, // <-- reference array
short ****tmp_mv, // <-- mv array
int pic_pix_x, // <-- absolute x-coordinate of regarded AxB block
int pic_pix_y, // <-- absolute y-coordinate of regarded AxB block
int blocktype, // <-- block type (1-16x16 ... 7-4x4)
short pred_mv1[2], // <-- motion vector predictor (x|y) in sub-pel units
short pred_mv2[2], // <-- motion vector predictor (x|y) in sub-pel units
short mv[2], // <--> in: search center (x|y) / out: motion vector (x|y) - in pel units
short s_mv[2], // <--> in: search center (x|y) / out: motion vector (x|y) - in pel units
int search_range, // <-- 1-d search range in pel units
int min_mcost, // <-- minimum motion cost (cost for center or huge value)
int iteration_no, // <-- bi pred iteration number
int lambda_factor, // <-- lagrangian parameter for determining motion cost
int apply_weights
)
{
int temp_Big_Hexagon_x[16];// = Big_Hexagon_x;
int temp_Big_Hexagon_y[16];// = Big_Hexagon_y;
int mvshift = 2; // motion vector shift for getting sub-pel units
int search_step,iYMinNow, iXMinNow;
int i,m,j;
float betaFourth_1,betaFourth_2;
int pos, cand_x, cand_y,mcost;
int blocksize_y = params->blc_size[blocktype][1]; // vertical block size
int blocksize_x = params->blc_size[blocktype][0]; // horizontal block size
int pred_x1 = (pic_pix_x << 2) + pred_mv1[0]; // predicted position x (in sub-pel units)
int pred_y1 = (pic_pix_y << 2) + pred_mv1[1]; // predicted position y (in sub-pel units)
int pred_x2 = (pic_pix_x << 2) + pred_mv2[0]; // predicted position x (in sub-pel units)
int pred_y2 = (pic_pix_y << 2) + pred_mv2[1]; // predicted position y (in sub-pel units)
short center2_x = pic_pix_x + mv[0]; // center position x (in pel units)
short center2_y = pic_pix_y + mv[1]; // center position y (in pel units)
short center1_x = pic_pix_x + s_mv[0]; // mvx of second pred (in pel units)
short center1_y = pic_pix_y + s_mv[1]; // mvy of second pred (in pel units)
short mb_x = pic_pix_x - img->opix_x;
short mb_y = pic_pix_y - img->opix_y;
short block_x = (mb_x >> 2);
short block_y = (mb_y >> 2);
int best_x = center2_x;
int best_y = center2_y;
int ET_Thred = Median_Pred_Thd_MB[blocktype];
short offset1 = (apply_weights ? (list == 0? wp_offset[list_offset ][ref][0]: wp_offset[list_offset + 1][0 ][ref]) : 0);
short offset2 = (apply_weights ? (list == 0? wp_offset[list_offset + 1][ref][0]: wp_offset[list_offset ][0 ][ref]) : 0);
ref_pic1_sub.luma = listX[list + list_offset][ref]->p_curr_img_sub;
ref_pic2_sub.luma = listX[list == 0 ? 1 + list_offset: list_offset][ 0 ]->p_curr_img_sub;
img_width = listX[list + list_offset][ref]->size_x;
img_height = listX[list + list_offset][ref]->size_y;
width_pad = listX[list + list_offset][ref]->size_x_pad;
height_pad = listX[list + list_offset][ref]->size_y_pad;
if (apply_weights)
{
weight1 = list == 0 ? wbp_weight[list_offset ][ref][0][0] : wbp_weight[list_offset + LIST_1][0 ][ref][0];
weight2 = list == 0 ? wbp_weight[list_offset + LIST_1][ref][0][0] : wbp_weight[list_offset ][0 ][ref][0];
offsetBi=(offset1 + offset2 + 1)>>1;
computeBiPred = computeBiPredSAD2; //ME only supports SAD computations
}
else
{
weight1 = 1<<luma_log_weight_denom;
weight2 = 1<<luma_log_weight_denom;
offsetBi = 0;
computeBiPred = computeBiPredSAD1; //ME only supports SAD computations
}
if (ChromaMEEnable )
{
ref_pic1_sub.crcb[0] = listX[list + list_offset][ref]->imgUV_sub[0];
ref_pic1_sub.crcb[1] = listX[list + list_offset][ref]->imgUV_sub[1];
ref_pic2_sub.crcb[0] = listX[list == 0 ? 1 + list_offset: list_offset][ 0 ]->imgUV_sub[0];
ref_pic2_sub.crcb[1] = listX[list == 0 ? 1 + list_offset: list_offset][ 0 ]->imgUV_sub[1];
width_pad_cr = listX[list + list_offset][ref]->size_x_cr_pad;
height_pad_cr = listX[list + list_offset][ref]->size_y_cr_pad;
if (apply_weights)
{
weight1_cr[0] = list == 0 ? wbp_weight[list_offset ][ref][0][1] : wbp_weight[list_offset + LIST_1][0 ][ref][1];
weight1_cr[1] = list == 0 ? wbp_weight[list_offset ][ref][0][2] : wbp_weight[list_offset + LIST_1][0 ][ref][2];
weight2_cr[0] = list == 0 ? wbp_weight[list_offset + LIST_1][ref][0][1] : wbp_weight[list_offset ][0 ][ref][1];
weight2_cr[1] = list == 0 ? wbp_weight[list_offset + LIST_1][ref][0][2] : wbp_weight[list_offset ][0 ][ref][2];
offsetBi_cr[0] = (list == 0)
? (wp_offset[list_offset ][ref][1] + wp_offset[list_offset + LIST_1][ref][1] + 1) >> 1
: (wp_offset[list_offset + LIST_1][0 ][1] + wp_offset[list_offset ][0 ][1] + 1) >> 1;
offsetBi_cr[1] = (list == 0)
? (wp_offset[list_offset ][ref][2] + wp_offset[list_offset + LIST_1][ref][2] + 1) >> 1
: (wp_offset[list_offset + LIST_1][0 ][2] + wp_offset[list_offset ][0 ][2] + 1) >> 1;
}
else
{
weight1_cr[0] = 1<<chroma_log_weight_denom;
weight1_cr[1] = 1<<chroma_log_weight_denom;
weight2_cr[0] = 1<<chroma_log_weight_denom;
weight2_cr[1] = 1<<chroma_log_weight_denom;
offsetBi_cr[0] = 0;
offsetBi_cr[1] = 0;
}
}
//===== set function for getting reference picture lines =====
if ((center2_x > search_range) && (center2_x < img_width -1-search_range-blocksize_x) &&
(center2_y > search_range) && (center2_y < img_height-1-search_range-blocksize_y) )
{
bipred2_access_method = FAST_ACCESS;
}
else
{
bipred2_access_method = UMV_ACCESS;
}
//===== set function for getting reference picture lines =====
if ((center1_y > search_range) && (center1_y < img_height-1-search_range-blocksize_y) )
{
bipred1_access_method = FAST_ACCESS;
}
else
{
bipred1_access_method = UMV_ACCESS;
}
//////////////////////////////////////////////////////////////////////////
//////allocate memory for search state//////////////////////////
memset(McostState[0],0,(2*search_range+1)*(2*search_range+1));
//check the center median predictor
cand_x = center2_x ;
cand_y = center2_y ;
mcost = MV_COST (lambda_factor, mvshift, center1_x, center1_y, pred_x1, pred_y1);
mcost += MV_COST (lambda_factor, mvshift, cand_x, cand_y, pred_x2, pred_y2);
mcost += computeBiPred( cur_pic,
blocksize_y, blocksize_x, INT_MAX,
(center1_x << 2) + IMG_PAD_SIZE_TIMES4,
(center1_y << 2) + IMG_PAD_SIZE_TIMES4,
(cand_x << 2) + IMG_PAD_SIZE_TIMES4,
(cand_y << 2) + IMG_PAD_SIZE_TIMES4);
McostState[search_range][search_range] = 1;
if (mcost < min_mcost)
{
min_mcost = mcost;
best_x = cand_x;
best_y = cand_y;
}
iXMinNow = best_x;
iYMinNow = best_y;
for (m = 0; m < 4; m++)
{
cand_x = iXMinNow + Diamond_x[m];
cand_y = iYMinNow + Diamond_y[m];
SEARCH_ONE_PIXEL_BIPRED;
}
if(center2_x != pic_pix_x || center2_y != pic_pix_y)
{
cand_x = pic_pix_x ;
cand_y = pic_pix_y ;
SEARCH_ONE_PIXEL_BIPRED;
iXMinNow = best_x;
iYMinNow = best_y;
for (m = 0; m < 4; m++)
{
cand_x = iXMinNow + Diamond_x[m];
cand_y = iYMinNow + Diamond_y[m];
SEARCH_ONE_PIXEL_BIPRED;
}
}
/***********************************init process*************************/
if( min_mcost < ET_Thred)
{
goto terminate_step;
}
else
{
int N_Bframe=0;
int n_Bframe=0;
short****** bipred_mv = img->bipred_mv[list];
N_Bframe = params->successive_Bframe;
n_Bframe = stats->frame_ctr[B_SLICE]%(N_Bframe+1);
/**************************** MV prediction **********************/
//MV uplayer prediction
// non for bipred mode
//MV ref-frame prediction
if(list==0)
{
if (img->field_picture)
{
pred_MV_ref[0] =(int) (bipred_mv[1][0][blocktype][block_y][block_x][0]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
pred_MV_ref[1] =(int) (bipred_mv[1][0][blocktype][block_y][block_x][1]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
}
else //frame case
{
pred_MV_ref[0] =(int) (bipred_mv[1][0][blocktype][block_y][block_x][0]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
pred_MV_ref[1] =(int) (bipred_mv[1][0][blocktype][block_y][block_x][1]*(-n_Bframe)/(N_Bframe-n_Bframe+1.0f));
}
}
/******************************SAD prediction**********************************/
pred_SAD =imin(imin(SAD_a,SAD_b),SAD_c); // pred_SAD_space
ET_Thred = Big_Hexagon_Thd_MB[blocktype];
///////Threshold defined for early termination///////////////////
if (pred_SAD == 0)
{
betaFourth_1=0;
betaFourth_2=0;
}
else
{
betaFourth_1 = Bsize[blocktype]/(pred_SAD*pred_SAD)-AlphaFourth_1[blocktype];
betaFourth_2 = Bsize[blocktype]/(pred_SAD*pred_SAD)-AlphaFourth_2[blocktype];
}
}
/***********************************end of init *************************/
// first_step: initial start point prediction
//prediction using mV of last ref moiton vector
if(list == 0)
{
cand_x = pic_pix_x + (pred_MV_ref[0]/4);
cand_y = pic_pix_y + (pred_MV_ref[1]/4);
SEARCH_ONE_PIXEL_BIPRED;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -