📄 me_umhexsmp.c
字号:
}
// Multi Big Hexagon Search
iXMinNow = best_x;
iYMinNow = best_y;
for(i = 1; i <= search_range/4; i++)
{
for (m = 0; m < 16; m++)
{
cand_x = iXMinNow + Big_Hexagon_X[m]*i;
cand_y = iYMinNow + Big_Hexagon_Y[m]*i;
SEARCH_ONE_PIXEL_HELPER
}
}
}
// Search up_layer predictor for non 16x16 blocks
if (blocktype > 1)
{
cand_x = pic_pix_x + (smpUMHEX_pred_MV_uplayer_X/4);
cand_y = pic_pix_y + (smpUMHEX_pred_MV_uplayer_Y/4);
SEARCH_ONE_PIXEL_HELPER
}
if(center_x != pic_pix_x || center_y != pic_pix_y)
{
cand_x = pic_pix_x;
cand_y = pic_pix_y;
SEARCH_ONE_PIXEL_HELPER
iXMinNow = best_x;
iYMinNow = best_y;
// Local diamond search
for (m = 0; m < 4; m++)
{
cand_x = iXMinNow + Diamond_X[m];
cand_y = iYMinNow + Diamond_Y[m];
SEARCH_ONE_PIXEL_HELPER
}
}
// If the minimum cost is small enough, do a local search
// and finish the search here
if (min_mcost < (ConvergeThreshold>>block_type_shift_factor[blocktype]))
{
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_HELPER
}
*mv_x = (short) (best_x - pic_pix_x);
*mv_y = (short) (best_y - pic_pix_y);
return min_mcost;
}
//second_step: Extended Hexagon-based Search
for(i = 0; i < search_range; i++)
{
iXMinNow = best_x;
iYMinNow = best_y;
for (m = 0; m < 6; m++)
{
cand_x = iXMinNow + Hexagon_X[m];
cand_y = iYMinNow + Hexagon_Y[m];
SEARCH_ONE_PIXEL_HELPER
}
// The minimum cost point happens in the center
if (best_x == iXMinNow && best_y == iYMinNow)
{
break;
}
}
//third_step: Small diamond search
for(i = 0; i < search_range; i++)
{
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_HELPER
}
// The minimum cost point happens in the center
if (best_x == iXMinNow && best_y == iYMinNow)
{
break;
}
}
*mv_x = (short) (best_x - pic_pix_x);
*mv_y = (short) (best_y - pic_pix_y);
return min_mcost;
}
/*!
***********************************************************************
* \brief
* Sub pixel block motion search enhanced
***********************************************************************
*/
int // ==> minimum motion cost after search
smpUMHEXFullSubPelBlockMotionSearch (imgpel* orig_pic, // <-- original pixel values for the AxB block
short ref, // <-- reference frame (0... or -1 (backward))
int list, // <-- reference picture list
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_mv_x, // <-- motion vector predictor (x) in sub-pel units
short pred_mv_y, // <-- motion vector predictor (y) in sub-pel units
short* mv_x, // <--> in: search center (x) / out: motion vector (x) - in pel units
short* mv_y, // <--> in: search center (y) / out: motion vector (y) - in pel units
int search_pos2, // <-- search positions for half-pel search (default: 9)
int search_pos4, // <-- search positions for quarter-pel search (default: 9)
int min_mcost, // <-- minimum motion cost (cost for center or huge value)
int lambda_factor // <-- lagrangian parameter for determining motion cost
)
{
int pos, best_pos, mcost;
int cand_mv_x, cand_mv_y;
int check_position0 = (!input->rdopt && img->type!=B_SLICE && ref==0 && blocktype==1 && *mv_x==0 && *mv_y==0);
int blocksize_x = input->blc_size[blocktype][0];
int blocksize_y = input->blc_size[blocktype][1];
int pic4_pix_x = ((pic_pix_x + IMG_PAD_SIZE)<< 2);
int pic4_pix_y = ((pic_pix_y + IMG_PAD_SIZE)<< 2);
int max_pos2 = ( !start_me_refinement_hp ? imax(1,search_pos2) : search_pos2);
int list_offset = img->mb_data[img->current_mb_nr].list_offset;
int apply_weights = ( (active_pps->weighted_pred_flag &&
(img->type == P_SLICE || img->type == SP_SLICE)) ||
(active_pps->weighted_bipred_idc && (img->type == B_SLICE)) )
&& input->UseWeightedReferenceME;
int cmv_x, cmv_y;
StorablePicture *ref_picture = listX[list+list_offset][ref];
int max_pos_x4 = ((ref_picture->size_x - blocksize_x + 2*IMG_PAD_SIZE)<<2);
int max_pos_y4 = ((ref_picture->size_y - blocksize_y + 2*IMG_PAD_SIZE)<<2);
dist_method = Q_PEL + 3 * apply_weights;
ref_pic_sub.luma = ref_picture->curr_imgY_sub;
img_width = ref_picture->size_x;
img_height = ref_picture->size_y;
width_pad = ref_picture->size_x_pad;
height_pad = ref_picture->size_y_pad;
if (apply_weights)
{
weight_luma = wp_weight[list + list_offset][ref][0];
offset_luma = wp_offset[list + list_offset][ref][0];
}
if (ChromaMEEnable)
{
ref_pic_sub.crcb[0] = ref_picture->imgUV_sub[0];
ref_pic_sub.crcb[1] = ref_picture->imgUV_sub[1];
width_pad_cr = ref_picture->size_x_cr_pad;
height_pad_cr = ref_picture->size_y_cr_pad;
if (apply_weights)
{
weight_cr[0] = wp_weight[list + list_offset][ref][1];
weight_cr[1] = wp_weight[list + list_offset][ref][2];
offset_cr[0] = wp_offset[list + list_offset][ref][1];
offset_cr[1] = wp_offset[list + list_offset][ref][2];
}
}
/*********************************
***** *****
***** HALF-PEL REFINEMENT *****
***** *****
*********************************/
//===== set function for getting pixel values =====
if ((pic4_pix_x + *mv_x > 1) && (pic4_pix_x + *mv_x < max_pos_x4 - 1) &&
(pic4_pix_y + *mv_y > 1) && (pic4_pix_y + *mv_y < max_pos_y4 - 1) )
{
ref_access_method = FAST_ACCESS;
}
else
{
ref_access_method = UMV_ACCESS;
}
//===== loop over search positions =====
for (best_pos = 0, pos = start_me_refinement_hp; pos < max_pos2; pos++)
{
cand_mv_x = *mv_x + (spiral_hpel_search_x[pos]); // quarter-pel units
cand_mv_y = *mv_y + (spiral_hpel_search_y[pos]); // quarter-pel units
//----- set motion vector cost -----
mcost = MV_COST_SMP (lambda_factor, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
if (mcost >= min_mcost) continue;
cmv_x = cand_mv_x + pic4_pix_x;
cmv_y = cand_mv_y + pic4_pix_y;
mcost += computeUniPred[dist_method]( orig_pic, blocksize_y, blocksize_x, min_mcost - mcost, cmv_x, cmv_y);
if (pos==0 && check_position0)
{
mcost -= WEIGHTED_COST (lambda_factor, 16);
}
if (mcost < min_mcost)
{
min_mcost = mcost;
best_pos = pos;
}
if (min_mcost < (SubPelThreshold3>>block_type_shift_factor[blocktype]))
{
break;
}
}
if (best_pos)
{
*mv_x += (spiral_hpel_search_x [best_pos]);
*mv_y += (spiral_hpel_search_y [best_pos]);
}
if ((*mv_x == 0) && (*mv_y == 0) && (pred_mv_x == 0 && pred_mv_y == 0) &&
(min_mcost < (SubPelThreshold1>>block_type_shift_factor[blocktype])) )
{
best_pos = 0;
return min_mcost;
}
if ( !start_me_refinement_qp )
min_mcost = INT_MAX;
/************************************
***** *****
***** QUARTER-PEL REFINEMENT *****
***** *****
************************************/
//===== set function for getting pixel values =====
if ((pic4_pix_x + *mv_x > 0) && (pic4_pix_x + *mv_x < max_pos_x4) &&
(pic4_pix_y + *mv_y > 0) && (pic4_pix_y + *mv_y < max_pos_y4) )
{
ref_access_method = FAST_ACCESS;
}
else
{
ref_access_method = UMV_ACCESS;
}
//===== loop over search positions =====
for (best_pos = 0, pos = start_me_refinement_qp; pos < search_pos4; pos++)
{
cand_mv_x = *mv_x + spiral_search_x[pos]; // quarter-pel units
cand_mv_y = *mv_y + spiral_search_y[pos]; // quarter-pel units
//----- set motion vector cost -----
mcost = MV_COST_SMP (lambda_factor, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
if (mcost >= min_mcost) continue;
cmv_x = cand_mv_x + pic4_pix_x;
cmv_y = cand_mv_y + pic4_pix_y;
mcost += computeUniPred[dist_method]( orig_pic, blocksize_y, blocksize_x, min_mcost - mcost, cmv_x, cmv_y);
if (mcost < min_mcost)
{
min_mcost = mcost;
best_pos = pos;
}
if (min_mcost < (SubPelThreshold3>>block_type_shift_factor[blocktype]))
{
break;
}
}
if (best_pos)
{
*mv_x += spiral_search_x [best_pos];
*mv_y += spiral_search_y [best_pos];
}
//===== return minimum motion cost =====
return min_mcost;
}
/*!
************************************************************************
* \brief
* Fast sub pixel block motion estimation
************************************************************************
*/
int // ==> minimum motion cost after search
smpUMHEXSubPelBlockMotionSearch (
imgpel* orig_pic, // <-- original pixel values for the AxB block
short ref, // <-- reference frame (0... or -1 (backward))
int list, // <-- reference picture list
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_mv_x, // <-- motion vector predictor (x) in sub-pel units
short pred_mv_y, // <-- motion vector predictor (y) in sub-pel units
short* mv_x, // <--> in: search center (x) / out: MV (x) - in pel units
short* mv_y, // <--> in: search center (y) / out: MV (y) - in pel units
int search_pos2, // <-- search positions for half-pel search (default: 9)
int search_pos4, // <-- search positions for quarter-pel search (default: 9)
int min_mcost, // <-- minimum motion cost (cost for center or huge value)
int lambda_factor) // <-- lagrangian parameter for determining motion cost
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -