Refactored warp_filter_test to allow reuse by external tests.

Change-Id: Id32a6a21ffda48ef16b027b55f9082614f389003
This commit is contained in:
Sean Purser-Haskell 2017-03-30 14:56:50 -07:00 коммит произвёл Sean Purser-haskell
Родитель c1a13998dc
Коммит 05a12ea97f
5 изменённых файлов: 192 добавлений и 123 удалений

Просмотреть файл

@ -44,6 +44,7 @@ if (CONFIG_GLOBAL_MOTION OR CONFIG_WARPED_MOTION)
set(AOM_UNIT_TEST_COMMON_SOURCES
${AOM_UNIT_TEST_COMMON_SOURCES}
"${AOM_ROOT}/test/warp_filter_test.cc")
"${AOM_ROOT}/test/warp_filter_test_util.cc")
endif ()
endif ()

Просмотреть файл

@ -20,6 +20,7 @@ LIBAOM_TEST_SRCS-yes += util.h
LIBAOM_TEST_SRCS-yes += video_source.h
LIBAOM_TEST_SRCS-yes += transform_test_base.h
LIBAOM_TEST_SRCS-yes += function_equivalence_test.h
LIBAOM_TEST_SRCS-yes += warp_filter_test_util.h
##
## BLACK BOX TESTS
@ -224,7 +225,7 @@ LIBAOM_TEST_SRCS-$(CONFIG_AV1_ENCODER) += av1_inv_txfm2d_test.cc
LIBAOM_TEST_SRCS-$(CONFIG_AV1) += av1_convolve_test.cc
LIBAOM_TEST_SRCS-$(CONFIG_AV1) += av1_convolve_optimz_test.cc
ifneq ($(findstring yes,$(CONFIG_GLOBAL_MOTION) $(CONFIG_WARPED_MOTION)),)
LIBAOM_TEST_SRCS-$(HAVE_SSE2) += warp_filter_test.cc
LIBAOM_TEST_SRCS-$(HAVE_SSE2) += warp_filter_test.cc warp_filter_test_util.cc
endif
ifeq ($(CONFIG_LOOP_RESTORATION),yes)
LIBAOM_TEST_SRCS-$(HAVE_SSE4_1) += selfguided_filter_test.cc

Просмотреть файл

@ -10,135 +10,18 @@
*/
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
#include "./av1_rtcd.h"
#include "./aom_dsp_rtcd.h"
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "av1/common/mv.h"
#include "test/warp_filter_test_util.h"
using std::tr1::tuple;
using std::tr1::make_tuple;
using libaom_test::ACMRandom;
typedef tuple<int, int, int> WarpTestParam;
using libaom_test::AV1WarpFilter::AV1WarpFilterTest;
namespace {
class AV1WarpFilterTest : public ::testing::TestWithParam<WarpTestParam> {
public:
virtual ~AV1WarpFilterTest() {}
virtual void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
TEST_P(AV1WarpFilterTest, CheckOutput) { RunCheckOutput(av1_warp_affine_sse2); }
virtual void TearDown() { libaom_test::ClearSystemState(); }
protected:
int32_t random_param(int bits) {
// 1 in 8 chance of generating zero (arbitrarily chosen)
if (((rnd_.Rand8()) & 7) == 0) return 0;
// Otherwise, enerate uniform values in the range
// [-(1 << bits), 1] U [1, 1<<bits]
int32_t v = 1 + (rnd_.Rand16() & ((1 << bits) - 1));
if ((rnd_.Rand8()) & 1) return -v;
return v;
}
void generate_model(int32_t *mat, int32_t *alpha, int32_t *beta,
int32_t *gamma, int32_t *delta) {
while (1) {
mat[0] = random_param(WARPEDMODEL_PREC_BITS + 6);
mat[1] = random_param(WARPEDMODEL_PREC_BITS + 6);
mat[2] = (random_param(WARPEDMODEL_PREC_BITS - 3)) +
(1 << WARPEDMODEL_PREC_BITS);
mat[3] = random_param(WARPEDMODEL_PREC_BITS - 3);
// 50/50 chance of generating ROTZOOM vs. AFFINE models
if (rnd_.Rand8() & 1) {
// AFFINE
mat[4] = random_param(WARPEDMODEL_PREC_BITS - 3);
mat[5] = (random_param(WARPEDMODEL_PREC_BITS - 3)) +
(1 << WARPEDMODEL_PREC_BITS);
} else {
mat[4] = -mat[3];
mat[5] = mat[2];
}
// Calculate the derived parameters and check that they are suitable
// for the warp filter.
assert(mat[2] != 0);
*alpha = mat[2] - (1 << WARPEDMODEL_PREC_BITS);
*beta = mat[3];
*gamma = ((int64_t)mat[4] << WARPEDMODEL_PREC_BITS) / mat[2];
*delta = mat[5] - (((int64_t)mat[3] * mat[4] + (mat[2] / 2)) / mat[2]) -
(1 << WARPEDMODEL_PREC_BITS);
if ((4 * abs(*alpha) + 7 * abs(*beta) > (1 << WARPEDMODEL_PREC_BITS)) ||
(4 * abs(*gamma) + 7 * abs(*delta) > (1 << WARPEDMODEL_PREC_BITS)))
continue;
// We have a valid model, so finish
return;
}
}
void RunCheckOutput() {
const int w = 128, h = 128;
const int border = 16;
const int stride = w + 2 * border;
const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
const int num_iters = GET_PARAM(2);
int i, j, sub_x, sub_y;
uint8_t *input_ = new uint8_t[h * stride];
uint8_t *input = input_ + border;
uint8_t *output = new uint8_t[out_w * out_h];
uint8_t *output2 = new uint8_t[out_w * out_h];
int32_t mat[8], alpha, beta, gamma, delta;
// Generate an input block and extend its borders horizontally
for (i = 0; i < h; ++i)
for (j = 0; j < w; ++j) input[i * stride + j] = rnd_.Rand8();
for (i = 0; i < h; ++i) {
memset(input + i * stride - border, input[i * stride], border);
memset(input + i * stride + w, input[i * stride + (w - 1)], border);
}
/* Try different sizes of prediction block */
for (i = 0; i < num_iters; ++i) {
for (sub_x = 0; sub_x < 2; ++sub_x)
for (sub_y = 0; sub_y < 2; ++sub_y) {
generate_model(mat, &alpha, &beta, &gamma, &delta);
av1_warp_affine_c(mat, input, w, h, stride, output, 32, 32, out_w,
out_h, out_w, sub_x, sub_y, 0, alpha, beta, gamma,
delta);
av1_warp_affine_sse2(mat, input, w, h, stride, output2, 32, 32, out_w,
out_h, out_w, sub_x, sub_y, 0, alpha, beta,
gamma, delta);
for (j = 0; j < out_w * out_h; ++j)
ASSERT_EQ(output[j], output2[j])
<< "Pixel mismatch at index " << j << " = (" << (j % out_w)
<< ", " << (j / out_w) << ") on iteration " << i;
}
}
delete[] input_;
delete[] output;
delete[] output2;
}
ACMRandom rnd_;
};
TEST_P(AV1WarpFilterTest, CheckOutput) { RunCheckOutput(); }
const WarpTestParam params[] = {
make_tuple(4, 4, 50000), make_tuple(8, 8, 50000), make_tuple(64, 64, 1000),
make_tuple(4, 16, 20000), make_tuple(32, 8, 10000),
};
INSTANTIATE_TEST_CASE_P(SSE2, AV1WarpFilterTest, ::testing::ValuesIn(params));
INSTANTIATE_TEST_CASE_P(SSE2, AV1WarpFilterTest,
libaom_test::AV1WarpFilter::GetDefaultParams());
} // namespace

Просмотреть файл

@ -0,0 +1,123 @@
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include "test/warp_filter_test_util.h"
using std::tr1::tuple;
using std::tr1::make_tuple;
using std::vector;
using libaom_test::ACMRandom;
using libaom_test::AV1WarpFilter::AV1WarpFilterTest;
using libaom_test::AV1WarpFilter::WarpTestParam;
::testing::internal::ParamGenerator<WarpTestParam>
libaom_test::AV1WarpFilter::GetDefaultParams() {
const WarpTestParam defaultParams[] = {
make_tuple(4, 4, 50000), make_tuple(8, 8, 50000),
make_tuple(64, 64, 1000), make_tuple(4, 16, 20000),
make_tuple(32, 8, 10000),
};
return ::testing::ValuesIn(defaultParams);
}
AV1WarpFilterTest::~AV1WarpFilterTest() {}
void AV1WarpFilterTest::SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
void AV1WarpFilterTest::TearDown() { libaom_test::ClearSystemState(); }
int32_t AV1WarpFilterTest::random_param(int bits) {
// 1 in 8 chance of generating zero (arbitrarily chosen)
if (((rnd_.Rand8()) & 7) == 0) return 0;
// Otherwise, enerate uniform values in the range
// [-(1 << bits), 1] U [1, 1<<bits]
int32_t v = 1 + (rnd_.Rand16() & ((1 << bits) - 1));
if ((rnd_.Rand8()) & 1) return -v;
return v;
}
void AV1WarpFilterTest::generate_model(int32_t *mat, int32_t *alpha,
int32_t *beta, int32_t *gamma,
int32_t *delta) {
while (1) {
mat[0] = random_param(WARPEDMODEL_PREC_BITS + 6);
mat[1] = random_param(WARPEDMODEL_PREC_BITS + 6);
mat[2] = (random_param(WARPEDMODEL_PREC_BITS - 3)) +
(1 << WARPEDMODEL_PREC_BITS);
mat[3] = random_param(WARPEDMODEL_PREC_BITS - 3);
// 50/50 chance of generating ROTZOOM vs. AFFINE models
if (rnd_.Rand8() & 1) {
// AFFINE
mat[4] = random_param(WARPEDMODEL_PREC_BITS - 3);
mat[5] = (random_param(WARPEDMODEL_PREC_BITS - 3)) +
(1 << WARPEDMODEL_PREC_BITS);
} else {
mat[4] = -mat[3];
mat[5] = mat[2];
}
// Calculate the derived parameters and check that they are suitable
// for the warp filter.
assert(mat[2] != 0);
*alpha = mat[2] - (1 << WARPEDMODEL_PREC_BITS);
*beta = mat[3];
*gamma = ((int64_t)mat[4] << WARPEDMODEL_PREC_BITS) / mat[2];
*delta = mat[5] - (((int64_t)mat[3] * mat[4] + (mat[2] / 2)) / mat[2]) -
(1 << WARPEDMODEL_PREC_BITS);
if ((4 * abs(*alpha) + 7 * abs(*beta) > (1 << WARPEDMODEL_PREC_BITS)) ||
(4 * abs(*gamma) + 7 * abs(*delta) > (1 << WARPEDMODEL_PREC_BITS)))
continue;
// We have a valid model, so finish
return;
}
}
void AV1WarpFilterTest::RunCheckOutput(warp_affine_func test_impl) {
const int w = 128, h = 128;
const int border = 16;
const int stride = w + 2 * border;
const int out_w = GET_PARAM(0), out_h = GET_PARAM(1);
const int num_iters = GET_PARAM(2);
int i, j, sub_x, sub_y;
uint8_t *input_ = new uint8_t[h * stride];
uint8_t *input = input_ + border;
uint8_t *output = new uint8_t[out_w * out_h];
uint8_t *output2 = new uint8_t[out_w * out_h];
int32_t mat[8], alpha, beta, gamma, delta;
// Generate an input block and extend its borders horizontally
for (i = 0; i < h; ++i)
for (j = 0; j < w; ++j) input[i * stride + j] = rnd_.Rand8();
for (i = 0; i < h; ++i) {
memset(input + i * stride - border, input[i * stride], border);
memset(input + i * stride + w, input[i * stride + (w - 1)], border);
}
/* Try different sizes of prediction block */
for (i = 0; i < num_iters; ++i) {
for (sub_x = 0; sub_x < 2; ++sub_x)
for (sub_y = 0; sub_y < 2; ++sub_y) {
generate_model(mat, &alpha, &beta, &gamma, &delta);
av1_warp_affine_c(mat, input, w, h, stride, output, 32, 32, out_w,
out_h, out_w, sub_x, sub_y, 0, alpha, beta, gamma,
delta);
test_impl(mat, input, w, h, stride, output2, 32, 32, out_w, out_h,
out_w, sub_x, sub_y, 0, alpha, beta, gamma, delta);
for (j = 0; j < out_w * out_h; ++j)
ASSERT_EQ(output[j], output2[j])
<< "Pixel mismatch at index " << j << " = (" << (j % out_w)
<< ", " << (j / out_w) << ") on iteration " << i;
}
}
}

Просмотреть файл

@ -0,0 +1,61 @@
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#ifndef TEST_WARP_FILTER_TEST_UTIL_H_
#define TEST_WARP_FILTER_TEST_UTIL_H_
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
#include "test/acm_random.h"
#include "test/util.h"
#include "./av1_rtcd.h"
#include "./aom_dsp_rtcd.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "av1/common/mv.h"
namespace libaom_test {
namespace AV1WarpFilter {
typedef void (*warp_affine_func)(int32_t *mat, uint8_t *ref, int width,
int height, int stride, uint8_t *pred,
int p_col, int p_row, int p_width,
int p_height, int p_stride, int subsampling_x,
int subsampling_y, int ref_frm, int32_t alpha,
int32_t beta, int32_t gamma, int32_t delta);
typedef std::tr1::tuple<int, int, int> WarpTestParam;
::testing::internal::ParamGenerator<WarpTestParam> GetDefaultParams();
class AV1WarpFilterTest : public ::testing::TestWithParam<WarpTestParam> {
public:
virtual ~AV1WarpFilterTest();
virtual void SetUp();
virtual void TearDown();
protected:
int32_t random_param(int bits);
void generate_model(int32_t *mat, int32_t *alpha, int32_t *beta,
int32_t *gamma, int32_t *delta);
void RunCheckOutput(warp_affine_func test_impl);
libaom_test::ACMRandom rnd_;
};
} // namespace AV1WarpFilter
} // namespace libaom_test
#endif // TEST_WARP_FILTER_TEST_UTIL_H_