2012-06-25 18:34:10 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
2012-07-24 00:09:51 +02:00
|
|
|
#include "test/acm_random.h"
|
2013-06-18 07:58:40 +02:00
|
|
|
#include "test/clear_system_state.h"
|
2012-11-27 22:08:05 +01:00
|
|
|
#include "test/register_state_check.h"
|
2012-06-25 18:34:10 +02:00
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
2014-01-18 22:03:31 +01:00
|
|
|
|
2013-09-05 17:45:56 +02:00
|
|
|
#include "./vpx_config.h"
|
|
|
|
#include "./vp8_rtcd.h"
|
2012-06-25 18:34:10 +02:00
|
|
|
#include "vp8/common/blockd.h"
|
2012-08-28 02:13:09 +02:00
|
|
|
#include "vpx_mem/vpx_mem.h"
|
2012-06-25 18:34:10 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-07-24 00:09:51 +02:00
|
|
|
using libvpx_test::ACMRandom;
|
|
|
|
|
2012-06-25 18:34:10 +02:00
|
|
|
class IntraPredBase {
|
2013-06-18 07:58:40 +02:00
|
|
|
public:
|
2014-03-19 03:25:31 +01:00
|
|
|
virtual ~IntraPredBase() { libvpx_test::ClearSystemState(); }
|
2013-06-18 07:58:40 +02:00
|
|
|
|
2012-06-25 18:34:10 +02:00
|
|
|
protected:
|
2013-09-26 19:38:59 +02:00
|
|
|
void SetupMacroblock(MACROBLOCKD *mbptr,
|
|
|
|
MODE_INFO *miptr,
|
|
|
|
uint8_t *data,
|
|
|
|
int block_size,
|
|
|
|
int stride,
|
2012-06-25 18:34:10 +02:00
|
|
|
int num_planes) {
|
2013-09-26 19:38:59 +02:00
|
|
|
mbptr_ = mbptr;
|
|
|
|
miptr_ = miptr;
|
|
|
|
mbptr_->up_available = 1;
|
|
|
|
mbptr_->left_available = 1;
|
|
|
|
mbptr_->mode_info_context = miptr_;
|
2012-06-25 18:34:10 +02:00
|
|
|
stride_ = stride;
|
|
|
|
block_size_ = block_size;
|
|
|
|
num_planes_ = num_planes;
|
|
|
|
for (int p = 0; p < num_planes; p++)
|
|
|
|
data_ptr_[p] = data + stride * (block_size + 1) * p +
|
|
|
|
stride + block_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FillRandom() {
|
|
|
|
// Fill edges with random data
|
2012-07-24 00:09:51 +02:00
|
|
|
ACMRandom rnd(ACMRandom::DeterministicSeed());
|
2012-06-25 18:34:10 +02:00
|
|
|
for (int p = 0; p < num_planes_; p++) {
|
|
|
|
for (int x = -1 ; x <= block_size_; x++)
|
2012-07-24 00:09:51 +02:00
|
|
|
data_ptr_[p][x - stride_] = rnd.Rand8();
|
2012-06-25 18:34:10 +02:00
|
|
|
for (int y = 0; y < block_size_; y++)
|
2012-07-24 00:09:51 +02:00
|
|
|
data_ptr_[p][y * stride_ - 1] = rnd.Rand8();
|
2012-06-25 18:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Predict(MB_PREDICTION_MODE mode) = 0;
|
|
|
|
|
|
|
|
void SetLeftUnavailable() {
|
2013-09-26 19:38:59 +02:00
|
|
|
mbptr_->left_available = 0;
|
2012-06-25 18:34:10 +02:00
|
|
|
for (int p = 0; p < num_planes_; p++)
|
|
|
|
for (int i = -1; i < block_size_; ++i)
|
|
|
|
data_ptr_[p][stride_ * i - 1] = 129;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTopUnavailable() {
|
2013-09-26 19:38:59 +02:00
|
|
|
mbptr_->up_available = 0;
|
2012-06-25 18:34:10 +02:00
|
|
|
for (int p = 0; p < num_planes_; p++)
|
|
|
|
memset(&data_ptr_[p][-1 - stride_], 127, block_size_ + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTopLeftUnavailable() {
|
|
|
|
SetLeftUnavailable();
|
|
|
|
SetTopUnavailable();
|
|
|
|
}
|
|
|
|
|
|
|
|
int BlockSizeLog2Min1() const {
|
|
|
|
switch (block_size_) {
|
|
|
|
case 16:
|
|
|
|
return 3;
|
|
|
|
case 8:
|
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check DC prediction output against a reference
|
|
|
|
void CheckDCPrediction() const {
|
|
|
|
for (int p = 0; p < num_planes_; p++) {
|
|
|
|
// calculate expected DC
|
|
|
|
int expected;
|
2013-09-26 19:38:59 +02:00
|
|
|
if (mbptr_->up_available || mbptr_->left_available) {
|
|
|
|
int sum = 0, shift = BlockSizeLog2Min1() + mbptr_->up_available +
|
|
|
|
mbptr_->left_available;
|
|
|
|
if (mbptr_->up_available)
|
2012-06-25 18:34:10 +02:00
|
|
|
for (int x = 0; x < block_size_; x++)
|
|
|
|
sum += data_ptr_[p][x - stride_];
|
2013-09-26 19:38:59 +02:00
|
|
|
if (mbptr_->left_available)
|
2012-06-25 18:34:10 +02:00
|
|
|
for (int y = 0; y < block_size_; y++)
|
|
|
|
sum += data_ptr_[p][y * stride_ - 1];
|
|
|
|
expected = (sum + (1 << (shift - 1))) >> shift;
|
2013-09-05 17:45:56 +02:00
|
|
|
} else {
|
2012-06-25 18:34:10 +02:00
|
|
|
expected = 0x80;
|
2013-09-05 17:45:56 +02:00
|
|
|
}
|
2012-06-25 18:34:10 +02:00
|
|
|
// check that all subsequent lines are equal to the first
|
|
|
|
for (int y = 1; y < block_size_; ++y)
|
|
|
|
ASSERT_EQ(0, memcmp(data_ptr_[p], &data_ptr_[p][y * stride_],
|
|
|
|
block_size_));
|
|
|
|
// within the first line, ensure that each pixel has the same value
|
|
|
|
for (int x = 1; x < block_size_; ++x)
|
|
|
|
ASSERT_EQ(data_ptr_[p][0], data_ptr_[p][x]);
|
|
|
|
// now ensure that that pixel has the expected (DC) value
|
|
|
|
ASSERT_EQ(expected, data_ptr_[p][0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check V prediction output against a reference
|
|
|
|
void CheckVPrediction() const {
|
|
|
|
// check that all lines equal the top border
|
|
|
|
for (int p = 0; p < num_planes_; p++)
|
|
|
|
for (int y = 0; y < block_size_; y++)
|
|
|
|
ASSERT_EQ(0, memcmp(&data_ptr_[p][-stride_],
|
|
|
|
&data_ptr_[p][y * stride_], block_size_));
|
|
|
|
}
|
|
|
|
|
|
|
|
// check H prediction output against a reference
|
|
|
|
void CheckHPrediction() const {
|
|
|
|
// for each line, ensure that each pixel is equal to the left border
|
|
|
|
for (int p = 0; p < num_planes_; p++)
|
|
|
|
for (int y = 0; y < block_size_; y++)
|
|
|
|
for (int x = 0; x < block_size_; x++)
|
|
|
|
ASSERT_EQ(data_ptr_[p][-1 + y * stride_],
|
|
|
|
data_ptr_[p][x + y * stride_]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ClipByte(int value) {
|
|
|
|
if (value > 255)
|
|
|
|
return 255;
|
|
|
|
else if (value < 0)
|
|
|
|
return 0;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check TM prediction output against a reference
|
|
|
|
void CheckTMPrediction() const {
|
|
|
|
for (int p = 0; p < num_planes_; p++)
|
|
|
|
for (int y = 0; y < block_size_; y++)
|
|
|
|
for (int x = 0; x < block_size_; x++) {
|
|
|
|
const int expected = ClipByte(data_ptr_[p][x - stride_]
|
|
|
|
+ data_ptr_[p][stride_ * y - 1]
|
|
|
|
- data_ptr_[p][-1 - stride_]);
|
|
|
|
ASSERT_EQ(expected, data_ptr_[p][y * stride_ + x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actual test
|
|
|
|
void RunTest() {
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("DC_PRED");
|
|
|
|
FillRandom();
|
|
|
|
Predict(DC_PRED);
|
|
|
|
CheckDCPrediction();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("DC_PRED LEFT");
|
|
|
|
FillRandom();
|
|
|
|
SetLeftUnavailable();
|
|
|
|
Predict(DC_PRED);
|
|
|
|
CheckDCPrediction();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("DC_PRED TOP");
|
|
|
|
FillRandom();
|
|
|
|
SetTopUnavailable();
|
|
|
|
Predict(DC_PRED);
|
|
|
|
CheckDCPrediction();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("DC_PRED TOP_LEFT");
|
|
|
|
FillRandom();
|
|
|
|
SetTopLeftUnavailable();
|
|
|
|
Predict(DC_PRED);
|
|
|
|
CheckDCPrediction();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("H_PRED");
|
|
|
|
FillRandom();
|
|
|
|
Predict(H_PRED);
|
|
|
|
CheckHPrediction();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("V_PRED");
|
|
|
|
FillRandom();
|
|
|
|
Predict(V_PRED);
|
|
|
|
CheckVPrediction();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("TM_PRED");
|
|
|
|
FillRandom();
|
|
|
|
Predict(TM_PRED);
|
|
|
|
CheckTMPrediction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 19:38:59 +02:00
|
|
|
MACROBLOCKD *mbptr_;
|
|
|
|
MODE_INFO *miptr_;
|
2012-06-25 18:34:10 +02:00
|
|
|
uint8_t *data_ptr_[2]; // in the case of Y, only [0] is used
|
|
|
|
int stride_;
|
|
|
|
int block_size_;
|
|
|
|
int num_planes_;
|
|
|
|
};
|
|
|
|
|
2014-07-17 03:57:42 +02:00
|
|
|
typedef void (*IntraPredYFunc)(MACROBLOCKD *x,
|
|
|
|
uint8_t *yabove_row,
|
|
|
|
uint8_t *yleft,
|
|
|
|
int left_stride,
|
|
|
|
uint8_t *ypred_ptr,
|
|
|
|
int y_stride);
|
2012-06-25 18:34:10 +02:00
|
|
|
|
2014-03-19 03:25:31 +01:00
|
|
|
class IntraPredYTest
|
|
|
|
: public IntraPredBase,
|
2014-07-17 03:57:42 +02:00
|
|
|
public ::testing::TestWithParam<IntraPredYFunc> {
|
2012-08-28 02:13:09 +02:00
|
|
|
public:
|
|
|
|
static void SetUpTestCase() {
|
2013-09-26 19:38:59 +02:00
|
|
|
mb_ = reinterpret_cast<MACROBLOCKD*>(
|
|
|
|
vpx_memalign(32, sizeof(MACROBLOCKD)));
|
|
|
|
mi_ = reinterpret_cast<MODE_INFO*>(
|
|
|
|
vpx_memalign(32, sizeof(MODE_INFO)));
|
2012-08-28 02:13:09 +02:00
|
|
|
data_array_ = reinterpret_cast<uint8_t*>(
|
|
|
|
vpx_memalign(kDataAlignment, kDataBufferSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDownTestCase() {
|
|
|
|
vpx_free(data_array_);
|
2013-09-26 19:38:59 +02:00
|
|
|
vpx_free(mi_);
|
|
|
|
vpx_free(mb_);
|
2012-08-28 02:13:09 +02:00
|
|
|
data_array_ = NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-25 18:34:10 +02:00
|
|
|
protected:
|
|
|
|
static const int kBlockSize = 16;
|
2012-08-28 02:13:09 +02:00
|
|
|
static const int kDataAlignment = 16;
|
2012-06-25 18:34:10 +02:00
|
|
|
static const int kStride = kBlockSize * 3;
|
2012-08-28 02:13:09 +02:00
|
|
|
// We use 48 so that the data pointer of the first pixel in each row of
|
|
|
|
// each macroblock is 16-byte aligned, and this gives us access to the
|
|
|
|
// top-left and top-right corner pixels belonging to the top-left/right
|
|
|
|
// macroblocks.
|
|
|
|
// We use 17 lines so we have one line above us for top-prediction.
|
|
|
|
static const int kDataBufferSize = kStride * (kBlockSize + 1);
|
2012-06-25 18:34:10 +02:00
|
|
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
pred_fn_ = GetParam();
|
2013-09-26 19:38:59 +02:00
|
|
|
SetupMacroblock(mb_, mi_, data_array_, kBlockSize, kStride, 1);
|
2012-06-25 18:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Predict(MB_PREDICTION_MODE mode) {
|
2013-09-26 19:38:59 +02:00
|
|
|
mbptr_->mode_info_context->mbmi.mode = mode;
|
2014-07-10 06:02:02 +02:00
|
|
|
ASM_REGISTER_STATE_CHECK(pred_fn_(mbptr_,
|
|
|
|
data_ptr_[0] - kStride,
|
|
|
|
data_ptr_[0] - 1, kStride,
|
|
|
|
data_ptr_[0], kStride));
|
2012-06-25 18:34:10 +02:00
|
|
|
}
|
|
|
|
|
2014-07-17 03:57:42 +02:00
|
|
|
IntraPredYFunc pred_fn_;
|
2012-08-28 02:13:09 +02:00
|
|
|
static uint8_t* data_array_;
|
2013-09-26 19:38:59 +02:00
|
|
|
static MACROBLOCKD * mb_;
|
|
|
|
static MODE_INFO *mi_;
|
2012-06-25 18:34:10 +02:00
|
|
|
};
|
|
|
|
|
2013-09-26 19:38:59 +02:00
|
|
|
MACROBLOCKD* IntraPredYTest::mb_ = NULL;
|
|
|
|
MODE_INFO* IntraPredYTest::mi_ = NULL;
|
2012-08-28 02:13:09 +02:00
|
|
|
uint8_t* IntraPredYTest::data_array_ = NULL;
|
|
|
|
|
2012-06-25 18:34:10 +02:00
|
|
|
TEST_P(IntraPredYTest, IntraPredTests) {
|
|
|
|
RunTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(C, IntraPredYTest,
|
|
|
|
::testing::Values(
|
|
|
|
vp8_build_intra_predictors_mby_s_c));
|
|
|
|
#if HAVE_SSE2
|
|
|
|
INSTANTIATE_TEST_CASE_P(SSE2, IntraPredYTest,
|
|
|
|
::testing::Values(
|
|
|
|
vp8_build_intra_predictors_mby_s_sse2));
|
|
|
|
#endif
|
|
|
|
#if HAVE_SSSE3
|
|
|
|
INSTANTIATE_TEST_CASE_P(SSSE3, IntraPredYTest,
|
|
|
|
::testing::Values(
|
|
|
|
vp8_build_intra_predictors_mby_s_ssse3));
|
|
|
|
#endif
|
2014-09-03 20:26:27 +02:00
|
|
|
#if HAVE_NEON
|
|
|
|
INSTANTIATE_TEST_CASE_P(NEON, IntraPredYTest,
|
|
|
|
::testing::Values(
|
|
|
|
vp8_build_intra_predictors_mby_s_neon));
|
|
|
|
#endif
|
2012-06-25 18:34:10 +02:00
|
|
|
|
2014-07-17 03:57:42 +02:00
|
|
|
typedef void (*IntraPredUvFunc)(MACROBLOCKD *x,
|
|
|
|
uint8_t *uabove_row,
|
|
|
|
uint8_t *vabove_row,
|
|
|
|
uint8_t *uleft,
|
|
|
|
uint8_t *vleft,
|
|
|
|
int left_stride,
|
|
|
|
uint8_t *upred_ptr,
|
|
|
|
uint8_t *vpred_ptr,
|
|
|
|
int pred_stride);
|
2012-06-25 18:34:10 +02:00
|
|
|
|
2014-03-19 03:25:31 +01:00
|
|
|
class IntraPredUVTest
|
|
|
|
: public IntraPredBase,
|
2014-07-17 03:57:42 +02:00
|
|
|
public ::testing::TestWithParam<IntraPredUvFunc> {
|
2012-08-28 02:13:09 +02:00
|
|
|
public:
|
|
|
|
static void SetUpTestCase() {
|
2013-09-26 19:38:59 +02:00
|
|
|
mb_ = reinterpret_cast<MACROBLOCKD*>(
|
|
|
|
vpx_memalign(32, sizeof(MACROBLOCKD)));
|
|
|
|
mi_ = reinterpret_cast<MODE_INFO*>(
|
|
|
|
vpx_memalign(32, sizeof(MODE_INFO)));
|
2012-08-28 02:13:09 +02:00
|
|
|
data_array_ = reinterpret_cast<uint8_t*>(
|
|
|
|
vpx_memalign(kDataAlignment, kDataBufferSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDownTestCase() {
|
|
|
|
vpx_free(data_array_);
|
2013-09-26 19:38:59 +02:00
|
|
|
vpx_free(mi_);
|
|
|
|
vpx_free(mb_);
|
2012-08-28 02:13:09 +02:00
|
|
|
data_array_ = NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-25 18:34:10 +02:00
|
|
|
protected:
|
|
|
|
static const int kBlockSize = 8;
|
2012-08-28 02:13:09 +02:00
|
|
|
static const int kDataAlignment = 8;
|
2012-06-25 18:34:10 +02:00
|
|
|
static const int kStride = kBlockSize * 3;
|
2012-08-28 02:13:09 +02:00
|
|
|
// We use 24 so that the data pointer of the first pixel in each row of
|
|
|
|
// each macroblock is 8-byte aligned, and this gives us access to the
|
|
|
|
// top-left and top-right corner pixels belonging to the top-left/right
|
|
|
|
// macroblocks.
|
|
|
|
// We use 9 lines so we have one line above us for top-prediction.
|
|
|
|
// [0] = U, [1] = V
|
|
|
|
static const int kDataBufferSize = 2 * kStride * (kBlockSize + 1);
|
2012-06-25 18:34:10 +02:00
|
|
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
pred_fn_ = GetParam();
|
2013-09-26 19:38:59 +02:00
|
|
|
SetupMacroblock(mb_, mi_, data_array_, kBlockSize, kStride, 2);
|
2012-06-25 18:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Predict(MB_PREDICTION_MODE mode) {
|
2013-09-26 19:38:59 +02:00
|
|
|
mbptr_->mode_info_context->mbmi.uv_mode = mode;
|
|
|
|
pred_fn_(mbptr_, data_ptr_[0] - kStride, data_ptr_[1] - kStride,
|
2012-06-25 18:34:10 +02:00
|
|
|
data_ptr_[0] - 1, data_ptr_[1] - 1, kStride,
|
|
|
|
data_ptr_[0], data_ptr_[1], kStride);
|
|
|
|
}
|
|
|
|
|
2014-07-17 03:57:42 +02:00
|
|
|
IntraPredUvFunc pred_fn_;
|
2012-06-25 18:34:10 +02:00
|
|
|
// We use 24 so that the data pointer of the first pixel in each row of
|
|
|
|
// each macroblock is 8-byte aligned, and this gives us access to the
|
|
|
|
// top-left and top-right corner pixels belonging to the top-left/right
|
|
|
|
// macroblocks.
|
|
|
|
// We use 9 lines so we have one line above us for top-prediction.
|
|
|
|
// [0] = U, [1] = V
|
2012-08-28 02:13:09 +02:00
|
|
|
static uint8_t* data_array_;
|
2013-09-26 19:38:59 +02:00
|
|
|
static MACROBLOCKD* mb_;
|
|
|
|
static MODE_INFO* mi_;
|
2012-06-25 18:34:10 +02:00
|
|
|
};
|
|
|
|
|
2013-09-26 19:38:59 +02:00
|
|
|
MACROBLOCKD* IntraPredUVTest::mb_ = NULL;
|
|
|
|
MODE_INFO* IntraPredUVTest::mi_ = NULL;
|
2012-08-28 02:13:09 +02:00
|
|
|
uint8_t* IntraPredUVTest::data_array_ = NULL;
|
|
|
|
|
2012-06-25 18:34:10 +02:00
|
|
|
TEST_P(IntraPredUVTest, IntraPredTests) {
|
|
|
|
RunTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(C, IntraPredUVTest,
|
|
|
|
::testing::Values(
|
|
|
|
vp8_build_intra_predictors_mbuv_s_c));
|
|
|
|
#if HAVE_SSE2
|
|
|
|
INSTANTIATE_TEST_CASE_P(SSE2, IntraPredUVTest,
|
|
|
|
::testing::Values(
|
|
|
|
vp8_build_intra_predictors_mbuv_s_sse2));
|
|
|
|
#endif
|
|
|
|
#if HAVE_SSSE3
|
|
|
|
INSTANTIATE_TEST_CASE_P(SSSE3, IntraPredUVTest,
|
|
|
|
::testing::Values(
|
|
|
|
vp8_build_intra_predictors_mbuv_s_ssse3));
|
|
|
|
#endif
|
2014-09-03 20:26:27 +02:00
|
|
|
#if HAVE_NEON
|
|
|
|
INSTANTIATE_TEST_CASE_P(NEON, IntraPredUVTest,
|
|
|
|
::testing::Values(
|
|
|
|
vp8_build_intra_predictors_mbuv_s_neon));
|
|
|
|
#endif
|
2012-06-25 18:34:10 +02:00
|
|
|
|
|
|
|
} // namespace
|