Some understandings of jm-to the whole pixel search _search

Source: Internet
Author: User
The whole pixel search mainly includes 3 function setupfastfullpelsearch,setmotionvectorpredictor,setuplargerblocks, all located in the middle of file mv_search.c.

1 The function of reference frame ref, to achieve list0 (forward), List1 (back) global pixel search, and statistics of various block mode sad value (whole pixel only calculate sad, see Blue Windmill FAQ quotes), so a macro block only need to calculate once, Is the entire macro block computational complexity of the largest function, through this function, you can see that the so-called search radius is only for the whole pixel search, the following I on the function step-by-step detailed annotation.

void Setupfastfullpelsearch (short ref, int list)//<--Reference frame parameter, list0 or 1
{
Short pmv[2];//Predictive vector x,y two directions
pel_t orig_blocks[256], *orgptr=orig_blocks, *refptr;//assign addresses to macro blocks, and the static value system is assigned only once.
int offset_x, offset_y, X, Y, Range_partly_outside, ref_x, Ref_y, POS, abs_x, Abs_y, Bindex, blky;
int LineSadBlk0, LINESADBLK1, LineSadBlk2, LINESADBLK3;
Calculates the sad allocation space for a 4x4 block, noting that the 4 4x4 blocks are 4 pieces within the same row within a macro block
int Max_width, max_height;
int Img_width, img_height;

Storablepicture *ref_picture;//Reference Frame
pel_t *ref_pic;//Reference Pixel

distpel** Block_sad = blocksad[list][ref][7];
[7] for 4x4 sub-block mode sad-value subscript
int search_range = max_search_range[list][ref];
To get the current frame of ref reference frame list Direction Prediction Search radius, a little doubt, can have different search radius
int max_pos = (2*search_range+1) * (2*search_range+1);
Calculate the maximum search point
int list_offset = img->mb_data[img->current_mb_nr].list_offset;
List direction offset, which is personally considered to be related to field encoding, when frame encoding is 0
int apply_weights = (Active_pps->weighted_pred_flag && (img->type = P_slice | | img->type = = SP_SLICE )) ||
(ACTIVE_PPS-&GT;WEIGHTED_BIPRED_IDC && (Img->type = = B_slice)));
Whether weight prediction

Ref_picture = Listx[list+list_offset][ref];
Get the frame of reference to prepare for the calculation of sad.
===== Use weighted Reference for ME = =
if (apply_weights && input->useweightedreferenceme)
Ref_pic = ref_picture->imgy_11_w;
Else
Ref_pic = ref_picture->imgy_11;
Whether to use weight prediction, using different reference pixel values
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;

===== Get Search Center:predictor the 16x16 block =====
Setmotionvectorpredictor (PMV, enc_picture->ref_idx[list], enc_picture->mv[list], ref, list, 0, 0, 16, 16);
The above forecast MV, the MV is 1/4 pixels per unit vector value, the next time this function.
search_center_x[list][ref] = pmv[0]/4;
search_center_y[list][ref] = pmv[1]/4;
Ref frame prediction Offset for current frame (integer pixel value)

if (!input->rdopt)
{
---Correct center so, 0,0 vector is inside---
search_center_x[list][ref] = max (-search_range, Min (search_range, search_center_x[list][ref));
search_center_y[list][ref] = max (-search_range, Min (search_range, search_center_y[list][ref));
}
search_center_x[list][ref] = CLIP3 ( -2047 + search_range, 2047-search_range, search_center_x[list][ref]);
search_center_y[list][ref] = CLIP3 (levelmvlimit[img->levelindex][0) + Search_range, levelmvlimit[img-> LEVELINDEX][1]-Search_range, search_center_y[list][ref]);
Saturation in the upper and lower directions
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];
Calculate absolute Offset (0,0) position in the upper-left corner of the entire image

===== Copy original block for fast access =====
for (y = img->opix_y; y < img->opix_y+16; y++)
for (x = img->opix_x; × < img->opix_x+16; x + +)
*orgptr++ = imgy_org [y][x];
Copy the original pixel into the array, the one-dimensional array is faster, so called fast access
===== 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; Pelyline_11 = Fastline16y_11;
}
Else
{
Range_partly_outside = 1;
}
Check for bounds, 1th macroblock 16 Search radius Of course out of bounds


===== 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])

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.