Commit d02642f2 authored by Sebastien Alaiwan's avatar Sebastien Alaiwan Committed by Frédéric BARBIER

Add inverse accuracy test for inv_tx_fm1d

Change-Id: I3cc9cb8135ec5e8aa20c8cff901a2f37b3b459ee
parent 38cdce8e
......@@ -9,6 +9,8 @@
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include <math.h>
#include "test/av1_txfm_test.h"
#include "test/util.h"
#include "av1/common/av1_fwd_txfm1d.h"
......@@ -45,6 +47,54 @@ const TxfmFunc inv_txfm_func_ls[][2] = {
const int8_t cos_bit[12] = { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13 };
const int8_t range_bit[12] = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 };
void reference_idct_1d_int(const int32_t *in, int32_t *out, int size) {
double input[64];
for (int i = 0; i < size; ++i) input[i] = in[i];
double output[64];
libaom_test::reference_idct_1d(input, output, size);
for (int i = 0; i < size; ++i)
out[i] = static_cast<int32_t>(round(output[i]));
}
void random_matrix(int32_t *dst, int len, ACMRandom *rnd) {
const int bits = 16;
const int maxVal = (1 << (bits - 1)) - 1;
const int minVal = -(1 << (bits - 1));
for (int i = 0; i < len; ++i) {
if (rnd->Rand8() % 10)
dst[i] = minVal + rnd->Rand16() % (1 << bits);
else
dst[i] = rnd->Rand8() % 2 ? minVal : maxVal;
}
}
TEST(av1_inv_txfm1d, InvAccuracyCheck) {
ACMRandom rnd(ACMRandom::DeterministicSeed());
const int count_test_block = 20000;
const int max_error[] = { 6, 10, 19, 28 };
for (int k = 0; k < count_test_block; ++k) {
// choose a random transform to test
const int txfm_type = rnd.Rand8() % NELEMENTS(inv_txfm_func_ls);
const int txfm_size = txfm_size_ls[txfm_type];
const TxfmFunc txfm_func = inv_txfm_func_ls[txfm_type][0];
int32_t input[64];
random_matrix(input, txfm_size, &rnd);
int32_t ref_output[64];
reference_idct_1d_int(input, ref_output, txfm_size);
int32_t output[64];
txfm_func(input, output, cos_bit, range_bit);
for (int i = 0; i < txfm_size; ++i) {
EXPECT_LE(abs(output[i] - ref_output[i]), max_error[txfm_type]);
}
}
}
TEST(av1_inv_txfm1d, round_trip) {
ACMRandom rnd(ACMRandom::DeterministicSeed());
for (int si = 0; si < NELEMENTS(fwd_txfm_func_ls); ++si) {
......
......@@ -18,6 +18,7 @@
#include "./av1_rtcd.h"
#include "./aom_dsp_rtcd.h"
#include "test/acm_random.h"
#include "test/av1_txfm_test.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
......@@ -29,19 +30,6 @@
using libaom_test::ACMRandom;
namespace {
const double kInvSqrt2 = 0.707106781186547524400844362104;
void reference_idct_1d(const double *in, double *out, int size) {
for (int n = 0; n < size; ++n) {
out[n] = 0;
for (int k = 0; k < size; ++k) {
if (k == 0)
out[n] += kInvSqrt2 * in[k] * cos(PI * (2 * n + 1) * k / (2 * size));
else
out[n] += in[k] * cos(PI * (2 * n + 1) * k / (2 * size));
}
}
}
typedef void (*IdctFunc)(const tran_low_t *in, tran_low_t *out);
......@@ -65,7 +53,7 @@ class TransTestBase {
}
inv_txfm_(input, output);
reference_idct_1d(ref_input, ref_output, txfm_size_);
libaom_test::reference_idct_1d(ref_input, ref_output, txfm_size_);
for (int ni = 0; ni < txfm_size_; ++ni) {
EXPECT_LE(
......
......@@ -76,6 +76,18 @@ void reference_dct_1d(const double *in, double *out, int size) {
}
}
void reference_idct_1d(const double *in, double *out, int size) {
for (int n = 0; n < size; ++n) {
out[n] = 0;
for (int k = 0; k < size; ++k) {
if (k == 0)
out[n] += invSqrt2 * in[k] * cos(M_PI * (2 * n + 1) * k / (2 * size));
else
out[n] += in[k] * cos(M_PI * (2 * n + 1) * k / (2 * size));
}
}
}
void reference_adst_1d(const double *in, double *out, int size) {
for (int k = 0; k < size; ++k) {
out[k] = 0;
......
......@@ -40,6 +40,7 @@ int get_txfm1d_size(TX_SIZE tx_size);
void get_txfm1d_type(TX_TYPE txfm2d_type, TYPE_TXFM *type0, TYPE_TXFM *type1);
void reference_dct_1d(const double *in, double *out, int size);
void reference_idct_1d(const double *in, double *out, int size);
void reference_adst_1d(const double *in, double *out, int size);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment