📄 me_fullsearch.c
字号:
height_pad = ref_picture->size_y_pad;
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;
}
/*********************************
***** *****
***** HALF-PEL REFINEMENT *****
***** *****
*********************************/
//===== set function for getting pixel values =====
if ((pic4_pix_x + mv[0] > 1) && (pic4_pix_x + mv[0] < max_pos_x4 - 1) &&
(pic4_pix_y + mv[1] > 1) && (pic4_pix_y + mv[1] < 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[0] + (spiral_hpel_search_x[pos]); // quarter-pel units
cand_mv_y = mv[1] + (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[0], pred_mv[1]);
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 (best_pos)
{
mv[0] += (spiral_hpel_search_x [best_pos]);
mv[1] += (spiral_hpel_search_y [best_pos]);
}
if ( !start_me_refinement_qp )
min_mcost = INT_MAX;
/************************************
***** *****
***** QUARTER-PEL REFINEMENT *****
***** *****
************************************/
//===== set function for getting pixel values =====
if ((pic4_pix_x + mv[0] > 0) && (pic4_pix_x + mv[0] < max_pos_x4) &&
(pic4_pix_y + mv[1] > 0) && (pic4_pix_y + mv[1] < max_pos_y4) )
{
ref_access_method = FAST_ACCESS;
}
else
{
ref_access_method = UMV_ACCESS;
}
dist_method = Q_PEL + 3 * apply_weights;
lambda_factor = lambda[Q_PEL];
//===== loop over search positions =====
for (best_pos = 0, pos = start_me_refinement_qp; pos < search_pos4; pos++)
{
cand_mv_x = mv[0] + spiral_search_x[pos]; // quarter-pel units
cand_mv_y = mv[1] + 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[0], pred_mv[1]);
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 (best_pos)
{
mv[0] += spiral_search_x [best_pos];
mv[1] += spiral_search_y [best_pos];
}
//===== return minimum motion cost =====
return min_mcost;
}
/*!
***********************************************************************
* \brief
* Bipred Sub pixel block motion search
***********************************************************************
*/
int // ==> minimum motion cost after search
SubPelBlockSearchBiPred (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_mv1[2], // <-- motion vector predictor (x) in sub-pel units
short pred_mv2[2], // <-- motion vector predictor (x) in sub-pel units
short mv[2], // <--> in: search center (x) / out: motion vector (x) - in pel units
short static_mv[2], // <--> in: search center (x) / out: motion vector (x) - 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, // <-- lagrangian parameter for determining motion cost
int apply_weights // <-- perform weight based ME
)
{
int list_offset = img->mb_data[img->current_mb_nr].list_offset;
int pos, best_pos, mcost;
int cand_mv_x, cand_mv_y;
int blocksize_x = params->blc_size[blocktype][0];
int blocksize_y = params->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 cmv_x, cmv_y;
int smv_x = static_mv[0] + pic4_pix_x;
int smv_y = static_mv[1] + pic4_pix_y;
StorablePicture *ref_picture1 = listX[list + list_offset][ref];
StorablePicture *ref_picture2 = listX[(list ^ 1) + list_offset][0];
int max_pos_x4 = ((ref_picture1->size_x - blocksize_x + 2*IMG_PAD_SIZE)<<2);
int max_pos_y4 = ((ref_picture1->size_y - blocksize_y + 2*IMG_PAD_SIZE)<<2);
int lambda_factor = lambda[H_PEL];
ref_pic1_sub.luma = ref_picture1->p_curr_img_sub;
ref_pic2_sub.luma = ref_picture2->p_curr_img_sub;
img_width = ref_picture1->size_x;
img_height = ref_picture1->size_y;
width_pad = ref_picture1->size_x_pad;
height_pad = ref_picture1->size_y_pad;
if (apply_weights)
{
computeBiPred = computeBiPred2[H_PEL];
}
else
{
computeBiPred = computeBiPred1[H_PEL];
}
if ( ChromaMEEnable )
{
ref_pic1_sub.crcb[0] = ref_picture1->imgUV_sub[0];
ref_pic1_sub.crcb[1] = ref_picture1->imgUV_sub[1];
ref_pic2_sub.crcb[0] = ref_picture2->imgUV_sub[0];
ref_pic2_sub.crcb[1] = ref_picture2->imgUV_sub[1];
width_pad_cr = ref_picture1->size_x_cr_pad;
height_pad_cr = ref_picture1->size_y_cr_pad;
}
/*********************************
***** *****
***** HALF-PEL REFINEMENT *****
***** *****
*********************************/
//===== set function for getting pixel values =====
if ((pic4_pix_x + mv[0] > 1) && (pic4_pix_x + mv[0] < max_pos_x4 - 1) &&
(pic4_pix_y + mv[1] > 1) && (pic4_pix_y + mv[1] < max_pos_y4 - 1))
{
bipred1_access_method = FAST_ACCESS;
}
else
{
bipred1_access_method = UMV_ACCESS;
}
if ((pic4_pix_x + static_mv[0] > 1) && (pic4_pix_x + static_mv[0] < max_pos_x4 - 1) &&
(pic4_pix_y + static_mv[1] > 1) && (pic4_pix_y + static_mv[1] < max_pos_y4 - 1))
{
bipred2_access_method = FAST_ACCESS;
}
else
{
bipred2_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[0] + (spiral_hpel_search_x[pos]); // quarter-pel units
cand_mv_y = mv[1] + (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_mv1[0], pred_mv1[1]);
mcost += MV_COST_SMP (lambda_factor, static_mv[0], static_mv[1], pred_mv2[0], pred_mv2[1]);
if (mcost >= min_mcost) continue;
cmv_x = cand_mv_x + pic4_pix_x;
cmv_y = cand_mv_y + pic4_pix_y;
mcost += computeBiPred(orig_pic, blocksize_y, blocksize_x,
min_mcost - mcost, cmv_x, cmv_y, smv_x, smv_y);
if (mcost < min_mcost)
{
min_mcost = mcost;
best_pos = pos;
}
}
if (best_pos)
{
mv[0] += (spiral_hpel_search_x [best_pos]);
mv[1] += (spiral_hpel_search_y [best_pos]);
}
computeBiPred = apply_weights? computeBiPred2[Q_PEL] : computeBiPred1[Q_PEL];
/************************************
***** *****
***** QUARTER-PEL REFINEMENT *****
***** *****
************************************/
//===== set function for getting pixel values =====
if ((pic4_pix_x + mv[0] > 0) && (pic4_pix_x + mv[0] < max_pos_x4) &&
(pic4_pix_y + mv[1] > 0) && (pic4_pix_y + mv[1] < max_pos_y4))
{
bipred1_access_method = FAST_ACCESS;
}
else
{
bipred1_access_method = UMV_ACCESS;
}
if ((pic4_pix_x + static_mv[0] > 0) && (pic4_pix_x + static_mv[0] < max_pos_x4) &&
(pic4_pix_y + static_mv[1] > 0) && (pic4_pix_y + static_mv[1] < max_pos_y4))
{
bipred2_access_method = FAST_ACCESS;
}
else
{
bipred2_access_method = UMV_ACCESS;
}
if ( !start_me_refinement_qp )
min_mcost = INT_MAX;
lambda_factor = lambda[Q_PEL];
//===== loop over search positions =====
for (best_pos = 0, pos = start_me_refinement_qp; pos < search_pos4; pos++)
{
cand_mv_x = mv[0] + spiral_search_x[pos]; // quarter-pel units
cand_mv_y = mv[1] + spiral_search_y[pos]; // quarter-pel units
//----- set motion vector cost -----
mcost = MV_COST_SMP (lambda_factor, cand_mv_x, cand_mv_y, pred_mv1[0], pred_mv1[1]);
mcost += MV_COST_SMP (lambda_factor, static_mv[0], static_mv[1], pred_mv2[0], pred_mv2[1]);
if (mcost >= min_mcost) continue;
cmv_x = cand_mv_x + pic4_pix_x;
cmv_y = cand_mv_y + pic4_pix_y;
mcost += computeBiPred(orig_pic, blocksize_y, blocksize_x,
min_mcost - mcost, cmv_x, cmv_y, smv_x, smv_y);
if (mcost < min_mcost)
{
min_mcost = mcost;
best_pos = pos;
}
}
if (best_pos)
{
mv[0] += spiral_search_x [best_pos];
mv[1] += spiral_search_y [best_pos];
}
//===== return minimum motion cost =====
return min_mcost;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -