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.
13 #include "third_party/googletest/src/include/gtest/gtest.h"
15 #include "vpx/vpx_integer.h"
16 #include "vpx_config.h"
18 #if CONFIG_VP8_ENCODER
19 # include "vp8/common/variance.h"
20 # include "vp8_rtcd.h"
22 #if CONFIG_VP9_ENCODER
23 # include "vp9/encoder/vp9_variance.h"
24 # include "vp9_rtcd.h"
30 using ::std::tr1::get
;
31 using ::std::tr1::make_tuple
;
32 using ::std::tr1::tuple
;
34 template<typename VarianceFunctionType
>
36 public ::testing::TestWithParam
<tuple
<int, int, VarianceFunctionType
> > {
38 virtual void SetUp() {
39 const tuple
<int, int, VarianceFunctionType
>& params
= this->GetParam();
40 width_
= get
<0>(params
);
41 height_
= get
<1>(params
);
42 variance_
= get
<2>(params
);
44 block_size_
= width_
* height_
;
45 src_
= new uint8_t[block_size_
];
46 ref_
= new uint8_t[block_size_
];
47 ASSERT_TRUE(src_
!= NULL
);
48 ASSERT_TRUE(ref_
!= NULL
);
51 virtual void TearDown() {
58 void OneQuarterTest();
65 VarianceFunctionType variance_
;
69 template<typename VarianceFunctionType
>
70 void VarianceTest
<VarianceFunctionType
>::ZeroTest() {
71 for (int i
= 0; i
<= 255; ++i
) {
72 memset(src_
, i
, block_size_
);
73 for (int j
= 0; j
<= 255; ++j
) {
74 memset(ref_
, j
, block_size_
);
76 const unsigned int var
= variance_(src_
, width_
, ref_
, width_
, &sse
);
77 EXPECT_EQ(0u, var
) << "src values: " << i
<< "ref values: " << j
;
82 template<typename VarianceFunctionType
>
83 void VarianceTest
<VarianceFunctionType
>::OneQuarterTest() {
84 memset(src_
, 255, block_size_
);
85 const int half
= block_size_
/ 2;
86 memset(ref_
, 255, half
);
87 memset(ref_
+ half
, 0, half
);
89 const unsigned int var
= variance_(src_
, width_
, ref_
, width_
, &sse
);
90 const unsigned int expected
= block_size_
* 255 * 255 / 4;
91 EXPECT_EQ(expected
, var
);
94 // -----------------------------------------------------------------------------
99 #if CONFIG_VP8_ENCODER
100 typedef VarianceTest
<vp8_variance_fn_t
> VP8VarianceTest
;
102 TEST_P(VP8VarianceTest
, Zero
) { ZeroTest(); }
103 TEST_P(VP8VarianceTest
, OneQuarter
) { OneQuarterTest(); }
105 const vp8_variance_fn_t variance4x4_c
= vp8_variance4x4_c
;
106 const vp8_variance_fn_t variance8x8_c
= vp8_variance8x8_c
;
107 const vp8_variance_fn_t variance8x16_c
= vp8_variance8x16_c
;
108 const vp8_variance_fn_t variance16x8_c
= vp8_variance16x8_c
;
109 const vp8_variance_fn_t variance16x16_c
= vp8_variance16x16_c
;
110 INSTANTIATE_TEST_CASE_P(
112 ::testing::Values(make_tuple(4, 4, variance4x4_c
),
113 make_tuple(8, 8, variance8x8_c
),
114 make_tuple(8, 16, variance8x16_c
),
115 make_tuple(16, 8, variance16x8_c
),
116 make_tuple(16, 16, variance16x16_c
)));
119 const vp8_variance_fn_t variance4x4_mmx
= vp8_variance4x4_mmx
;
120 const vp8_variance_fn_t variance8x8_mmx
= vp8_variance8x8_mmx
;
121 const vp8_variance_fn_t variance8x16_mmx
= vp8_variance8x16_mmx
;
122 const vp8_variance_fn_t variance16x8_mmx
= vp8_variance16x8_mmx
;
123 const vp8_variance_fn_t variance16x16_mmx
= vp8_variance16x16_mmx
;
124 INSTANTIATE_TEST_CASE_P(
125 MMX
, VP8VarianceTest
,
126 ::testing::Values(make_tuple(4, 4, variance4x4_mmx
),
127 make_tuple(8, 8, variance8x8_mmx
),
128 make_tuple(8, 16, variance8x16_mmx
),
129 make_tuple(16, 8, variance16x8_mmx
),
130 make_tuple(16, 16, variance16x16_mmx
)));
134 const vp8_variance_fn_t variance4x4_wmt
= vp8_variance4x4_wmt
;
135 const vp8_variance_fn_t variance8x8_wmt
= vp8_variance8x8_wmt
;
136 const vp8_variance_fn_t variance8x16_wmt
= vp8_variance8x16_wmt
;
137 const vp8_variance_fn_t variance16x8_wmt
= vp8_variance16x8_wmt
;
138 const vp8_variance_fn_t variance16x16_wmt
= vp8_variance16x16_wmt
;
139 INSTANTIATE_TEST_CASE_P(
140 SSE2
, VP8VarianceTest
,
141 ::testing::Values(make_tuple(4, 4, variance4x4_wmt
),
142 make_tuple(8, 8, variance8x8_wmt
),
143 make_tuple(8, 16, variance8x16_wmt
),
144 make_tuple(16, 8, variance16x8_wmt
),
145 make_tuple(16, 16, variance16x16_wmt
)));
147 #endif // CONFIG_VP8_ENCODER
151 // -----------------------------------------------------------------------------
156 #if CONFIG_VP9_ENCODER
157 typedef VarianceTest
<vp9_variance_fn_t
> VP9VarianceTest
;
159 TEST_P(VP9VarianceTest
, Zero
) { ZeroTest(); }
160 TEST_P(VP9VarianceTest
, OneQuarter
) { OneQuarterTest(); }
162 const vp9_variance_fn_t variance4x4_c
= vp9_variance4x4_c
;
163 const vp9_variance_fn_t variance8x8_c
= vp9_variance8x8_c
;
164 const vp9_variance_fn_t variance8x16_c
= vp9_variance8x16_c
;
165 const vp9_variance_fn_t variance16x8_c
= vp9_variance16x8_c
;
166 const vp9_variance_fn_t variance16x16_c
= vp9_variance16x16_c
;
167 INSTANTIATE_TEST_CASE_P(
169 ::testing::Values(make_tuple(4, 4, variance4x4_c
),
170 make_tuple(8, 8, variance8x8_c
),
171 make_tuple(8, 16, variance8x16_c
),
172 make_tuple(16, 8, variance16x8_c
),
173 make_tuple(16, 16, variance16x16_c
)));
176 const vp9_variance_fn_t variance4x4_mmx
= vp9_variance4x4_mmx
;
177 const vp9_variance_fn_t variance8x8_mmx
= vp9_variance8x8_mmx
;
178 const vp9_variance_fn_t variance8x16_mmx
= vp9_variance8x16_mmx
;
179 const vp9_variance_fn_t variance16x8_mmx
= vp9_variance16x8_mmx
;
180 const vp9_variance_fn_t variance16x16_mmx
= vp9_variance16x16_mmx
;
181 INSTANTIATE_TEST_CASE_P(
182 MMX
, VP9VarianceTest
,
183 ::testing::Values(make_tuple(4, 4, variance4x4_mmx
),
184 make_tuple(8, 8, variance8x8_mmx
),
185 make_tuple(8, 16, variance8x16_mmx
),
186 make_tuple(16, 8, variance16x8_mmx
),
187 make_tuple(16, 16, variance16x16_mmx
)));
191 const vp9_variance_fn_t variance4x4_wmt
= vp9_variance4x4_wmt
;
192 const vp9_variance_fn_t variance8x8_wmt
= vp9_variance8x8_wmt
;
193 const vp9_variance_fn_t variance8x16_wmt
= vp9_variance8x16_wmt
;
194 const vp9_variance_fn_t variance16x8_wmt
= vp9_variance16x8_wmt
;
195 const vp9_variance_fn_t variance16x16_wmt
= vp9_variance16x16_wmt
;
196 INSTANTIATE_TEST_CASE_P(
197 SSE2
, VP9VarianceTest
,
198 ::testing::Values(make_tuple(4, 4, variance4x4_wmt
),
199 make_tuple(8, 8, variance8x8_wmt
),
200 make_tuple(8, 16, variance8x16_wmt
),
201 make_tuple(16, 8, variance16x8_wmt
),
202 make_tuple(16, 16, variance16x16_wmt
)));
204 #endif // CONFIG_VP9_ENCODER