2012-06-29 01:26:31 +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 <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
2013-06-26 20:59:46 +02:00
|
|
|
#include "vpx_ports/mem.h"
|
2012-06-29 01:26:31 +02:00
|
|
|
|
|
|
|
extern "C" {
|
2012-11-09 02:09:30 +01:00
|
|
|
#include "vp9_rtcd.h"
|
2013-05-16 19:52:15 +02:00
|
|
|
void vp9_short_idct8x8_add_c(short *input, uint8_t *output, int pitch);
|
2012-06-29 01:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "acm_random.h"
|
|
|
|
#include "vpx/vpx_integer.h"
|
|
|
|
|
|
|
|
using libvpx_test::ACMRandom;
|
|
|
|
|
|
|
|
namespace {
|
2013-06-26 20:09:08 +02:00
|
|
|
void fdct8x8(int16_t *in, int16_t *out, uint8_t* /*dst*/,
|
|
|
|
int stride, int /*tx_type*/) {
|
2013-06-21 20:45:47 +02:00
|
|
|
vp9_short_fdct8x8_c(in, out, stride);
|
|
|
|
}
|
2013-06-26 20:09:08 +02:00
|
|
|
void idct8x8_add(int16_t* /*in*/, int16_t *out, uint8_t *dst,
|
|
|
|
int stride, int /*tx_type*/) {
|
2013-06-21 20:45:47 +02:00
|
|
|
vp9_short_idct8x8_add_c(out, dst, stride >> 1);
|
|
|
|
}
|
2013-06-26 20:09:08 +02:00
|
|
|
void fht8x8(int16_t *in, int16_t *out, uint8_t* /*dst*/,
|
|
|
|
int stride, int tx_type) {
|
2013-06-22 00:56:24 +02:00
|
|
|
// TODO(jingning): need to refactor this to test both _c and _sse2 functions,
|
|
|
|
// when we have all inverse dct functions done sse2.
|
|
|
|
#if HAVE_SSE2
|
|
|
|
vp9_short_fht8x8_sse2(in, out, stride >> 1, tx_type);
|
|
|
|
#else
|
2013-06-21 20:45:47 +02:00
|
|
|
vp9_short_fht8x8_c(in, out, stride >> 1, tx_type);
|
2013-06-22 00:56:24 +02:00
|
|
|
#endif
|
2013-06-21 20:45:47 +02:00
|
|
|
}
|
2013-06-26 20:09:08 +02:00
|
|
|
void iht8x8_add(int16_t* /*in*/, int16_t *out, uint8_t *dst,
|
2013-06-21 20:45:47 +02:00
|
|
|
int stride, int tx_type) {
|
|
|
|
vp9_short_iht8x8_add_c(out, dst, stride >> 1, tx_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
class FwdTrans8x8Test : public ::testing::TestWithParam<int> {
|
|
|
|
public:
|
2013-07-13 05:05:05 +02:00
|
|
|
virtual ~FwdTrans8x8Test() {}
|
|
|
|
virtual void SetUp() {
|
2013-06-21 20:45:47 +02:00
|
|
|
tx_type_ = GetParam();
|
|
|
|
if (tx_type_ == 0) {
|
|
|
|
fwd_txfm = fdct8x8;
|
|
|
|
inv_txfm = idct8x8_add;
|
|
|
|
} else {
|
|
|
|
fwd_txfm = fht8x8;
|
|
|
|
inv_txfm = iht8x8_add;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void RunFwdTxfm(int16_t *in, int16_t *out, uint8_t *dst,
|
|
|
|
int stride, int tx_type) {
|
|
|
|
(*fwd_txfm)(in, out, dst, stride, tx_type);
|
|
|
|
}
|
|
|
|
void RunInvTxfm(int16_t *in, int16_t *out, uint8_t *dst,
|
|
|
|
int stride, int tx_type) {
|
|
|
|
(*inv_txfm)(in, out, dst, stride, tx_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
int tx_type_;
|
|
|
|
void (*fwd_txfm)(int16_t*, int16_t*, uint8_t*, int, int);
|
|
|
|
void (*inv_txfm)(int16_t*, int16_t*, uint8_t*, int, int);
|
|
|
|
};
|
2012-06-29 01:26:31 +02:00
|
|
|
|
2013-06-21 20:45:47 +02:00
|
|
|
TEST_P(FwdTrans8x8Test, SignBiasCheck) {
|
2012-06-29 01:26:31 +02:00
|
|
|
ACMRandom rnd(ACMRandom::DeterministicSeed());
|
2013-06-26 20:59:46 +02:00
|
|
|
DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, 64);
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, int16_t, test_output_block, 64);
|
2012-06-29 01:26:31 +02:00
|
|
|
const int pitch = 16;
|
|
|
|
int count_sign_block[64][2];
|
|
|
|
const int count_test_block = 100000;
|
|
|
|
|
|
|
|
memset(count_sign_block, 0, sizeof(count_sign_block));
|
|
|
|
|
|
|
|
for (int i = 0; i < count_test_block; ++i) {
|
|
|
|
// Initialize a test block with input range [-255, 255].
|
|
|
|
for (int j = 0; j < 64; ++j)
|
|
|
|
test_input_block[j] = rnd.Rand8() - rnd.Rand8();
|
|
|
|
|
2013-06-21 20:45:47 +02:00
|
|
|
RunFwdTxfm(test_input_block, test_output_block, NULL, pitch, tx_type_);
|
2012-06-29 01:26:31 +02:00
|
|
|
|
|
|
|
for (int j = 0; j < 64; ++j) {
|
|
|
|
if (test_output_block[j] < 0)
|
|
|
|
++count_sign_block[j][0];
|
|
|
|
else if (test_output_block[j] > 0)
|
|
|
|
++count_sign_block[j][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < 64; ++j) {
|
2013-04-05 04:00:31 +02:00
|
|
|
const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]);
|
|
|
|
const int max_diff = 1125;
|
|
|
|
EXPECT_LT(diff, max_diff)
|
2013-06-21 20:45:47 +02:00
|
|
|
<< "Error: 8x8 FDCT/FHT has a sign bias > "
|
2013-04-05 04:00:31 +02:00
|
|
|
<< 1. * max_diff / count_test_block * 100 << "%"
|
|
|
|
<< " for input range [-255, 255] at index " << j
|
|
|
|
<< " count0: " << count_sign_block[j][0]
|
|
|
|
<< " count1: " << count_sign_block[j][1]
|
|
|
|
<< " diff: " << diff;
|
2012-06-29 01:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(count_sign_block, 0, sizeof(count_sign_block));
|
|
|
|
|
|
|
|
for (int i = 0; i < count_test_block; ++i) {
|
|
|
|
// Initialize a test block with input range [-15, 15].
|
|
|
|
for (int j = 0; j < 64; ++j)
|
|
|
|
test_input_block[j] = (rnd.Rand8() >> 4) - (rnd.Rand8() >> 4);
|
|
|
|
|
2013-06-21 20:45:47 +02:00
|
|
|
RunFwdTxfm(test_input_block, test_output_block, NULL, pitch, tx_type_);
|
2012-06-29 01:26:31 +02:00
|
|
|
|
|
|
|
for (int j = 0; j < 64; ++j) {
|
|
|
|
if (test_output_block[j] < 0)
|
|
|
|
++count_sign_block[j][0];
|
|
|
|
else if (test_output_block[j] > 0)
|
|
|
|
++count_sign_block[j][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < 64; ++j) {
|
2013-04-05 04:00:31 +02:00
|
|
|
const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]);
|
|
|
|
const int max_diff = 10000;
|
|
|
|
EXPECT_LT(diff, max_diff)
|
2013-06-21 20:45:47 +02:00
|
|
|
<< "Error: 4x4 FDCT/FHT has a sign bias > "
|
2013-04-05 04:00:31 +02:00
|
|
|
<< 1. * max_diff / count_test_block * 100 << "%"
|
|
|
|
<< " for input range [-15, 15] at index " << j
|
|
|
|
<< " count0: " << count_sign_block[j][0]
|
|
|
|
<< " count1: " << count_sign_block[j][1]
|
|
|
|
<< " diff: " << diff;
|
2012-06-29 01:26:31 +02:00
|
|
|
}
|
2013-06-21 20:45:47 +02:00
|
|
|
}
|
2012-06-29 01:26:31 +02:00
|
|
|
|
2013-06-21 20:45:47 +02:00
|
|
|
TEST_P(FwdTrans8x8Test, RoundTripErrorCheck) {
|
2012-06-29 01:26:31 +02:00
|
|
|
ACMRandom rnd(ACMRandom::DeterministicSeed());
|
|
|
|
int max_error = 0;
|
|
|
|
double total_error = 0;
|
|
|
|
const int count_test_block = 100000;
|
|
|
|
for (int i = 0; i < count_test_block; ++i) {
|
2013-06-26 20:59:46 +02:00
|
|
|
DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, 64);
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, int16_t, test_temp_block, 64);
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, 64);
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, uint8_t, src, 64);
|
2012-06-29 01:26:31 +02:00
|
|
|
|
2013-05-16 19:52:15 +02:00
|
|
|
for (int j = 0; j < 64; ++j) {
|
|
|
|
src[j] = rnd.Rand8();
|
|
|
|
dst[j] = rnd.Rand8();
|
|
|
|
}
|
2012-06-29 01:26:31 +02:00
|
|
|
// Initialize a test block with input range [-255, 255].
|
|
|
|
for (int j = 0; j < 64; ++j)
|
2013-05-16 19:52:15 +02:00
|
|
|
test_input_block[j] = src[j] - dst[j];
|
2012-06-29 01:26:31 +02:00
|
|
|
|
|
|
|
const int pitch = 16;
|
2013-06-21 20:45:47 +02:00
|
|
|
RunFwdTxfm(test_input_block, test_temp_block, dst, pitch, tx_type_);
|
2012-08-24 18:59:49 +02:00
|
|
|
for (int j = 0; j < 64; ++j){
|
|
|
|
if(test_temp_block[j] > 0) {
|
|
|
|
test_temp_block[j] += 2;
|
|
|
|
test_temp_block[j] /= 4;
|
|
|
|
test_temp_block[j] *= 4;
|
|
|
|
} else {
|
|
|
|
test_temp_block[j] -= 2;
|
|
|
|
test_temp_block[j] /= 4;
|
|
|
|
test_temp_block[j] *= 4;
|
|
|
|
}
|
|
|
|
}
|
2013-06-21 20:45:47 +02:00
|
|
|
RunInvTxfm(test_input_block, test_temp_block, dst, pitch, tx_type_);
|
2012-06-29 01:26:31 +02:00
|
|
|
|
|
|
|
for (int j = 0; j < 64; ++j) {
|
2013-05-16 19:52:15 +02:00
|
|
|
const int diff = dst[j] - src[j];
|
2012-06-29 01:26:31 +02:00
|
|
|
const int error = diff * diff;
|
|
|
|
if (max_error < error)
|
|
|
|
max_error = error;
|
|
|
|
total_error += error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_GE(1, max_error)
|
2013-06-21 20:45:47 +02:00
|
|
|
<< "Error: 8x8 FDCT/IDCT or FHT/IHT has an individual roundtrip error > 1";
|
2012-06-29 01:26:31 +02:00
|
|
|
|
2012-08-03 02:03:14 +02:00
|
|
|
EXPECT_GE(count_test_block/5, total_error)
|
2013-06-21 20:45:47 +02:00
|
|
|
<< "Error: 8x8 FDCT/IDCT or FHT/IHT has average roundtrip "
|
|
|
|
"error > 1/5 per block";
|
|
|
|
}
|
2012-06-29 01:26:31 +02:00
|
|
|
|
2013-06-21 20:45:47 +02:00
|
|
|
TEST_P(FwdTrans8x8Test, ExtremalCheck) {
|
2012-06-29 01:26:31 +02:00
|
|
|
ACMRandom rnd(ACMRandom::DeterministicSeed());
|
|
|
|
int max_error = 0;
|
|
|
|
double total_error = 0;
|
|
|
|
const int count_test_block = 100000;
|
|
|
|
for (int i = 0; i < count_test_block; ++i) {
|
2013-06-26 20:59:46 +02:00
|
|
|
DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, 64);
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, int16_t, test_temp_block, 64);
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, 64);
|
|
|
|
DECLARE_ALIGNED_ARRAY(16, uint8_t, src, 64);
|
2012-06-29 01:26:31 +02:00
|
|
|
|
2013-05-16 19:52:15 +02:00
|
|
|
for (int j = 0; j < 64; ++j) {
|
|
|
|
src[j] = rnd.Rand8() % 2 ? 255 : 0;
|
|
|
|
dst[j] = src[j] > 0 ? 0 : 255;
|
|
|
|
}
|
|
|
|
// Initialize a test block with input range [-255, 255].
|
2012-06-29 01:26:31 +02:00
|
|
|
for (int j = 0; j < 64; ++j)
|
2013-05-16 19:52:15 +02:00
|
|
|
test_input_block[j] = src[j] - dst[j];
|
2012-06-29 01:26:31 +02:00
|
|
|
|
|
|
|
const int pitch = 16;
|
2013-06-21 20:45:47 +02:00
|
|
|
RunFwdTxfm(test_input_block, test_temp_block, dst, pitch, tx_type_);
|
|
|
|
RunInvTxfm(test_input_block, test_temp_block, dst, pitch, tx_type_);
|
2012-06-29 01:26:31 +02:00
|
|
|
|
|
|
|
for (int j = 0; j < 64; ++j) {
|
2013-05-16 19:52:15 +02:00
|
|
|
const int diff = dst[j] - src[j];
|
2012-06-29 01:26:31 +02:00
|
|
|
const int error = diff * diff;
|
|
|
|
if (max_error < error)
|
|
|
|
max_error = error;
|
|
|
|
total_error += error;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_GE(1, max_error)
|
2013-06-21 20:45:47 +02:00
|
|
|
<< "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has an"
|
2012-06-29 01:26:31 +02:00
|
|
|
<< " individual roundtrip error > 1";
|
|
|
|
|
2012-08-03 02:03:14 +02:00
|
|
|
EXPECT_GE(count_test_block/5, total_error)
|
2013-06-21 20:45:47 +02:00
|
|
|
<< "Error: Extremal 8x8 FDCT/IDCT or FHT/IHT has average"
|
2012-08-03 02:03:14 +02:00
|
|
|
<< " roundtrip error > 1/5 per block";
|
2012-06-29 01:26:31 +02:00
|
|
|
}
|
2013-06-21 20:45:47 +02:00
|
|
|
}
|
2012-06-29 01:26:31 +02:00
|
|
|
|
2013-06-21 20:45:47 +02:00
|
|
|
INSTANTIATE_TEST_CASE_P(VP9, FwdTrans8x8Test, ::testing::Range(0, 4));
|
2012-06-29 01:26:31 +02:00
|
|
|
} // namespace
|