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.
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"
15 #include "./vpx_config.h"
16 #include "./vp9_rtcd.h"
17 #include "./vpx_dsp_rtcd.h"
18 #include "vp9/common/vp9_blockd.h"
19 #include "vpx_mem/vpx_mem.h"
21 typedef void (*SubtractFunc)(int rows, int cols,
22 int16_t *diff_ptr, ptrdiff_t diff_stride,
23 const uint8_t *src_ptr, ptrdiff_t src_stride,
24 const uint8_t *pred_ptr, ptrdiff_t pred_stride);
28 class VP9SubtractBlockTest : public ::testing::TestWithParam<SubtractFunc> {
30 virtual void TearDown() {
31 libvpx_test::ClearSystemState();
35 using libvpx_test::ACMRandom;
37 TEST_P(VP9SubtractBlockTest, SimpleSubtract) {
38 ACMRandom rnd(ACMRandom::DeterministicSeed());
40 // FIXME(rbultje) split in its own file
41 for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
42 bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
43 const int block_width = 4 * num_4x4_blocks_wide_lookup[bsize];
44 const int block_height = 4 * num_4x4_blocks_high_lookup[bsize];
45 int16_t *diff = reinterpret_cast<int16_t *>(
46 vpx_memalign(16, sizeof(*diff) * block_width * block_height * 2));
47 uint8_t *pred = reinterpret_cast<uint8_t *>(
48 vpx_memalign(16, block_width * block_height * 2));
49 uint8_t *src = reinterpret_cast<uint8_t *>(
50 vpx_memalign(16, block_width * block_height * 2));
52 for (int n = 0; n < 100; n++) {
53 for (int r = 0; r < block_height; ++r) {
54 for (int c = 0; c < block_width * 2; ++c) {
55 src[r * block_width * 2 + c] = rnd.Rand8();
56 pred[r * block_width * 2 + c] = rnd.Rand8();
60 GetParam()(block_height, block_width, diff, block_width,
61 src, block_width, pred, block_width);
63 for (int r = 0; r < block_height; ++r) {
64 for (int c = 0; c < block_width; ++c) {
65 EXPECT_EQ(diff[r * block_width + c],
66 (src[r * block_width + c] -
67 pred[r * block_width + c])) << "r = " << r
69 << ", bs = " << bsize;
73 GetParam()(block_height, block_width, diff, block_width * 2,
74 src, block_width * 2, pred, block_width * 2);
76 for (int r = 0; r < block_height; ++r) {
77 for (int c = 0; c < block_width; ++c) {
78 EXPECT_EQ(diff[r * block_width * 2 + c],
79 (src[r * block_width * 2 + c] -
80 pred[r * block_width * 2 + c])) << "r = " << r
82 << ", bs = " << bsize;
92 INSTANTIATE_TEST_CASE_P(C, VP9SubtractBlockTest,
93 ::testing::Values(vpx_subtract_block_c));
95 #if HAVE_SSE2 && CONFIG_USE_X86INC
96 INSTANTIATE_TEST_CASE_P(SSE2, VP9SubtractBlockTest,
97 ::testing::Values(vpx_subtract_block_sse2));
100 INSTANTIATE_TEST_CASE_P(NEON, VP9SubtractBlockTest,
101 ::testing::Values(vpx_subtract_block_neon));