Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libvpx / source / libvpx / test / subtract_test.cc
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"
15 #include "./vpx_config.h"
16 #include "./vp8_rtcd.h"
17 #include "vp8/common/blockd.h"
18 #include "vp8/encoder/block.h"
19 #include "vpx_mem/vpx_mem.h"
20
21 typedef void (*SubtractBlockFunc)(BLOCK *be, BLOCKD *bd, int pitch);
22
23 namespace {
24
25 class SubtractBlockTest : public ::testing::TestWithParam<SubtractBlockFunc> {
26  public:
27   virtual void TearDown() {
28     libvpx_test::ClearSystemState();
29   }
30 };
31
32 using libvpx_test::ACMRandom;
33
34 TEST_P(SubtractBlockTest, SimpleSubtract) {
35   ACMRandom rnd(ACMRandom::DeterministicSeed());
36   BLOCK be;
37   BLOCKD bd;
38   // in libvpx, this stride is always 16
39   const int kDiffPredStride = 16;
40   const int kSrcStride[] = {32, 16, 8, 4, 0};
41   const int kBlockWidth = 4;
42   const int kBlockHeight = 4;
43
44   // Allocate... align to 16 for mmx/sse tests
45   uint8_t *source = reinterpret_cast<uint8_t*>(
46       vpx_memalign(16, kBlockHeight * kSrcStride[0] * sizeof(*source)));
47   be.src_diff = reinterpret_cast<int16_t*>(
48       vpx_memalign(16, kBlockHeight * kDiffPredStride * sizeof(*be.src_diff)));
49   bd.predictor = reinterpret_cast<unsigned char*>(
50       vpx_memalign(16, kBlockHeight * kDiffPredStride * sizeof(*bd.predictor)));
51
52   for (int i = 0; kSrcStride[i] > 0; ++i) {
53     // start at block0
54     be.src = 0;
55     be.base_src = &source;
56     be.src_stride = kSrcStride[i];
57
58     // set difference
59     int16_t *src_diff = be.src_diff;
60     for (int r = 0; r < kBlockHeight; ++r) {
61       for (int c = 0; c < kBlockWidth; ++c) {
62         src_diff[c] = static_cast<int16_t>(0xa5a5u);
63       }
64       src_diff += kDiffPredStride;
65     }
66
67     // set destination
68     uint8_t *base_src = *be.base_src;
69     for (int r = 0; r < kBlockHeight; ++r) {
70       for (int c = 0; c < kBlockWidth; ++c) {
71         base_src[c] = rnd.Rand8();
72       }
73       base_src += be.src_stride;
74     }
75
76     // set predictor
77     uint8_t *predictor = bd.predictor;
78     for (int r = 0; r < kBlockHeight; ++r) {
79       for (int c = 0; c < kBlockWidth; ++c) {
80         predictor[c] = rnd.Rand8();
81       }
82       predictor += kDiffPredStride;
83     }
84
85     ASM_REGISTER_STATE_CHECK(GetParam()(&be, &bd, kDiffPredStride));
86
87     base_src = *be.base_src;
88     src_diff = be.src_diff;
89     predictor = bd.predictor;
90     for (int r = 0; r < kBlockHeight; ++r) {
91       for (int c = 0; c < kBlockWidth; ++c) {
92         EXPECT_EQ(base_src[c], (src_diff[c] + predictor[c])) << "r = " << r
93                                                              << ", c = " << c;
94       }
95       src_diff += kDiffPredStride;
96       predictor += kDiffPredStride;
97       base_src += be.src_stride;
98     }
99   }
100   vpx_free(be.src_diff);
101   vpx_free(source);
102   vpx_free(bd.predictor);
103 }
104
105 INSTANTIATE_TEST_CASE_P(C, SubtractBlockTest,
106                         ::testing::Values(vp8_subtract_b_c));
107
108 #if HAVE_NEON
109 INSTANTIATE_TEST_CASE_P(NEON, SubtractBlockTest,
110                         ::testing::Values(vp8_subtract_b_neon));
111 #endif
112
113 #if HAVE_MMX
114 INSTANTIATE_TEST_CASE_P(MMX, SubtractBlockTest,
115                         ::testing::Values(vp8_subtract_b_mmx));
116 #endif
117
118 #if HAVE_SSE2
119 INSTANTIATE_TEST_CASE_P(SSE2, SubtractBlockTest,
120                         ::testing::Values(vp8_subtract_b_sse2));
121 #endif
122
123 }  // namespace