Removed shadow warnings : postproc.c decodframe.c threading.c
[aom.git] / test / fdct4x4_test.cc
blobebec890d6e3df99ec478e43de5620ee4172d5ae2
1 /*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
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 */
11 #include <math.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include "third_party/googletest/src/include/gtest/gtest.h"
17 extern "C" {
18 #include "vp9_rtcd.h"
21 #include "acm_random.h"
22 #include "vpx/vpx_integer.h"
24 using libvpx_test::ACMRandom;
26 namespace {
28 TEST(Vp9FdctTest, SignBiasCheck) {
29 ACMRandom rnd(ACMRandom::DeterministicSeed());
30 int16_t test_input_block[16];
31 int16_t test_output_block[16];
32 const int pitch = 8;
33 int count_sign_block[16][2];
34 const int count_test_block = 1000000;
36 memset(count_sign_block, 0, sizeof(count_sign_block));
38 for (int i = 0; i < count_test_block; ++i) {
39 // Initialize a test block with input range [-255, 255].
40 for (int j = 0; j < 16; ++j)
41 test_input_block[j] = rnd.Rand8() - rnd.Rand8();
43 // TODO(Yaowu): this should be converted to a parameterized test
44 // to test optimized versions of this function.
45 vp9_short_fdct4x4_c(test_input_block, test_output_block, pitch);
47 for (int j = 0; j < 16; ++j) {
48 if (test_output_block[j] < 0)
49 ++count_sign_block[j][0];
50 else if (test_output_block[j] > 0)
51 ++count_sign_block[j][1];
55 for (int j = 0; j < 16; ++j) {
56 const bool bias_acceptable = (abs(count_sign_block[j][0] -
57 count_sign_block[j][1]) < 10000);
58 EXPECT_TRUE(bias_acceptable)
59 << "Error: 4x4 FDCT has a sign bias > 1%"
60 << " for input range [-255, 255] at index " << j;
63 memset(count_sign_block, 0, sizeof(count_sign_block));
65 for (int i = 0; i < count_test_block; ++i) {
66 // Initialize a test block with input range [-15, 15].
67 for (int j = 0; j < 16; ++j)
68 test_input_block[j] = (rnd.Rand8() >> 4) - (rnd.Rand8() >> 4);
70 // TODO(Yaowu): this should be converted to a parameterized test
71 // to test optimized versions of this function.
72 vp9_short_fdct4x4_c(test_input_block, test_output_block, pitch);
74 for (int j = 0; j < 16; ++j) {
75 if (test_output_block[j] < 0)
76 ++count_sign_block[j][0];
77 else if (test_output_block[j] > 0)
78 ++count_sign_block[j][1];
82 for (int j = 0; j < 16; ++j) {
83 const bool bias_acceptable = (abs(count_sign_block[j][0] -
84 count_sign_block[j][1]) < 100000);
85 EXPECT_TRUE(bias_acceptable)
86 << "Error: 4x4 FDCT has a sign bias > 10%"
87 << " for input range [-15, 15] at index " << j;
91 TEST(Vp9FdctTest, RoundTripErrorCheck) {
92 ACMRandom rnd(ACMRandom::DeterministicSeed());
93 int max_error = 0;
94 double total_error = 0;
95 const int count_test_block = 1000000;
96 for (int i = 0; i < count_test_block; ++i) {
97 int16_t test_input_block[16];
98 int16_t test_temp_block[16];
99 int16_t test_output_block[16];
101 // Initialize a test block with input range [-255, 255].
102 for (int j = 0; j < 16; ++j)
103 test_input_block[j] = rnd.Rand8() - rnd.Rand8();
105 // TODO(Yaowu): this should be converted to a parameterized test
106 // to test optimized versions of this function.
107 const int pitch = 8;
108 vp9_short_fdct4x4_c(test_input_block, test_temp_block, pitch);
110 for (int j = 0; j < 16; ++j) {
111 if(test_temp_block[j] > 0) {
112 test_temp_block[j] += 2;
113 test_temp_block[j] /= 4;
114 test_temp_block[j] *= 4;
115 } else {
116 test_temp_block[j] -= 2;
117 test_temp_block[j] /= 4;
118 test_temp_block[j] *= 4;
122 // Because the bitstream is not frozen yet, use the idct in the codebase.
123 vp9_short_idct4x4llm_c(test_temp_block, test_output_block, pitch);
125 for (int j = 0; j < 16; ++j) {
126 const int diff = test_input_block[j] - test_output_block[j];
127 const int error = diff * diff;
128 if (max_error < error)
129 max_error = error;
130 total_error += error;
133 EXPECT_GE(1, max_error)
134 << "Error: FDCT/IDCT has an individual roundtrip error > 1";
136 EXPECT_GE(count_test_block, total_error)
137 << "Error: FDCT/IDCT has average roundtrip error > 1 per block";
140 } // namespace