📄 mv-search.c
字号:
#ifdef EIGHTH_PEL
mcost = MV_COST (lambda_factor, mv_shift, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
#else
mcost = MV_COST (lambda_factor, 0, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
#endif
if (check_position0 && pos==0)
{
mcost -= WEIGHTED_COST (lambda_factor, 16);
}
if (mcost >= min_mcost) continue;
cmv_x = cand_mv_x + pic4_pix_x;
cmv_y = cand_mv_y + pic4_pix_y;
//----- add up SATD -----
for (y0=0, abort_search=0; y0<blocksize_y && !abort_search; y0+=4)
{
y_offset = (y0>7)*ypels;
ry0 = (y0<<2) + cmv_y;
ry4 = ry0 + 4;
ry8 = ry4 + 4;
ry12 = ry8 + 4;
y1 = y0 + 1;
y2 = y1 + 1;
y3 = y2 + 1;
for (x0=0; x0<blocksize_x; x0+=BLOCK_SIZE)
{
rx0 = (x0<<2) + cmv_x;
d = diff;
orig_line = &orig_pic [y0][x0];
ref_line = get_line (ref_pic, ry0, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line - *(ref_line += 4);
orig_line = &orig_pic [y1][x0];
ref_line = get_line (ref_pic, ry4, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line - *(ref_line += 4);
orig_line = &orig_pic [y2][x0];
ref_line = get_line (ref_pic, ry8, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line - *(ref_line += 4);
orig_line = &orig_pic [y3][x0];
ref_line = get_line (ref_pic, ry12, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line - *(ref_line += 4);
if (!test8x8transform)
{
if ((mcost += SATD (diff, halfpelhadamard)) > min_mcost)
{
abort_search = 1;
break;
}
}
else
{
i = (x0&0x7) + (x0>7) * 64 + y_offset;
for(k=0, j=y0; j<BLOCK_SIZE + y0; j++, k+=BLOCK_SIZE)
memcpy(&(c_diff[i + ((j&0x7)<<3)]), &diff[k], BLOCK_SIZE*sizeof(int));
}
}
}
if(test8x8transform)
mcost += find_SATD (c_diff, blocktype);
if (mcost < min_mcost)
{
min_mcost = mcost;
best_pos = pos;
}
}
if (best_pos)
{
*mv_x += (spiral_hpel_search_x [best_pos]);
*mv_y += (spiral_hpel_search_y [best_pos]);
}
if (input->hadamard == 2)
min_mcost = INT_MAX;
test8x8transform = input->Transform8x8Mode && blocktype <= 4 && input->hadamard;
/************************************
***** *****
***** 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) )
{
get_line = FastLine4X;
}
else
{
get_line = UMVLine4X;
}
//===== loop over search positions =====
for (best_pos = 0, pos = qpelstart; 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 -----
#ifdef EIGHTH_PEL
mcost = MV_COST (lambda_factor, mv_shift, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
#else
mcost = MV_COST (lambda_factor, 0, cand_mv_x, cand_mv_y, pred_mv_x, pred_mv_y);
#endif
if (mcost >= min_mcost) continue;
cmv_x = cand_mv_x + pic4_pix_x;
cmv_y = cand_mv_y + pic4_pix_y;
//----- add up SATD -----
for (y0=0, abort_search=0; y0<blocksize_y && !abort_search; y0+=4)
{
y_offset = (y0>7)*ypels;
ry0 = (y0<<2) + cmv_y;
ry4 = ry0 + 4;
ry8 = ry4 + 4;
ry12 = ry8 + 4;
y1 = y0 + 1;
y2 = y1 + 1;
y3 = y2 + 1;
for (x0=0; x0<blocksize_x; x0+=BLOCK_SIZE)
{
rx0 = (x0<<2) + cmv_x;
d = diff;
orig_line = &orig_pic [y0][x0];
ref_line = get_line (ref_pic, ry0, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line - *(ref_line += 4);
orig_line = &orig_pic [y1][x0];
ref_line = get_line (ref_pic, ry4, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line - *(ref_line += 4);
orig_line = &orig_pic [y2][x0];
ref_line = get_line (ref_pic, ry8, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line - *(ref_line += 4);
orig_line = &orig_pic [y3][x0];
ref_line = get_line (ref_pic, ry12, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4);
*d++ = *orig_line++ - *(ref_line += 4);
*d = *orig_line - *(ref_line += 4);
if (!test8x8transform)
{
if ((mcost += SATD (diff, input->hadamard)) > min_mcost)
{
abort_search = 1;
break;
}
}
else
{
i = (x0&0x7) + (x0>7) * 64 + y_offset;
for(k=0, j=y0; j<y0 + BLOCK_SIZE; j++, k+=BLOCK_SIZE)
memcpy(&(c_diff[i + ((j&0x7)<<3)]), &diff[k], BLOCK_SIZE*sizeof(int));
}
}
}
if(test8x8transform)
mcost += find_SATD (c_diff, blocktype);
if (mcost < min_mcost)
{
min_mcost = mcost;
best_pos = pos;
}
}
if (best_pos)
{
*mv_x += spiral_search_x [best_pos];
*mv_y += spiral_search_y [best_pos];
}
#ifdef EIGHTH_PEL
/***********************************
***** *****
***** EIGHTH-PEL REFINEMENT *****
***** *****
***********************************/
if (img->mv_res)
{
//===== convert search center to eighth-pel units (double resolution) =====
*mv_x <<= 1;
*mv_y <<= 1;
pic4_pix_x <<= 1;
pic4_pix_y <<= 1;
//===== set function for getting pixel values =====
if ((pic4_pix_x + *mv_x > 1) && (pic4_pix_x + *mv_x < 2*max_pos_x4 - 2) &&
(pic4_pix_y + *mv_y > 1) && (pic4_pix_y + *mv_y < 2*max_pos_y4 - 2))
get_line = FastLine4X8;
else
get_line = UMVLine4X8;
//===== loop over search positions =====
for (best_pos = 0, pos = 1; pos < search_pos8; pos++)
{
cand_mv_x = *mv_x + spiral_search_x[pos]; // eighth-pel units
cand_mv_y = *mv_y + spiral_search_y[pos]; // eighth-pel units
//----- set motion vector cost -----
mcost = MV_COST (lambda_factor, 0, 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;
//----- add up SATD -----
for (y0=0, abort_search=0; y0<blocksize_y && !abort_search; y0+=BLOCK_SIZE)
{
y_offset = (y0>7)*ypels;
ry0 = (y0<<3) + cmv_y;
ry4 = ry0 + 8;
ry8 = ry4 + 8;
ry12 = ry8 + 8;
y1 = y0 + 1;
y2 = y1 + 1;
y3 = y2 + 1;
for (x0=0; x0<blocksize_x; x0+=BLOCK_SIZE)
{
rx0 = (x0<<3) + cmv_x;
d = diff;
orig_line = &orig_pic [y0][x0];
ref_line = get_line (ref_pic, ry0, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4 );
*d++ = *orig_line++ - *(ref_line += 4 );
*d++ = *orig_line - *(ref_line += 4 );
orig_line = &orig_pic [y1][x0];
ref_line = get_line (ref_pic, ry4, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4 );
*d++ = *orig_line++ - *(ref_line += 4 );
*d++ = *orig_line - *(ref_line += 4 );
orig_line = &orig_pic [y2][x0];
ref_line = get_line (ref_pic, ry8, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4 );
*d++ = *orig_line++ - *(ref_line += 4 );
*d++ = *orig_line - *(ref_line += 4 );
orig_line = &orig_pic [y3][x0];
ref_line = get_line (ref_pic, ry12, rx0, img_height, img_width);
*d++ = *orig_line++ - *(ref_line );
*d++ = *orig_line++ - *(ref_line += 4 );
*d++ = *orig_line++ - *(ref_line += 4 );
*d = *orig_line - *(ref_line += 4 );
if (!test8x8transform)
{
if ((mcost += SATD (diff, input->hadamard)) > min_mcost)
{
abort_search = 1;
break;
}
}
else
{
i = (x0&0x7) + (x0>7) * 64 + y_offset;
for(k=0, j=y0; j<BLOCK_SIZE + y0; j++, k+=BLOCK_SIZE)
memcpy(&(c_diff[i + ((j&0x7)<<3)]), &diff[k], BLOCK_SIZE*sizeof(int));
}
}
}
if (test8x8transform)
mcost += find_SATD (c_diff, blocktype);
if (mcost < min_mcost)
{
min_mcost = mcost;
best_pos = pos;
}
}
if (best_pos)
{
*mv_x += spiral_search_x [best_pos];
*mv_y += spiral_search_y [best_pos];
}
}
#endif
//===== return minimum motion cost =====
return min_mcost;
}
/*!
***********************************************************************
* \brief
* Sub pixel block motion search enhanced
***********************************************************************
*/
int // ==> minimum motion cost after search
simplified_FastFullSubPelBlockMotionSearch (pel_t** 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)
int pred_mv_x, // <-- motion vector predictor (x) in sub-pel units
int 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)
#ifdef EIGHTH_PEL
int search_pos8, // <-- search positions for eighth-pel search (default: 9)
#endif
int min_mcost, // <-- minimum motion cost (cost for center or huge value)
int lambda_factor // <-- lagrangian parameter for determining motion cost
)
{
int j, i, k;
int c_diff[MB_PIXELS];
int diff[16], *d;
int pos, best_pos, mcost, abort_search;
int y0, y1, y2, y3;
int x0;
int ry0, ry4, ry8, ry12, rx0;
#ifdef EIGHTH_PEL
int mv_shift = (img->mv_res ? 1 : 0);
#endif
int cand_mv_x, ca
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -