blob: 9ab60b1c3552f0ea82c9b5354a374c2e839dfa33 [file] [log] [blame]
John Koleszar5ca6a362013-01-25 09:47:09 -08001/*
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
Tero Rintaluomae326cec2013-08-22 11:29:19 +030011#include <string.h>
James Zern8fb48af2013-05-02 13:08:19 -070012#include "test/acm_random.h"
13#include "test/register_state_check.h"
14#include "test/util.h"
15#include "third_party/googletest/src/include/gtest/gtest.h"
John Koleszar5ca6a362013-01-25 09:47:09 -080016
17extern "C" {
18#include "./vpx_config.h"
19#include "./vp9_rtcd.h"
John Koleszar557a1b22013-02-20 16:13:01 -080020#include "vp9/common/vp9_filter.h"
John Koleszar29d47ac2013-02-07 17:00:37 -080021#include "vpx_mem/vpx_mem.h"
John Koleszar6fd7dd12013-02-20 15:59:20 -080022#include "vpx_ports/mem.h"
John Koleszar5ca6a362013-01-25 09:47:09 -080023}
John Koleszar5ca6a362013-01-25 09:47:09 -080024
25namespace {
Ronald S. Bultjedecead72013-07-10 11:17:19 -070026typedef void (*convolve_fn_t)(const uint8_t *src, ptrdiff_t src_stride,
27 uint8_t *dst, ptrdiff_t dst_stride,
John Koleszar5ca6a362013-01-25 09:47:09 -080028 const int16_t *filter_x, int filter_x_stride,
29 const int16_t *filter_y, int filter_y_stride,
30 int w, int h);
31
32struct ConvolveFunctions {
33 ConvolveFunctions(convolve_fn_t h8, convolve_fn_t h8_avg,
34 convolve_fn_t v8, convolve_fn_t v8_avg,
35 convolve_fn_t hv8, convolve_fn_t hv8_avg)
36 : h8_(h8), v8_(v8), hv8_(hv8), h8_avg_(h8_avg), v8_avg_(v8_avg),
37 hv8_avg_(hv8_avg) {}
38
39 convolve_fn_t h8_;
40 convolve_fn_t v8_;
41 convolve_fn_t hv8_;
42 convolve_fn_t h8_avg_;
43 convolve_fn_t v8_avg_;
44 convolve_fn_t hv8_avg_;
45};
46
Joshua Litt51490e52013-11-18 17:07:55 -080047typedef std::tr1::tuple<int, int, const ConvolveFunctions*> convolve_param_t;
48
John Koleszar5ca6a362013-01-25 09:47:09 -080049// Reference 8-tap subpixel filter, slightly modified to fit into this test.
50#define VP9_FILTER_WEIGHT 128
51#define VP9_FILTER_SHIFT 7
James Zern8fb48af2013-05-02 13:08:19 -070052uint8_t clip_pixel(int x) {
John Koleszar5ca6a362013-01-25 09:47:09 -080053 return x < 0 ? 0 :
54 x > 255 ? 255 :
55 x;
56}
57
James Zern8fb48af2013-05-02 13:08:19 -070058void filter_block2d_8_c(const uint8_t *src_ptr,
59 const unsigned int src_stride,
60 const int16_t *HFilter,
61 const int16_t *VFilter,
62 uint8_t *dst_ptr,
63 unsigned int dst_stride,
64 unsigned int output_width,
65 unsigned int output_height) {
John Koleszar5ca6a362013-01-25 09:47:09 -080066 // Between passes, we use an intermediate buffer whose height is extended to
67 // have enough horizontally filtered values as input for the vertical pass.
68 // This buffer is allocated to be big enough for the largest block type we
69 // support.
70 const int kInterp_Extend = 4;
71 const unsigned int intermediate_height =
James Zern8fb48af2013-05-02 13:08:19 -070072 (kInterp_Extend - 1) + output_height + kInterp_Extend;
John Koleszar5ca6a362013-01-25 09:47:09 -080073
74 /* Size of intermediate_buffer is max_intermediate_height * filter_max_width,
75 * where max_intermediate_height = (kInterp_Extend - 1) + filter_max_height
76 * + kInterp_Extend
77 * = 3 + 16 + 4
78 * = 23
79 * and filter_max_width = 16
80 */
John Koleszara9ebbcc2013-04-18 13:05:38 -070081 uint8_t intermediate_buffer[71 * 64];
John Koleszar5ca6a362013-01-25 09:47:09 -080082 const int intermediate_next_stride = 1 - intermediate_height * output_width;
83
84 // Horizontal pass (src -> transposed intermediate).
85 {
86 uint8_t *output_ptr = intermediate_buffer;
87 const int src_next_row_stride = src_stride - output_width;
88 unsigned int i, j;
89 src_ptr -= (kInterp_Extend - 1) * src_stride + (kInterp_Extend - 1);
90 for (i = 0; i < intermediate_height; ++i) {
91 for (j = 0; j < output_width; ++j) {
92 // Apply filter...
James Zern8fb48af2013-05-02 13:08:19 -070093 const int temp = (src_ptr[0] * HFilter[0]) +
94 (src_ptr[1] * HFilter[1]) +
95 (src_ptr[2] * HFilter[2]) +
96 (src_ptr[3] * HFilter[3]) +
97 (src_ptr[4] * HFilter[4]) +
98 (src_ptr[5] * HFilter[5]) +
99 (src_ptr[6] * HFilter[6]) +
100 (src_ptr[7] * HFilter[7]) +
101 (VP9_FILTER_WEIGHT >> 1); // Rounding
John Koleszar5ca6a362013-01-25 09:47:09 -0800102
103 // Normalize back to 0-255...
104 *output_ptr = clip_pixel(temp >> VP9_FILTER_SHIFT);
105 ++src_ptr;
106 output_ptr += intermediate_height;
107 }
108 src_ptr += src_next_row_stride;
109 output_ptr += intermediate_next_stride;
110 }
111 }
112
113 // Vertical pass (transposed intermediate -> dst).
114 {
115 uint8_t *src_ptr = intermediate_buffer;
116 const int dst_next_row_stride = dst_stride - output_width;
117 unsigned int i, j;
118 for (i = 0; i < output_height; ++i) {
119 for (j = 0; j < output_width; ++j) {
120 // Apply filter...
James Zern8fb48af2013-05-02 13:08:19 -0700121 const int temp = (src_ptr[0] * VFilter[0]) +
122 (src_ptr[1] * VFilter[1]) +
123 (src_ptr[2] * VFilter[2]) +
124 (src_ptr[3] * VFilter[3]) +
125 (src_ptr[4] * VFilter[4]) +
126 (src_ptr[5] * VFilter[5]) +
127 (src_ptr[6] * VFilter[6]) +
128 (src_ptr[7] * VFilter[7]) +
129 (VP9_FILTER_WEIGHT >> 1); // Rounding
John Koleszar5ca6a362013-01-25 09:47:09 -0800130
131 // Normalize back to 0-255...
132 *dst_ptr++ = clip_pixel(temp >> VP9_FILTER_SHIFT);
133 src_ptr += intermediate_height;
134 }
135 src_ptr += intermediate_next_stride;
136 dst_ptr += dst_next_row_stride;
137 }
138 }
139}
140
James Zern8fb48af2013-05-02 13:08:19 -0700141void block2d_average_c(uint8_t *src,
142 unsigned int src_stride,
143 uint8_t *output_ptr,
144 unsigned int output_stride,
145 unsigned int output_width,
146 unsigned int output_height) {
John Koleszar5ca6a362013-01-25 09:47:09 -0800147 unsigned int i, j;
148 for (i = 0; i < output_height; ++i) {
149 for (j = 0; j < output_width; ++j) {
150 output_ptr[j] = (output_ptr[j] + src[i * src_stride + j] + 1) >> 1;
151 }
152 output_ptr += output_stride;
153 }
154}
155
James Zern8fb48af2013-05-02 13:08:19 -0700156void filter_average_block2d_8_c(const uint8_t *src_ptr,
157 const unsigned int src_stride,
158 const int16_t *HFilter,
159 const int16_t *VFilter,
160 uint8_t *dst_ptr,
161 unsigned int dst_stride,
162 unsigned int output_width,
163 unsigned int output_height) {
164 uint8_t tmp[64 * 64];
John Koleszar5ca6a362013-01-25 09:47:09 -0800165
John Koleszara9ebbcc2013-04-18 13:05:38 -0700166 assert(output_width <= 64);
167 assert(output_height <= 64);
168 filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp, 64,
John Koleszar5ca6a362013-01-25 09:47:09 -0800169 output_width, output_height);
John Koleszara9ebbcc2013-04-18 13:05:38 -0700170 block2d_average_c(tmp, 64, dst_ptr, dst_stride,
John Koleszar5ca6a362013-01-25 09:47:09 -0800171 output_width, output_height);
172}
173
Joshua Litt51490e52013-11-18 17:07:55 -0800174class ConvolveTest : public ::testing::TestWithParam<convolve_param_t> {
John Koleszar29d47ac2013-02-07 17:00:37 -0800175 public:
176 static void SetUpTestCase() {
177 // Force input_ to be unaligned, output to be 16 byte aligned.
178 input_ = reinterpret_cast<uint8_t*>(
James Zernb0e57752013-05-02 12:29:34 -0700179 vpx_memalign(kDataAlignment, kInputBufferSize + 1)) + 1;
John Koleszar29d47ac2013-02-07 17:00:37 -0800180 output_ = reinterpret_cast<uint8_t*>(
James Zernb0e57752013-05-02 12:29:34 -0700181 vpx_memalign(kDataAlignment, kOutputBufferSize));
John Koleszar29d47ac2013-02-07 17:00:37 -0800182 }
183
184 static void TearDownTestCase() {
185 vpx_free(input_ - 1);
186 input_ = NULL;
187 vpx_free(output_);
188 output_ = NULL;
189 }
190
James Zern8fb48af2013-05-02 13:08:19 -0700191 protected:
192 static const int kDataAlignment = 16;
Tero Rintaluomae326cec2013-08-22 11:29:19 +0300193 static const int kOuterBlockSize = 256;
James Zern8fb48af2013-05-02 13:08:19 -0700194 static const int kInputStride = kOuterBlockSize;
195 static const int kOutputStride = kOuterBlockSize;
196 static const int kMaxDimension = 64;
197 static const int kInputBufferSize = kOuterBlockSize * kOuterBlockSize;
198 static const int kOutputBufferSize = kOuterBlockSize * kOuterBlockSize;
John Koleszar5ca6a362013-01-25 09:47:09 -0800199
James Zern8fb48af2013-05-02 13:08:19 -0700200 int Width() const { return GET_PARAM(0); }
201 int Height() const { return GET_PARAM(1); }
202 int BorderLeft() const {
203 const int center = (kOuterBlockSize - Width()) / 2;
204 return (center + (kDataAlignment - 1)) & ~(kDataAlignment - 1);
205 }
206 int BorderTop() const { return (kOuterBlockSize - Height()) / 2; }
John Koleszar5ca6a362013-01-25 09:47:09 -0800207
James Zern8fb48af2013-05-02 13:08:19 -0700208 bool IsIndexInBorder(int i) {
209 return (i < BorderTop() * kOuterBlockSize ||
210 i >= (BorderTop() + Height()) * kOuterBlockSize ||
211 i % kOuterBlockSize < BorderLeft() ||
212 i % kOuterBlockSize >= (BorderLeft() + Width()));
213 }
214
215 virtual void SetUp() {
216 UUT_ = GET_PARAM(2);
Johann158c80c2013-05-23 12:50:41 -0700217 /* Set up guard blocks for an inner block centered in the outer block */
James Zern8fb48af2013-05-02 13:08:19 -0700218 for (int i = 0; i < kOutputBufferSize; ++i) {
219 if (IsIndexInBorder(i))
220 output_[i] = 255;
221 else
222 output_[i] = 0;
John Koleszar5ca6a362013-01-25 09:47:09 -0800223 }
224
James Zern8fb48af2013-05-02 13:08:19 -0700225 ::libvpx_test::ACMRandom prng;
226 for (int i = 0; i < kInputBufferSize; ++i)
227 input_[i] = prng.Rand8Extremes();
228 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800229
Tero Rintaluomae326cec2013-08-22 11:29:19 +0300230 void SetConstantInput(int value) {
231 memset(input_, value, kInputBufferSize);
232 }
233
James Zern8fb48af2013-05-02 13:08:19 -0700234 void CheckGuardBlocks() {
235 for (int i = 0; i < kOutputBufferSize; ++i) {
236 if (IsIndexInBorder(i))
237 EXPECT_EQ(255, output_[i]);
John Koleszar5ca6a362013-01-25 09:47:09 -0800238 }
James Zern8fb48af2013-05-02 13:08:19 -0700239 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800240
James Zern8fb48af2013-05-02 13:08:19 -0700241 uint8_t* input() const {
242 return input_ + BorderTop() * kOuterBlockSize + BorderLeft();
243 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800244
James Zern8fb48af2013-05-02 13:08:19 -0700245 uint8_t* output() const {
246 return output_ + BorderTop() * kOuterBlockSize + BorderLeft();
247 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800248
James Zern8fb48af2013-05-02 13:08:19 -0700249 const ConvolveFunctions* UUT_;
250 static uint8_t* input_;
251 static uint8_t* output_;
John Koleszar5ca6a362013-01-25 09:47:09 -0800252};
John Koleszar29d47ac2013-02-07 17:00:37 -0800253uint8_t* ConvolveTest::input_ = NULL;
254uint8_t* ConvolveTest::output_ = NULL;
John Koleszar5ca6a362013-01-25 09:47:09 -0800255
256TEST_P(ConvolveTest, GuardBlocks) {
257 CheckGuardBlocks();
258}
259
260TEST_P(ConvolveTest, CopyHoriz) {
261 uint8_t* const in = input();
262 uint8_t* const out = output();
James Zerne7b599f2013-06-17 23:11:01 -0700263 DECLARE_ALIGNED(256, const int16_t, filter8[8]) = {0, 0, 0, 128, 0, 0, 0, 0};
John Koleszar5ca6a362013-01-25 09:47:09 -0800264
265 REGISTER_STATE_CHECK(
266 UUT_->h8_(in, kInputStride, out, kOutputStride, filter8, 16, filter8, 16,
267 Width(), Height()));
268
269 CheckGuardBlocks();
270
271 for (int y = 0; y < Height(); ++y)
272 for (int x = 0; x < Width(); ++x)
273 ASSERT_EQ(out[y * kOutputStride + x], in[y * kInputStride + x])
274 << "(" << x << "," << y << ")";
275}
276
277TEST_P(ConvolveTest, CopyVert) {
278 uint8_t* const in = input();
279 uint8_t* const out = output();
James Zerne7b599f2013-06-17 23:11:01 -0700280 DECLARE_ALIGNED(256, const int16_t, filter8[8]) = {0, 0, 0, 128, 0, 0, 0, 0};
John Koleszar5ca6a362013-01-25 09:47:09 -0800281
282 REGISTER_STATE_CHECK(
283 UUT_->v8_(in, kInputStride, out, kOutputStride, filter8, 16, filter8, 16,
284 Width(), Height()));
285
286 CheckGuardBlocks();
287
288 for (int y = 0; y < Height(); ++y)
289 for (int x = 0; x < Width(); ++x)
290 ASSERT_EQ(out[y * kOutputStride + x], in[y * kInputStride + x])
291 << "(" << x << "," << y << ")";
292}
293
294TEST_P(ConvolveTest, Copy2D) {
295 uint8_t* const in = input();
296 uint8_t* const out = output();
James Zerne7b599f2013-06-17 23:11:01 -0700297 DECLARE_ALIGNED(256, const int16_t, filter8[8]) = {0, 0, 0, 128, 0, 0, 0, 0};
John Koleszar5ca6a362013-01-25 09:47:09 -0800298
299 REGISTER_STATE_CHECK(
300 UUT_->hv8_(in, kInputStride, out, kOutputStride, filter8, 16, filter8, 16,
301 Width(), Height()));
302
303 CheckGuardBlocks();
304
305 for (int y = 0; y < Height(); ++y)
306 for (int x = 0; x < Width(); ++x)
307 ASSERT_EQ(out[y * kOutputStride + x], in[y * kInputStride + x])
308 << "(" << x << "," << y << ")";
309}
310
John Koleszar557a1b22013-02-20 16:13:01 -0800311const int16_t (*kTestFilterList[])[8] = {
312 vp9_bilinear_filters,
John Koleszar557a1b22013-02-20 16:13:01 -0800313 vp9_sub_pel_filters_8,
314 vp9_sub_pel_filters_8s,
315 vp9_sub_pel_filters_8lp
316};
John Koleszara9ebbcc2013-04-18 13:05:38 -0700317const int kNumFilterBanks = sizeof(kTestFilterList) /
James Zern8fb48af2013-05-02 13:08:19 -0700318 sizeof(kTestFilterList[0]);
John Koleszara9ebbcc2013-04-18 13:05:38 -0700319const int kNumFilters = 16;
320
321TEST(ConvolveTest, FiltersWontSaturateWhenAddedPairwise) {
322 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
323 const int16_t (*filters)[8] = kTestFilterList[filter_bank];
324 for (int i = 0; i < kNumFilters; i++) {
325 const int p0 = filters[i][0] + filters[i][1];
326 const int p1 = filters[i][2] + filters[i][3];
327 const int p2 = filters[i][4] + filters[i][5];
328 const int p3 = filters[i][6] + filters[i][7];
329 EXPECT_LE(p0, 128);
330 EXPECT_LE(p1, 128);
331 EXPECT_LE(p2, 128);
332 EXPECT_LE(p3, 128);
333 EXPECT_LE(p0 + p3, 128);
334 EXPECT_LE(p0 + p3 + p1, 128);
335 EXPECT_LE(p0 + p3 + p1 + p2, 128);
336 EXPECT_EQ(p0 + p1 + p2 + p3, 128);
337 }
338 }
339}
John Koleszar557a1b22013-02-20 16:13:01 -0800340
John Koleszar04c24072013-02-20 16:32:02 -0800341const int16_t kInvalidFilter[8] = { 0 };
342
John Koleszar5ca6a362013-01-25 09:47:09 -0800343TEST_P(ConvolveTest, MatchesReferenceSubpixelFilter) {
344 uint8_t* const in = input();
345 uint8_t* const out = output();
346 uint8_t ref[kOutputStride * kMaxDimension];
347
John Koleszar5ca6a362013-01-25 09:47:09 -0800348
John Koleszar557a1b22013-02-20 16:13:01 -0800349 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
350 const int16_t (*filters)[8] = kTestFilterList[filter_bank];
John Koleszar5ca6a362013-01-25 09:47:09 -0800351
John Koleszar557a1b22013-02-20 16:13:01 -0800352 for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
353 for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
354 filter_block2d_8_c(in, kInputStride,
355 filters[filter_x], filters[filter_y],
356 ref, kOutputStride,
357 Width(), Height());
John Koleszar5ca6a362013-01-25 09:47:09 -0800358
John Koleszar557a1b22013-02-20 16:13:01 -0800359 if (filters == vp9_sub_pel_filters_8lp || (filter_x && filter_y))
360 REGISTER_STATE_CHECK(
361 UUT_->hv8_(in, kInputStride, out, kOutputStride,
362 filters[filter_x], 16, filters[filter_y], 16,
363 Width(), Height()));
364 else if (filter_y)
365 REGISTER_STATE_CHECK(
366 UUT_->v8_(in, kInputStride, out, kOutputStride,
John Koleszar04c24072013-02-20 16:32:02 -0800367 kInvalidFilter, 16, filters[filter_y], 16,
John Koleszar557a1b22013-02-20 16:13:01 -0800368 Width(), Height()));
369 else
370 REGISTER_STATE_CHECK(
371 UUT_->h8_(in, kInputStride, out, kOutputStride,
John Koleszar04c24072013-02-20 16:32:02 -0800372 filters[filter_x], 16, kInvalidFilter, 16,
John Koleszar557a1b22013-02-20 16:13:01 -0800373 Width(), Height()));
John Koleszar5ca6a362013-01-25 09:47:09 -0800374
John Koleszar557a1b22013-02-20 16:13:01 -0800375 CheckGuardBlocks();
John Koleszar5ca6a362013-01-25 09:47:09 -0800376
John Koleszar557a1b22013-02-20 16:13:01 -0800377 for (int y = 0; y < Height(); ++y)
378 for (int x = 0; x < Width(); ++x)
379 ASSERT_EQ(ref[y * kOutputStride + x], out[y * kOutputStride + x])
380 << "mismatch at (" << x << "," << y << "), "
381 << "filters (" << filter_bank << ","
382 << filter_x << "," << filter_y << ")";
383 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800384 }
385 }
386}
387
388TEST_P(ConvolveTest, MatchesReferenceAveragingSubpixelFilter) {
389 uint8_t* const in = input();
390 uint8_t* const out = output();
391 uint8_t ref[kOutputStride * kMaxDimension];
392
393 // Populate ref and out with some random data
394 ::libvpx_test::ACMRandom prng;
395 for (int y = 0; y < Height(); ++y) {
396 for (int x = 0; x < Width(); ++x) {
John Koleszara9ebbcc2013-04-18 13:05:38 -0700397 const uint8_t r = prng.Rand8Extremes();
John Koleszar5ca6a362013-01-25 09:47:09 -0800398
399 out[y * kOutputStride + x] = r;
400 ref[y * kOutputStride + x] = r;
401 }
402 }
403
John Koleszar557a1b22013-02-20 16:13:01 -0800404 const int kNumFilterBanks = sizeof(kTestFilterList) /
405 sizeof(kTestFilterList[0]);
John Koleszar5ca6a362013-01-25 09:47:09 -0800406
John Koleszar557a1b22013-02-20 16:13:01 -0800407 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
408 const int16_t (*filters)[8] = kTestFilterList[filter_bank];
409 const int kNumFilters = 16;
John Koleszar5ca6a362013-01-25 09:47:09 -0800410
John Koleszar557a1b22013-02-20 16:13:01 -0800411 for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
412 for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
413 filter_average_block2d_8_c(in, kInputStride,
414 filters[filter_x], filters[filter_y],
415 ref, kOutputStride,
416 Width(), Height());
John Koleszar5ca6a362013-01-25 09:47:09 -0800417
John Koleszar557a1b22013-02-20 16:13:01 -0800418 if (filters == vp9_sub_pel_filters_8lp || (filter_x && filter_y))
419 REGISTER_STATE_CHECK(
420 UUT_->hv8_avg_(in, kInputStride, out, kOutputStride,
421 filters[filter_x], 16, filters[filter_y], 16,
422 Width(), Height()));
423 else if (filter_y)
424 REGISTER_STATE_CHECK(
425 UUT_->v8_avg_(in, kInputStride, out, kOutputStride,
426 filters[filter_x], 16, filters[filter_y], 16,
427 Width(), Height()));
428 else
429 REGISTER_STATE_CHECK(
430 UUT_->h8_avg_(in, kInputStride, out, kOutputStride,
431 filters[filter_x], 16, filters[filter_y], 16,
432 Width(), Height()));
John Koleszar5ca6a362013-01-25 09:47:09 -0800433
John Koleszar557a1b22013-02-20 16:13:01 -0800434 CheckGuardBlocks();
John Koleszar5ca6a362013-01-25 09:47:09 -0800435
John Koleszar557a1b22013-02-20 16:13:01 -0800436 for (int y = 0; y < Height(); ++y)
437 for (int x = 0; x < Width(); ++x)
438 ASSERT_EQ(ref[y * kOutputStride + x], out[y * kOutputStride + x])
439 << "mismatch at (" << x << "," << y << "), "
440 << "filters (" << filter_bank << ","
441 << filter_x << "," << filter_y << ")";
442 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800443 }
444 }
445}
446
John Koleszar6fd7dd12013-02-20 15:59:20 -0800447DECLARE_ALIGNED(256, const int16_t, kChangeFilters[16][8]) = {
448 { 0, 0, 0, 0, 0, 0, 0, 128},
449 { 0, 0, 0, 0, 0, 0, 128},
450 { 0, 0, 0, 0, 0, 128},
451 { 0, 0, 0, 0, 128},
452 { 0, 0, 0, 128},
453 { 0, 0, 128},
454 { 0, 128},
455 { 128},
456 { 0, 0, 0, 0, 0, 0, 0, 128},
457 { 0, 0, 0, 0, 0, 0, 128},
458 { 0, 0, 0, 0, 0, 128},
459 { 0, 0, 0, 0, 128},
460 { 0, 0, 0, 128},
461 { 0, 0, 128},
462 { 0, 128},
463 { 128}
464};
465
Adrian Grange3f108312013-08-22 16:02:18 -0700466/* This test exercises the horizontal and vertical filter functions. */
John Koleszar5ca6a362013-01-25 09:47:09 -0800467TEST_P(ConvolveTest, ChangeFilterWorks) {
468 uint8_t* const in = input();
469 uint8_t* const out = output();
Adrian Grange3f108312013-08-22 16:02:18 -0700470
471 /* Assume that the first input sample is at the 8/16th position. */
472 const int kInitialSubPelOffset = 8;
473
474 /* Filters are 8-tap, so the first filter tap will be applied to the pixel
475 * at position -3 with respect to the current filtering position. Since
476 * kInitialSubPelOffset is set to 8, we first select sub-pixel filter 8,
477 * which is non-zero only in the last tap. So, applying the filter at the
478 * current input position will result in an output equal to the pixel at
479 * offset +4 (-3 + 7) with respect to the current filtering position.
480 */
John Koleszara9ebbcc2013-04-18 13:05:38 -0700481 const int kPixelSelected = 4;
John Koleszar5ca6a362013-01-25 09:47:09 -0800482
Adrian Grange3f108312013-08-22 16:02:18 -0700483 /* Assume that each output pixel requires us to step on by 17/16th pixels in
484 * the input.
485 */
486 const int kInputPixelStep = 17;
487
488 /* The filters are setup in such a way that the expected output produces
489 * sets of 8 identical output samples. As the filter position moves to the
490 * next 1/16th pixel position the only active (=128) filter tap moves one
491 * position to the left, resulting in the same input pixel being replicated
492 * in to the output for 8 consecutive samples. After each set of 8 positions
493 * the filters select a different input pixel. kFilterPeriodAdjust below
494 * computes which input pixel is written to the output for a specified
495 * x or y position.
496 */
497
498 /* Test the horizontal filter. */
John Koleszar5ca6a362013-01-25 09:47:09 -0800499 REGISTER_STATE_CHECK(UUT_->h8_(in, kInputStride, out, kOutputStride,
Adrian Grange3f108312013-08-22 16:02:18 -0700500 kChangeFilters[kInitialSubPelOffset],
501 kInputPixelStep, NULL, 0, Width(), Height()));
John Koleszar5ca6a362013-01-25 09:47:09 -0800502
John Koleszar6fd7dd12013-02-20 15:59:20 -0800503 for (int x = 0; x < Width(); ++x) {
John Koleszara9ebbcc2013-04-18 13:05:38 -0700504 const int kFilterPeriodAdjust = (x >> 3) << 3;
Adrian Grange3f108312013-08-22 16:02:18 -0700505 const int ref_x =
506 kPixelSelected + ((kInitialSubPelOffset
507 + kFilterPeriodAdjust * kInputPixelStep)
508 >> SUBPEL_BITS);
509 ASSERT_EQ(in[ref_x], out[x]) << "x == " << x << "width = " << Width();
John Koleszar5ca6a362013-01-25 09:47:09 -0800510 }
511
Adrian Grange3f108312013-08-22 16:02:18 -0700512 /* Test the vertical filter. */
John Koleszar5ca6a362013-01-25 09:47:09 -0800513 REGISTER_STATE_CHECK(UUT_->v8_(in, kInputStride, out, kOutputStride,
Adrian Grange3f108312013-08-22 16:02:18 -0700514 NULL, 0, kChangeFilters[kInitialSubPelOffset],
515 kInputPixelStep, Width(), Height()));
John Koleszar5ca6a362013-01-25 09:47:09 -0800516
John Koleszar6fd7dd12013-02-20 15:59:20 -0800517 for (int y = 0; y < Height(); ++y) {
John Koleszara9ebbcc2013-04-18 13:05:38 -0700518 const int kFilterPeriodAdjust = (y >> 3) << 3;
Adrian Grange3f108312013-08-22 16:02:18 -0700519 const int ref_y =
520 kPixelSelected + ((kInitialSubPelOffset
521 + kFilterPeriodAdjust * kInputPixelStep)
522 >> SUBPEL_BITS);
John Koleszara9ebbcc2013-04-18 13:05:38 -0700523 ASSERT_EQ(in[ref_y * kInputStride], out[y * kInputStride]) << "y == " << y;
John Koleszar5ca6a362013-01-25 09:47:09 -0800524 }
525
Adrian Grange3f108312013-08-22 16:02:18 -0700526 /* Test the horizontal and vertical filters in combination. */
John Koleszar5ca6a362013-01-25 09:47:09 -0800527 REGISTER_STATE_CHECK(UUT_->hv8_(in, kInputStride, out, kOutputStride,
Adrian Grange3f108312013-08-22 16:02:18 -0700528 kChangeFilters[kInitialSubPelOffset],
529 kInputPixelStep,
530 kChangeFilters[kInitialSubPelOffset],
531 kInputPixelStep,
John Koleszar5ca6a362013-01-25 09:47:09 -0800532 Width(), Height()));
533
John Koleszar6fd7dd12013-02-20 15:59:20 -0800534 for (int y = 0; y < Height(); ++y) {
John Koleszara9ebbcc2013-04-18 13:05:38 -0700535 const int kFilterPeriodAdjustY = (y >> 3) << 3;
Adrian Grange3f108312013-08-22 16:02:18 -0700536 const int ref_y =
537 kPixelSelected + ((kInitialSubPelOffset
538 + kFilterPeriodAdjustY * kInputPixelStep)
539 >> SUBPEL_BITS);
John Koleszar6fd7dd12013-02-20 15:59:20 -0800540 for (int x = 0; x < Width(); ++x) {
John Koleszara9ebbcc2013-04-18 13:05:38 -0700541 const int kFilterPeriodAdjustX = (x >> 3) << 3;
Adrian Grange3f108312013-08-22 16:02:18 -0700542 const int ref_x =
543 kPixelSelected + ((kInitialSubPelOffset
544 + kFilterPeriodAdjustX * kInputPixelStep)
545 >> SUBPEL_BITS);
John Koleszar6fd7dd12013-02-20 15:59:20 -0800546
547 ASSERT_EQ(in[ref_y * kInputStride + ref_x], out[y * kOutputStride + x])
John Koleszar5ca6a362013-01-25 09:47:09 -0800548 << "x == " << x << ", y == " << y;
549 }
550 }
551}
552
Tero Rintaluomae326cec2013-08-22 11:29:19 +0300553/* This test exercises that enough rows and columns are filtered with every
554 possible initial fractional positions and scaling steps. */
555TEST_P(ConvolveTest, CheckScalingFiltering) {
556 uint8_t* const in = input();
557 uint8_t* const out = output();
558
559 SetConstantInput(127);
560
561 for (int frac = 0; frac < 16; ++frac) {
562 for (int step = 1; step <= 32; ++step) {
563 /* Test the horizontal and vertical filters in combination. */
564 REGISTER_STATE_CHECK(UUT_->hv8_(in, kInputStride, out, kOutputStride,
565 vp9_sub_pel_filters_8[frac], step,
566 vp9_sub_pel_filters_8[frac], step,
567 Width(), Height()));
568
569 CheckGuardBlocks();
570
571 for (int y = 0; y < Height(); ++y) {
572 for (int x = 0; x < Width(); ++x) {
573 ASSERT_EQ(in[y * kInputStride + x], out[y * kOutputStride + x])
574 << "x == " << x << ", y == " << y
575 << ", frac == " << frac << ", step == " << step;
576 }
577 }
578 }
579 }
580}
581
John Koleszar5ca6a362013-01-25 09:47:09 -0800582using std::tr1::make_tuple;
583
John Koleszar5ca6a362013-01-25 09:47:09 -0800584const ConvolveFunctions convolve8_c(
585 vp9_convolve8_horiz_c, vp9_convolve8_avg_horiz_c,
586 vp9_convolve8_vert_c, vp9_convolve8_avg_vert_c,
587 vp9_convolve8_c, vp9_convolve8_avg_c);
588
589INSTANTIATE_TEST_CASE_P(C, ConvolveTest, ::testing::Values(
John Koleszar5ca6a362013-01-25 09:47:09 -0800590 make_tuple(4, 4, &convolve8_c),
591 make_tuple(8, 4, &convolve8_c),
John Koleszara9ebbcc2013-04-18 13:05:38 -0700592 make_tuple(4, 8, &convolve8_c),
John Koleszar5ca6a362013-01-25 09:47:09 -0800593 make_tuple(8, 8, &convolve8_c),
John Koleszar6a4f7082013-02-08 17:49:44 -0800594 make_tuple(16, 8, &convolve8_c),
John Koleszara9ebbcc2013-04-18 13:05:38 -0700595 make_tuple(8, 16, &convolve8_c),
596 make_tuple(16, 16, &convolve8_c),
597 make_tuple(32, 16, &convolve8_c),
598 make_tuple(16, 32, &convolve8_c),
599 make_tuple(32, 32, &convolve8_c),
600 make_tuple(64, 32, &convolve8_c),
601 make_tuple(32, 64, &convolve8_c),
602 make_tuple(64, 64, &convolve8_c)));
John Koleszar29d47ac2013-02-07 17:00:37 -0800603
Yunqing Wang3fb728c2013-10-10 13:51:35 -0700604#if HAVE_SSE2
605const ConvolveFunctions convolve8_sse2(
606 vp9_convolve8_horiz_sse2, vp9_convolve8_avg_horiz_sse2,
607 vp9_convolve8_vert_sse2, vp9_convolve8_avg_vert_sse2,
608 vp9_convolve8_sse2, vp9_convolve8_avg_sse2);
609
610INSTANTIATE_TEST_CASE_P(SSE2, ConvolveTest, ::testing::Values(
611 make_tuple(4, 4, &convolve8_sse2),
612 make_tuple(8, 4, &convolve8_sse2),
613 make_tuple(4, 8, &convolve8_sse2),
614 make_tuple(8, 8, &convolve8_sse2),
615 make_tuple(16, 8, &convolve8_sse2),
616 make_tuple(8, 16, &convolve8_sse2),
617 make_tuple(16, 16, &convolve8_sse2),
618 make_tuple(32, 16, &convolve8_sse2),
619 make_tuple(16, 32, &convolve8_sse2),
620 make_tuple(32, 32, &convolve8_sse2),
621 make_tuple(64, 32, &convolve8_sse2),
622 make_tuple(32, 64, &convolve8_sse2),
623 make_tuple(64, 64, &convolve8_sse2)));
624#endif
625
John Koleszar29d47ac2013-02-07 17:00:37 -0800626#if HAVE_SSSE3
627const ConvolveFunctions convolve8_ssse3(
Jim Bankoskic3809f32013-08-05 12:07:30 -0700628 vp9_convolve8_horiz_ssse3, vp9_convolve8_avg_horiz_ssse3,
629 vp9_convolve8_vert_ssse3, vp9_convolve8_avg_vert_ssse3,
630 vp9_convolve8_ssse3, vp9_convolve8_avg_ssse3);
John Koleszar29d47ac2013-02-07 17:00:37 -0800631
632INSTANTIATE_TEST_CASE_P(SSSE3, ConvolveTest, ::testing::Values(
633 make_tuple(4, 4, &convolve8_ssse3),
634 make_tuple(8, 4, &convolve8_ssse3),
John Koleszara9ebbcc2013-04-18 13:05:38 -0700635 make_tuple(4, 8, &convolve8_ssse3),
John Koleszar29d47ac2013-02-07 17:00:37 -0800636 make_tuple(8, 8, &convolve8_ssse3),
John Koleszar6a4f7082013-02-08 17:49:44 -0800637 make_tuple(16, 8, &convolve8_ssse3),
John Koleszara9ebbcc2013-04-18 13:05:38 -0700638 make_tuple(8, 16, &convolve8_ssse3),
639 make_tuple(16, 16, &convolve8_ssse3),
640 make_tuple(32, 16, &convolve8_ssse3),
641 make_tuple(16, 32, &convolve8_ssse3),
642 make_tuple(32, 32, &convolve8_ssse3),
643 make_tuple(64, 32, &convolve8_ssse3),
644 make_tuple(32, 64, &convolve8_ssse3),
645 make_tuple(64, 64, &convolve8_ssse3)));
John Koleszar29d47ac2013-02-07 17:00:37 -0800646#endif
Johann158c80c2013-05-23 12:50:41 -0700647
648#if HAVE_NEON
649const ConvolveFunctions convolve8_neon(
Johanna15bebf2013-07-12 16:12:58 -0700650 vp9_convolve8_horiz_neon, vp9_convolve8_avg_horiz_neon,
651 vp9_convolve8_vert_neon, vp9_convolve8_avg_vert_neon,
Johann59dc4e92013-07-16 10:13:06 -0700652 vp9_convolve8_neon, vp9_convolve8_avg_neon);
Johann158c80c2013-05-23 12:50:41 -0700653
654INSTANTIATE_TEST_CASE_P(NEON, ConvolveTest, ::testing::Values(
655 make_tuple(4, 4, &convolve8_neon),
656 make_tuple(8, 4, &convolve8_neon),
657 make_tuple(4, 8, &convolve8_neon),
658 make_tuple(8, 8, &convolve8_neon),
659 make_tuple(16, 8, &convolve8_neon),
660 make_tuple(8, 16, &convolve8_neon),
661 make_tuple(16, 16, &convolve8_neon),
662 make_tuple(32, 16, &convolve8_neon),
663 make_tuple(16, 32, &convolve8_neon),
664 make_tuple(32, 32, &convolve8_neon),
665 make_tuple(64, 32, &convolve8_neon),
666 make_tuple(32, 64, &convolve8_neon),
667 make_tuple(64, 64, &convolve8_neon)));
668#endif
Parag Salasakar40edab52013-09-13 15:18:32 +0530669
670#if HAVE_DSPR2
671const ConvolveFunctions convolve8_dspr2(
672 vp9_convolve8_horiz_dspr2, vp9_convolve8_avg_horiz_dspr2,
673 vp9_convolve8_vert_dspr2, vp9_convolve8_avg_vert_dspr2,
674 vp9_convolve8_dspr2, vp9_convolve8_avg_dspr2);
675
676INSTANTIATE_TEST_CASE_P(DSPR2, ConvolveTest, ::testing::Values(
677 make_tuple(4, 4, &convolve8_dspr2),
678 make_tuple(8, 4, &convolve8_dspr2),
679 make_tuple(4, 8, &convolve8_dspr2),
680 make_tuple(8, 8, &convolve8_dspr2),
681 make_tuple(16, 8, &convolve8_dspr2),
682 make_tuple(8, 16, &convolve8_dspr2),
683 make_tuple(16, 16, &convolve8_dspr2),
684 make_tuple(32, 16, &convolve8_dspr2),
685 make_tuple(16, 32, &convolve8_dspr2),
686 make_tuple(32, 32, &convolve8_dspr2),
687 make_tuple(64, 32, &convolve8_dspr2),
688 make_tuple(32, 64, &convolve8_dspr2),
689 make_tuple(64, 64, &convolve8_dspr2)));
690#endif
James Zern8fb48af2013-05-02 13:08:19 -0700691} // namespace