📄 me_umhexsmp.c
字号:
(cand_y << 2) + IMG_PAD_SIZE_TIMES4);
if (mcost < min_mcost)
{
min_mcost = mcost;
best_x = cand_x;
best_y = cand_y;
}
iXMinNow = best_x;
iYMinNow = best_y;
if (0 != pred_mv_x1 || 0 != pred_mv_y1 || 0 != pred_mv_x2 || 0 != pred_mv_y2)
{
cand_x = pic_pix_x;
cand_y = pic_pix_y;
SEARCH_ONE_PIXEL_BIPRED_HELPER;
}
// If the min_mcost is small enough, do a local search then terminate
// This is good for stationary or quasi-stationary areas
if ((min_mcost<<3) < (ConvergeThreshold>>(block_type_shift_factor[blocktype])))
{
for (m = 0; m < 4; m++)
{
cand_x = iXMinNow + Diamond_X[m];
cand_y = iYMinNow + Diamond_Y[m];
SEARCH_ONE_PIXEL_BIPRED_HELPER;
}
*mv_x = best_x - pic_pix_x;
*mv_y = best_y - pic_pix_y;
return min_mcost;
}
// Small local search
for (m = 0; m < 4; m++)
{
cand_x = iXMinNow + Diamond_X[m];
cand_y = iYMinNow + Diamond_Y[m];
SEARCH_ONE_PIXEL_BIPRED_HELPER;
}
// First_step: Symmetrical-cross search
// If distortion is large, use large shapes. Otherwise, compact shapes are faster
if ((blocktype == 1 &&
(min_mcost<<2) > (SymmetricalCrossSearchThreshold1>>block_type_shift_factor[blocktype])) ||
((min_mcost<<2) > (SymmetricalCrossSearchThreshold2>>block_type_shift_factor[blocktype])))
{
iXMinNow = best_x;
iYMinNow = best_y;
for (i = 1; i <= search_range / 2; i++)
{
search_step = (i<<1) - 1;
cand_x = iXMinNow + search_step;
cand_y = iYMinNow;
SEARCH_ONE_PIXEL_BIPRED_HELPER
cand_x = iXMinNow - search_step;
SEARCH_ONE_PIXEL_BIPRED_HELPER
cand_x = iXMinNow;
cand_y = iYMinNow + search_step;
SEARCH_ONE_PIXEL_BIPRED_HELPER
cand_y = iYMinNow - search_step;
SEARCH_ONE_PIXEL_BIPRED_HELPER
}
// Hexagon Search
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_BIPRED_HELPER
}
// 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_BIPRED_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_BIPRED_HELPER
}
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_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_BIPRED_HELPER
}
}
// If the minimum cost is small enough, do a local search
// and finish the search here
if ((min_mcost<<2) < (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_BIPRED_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_BIPRED_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_BIPRED_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
* Set neighbouring block mode (intra/inter)
* used for fast motion estimation
************************************************************************
*/
void smpUMHEX_decide_intrabk_SAD()
{
if (img->type != I_SLICE)
{
if (img->pix_x == 0 && img->pix_y == 0)
{
smpUMHEX_flag_intra_SAD = 0;
}
else if (img->pix_x == 0)
{
smpUMHEX_flag_intra_SAD = smpUMHEX_flag_intra[(img->pix_x)>>4];
}
else if (img->pix_y == 0)
{
smpUMHEX_flag_intra_SAD = smpUMHEX_flag_intra[((img->pix_x)>>4)-1];
}
else
{
smpUMHEX_flag_intra_SAD = ((smpUMHEX_flag_intra[(img->pix_x)>>4])||
(smpUMHEX_flag_intra[((img->pix_x)>>4)-1])||
(smpUMHEX_flag_intra[((img->pix_x)>>4)+1])) ;
}
}
return;
}
/*!
************************************************************************
* \brief
* Set cost to zero if neighbouring block is intra
* used for fast motion estimation
************************************************************************
*/
void smpUMHEX_skip_intrabk_SAD(int best_mode, int ref_max)
{
short i, j, k;
if (img->number > 0)
{
smpUMHEX_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++)
{
smpUMHEX_l0_cost[k][j][i] = 0;
smpUMHEX_l1_cost[k][j][i] = 0;
}
}
}
}
return;
}
/*!
************************************************************************
* \brief
* Set up prediction MV and prediction up layer cost
* used for fast motion estimation
************************************************************************
*/
void smpUMHEX_setup(short ref,
int list,
int block_y,
int block_x,
int blocktype,
short ******all_mv)
{
if (blocktype > 6)
{
smpUMHEX_pred_MV_uplayer_X = all_mv[block_y][block_x][list][ref][5][0];
smpUMHEX_pred_MV_uplayer_Y = all_mv[block_y][block_x][list][ref][5][1];
}
else if (blocktype > 4)
{
smpUMHEX_pred_MV_uplayer_X = all_mv[block_y][block_x][list][ref][4][0];
smpUMHEX_pred_MV_uplayer_Y = all_mv[block_y][block_x][list][ref][4][1];
}
else if (blocktype == 4)
{
smpUMHEX_pred_MV_uplayer_X = all_mv[block_y][block_x][list][ref][2][0];
smpUMHEX_pred_MV_uplayer_Y = all_mv[block_y][block_x][list][ref][2][1];
}
else if (blocktype > 1)
{
smpUMHEX_pred_MV_uplayer_X = all_mv[block_y][block_x][list][ref][1][0];
smpUMHEX_pred_MV_uplayer_Y = all_mv[block_y][block_x][list][ref][1][1];
}
if (blocktype > 1)
{
if (blocktype > 6)
{
smpUMHEX_pred_SAD_uplayer = (list==1) ?
(smpUMHEX_l1_cost[5][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x])
: (smpUMHEX_l0_cost[5][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x]);
smpUMHEX_pred_SAD_uplayer /= 2;
}
else if (blocktype > 4)
{
smpUMHEX_pred_SAD_uplayer = (list==1) ?
(smpUMHEX_l1_cost[4][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x])
: (smpUMHEX_l0_cost[4][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x]);
smpUMHEX_pred_SAD_uplayer /= 2;
}
else if (blocktype == 4)
{
smpUMHEX_pred_SAD_uplayer = (list==1) ?
(smpUMHEX_l1_cost[2][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x])
: (smpUMHEX_l0_cost[2][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x]);
smpUMHEX_pred_SAD_uplayer /= 2;
}
else
{
smpUMHEX_pred_SAD_uplayer = (list==1) ?
(smpUMHEX_l1_cost[1][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x])
: (smpUMHEX_l0_cost[1][(img->pix_y>>2)+block_y][(img->pix_x>>2)+block_x]);
smpUMHEX_pred_SAD_uplayer /= 2;
}
smpUMHEX_pred_SAD_uplayer = smpUMHEX_flag_intra_SAD ? 0 : smpUMHEX_pred_SAD_uplayer;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -