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