1 /*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <math.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "gtest/gtest.h"
16
17 #include "./vpx_dsp_rtcd.h"
18 #include "test/acm_random.h"
19 #include "vpx/vpx_integer.h"
20
21 using libvpx_test::ACMRandom;
22
23 namespace {
24
reference_dct_1d(double input[8],double output[8])25 void reference_dct_1d(double input[8], double output[8]) {
26 const double kPi = 3.141592653589793238462643383279502884;
27 const double kInvSqrt2 = 0.707106781186547524400844362104;
28 for (int k = 0; k < 8; k++) {
29 output[k] = 0.0;
30 for (int n = 0; n < 8; n++) {
31 output[k] += input[n] * cos(kPi * (2 * n + 1) * k / 16.0);
32 }
33 if (k == 0) output[k] = output[k] * kInvSqrt2;
34 }
35 }
36
reference_dct_2d(int16_t input[64],double output[64])37 void reference_dct_2d(int16_t input[64], double output[64]) {
38 // First transform columns
39 for (int i = 0; i < 8; ++i) {
40 double temp_in[8], temp_out[8];
41 for (int j = 0; j < 8; ++j) temp_in[j] = input[j * 8 + i];
42 reference_dct_1d(temp_in, temp_out);
43 for (int j = 0; j < 8; ++j) output[j * 8 + i] = temp_out[j];
44 }
45 // Then transform rows
46 for (int i = 0; i < 8; ++i) {
47 double temp_in[8], temp_out[8];
48 for (int j = 0; j < 8; ++j) temp_in[j] = output[j + i * 8];
49 reference_dct_1d(temp_in, temp_out);
50 for (int j = 0; j < 8; ++j) output[j + i * 8] = temp_out[j];
51 }
52 // Scale by some magic number
53 for (int i = 0; i < 64; ++i) output[i] *= 2;
54 }
55
TEST(VP9Idct8x8Test,AccuracyCheck)56 TEST(VP9Idct8x8Test, AccuracyCheck) {
57 ACMRandom rnd(ACMRandom::DeterministicSeed());
58 const int count_test_block = 10000;
59 for (int i = 0; i < count_test_block; ++i) {
60 int16_t input[64];
61 tran_low_t coeff[64];
62 double output_r[64];
63 uint8_t dst[64], src[64];
64
65 for (int j = 0; j < 64; ++j) {
66 src[j] = rnd.Rand8();
67 dst[j] = rnd.Rand8();
68 }
69 // Initialize a test block with input range [-255, 255].
70 for (int j = 0; j < 64; ++j) input[j] = src[j] - dst[j];
71
72 reference_dct_2d(input, output_r);
73 for (int j = 0; j < 64; ++j) {
74 coeff[j] = static_cast<tran_low_t>(round(output_r[j]));
75 }
76 vpx_idct8x8_64_add_c(coeff, dst, 8);
77 for (int j = 0; j < 64; ++j) {
78 const int diff = dst[j] - src[j];
79 const int error = diff * diff;
80 EXPECT_GE(1, error) << "Error: 8x8 FDCT/IDCT has error " << error
81 << " at index " << j;
82 }
83 }
84 }
85
86 } // namespace
87