vp9_subtract_test.cc revision 91037db265ecdd914a26e056cf69207b4f50924e
1/*
2 *  Copyright (c) 2012 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 "third_party/googletest/src/include/gtest/gtest.h"
12#include "test/acm_random.h"
13#include "test/clear_system_state.h"
14#include "test/register_state_check.h"
15extern "C" {
16#include "./vpx_config.h"
17#include "./vp9_rtcd.h"
18#include "vp9/common/vp9_blockd.h"
19#include "vpx_mem/vpx_mem.h"
20}
21
22typedef void (*subtract_fn_t)(int rows, int cols,
23                              int16_t *diff_ptr, ptrdiff_t diff_stride,
24                              const uint8_t *src_ptr, ptrdiff_t src_stride,
25                              const uint8_t *pred_ptr, ptrdiff_t pred_stride);
26
27namespace vp9 {
28
29class VP9SubtractBlockTest : public ::testing::TestWithParam<subtract_fn_t> {
30 public:
31  virtual void TearDown() {
32    libvpx_test::ClearSystemState();
33  }
34};
35
36using libvpx_test::ACMRandom;
37
38TEST_P(VP9SubtractBlockTest, SimpleSubtract) {
39  ACMRandom rnd(ACMRandom::DeterministicSeed());
40
41  // FIXME(rbultje) split in its own file
42  for (BLOCK_SIZE_TYPE bsize = BLOCK_SIZE_AB4X4; bsize < BLOCK_SIZE_TYPES;
43       bsize = static_cast<BLOCK_SIZE_TYPE>(static_cast<int>(bsize) + 1)) {
44    const int block_width  = 4 << b_width_log2(bsize);
45    const int block_height = 4 << b_height_log2(bsize);
46    int16_t *diff = reinterpret_cast<int16_t *>(
47        vpx_memalign(16, sizeof(*diff) * block_width * block_height * 2));
48    uint8_t *pred = reinterpret_cast<uint8_t *>(
49        vpx_memalign(16, block_width * block_height * 2));
50    uint8_t *src  = reinterpret_cast<uint8_t *>(
51        vpx_memalign(16, block_width * block_height * 2));
52
53    for (int n = 0; n < 100; n++) {
54      for (int r = 0; r < block_height; ++r) {
55        for (int c = 0; c < block_width * 2; ++c) {
56          src[r * block_width * 2 + c] = rnd.Rand8();
57          pred[r * block_width * 2 + c] = rnd.Rand8();
58        }
59      }
60
61      GetParam()(block_height, block_width, diff, block_width,
62                 src, block_width, pred, block_width);
63
64      for (int r = 0; r < block_height; ++r) {
65        for (int c = 0; c < block_width; ++c) {
66          EXPECT_EQ(diff[r * block_width + c],
67                    (src[r * block_width + c] -
68                     pred[r * block_width + c])) << "r = " << r
69                                                 << ", c = " << c
70                                                 << ", bs = " << bsize;
71        }
72      }
73
74      GetParam()(block_height, block_width, diff, block_width * 2,
75                 src, block_width * 2, pred, block_width * 2);
76
77      for (int r = 0; r < block_height; ++r) {
78        for (int c = 0; c < block_width; ++c) {
79          EXPECT_EQ(diff[r * block_width * 2 + c],
80                    (src[r * block_width * 2 + c] -
81                     pred[r * block_width * 2 + c])) << "r = " << r
82                                                     << ", c = " << c
83                                                     << ", bs = " << bsize;
84        }
85      }
86    }
87    vpx_free(diff);
88    vpx_free(pred);
89    vpx_free(src);
90  }
91}
92
93INSTANTIATE_TEST_CASE_P(C, VP9SubtractBlockTest,
94                        ::testing::Values(vp9_subtract_block_c));
95
96#if HAVE_SSE2
97INSTANTIATE_TEST_CASE_P(SSE2, VP9SubtractBlockTest,
98                        ::testing::Values(vp9_subtract_block_sse2));
99#endif
100
101}  // namespace vp9
102