blob: f99a4075f8933e4af9c2ae278eab7e79a1c29ee5 [file] [log] [blame]
Daniel Kangfed8a182012-08-02 17:03:14 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Daniel Kangfed8a182012-08-02 17:03:14 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*/
Daniel Kangfed8a182012-08-02 17:03:14 -070011
12#include <math.h>
13#include <stdlib.h>
14#include <string.h>
15
Tom Finegan7a07ece2017-02-07 17:14:05 -080016#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Daniel Kangfed8a182012-08-02 17:03:14 -070017
Yaowu Xuf883b422016-08-30 14:01:10 -070018#include "./aom_dsp_rtcd.h"
Yaowu Xuafffa3d2013-09-05 08:45:56 -070019#include "test/acm_random.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070020#include "aom/aom_integer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070021#include "aom_ports/msvc.h" // for round()
Daniel Kangfed8a182012-08-02 17:03:14 -070022
Yaowu Xuc27fc142016-08-22 16:08:15 -070023using libaom_test::ACMRandom;
Daniel Kangfed8a182012-08-02 17:03:14 -070024
25namespace {
26
27void reference_dct_1d(double input[8], double output[8]) {
28 const double kPi = 3.141592653589793238462643383279502884;
29 const double kInvSqrt2 = 0.707106781186547524400844362104;
30 for (int k = 0; k < 8; k++) {
31 output[k] = 0.0;
32 for (int n = 0; n < 8; n++)
clang-format3a826f12016-08-11 17:46:05 -070033 output[k] += input[n] * cos(kPi * (2 * n + 1) * k / 16.0);
34 if (k == 0) output[k] = output[k] * kInvSqrt2;
Daniel Kangfed8a182012-08-02 17:03:14 -070035 }
36}
37
38void reference_dct_2d(int16_t input[64], double output[64]) {
39 // First transform columns
40 for (int i = 0; i < 8; ++i) {
41 double temp_in[8], temp_out[8];
clang-format3a826f12016-08-11 17:46:05 -070042 for (int j = 0; j < 8; ++j) temp_in[j] = input[j * 8 + i];
Daniel Kangfed8a182012-08-02 17:03:14 -070043 reference_dct_1d(temp_in, temp_out);
clang-format3a826f12016-08-11 17:46:05 -070044 for (int j = 0; j < 8; ++j) output[j * 8 + i] = temp_out[j];
Daniel Kangfed8a182012-08-02 17:03:14 -070045 }
46 // Then transform rows
47 for (int i = 0; i < 8; ++i) {
48 double temp_in[8], temp_out[8];
clang-format3a826f12016-08-11 17:46:05 -070049 for (int j = 0; j < 8; ++j) temp_in[j] = output[j + i * 8];
Daniel Kangfed8a182012-08-02 17:03:14 -070050 reference_dct_1d(temp_in, temp_out);
clang-format3a826f12016-08-11 17:46:05 -070051 for (int j = 0; j < 8; ++j) output[j + i * 8] = temp_out[j];
Daniel Kangfed8a182012-08-02 17:03:14 -070052 }
53 // Scale by some magic number
clang-format3a826f12016-08-11 17:46:05 -070054 for (int i = 0; i < 64; ++i) output[i] *= 2;
Daniel Kangfed8a182012-08-02 17:03:14 -070055}
56
Yaowu Xuf883b422016-08-30 14:01:10 -070057TEST(AV1Idct8x8Test, AccuracyCheck) {
Daniel Kangfed8a182012-08-02 17:03:14 -070058 ACMRandom rnd(ACMRandom::DeterministicSeed());
59 const int count_test_block = 10000;
60 for (int i = 0; i < count_test_block; ++i) {
Deb Mukherjee10783d42014-09-02 16:34:09 -070061 int16_t input[64];
62 tran_low_t coeff[64];
Daniel Kangfed8a182012-08-02 17:03:14 -070063 double output_r[64];
Scott LaVarnway794a7be2013-05-16 13:52:15 -040064 uint8_t dst[64], src[64];
Daniel Kangfed8a182012-08-02 17:03:14 -070065
Scott LaVarnway794a7be2013-05-16 13:52:15 -040066 for (int j = 0; j < 64; ++j) {
67 src[j] = rnd.Rand8();
68 dst[j] = rnd.Rand8();
69 }
Daniel Kangfed8a182012-08-02 17:03:14 -070070 // Initialize a test block with input range [-255, 255].
clang-format3a826f12016-08-11 17:46:05 -070071 for (int j = 0; j < 64; ++j) input[j] = src[j] - dst[j];
Daniel Kangfed8a182012-08-02 17:03:14 -070072
Daniel Kangfed8a182012-08-02 17:03:14 -070073 reference_dct_2d(input, output_r);
74 for (int j = 0; j < 64; ++j)
James Zern6bbb8b72016-06-27 20:43:04 -070075 coeff[j] = static_cast<tran_low_t>(round(output_r[j]));
Yaowu Xuf883b422016-08-30 14:01:10 -070076 aom_idct8x8_64_add_c(coeff, dst, 8);
Daniel Kangfed8a182012-08-02 17:03:14 -070077 for (int j = 0; j < 64; ++j) {
Scott LaVarnway794a7be2013-05-16 13:52:15 -040078 const int diff = dst[j] - src[j];
Daniel Kangfed8a182012-08-02 17:03:14 -070079 const int error = diff * diff;
clang-format3a826f12016-08-11 17:46:05 -070080 EXPECT_GE(1, error) << "Error: 8x8 FDCT/IDCT has error " << error
81 << " at index " << j;
Daniel Kangfed8a182012-08-02 17:03:14 -070082 }
83 }
84}
85
86} // namespace