Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * 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. |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 10 | */ |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 11 | |
| 12 | #include <math.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 16 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 17 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 18 | #include "./aom_dsp_rtcd.h" |
Yaowu Xu | afffa3d | 2013-09-05 08:45:56 -0700 | [diff] [blame] | 19 | #include "test/acm_random.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 21 | #include "aom_ports/msvc.h" // for round() |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 22 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | using libaom_test::ACMRandom; |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 24 | |
| 25 | namespace { |
| 26 | |
| 27 | void 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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 33 | output[k] += input[n] * cos(kPi * (2 * n + 1) * k / 16.0); |
| 34 | if (k == 0) output[k] = output[k] * kInvSqrt2; |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
| 38 | void 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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 42 | for (int j = 0; j < 8; ++j) temp_in[j] = input[j * 8 + i]; |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 43 | reference_dct_1d(temp_in, temp_out); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 44 | for (int j = 0; j < 8; ++j) output[j * 8 + i] = temp_out[j]; |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 45 | } |
| 46 | // Then transform rows |
| 47 | for (int i = 0; i < 8; ++i) { |
| 48 | double temp_in[8], temp_out[8]; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 49 | for (int j = 0; j < 8; ++j) temp_in[j] = output[j + i * 8]; |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 50 | reference_dct_1d(temp_in, temp_out); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 51 | for (int j = 0; j < 8; ++j) output[j + i * 8] = temp_out[j]; |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 52 | } |
| 53 | // Scale by some magic number |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 54 | for (int i = 0; i < 64; ++i) output[i] *= 2; |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Daniel Kang | fed8a18 | 2012-08-02 17:03:14 -0700 | [diff] [blame] | 57 | } // namespace |