Merge "Add zoom break out for kf boost loop."
[platform/upstream/libvpx.git] / test / idct_test.cc
1 /*
2  *  Copyright (c) 2010 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 "./vpx_config.h"
12 #include "./vp8_rtcd.h"
13
14 #include "third_party/googletest/src/include/gtest/gtest.h"
15
16 #include "test/buffer.h"
17 #include "test/clear_system_state.h"
18 #include "test/register_state_check.h"
19 #include "vpx/vpx_integer.h"
20
21 typedef void (*IdctFunc)(int16_t *input, unsigned char *pred_ptr,
22                          int pred_stride, unsigned char *dst_ptr,
23                          int dst_stride);
24 namespace {
25
26 using libvpx_test::Buffer;
27
28 class IDCTTest : public ::testing::TestWithParam<IdctFunc> {
29  protected:
30   virtual void SetUp() {
31     UUT = GetParam();
32
33     input = new Buffer<int16_t>(4, 4, 0);
34     ASSERT_TRUE(input != NULL);
35     ASSERT_TRUE(input->Init());
36     predict = new Buffer<uint8_t>(4, 4, 3);
37     ASSERT_TRUE(predict != NULL);
38     ASSERT_TRUE(predict->Init());
39     output = new Buffer<uint8_t>(4, 4, 3);
40     ASSERT_TRUE(output != NULL);
41     ASSERT_TRUE(output->Init());
42   }
43
44   virtual void TearDown() {
45     delete input;
46     delete predict;
47     delete output;
48     libvpx_test::ClearSystemState();
49   }
50
51   IdctFunc UUT;
52   Buffer<int16_t> *input;
53   Buffer<uint8_t> *predict;
54   Buffer<uint8_t> *output;
55 };
56
57 TEST_P(IDCTTest, TestAllZeros) {
58   // When the input is '0' the output will be '0'.
59   input->Set(0);
60   predict->Set(0);
61   output->Set(0);
62
63   ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
64                                predict->stride(), output->TopLeftPixel(),
65                                output->stride()));
66
67   ASSERT_TRUE(input->CheckValues(0));
68   ASSERT_TRUE(input->CheckPadding());
69   ASSERT_TRUE(output->CheckValues(0));
70   ASSERT_TRUE(output->CheckPadding());
71 }
72
73 TEST_P(IDCTTest, TestAllOnes) {
74   input->Set(0);
75   // When the first element is '4' it will fill the output buffer with '1'.
76   input->TopLeftPixel()[0] = 4;
77   predict->Set(0);
78   output->Set(0);
79
80   ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
81                                predict->stride(), output->TopLeftPixel(),
82                                output->stride()));
83
84   ASSERT_TRUE(output->CheckValues(1));
85   ASSERT_TRUE(output->CheckPadding());
86 }
87
88 TEST_P(IDCTTest, TestAddOne) {
89   // Set the transform output to '1' and make sure it gets added to the
90   // prediction buffer.
91   input->Set(0);
92   input->TopLeftPixel()[0] = 4;
93   output->Set(0);
94
95   uint8_t *pred = predict->TopLeftPixel();
96   for (int y = 0; y < 4; ++y) {
97     for (int x = 0; x < 4; ++x) {
98       pred[y * predict->stride() + x] = y * 4 + x;
99     }
100   }
101
102   ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
103                                predict->stride(), output->TopLeftPixel(),
104                                output->stride()));
105
106   uint8_t const *out = output->TopLeftPixel();
107   for (int y = 0; y < 4; ++y) {
108     for (int x = 0; x < 4; ++x) {
109       EXPECT_EQ(1 + y * 4 + x, out[y * output->stride() + x]);
110     }
111   }
112
113   if (HasFailure()) {
114     output->DumpBuffer();
115   }
116
117   ASSERT_TRUE(output->CheckPadding());
118 }
119
120 TEST_P(IDCTTest, TestWithData) {
121   // Test a single known input.
122   predict->Set(0);
123
124   int16_t *in = input->TopLeftPixel();
125   for (int y = 0; y < 4; ++y) {
126     for (int x = 0; x < 4; ++x) {
127       in[y * input->stride() + x] = y * 4 + x;
128     }
129   }
130
131   ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
132                                predict->stride(), output->TopLeftPixel(),
133                                output->stride()));
134
135   uint8_t *out = output->TopLeftPixel();
136   for (int y = 0; y < 4; ++y) {
137     for (int x = 0; x < 4; ++x) {
138       switch (y * 4 + x) {
139         case 0: EXPECT_EQ(11, out[y * output->stride() + x]); break;
140         case 2:
141         case 5:
142         case 8: EXPECT_EQ(3, out[y * output->stride() + x]); break;
143         case 10: EXPECT_EQ(1, out[y * output->stride() + x]); break;
144         default: EXPECT_EQ(0, out[y * output->stride() + x]);
145       }
146     }
147   }
148
149   if (HasFailure()) {
150     output->DumpBuffer();
151   }
152
153   ASSERT_TRUE(output->CheckPadding());
154 }
155
156 INSTANTIATE_TEST_CASE_P(C, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_c));
157
158 #if HAVE_NEON
159 INSTANTIATE_TEST_CASE_P(NEON, IDCTTest,
160                         ::testing::Values(vp8_short_idct4x4llm_neon));
161 #endif  // HAVE_NEON
162
163 #if HAVE_MMX
164 INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
165                         ::testing::Values(vp8_short_idct4x4llm_mmx));
166 #endif  // HAVE_MMX
167
168 #if HAVE_MSA
169 INSTANTIATE_TEST_CASE_P(MSA, IDCTTest,
170                         ::testing::Values(vp8_short_idct4x4llm_msa));
171 #endif  // HAVE_MSA
172
173 #if HAVE_MMI
174 INSTANTIATE_TEST_CASE_P(MMI, IDCTTest,
175                         ::testing::Values(vp8_short_idct4x4llm_mmi));
176 #endif  // HAVE_MMI
177 }  // namespace