📄 me.h
字号:
/*////////////////////////////////////////////////////////////////////////////////// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright(c) 2002-2005 Intel Corporation. All Rights Reserved.//*/#ifndef _ME_H__#define _ME_H__#include "ippdefs.h"#include "vm_time.h"#define DO_SEARCH(METRIC, STEP_MIN) \ /* new ID for matrix of search points */ \ me_matrix_id = (me_matrix_id + 1) & 255; \ if (!me_matrix_id) { \ ippsZero_8u(th->me_matrix_buff, th->me_matrix_size); \ me_matrix_id = 1; \ } \ th->me_matrix_id = me_matrix_id; \ \ /* initial point */ \ BestMAD = INT_MAX; \ XN = X; \ YN = Y; \ TRY_POSITION(METRIC); \ \ if (first_search) { \ first_search = 0; \ XN = InitialMV0.x; \ YN = InitialMV0.y >> FIELD_FLAG; \ /*XN = XN &~ 1; \ YN = YN &~ 1;*/ \ if (XN < limit_left) XN = limit_left; \ if (XN > limit_right) XN = limit_right; \ if (YN < limit_top) YN = limit_top; \ if (YN > limit_bottom) YN = limit_bottom; \ TRY_POSITION(METRIC); \ \ XN = InitialMV1.x; \ YN = InitialMV1.y >> FIELD_FLAG; \ /*XN = XN &~ 1; \ YN = YN &~ 1;*/ \ if (XN < limit_left) XN = limit_left; \ if (XN > limit_right) XN = limit_right; \ if (YN < limit_top) YN = limit_top; \ if (YN > limit_bottom) YN = limit_bottom; \ TRY_POSITION(METRIC); \ X = XMIN; \ Y = YMIN; \ } \ \ while (step_hor >= STEP_MIN || step_ver >= STEP_MIN) \ { \ for (k = 0; k < num_steps; k++) { \ min_point = 0; \ \ YN = Y; \ XN = X - step_hor; \ if (XN >= limit_left) \ { \ TRY_POSITION(METRIC); \ } \ XN = X + step_hor; \ if (XN <= limit_right) \ { \ TRY_POSITION(METRIC); \ } \ \ XN = X; \ YN = Y - step_ver; \ if (YN >= limit_top) \ { \ TRY_POSITION(METRIC); \ } \ YN = Y + step_ver; \ if (YN <= limit_bottom) \ { \ TRY_POSITION(METRIC); \ } \ \ if (diamond && step_hor > 1 && step_ver > 1) { \ XN = X - step_hor/2; \ if (XN >= limit_left) { \ YN = Y - step_ver/2; \ if (YN >= limit_top) \ { \ TRY_POSITION(METRIC); \ } \ YN = Y + step_ver/2; \ if (YN <= limit_bottom) \ { \ TRY_POSITION(METRIC); \ } \ } \ XN = X + step_hor/2; \ if (XN <= limit_right) { \ YN = Y - step_ver/2; \ if (YN >= limit_top) \ { \ TRY_POSITION(METRIC); \ } \ YN = Y + step_ver/2; \ if (YN <= limit_bottom) \ { \ TRY_POSITION(METRIC); \ } \ } \ } \ \ X = XMIN; \ Y = YMIN; \ \ if (!min_point) break; \ } \ \ step_hor >>= 1; \ step_ver >>= 1; \ num_steps = num_steps1; \ }#endif /* _ME_H__ */#if defined(ME_FUNC) && defined(TRY_POSITION)Ipp32s ippMPEG2VideoEncoder::ME_FUNC(ME_PARAMS){ int step_hor, step_ver, step_min; Ipp32s BestMAD, MAD; Ipp32s X, Y, XN, YN, XMIN = 0, YMIN = 0; int min_point; Ipp8u* ref_data; int flag; Ipp32s Var[2][4], Mean[2][4]; int min_index = 0; int me_matrix_w; int me_matrix_h; Ipp8u *me_matrix; int me_matrix_id; int k, num_steps, num_steps1; int me_alg_num; int diamond = 0; int field_select = 0; int first_search = 1; vm_tick t_start, t_end; t_start = GET_TICKS; mpeg2_assert(limit_top <= 0); mpeg2_assert(limit_left <= 0); mpeg2_assert(limit_bottom >= 0); mpeg2_assert(limit_right >= 0); limit_left <<= 1; limit_right <<= 1; limit_top <<= 1; limit_bottom <<= 1; limit_right--; limit_bottom--; /* matrix of search points */ me_matrix_w = limit_right + 1- limit_left; me_matrix_h = limit_bottom + 1 - limit_top; if (me_matrix_w*me_matrix_h > th->me_matrix_size) { if (th->me_matrix_buff) delete th->me_matrix_buff; th->me_matrix_size = me_matrix_w*me_matrix_h; th->me_matrix_buff = new Ipp8u[th->me_matrix_size]; ippsZero_8u(th->me_matrix_buff, th->me_matrix_size); th->me_matrix_id = 0; } me_matrix = th->me_matrix_buff - limit_top*me_matrix_w - limit_left; me_matrix_id = th->me_matrix_id; /* search algorithm */ me_alg_num = encodeInfo.me_alg_num; //me_alg_num = 2; if (me_alg_num >= 10) { // no half-pixel me_alg_num -= 10; step_min = 2; } else { step_min = 1; } if (me_alg_num == 9) { // full search BestMAD = INT_MAX; for (YN = limit_top; YN <= limit_bottom; YN += step_min) { for (XN = limit_left; XN <= limit_right; XN += step_min) { TRY_POSITION(VARMEAN_FUNC); } } goto exit_me; } if (me_alg_num == 3) { // combined search if (((i>>4) & 7) != 3) { me_alg_num = 1; // local search } else { me_alg_num = 2; // global logarithmic search } } switch (me_alg_num) { default: case 1: // local search num_steps = INT_MAX; step_hor = step_ver = 2; break; case 2: // global logarithmic search num_steps = 1; //step_hor = min(X - limit_right, X - limit_left)/2; //step_ver = min(Y - limit_bottom, Y - limit_top)/2; step_hor = (limit_right - limit_left)/4; step_ver = (limit_bottom - limit_top)/4; if (step_hor < 2) step_hor = 2; if (step_ver < 2) step_ver = 2; break; } num_steps1 = 1; X = 0; Y = 0; DO_SEARCH(SAD_FUNC, step_min); // metric VAR=SUM(x*x) BestMAD = INT_MAX; XN = X; YN = Y; me_matrix[YN*me_matrix_w + XN] = 0; TRY_POSITION(VARMEAN_FUNC);exit_me: if (picture_structure != FRAME_PICTURE) { if (picture_structure == TOP_FIELD) { field_select = 0; } else { field_select = 1; } if (YOffsetToOtherField) { // try another field Ipp32s MAD2; Ipp32s tmp; pRef += YOffsetToOtherField; tmp = YOffsetToOtherField; YOffsetToOtherField = 0; // to prevent infinitive calls MAD2 = ME_FUNC(pRef, RefStep, pBlock, BlockStep, pSrcMean, pDstVar, pDstMean, limit_left, limit_right, limit_top, limit_bottom, InitialMV0, InitialMV1, vector, th, i, j, vertical_field_select, currMAD); YOffsetToOtherField = tmp; // restore if (MAD2 < BestMAD) { vector->offset_l += YOffsetToOtherField; vector->offset_c += UVOffsetToOtherField; *vertical_field_select = 1 - field_select; return MAD2; } } } if (currMAD != NULL) { if (BestMAD >= *currMAD) return -1; *currMAD = BestMAD; } if (pDstVar != NULL) { memcpy(pDstVar, Var[min_index], NUM_BLOCKS*sizeof(Ipp32s)); } if (pDstMean != NULL) { memcpy(pDstMean, Mean[min_index], NUM_BLOCKS*sizeof(Ipp32s)); }#if FIELD_FLAG == 0 SET_MOTION_VECTOR(vector, XMIN, YMIN);#else SET_FIELD_VECTOR(vector, XMIN, YMIN, field_select);#endif *vertical_field_select = field_select; t_end = GET_TICKS; motion_estimation_time += (int)(t_end - t_start); return BestMAD;}#endif /* defined(ME_FUNC) && defined(TRY_POSITION) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -