Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'tz-changes'
  • Loading branch information
aryla committed Mar 1, 2018
2 parents 9c2d007 + b64e467 commit c136044
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions src/search_inter.c
Expand Up @@ -478,6 +478,7 @@ static bool early_terminate(inter_search_info_t *info)
void kvz_tz_pattern_search(inter_search_info_t *info,
unsigned pattern_type,
const int iDist,
vector2d_t mv,
int *best_dist)
{
assert(pattern_type < 4);
Expand Down Expand Up @@ -573,8 +574,6 @@ void kvz_tz_pattern_search(inter_search_info_t *info,
};
}

const vector2d_t mv = { info->best_mv.x >> 2, info->best_mv.y >> 2 };

// Compute SAD values for all chosen points.
int best_index = -1;
for (int i = 0; i < n_points; i++) {
Expand Down Expand Up @@ -615,8 +614,9 @@ static void tz_search(inter_search_info_t *info, vector2d_t extra_mv)
const int iRaster = 5; // search distance limit and downsampling factor for step 3
const unsigned step2_type = 0; // search patterns for steps 2 and 4
const unsigned step4_type = 0;
const bool bRasterRefinementEnable = true; // enable step 4 mode 1
const bool bStarRefinementEnable = false; // enable step 4 mode 2 (only one mode will be executed)
const bool use_raster_scan = false; // enable step 3
const bool use_raster_refinement = false; // enable step 4 mode 1
const bool use_star_refinement = true; // enable step 4 mode 2 (only one mode will be executed)

int best_dist = 0;
info->best_cost = UINT32_MAX;
Expand All @@ -632,30 +632,55 @@ static void tz_search(inter_search_info_t *info, vector2d_t extra_mv)
return;
}

//step 2, grid search
vector2d_t start = { info->best_mv.x >> 2, info->best_mv.y >> 2 };

// step 2, grid search
int rounds_without_improvement = 0;
for (int iDist = 1; iDist <= iSearchRange; iDist *= 2) {
kvz_tz_pattern_search(info, step2_type, iDist, &best_dist);
kvz_tz_pattern_search(info, step2_type, iDist, start, &best_dist);

// Break the loop if the last three rounds didn't produce a better MV.
if (best_dist != iDist) rounds_without_improvement++;
if (rounds_without_improvement >= 3) break;
}

if (start.x != 0 || start.y != 0) {
// repeat step 2 starting from the zero MV
start.x = 0;
start.y = 0;
rounds_without_improvement = 0;
for (int iDist = 1; iDist <= iSearchRange/2; iDist *= 2) {
kvz_tz_pattern_search(info, step2_type, iDist, start, &best_dist);

if (best_dist != iDist) rounds_without_improvement++;
if (rounds_without_improvement >= 3) break;
}
}

//step 3, raster scan
if (best_dist > iRaster) {
if (use_raster_scan && best_dist > iRaster) {
best_dist = iRaster;
kvz_tz_raster_search(info, iSearchRange, iRaster);
}

//step 4

//raster refinement
if (bRasterRefinementEnable && best_dist > 0) {
if (use_raster_refinement && best_dist > 0) {
for (int iDist = best_dist >> 1; iDist > 0; iDist >>= 1) {
kvz_tz_pattern_search(info, step4_type, iDist, &best_dist);
start.x = info->best_mv.x >> 2;
start.y = info->best_mv.y >> 2;
kvz_tz_pattern_search(info, step4_type, iDist, start, &best_dist);
}
}

//star refinement (repeat step 2 for the current starting point)
if (bStarRefinementEnable && best_dist > 0) {
while (use_star_refinement && best_dist > 0) {
best_dist = 0;
start.x = info->best_mv.x >> 2;
start.y = info->best_mv.y >> 2;
for (int iDist = 1; iDist <= iSearchRange; iDist *= 2) {
kvz_tz_pattern_search(info, step4_type, iDist, &best_dist);
kvz_tz_pattern_search(info, step4_type, iDist, start, &best_dist);
}
}
}
Expand Down

0 comments on commit c136044

Please sign in to comment.