柯兄写的文档,直接贴上来的。
调用处:
Void TEncSearch::xPatternSearchFast()èxTZSearch()
1. 相关结构
TZ_SEARCH_CONFIGURATION : 控制搜索过程
ntTZSearchStruct cStruct : 存放搜索过程的中间最优结果
搜索结构定义如下:
typedef struct
{
Pel* piRefY; //设置:cStruct.piRefY = piRefY;
Int iYStride; // 设置: cStruct.iYStride = iRefStride;
Int iBestX; //在xTZSearchHelp()中设置以下变量
Int iBestY;
UInt uiBestRound; // 菱形或方形搜索的轮数, 控制复杂度
UInt uiBestDistance;
UInt uiBestSad; //
UChar ucPointNr; // 存放搜索点的位置
} IntTZSearchStruct;
搜索点的位置说明:
12 3
40 5
67 8
2. 算法步骤
图1 8点Diamond搜索(半径<=8)
(1) 以当前位置为参考原点,在相对位置 为预测mv(如果bTestOtherPredictedMV开关打开)和相对位置 为0(如果bTestZeroVector开关打开)中,选择最佳(失真代价最小)的位置作为起始点.
(2) 在搜索范围内, 以2的指数次(幂次idx为0, 1, 2, .., 6),逐步扩大搜索步长:
for ( iDist = 1; iDist<= (Int)uiSearchRange;iDist*=2 ) // 例如uiSearchRange为64
{
if ( bFirstSearchDiamond == 1 ) // 控制先搜哪种模式(Diamond or Square)的开关
{
// pcPatternKey表示当前CU,即原始图像的CU, cStruct中的有参考图像的内容piRefY
// pcMvSrchRngLT是根据搜索起始点和搜索范围计算出来的左边和上边边界
// iDist为搜索步长
xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT,
pcMvSrchRngRB, iStartX, iStartY, iDist );
//每次搜索, cStruct.uiBestRound++
}
else
{
xTZ8PointSquareSearch ( pcPatternKey,cStruct, pcMvSrchRngLT,
pcMvSrchRngRB, iStartX,iStartY, iDist);
//每次搜索, cStruct.uiBestRound++
}
// 在每个中心点,最多搜索uiFirstSearchRounds次, 默认初始化为3次