📄 me_fullfast.c
字号:
int abs_y4, abs_x4;
int i, j, k;
int level_dist = F_PEL + apply_weights * 3;
int pixel_x, pixel_y;
for ( j= img->opix_y; j < img->opix_y + MB_BLOCK_SIZE; j +=BLOCK_SIZE)
{
for (pixel_y = j; pixel_y < j + BLOCK_SIZE; pixel_y++)
{
memcpy( srcptr, &imgY_org[pixel_y][img->opix_x], BLOCK_SIZE * sizeof(imgpel));
memcpy( srcptr + 16, &imgY_org[pixel_y][img->opix_x + BLOCK_SIZE], BLOCK_SIZE * sizeof(imgpel));
memcpy( srcptr + 32, &imgY_org[pixel_y][img->opix_x + 2 * BLOCK_SIZE], BLOCK_SIZE * sizeof(imgpel));
memcpy( srcptr + 48, &imgY_org[pixel_y][img->opix_x + 3 * BLOCK_SIZE], BLOCK_SIZE * sizeof(imgpel));
srcptr += BLOCK_SIZE;
}
srcptr += 48;
}
// storage format is different from that of orig_pic
// for YUV 4:2:0 we have:
// YYYY
// YYYY
// U U
//
// V V
//
if (ChromaMEEnable)
{
imgpel *auxptr;
int bsx_c = BLOCK_SIZE >> (chroma_shift_x - 2);
int bsy_c = BLOCK_SIZE >> (chroma_shift_y - 2);
int pic_pix_x_c = img->opix_x >> (chroma_shift_x - 2);
int pic_pix_y_c = img->opix_y >> (chroma_shift_y - 2);
// copy the original cmp1 and cmp2 data to the orig_pic matrix
// This seems to be wrong.
for (k=0; k<2; k++)
{
srcptr = auxptr = orig_pels + (256 << k);
for ( pixel_y = 0, i = 0; i < (BLOCK_SIZE >> (chroma_shift_y - 2)); i++, pixel_y += bsy_c )
{
for ( pixel_x = 0, k = 0; k < (BLOCK_SIZE >> (chroma_shift_x - 2)); k++, pixel_x += bsx_c )
{
srcptr = auxptr;
for (j = 0; j < bsy_c; j++)
{
memcpy( srcptr, &imgUV_org[k][pic_pix_y_c + pixel_y + j][pic_pix_x_c + pixel_x], bsx_c * sizeof(imgpel));
srcptr += bsx_c;
}
auxptr += MB_BLOCK_SIZE;
}
}
}
}
ref_picture = listX[list+list_offset][ref];
ref_access_method = FAST_ACCESS;
//===== Use weighted Reference for ME ====
ref_pic_sub.luma = ref_picture->curr_imgY_sub;
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];
}
}
max_width = ref_picture->size_x - 17;
max_height = ref_picture->size_y - 17;
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;
//===== get search center: predictor of 16x16 block =====
SetMotionVectorPredictor (pmv, enc_picture->ref_idx[list], enc_picture->mv[list], ref, list, 0, 0, 16, 16);
search_center_x[list][ref] = pmv[0] / 4;
search_center_y[list][ref] = pmv[1] / 4;
if (!input->rdopt)
{
//--- correct center so that (0,0) vector is inside ---
search_center_x[list][ref] = iClip3(-search_range, search_range, search_center_x[list][ref]);
search_center_y[list][ref] = iClip3(-search_range, search_range, search_center_y[list][ref]);
}
search_center_x[list][ref] = iClip3(-2047 + search_range, 2047 - search_range, search_center_x[list][ref]);
search_center_y[list][ref] = iClip3(LEVELMVLIMIT[img->LevelIndex][0] + search_range, LEVELMVLIMIT[img->LevelIndex][1] - search_range, search_center_y[list][ref]);
search_center_x[list][ref] += img->opix_x;
search_center_y[list][ref] += img->opix_y;
offset_x = search_center_x[list][ref];
offset_y = search_center_y[list][ref];
//===== check if whole search range is inside image =====
if (offset_x >= search_range && offset_x <= max_width - search_range &&
offset_y >= search_range && offset_y <= max_height - search_range )
{
range_partly_outside = 0;
}
else
{
range_partly_outside = 1;
}
//===== determine position of (0,0)-vector =====
if (!input->rdopt)
{
ref_x = img->opix_x - offset_x;
ref_y = img->opix_y - offset_y;
for (pos = 0; pos < max_pos; pos++)
{
if (ref_x == spiral_search_x[pos] &&
ref_y == spiral_search_y[pos])
{
pos_00[list][ref] = pos;
break;
}
}
}
//===== loop over search range (spiral search): get blockwise SAD =====
for (pos = 0; pos < max_pos; pos++)
{
abs_y = offset_y + spiral_search_y[pos];
abs_x = offset_x + spiral_search_x[pos];
abs_y4 = (abs_y + IMG_PAD_SIZE) << 2;
abs_x4 = (abs_x + IMG_PAD_SIZE) << 2;
if (range_partly_outside)
{
if (abs_y >= 0 && abs_y <= max_height &&
abs_x >= 0 && abs_x <= max_width )
{
ref_access_method = FAST_ACCESS;
}
else
{
ref_access_method = UMV_ACCESS;
}
}
srcptr = orig_pels;
bindex = 0;
for (blky = 0; blky < 4; blky++)
{
block_sad[bindex++][pos] = computeUniPred[level_dist](srcptr, 4, 4, INT_MAX, abs_x4, abs_y4);
srcptr += 16;
block_sad[bindex++][pos] = computeUniPred[level_dist](srcptr, 4, 4, INT_MAX, abs_x4 + 16, abs_y4);
srcptr += 16;
block_sad[bindex++][pos] = computeUniPred[level_dist](srcptr, 4, 4, INT_MAX, abs_x4 + 32, abs_y4);
srcptr += 16;
block_sad[bindex++][pos] = computeUniPred[level_dist](srcptr, 4, 4, INT_MAX, abs_x4 + 48, abs_y4);
srcptr += 16;
abs_y4 += 16;
}
}
//===== combine SAD's for larger block types =====
SetupLargerBlocks (list, ref, max_pos);
//===== set flag marking that search setup have been done =====
search_setup_done[list][ref] = 1;
}
#else
void SetupFastFullPelSearch (short ref, int list) // <-- reference frame parameter, list0 or 1
{
short pmv[2];
static imgpel orig_pels[768];
imgpel *srcptr = orig_pels, *refptr;
int k, x, y;
int abs_y4, abs_x4;
int offset_x, offset_y, range_partly_outside, ref_x, ref_y, pos, abs_x, abs_y, bindex, blky;
int LineSadBlk0, LineSadBlk1, LineSadBlk2, LineSadBlk3;
int max_width, max_height;
int img_width, img_height;
StorablePicture *ref_picture;
distpel** block_sad = BlockSAD[list][ref][7];
int search_range = max_search_range[list][ref];
int max_pos = (2*search_range+1) * (2*search_range+1);
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 weighted_pel;
int *dist_method = input->MEErrorMetric[0] ? img->quad : byte_abs;
ref_picture = listX[list+list_offset][ref];
ref_access_method = FAST_ACCESS;
ref_pic_sub.luma = ref_picture->curr_imgY_sub;
max_width = ref_picture->size_x - 17;
max_height = ref_picture->size_y - 17;
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];
}
}
//===== get search center: predictor of 16x16 block =====
SetMotionVectorPredictor (pmv, enc_picture->ref_idx[list], enc_picture->mv[list], ref, list, 0, 0, 16, 16);
search_center_x[list][ref] = pmv[0] / 4;
search_center_y[list][ref] = pmv[1] / 4;
if (!input->rdopt)
{
//--- correct center so that (0,0) vector is inside ---
search_center_x[list][ref] = iClip3(-search_range, search_range, search_center_x[list][ref]);
search_center_y[list][ref] = iClip3(-search_range, search_range, search_center_y[list][ref]);
}
search_center_x[list][ref] = iClip3(-2047 + search_range, 2047 - search_range, search_center_x[list][ref]);
search_center_y[list][ref] = iClip3(LEVELMVLIMIT[img->LevelIndex][0] + search_range, LEVELMVLIMIT[img->LevelIndex][1] - search_range, search_center_y[list][ref]);
search_center_x[list][ref] += img->opix_x;
search_center_y[list][ref] += img->opix_y;
offset_x = search_center_x[list][ref];
offset_y = search_center_y[list][ref];
//===== copy original block for fast access =====
for (y = img->opix_y; y < img->opix_y+MB_BLOCK_SIZE; y++)
{
memcpy(srcptr, &imgY_org[y][img->opix_x], MB_BLOCK_SIZE * sizeof(imgpel));
srcptr += MB_BLOCK_SIZE;
}
if ( ChromaMEEnable)
{
for (k = 0; k < 2; k++)
{
for (y = img->opix_c_y; y < img->opix_c_y + img->mb_cr_size_y; y++)
{
memcpy(srcptr, &imgUV_org[k][y][img->opix_c_x], img->mb_cr_size_x * sizeof(imgpel));
srcptr += img->mb_cr_size_x;
}
}
}
//===== check if whole search range is inside image =====
if (offset_x >= search_range && offset_x <= max_width - search_range &&
offset_y >= search_range && offset_y <= max_height - search_range )
{
range_partly_outside = 0;
}
else
{
range_partly_outside = 1;
}
//===== determine position of (0,0)-vector =====
if (!input->rdopt)
{
ref_x = img->opix_x - offset_x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -