]> granicus.if.org Git - libvpx/blob - test/idct_test.cc
Merge "Improved 8t filters"
[libvpx] / 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 extern "C" {
12 #include "./vpx_config.h"
13 #include "./vp8_rtcd.h"
14 }
15 #include "test/clear_system_state.h"
16 #include "test/register_state_check.h"
17 #include "third_party/googletest/src/include/gtest/gtest.h"
18
19 #include "vpx/vpx_integer.h"
20
21 typedef void (*idct_fn_t)(int16_t *input, unsigned char *pred_ptr,
22                           int pred_stride, unsigned char *dst_ptr,
23                           int dst_stride);
24 namespace {
25 class IDCTTest : public ::testing::TestWithParam<idct_fn_t> {
26  protected:
27   virtual void SetUp() {
28     int i;
29
30     UUT = GetParam();
31     memset(input, 0, sizeof(input));
32     /* Set up guard blocks */
33     for (i = 0; i < 256; i++) output[i] = ((i & 0xF) < 4 && (i < 64)) ? 0 : -1;
34   }
35
36   virtual void TearDown() { libvpx_test::ClearSystemState(); }
37
38   idct_fn_t UUT;
39   int16_t input[16];
40   unsigned char output[256];
41   unsigned char predict[256];
42 };
43
44 TEST_P(IDCTTest, TestGuardBlocks) {
45   int i;
46
47   for (i = 0; i < 256; i++)
48     if ((i & 0xF) < 4 && i < 64)
49       EXPECT_EQ(0, output[i]) << i;
50     else
51       EXPECT_EQ(255, output[i]);
52 }
53
54 TEST_P(IDCTTest, TestAllZeros) {
55   int i;
56
57   REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
58
59   for (i = 0; i < 256; i++)
60     if ((i & 0xF) < 4 && i < 64)
61       EXPECT_EQ(0, output[i]) << "i==" << i;
62     else
63       EXPECT_EQ(255, output[i]) << "i==" << i;
64 }
65
66 TEST_P(IDCTTest, TestAllOnes) {
67   int i;
68
69   input[0] = 4;
70   REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
71
72   for (i = 0; i < 256; i++)
73     if ((i & 0xF) < 4 && i < 64)
74       EXPECT_EQ(1, output[i]) << "i==" << i;
75     else
76       EXPECT_EQ(255, output[i]) << "i==" << i;
77 }
78
79 TEST_P(IDCTTest, TestAddOne) {
80   int i;
81
82   for (i = 0; i < 256; i++) predict[i] = i;
83   input[0] = 4;
84   REGISTER_STATE_CHECK(UUT(input, predict, 16, output, 16));
85
86   for (i = 0; i < 256; i++)
87     if ((i & 0xF) < 4 && i < 64)
88       EXPECT_EQ(i + 1, output[i]) << "i==" << i;
89     else
90       EXPECT_EQ(255, output[i]) << "i==" << i;
91 }
92
93 TEST_P(IDCTTest, TestWithData) {
94   int i;
95
96   for (i = 0; i < 16; i++) input[i] = i;
97
98   REGISTER_STATE_CHECK(UUT(input, output, 16, output, 16));
99
100   for (i = 0; i < 256; i++)
101     if ((i & 0xF) > 3 || i > 63)
102       EXPECT_EQ(255, output[i]) << "i==" << i;
103     else if (i == 0)
104       EXPECT_EQ(11, output[i]) << "i==" << i;
105     else if (i == 34)
106       EXPECT_EQ(1, output[i]) << "i==" << i;
107     else if (i == 2 || i == 17 || i == 32)
108       EXPECT_EQ(3, output[i]) << "i==" << i;
109     else
110       EXPECT_EQ(0, output[i]) << "i==" << i;
111 }
112
113 INSTANTIATE_TEST_CASE_P(C, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_c));
114 #if HAVE_MMX
115 INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
116                         ::testing::Values(vp8_short_idct4x4llm_mmx));
117 #endif
118 }