Merge "remove mmx variance functions"
[aom.git] / test / idct8x8_test.cc
blob7f9d751d650a3ac471553285e96e359f1432e40b
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 #include "./vpx_dsp_rtcd.h"
18 #include "test/acm_random.h"
19 #include "vpx/vpx_integer.h"
21 using libvpx_test::ACMRandom;
23 namespace {
25 #ifdef _MSC_VER
26 static int round(double x) {
27 if (x < 0)
28 return static_cast<int>(ceil(x - 0.5));
29 else
30 return static_cast<int>(floor(x + 0.5));
32 #endif
34 void reference_dct_1d(double input[8], double output[8]) {
35 const double kPi = 3.141592653589793238462643383279502884;
36 const double kInvSqrt2 = 0.707106781186547524400844362104;
37 for (int k = 0; k < 8; k++) {
38 output[k] = 0.0;
39 for (int n = 0; n < 8; n++)
40 output[k] += input[n]*cos(kPi*(2*n+1)*k/16.0);
41 if (k == 0)
42 output[k] = output[k]*kInvSqrt2;
46 void reference_dct_2d(int16_t input[64], double output[64]) {
47 // First transform columns
48 for (int i = 0; i < 8; ++i) {
49 double temp_in[8], temp_out[8];
50 for (int j = 0; j < 8; ++j)
51 temp_in[j] = input[j*8 + i];
52 reference_dct_1d(temp_in, temp_out);
53 for (int j = 0; j < 8; ++j)
54 output[j*8 + i] = temp_out[j];
56 // Then transform rows
57 for (int i = 0; i < 8; ++i) {
58 double temp_in[8], temp_out[8];
59 for (int j = 0; j < 8; ++j)
60 temp_in[j] = output[j + i*8];
61 reference_dct_1d(temp_in, temp_out);
62 for (int j = 0; j < 8; ++j)
63 output[j + i*8] = temp_out[j];
65 // Scale by some magic number
66 for (int i = 0; i < 64; ++i)
67 output[i] *= 2;
70 TEST(VP9Idct8x8Test, AccuracyCheck) {
71 ACMRandom rnd(ACMRandom::DeterministicSeed());
72 const int count_test_block = 10000;
73 for (int i = 0; i < count_test_block; ++i) {
74 int16_t input[64];
75 tran_low_t coeff[64];
76 double output_r[64];
77 uint8_t dst[64], src[64];
79 for (int j = 0; j < 64; ++j) {
80 src[j] = rnd.Rand8();
81 dst[j] = rnd.Rand8();
83 // Initialize a test block with input range [-255, 255].
84 for (int j = 0; j < 64; ++j)
85 input[j] = src[j] - dst[j];
87 reference_dct_2d(input, output_r);
88 for (int j = 0; j < 64; ++j)
89 coeff[j] = round(output_r[j]);
90 vpx_idct8x8_64_add_c(coeff, dst, 8);
91 for (int j = 0; j < 64; ++j) {
92 const int diff = dst[j] - src[j];
93 const int error = diff * diff;
94 EXPECT_GE(1, error)
95 << "Error: 8x8 FDCT/IDCT has error " << error
96 << " at index " << j;
101 } // namespace