OLD | NEW |
(Empty) | |
| 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 |
| 12 #include <string.h> |
| 13 #include <limits.h> |
| 14 #include <stdio.h> |
| 15 |
| 16 #include "./vpx_config.h" |
| 17 #if CONFIG_VP9_ENCODER |
| 18 #include "./vp9_rtcd.h" |
| 19 #endif |
| 20 #include "vpx_mem/vpx_mem.h" |
| 21 |
| 22 #include "test/acm_random.h" |
| 23 #include "test/clear_system_state.h" |
| 24 #include "test/register_state_check.h" |
| 25 #include "test/util.h" |
| 26 #include "third_party/googletest/src/include/gtest/gtest.h" |
| 27 |
| 28 using libvpx_test::ACMRandom; |
| 29 |
| 30 namespace { |
| 31 class AverageTestBase : public ::testing::Test { |
| 32 public: |
| 33 AverageTestBase(int width, int height) : width_(width), height_(height) {} |
| 34 |
| 35 static void SetUpTestCase() { |
| 36 source_data_ = reinterpret_cast<uint8_t*>( |
| 37 vpx_memalign(kDataAlignment, kDataBlockSize)); |
| 38 } |
| 39 |
| 40 static void TearDownTestCase() { |
| 41 vpx_free(source_data_); |
| 42 source_data_ = NULL; |
| 43 } |
| 44 |
| 45 virtual void TearDown() { |
| 46 libvpx_test::ClearSystemState(); |
| 47 } |
| 48 |
| 49 protected: |
| 50 // Handle blocks up to 4 blocks 64x64 with stride up to 128 |
| 51 static const int kDataAlignment = 16; |
| 52 static const int kDataBlockSize = 64 * 128; |
| 53 |
| 54 virtual void SetUp() { |
| 55 source_stride_ = (width_ + 31) & ~31; |
| 56 rnd_.Reset(ACMRandom::DeterministicSeed()); |
| 57 } |
| 58 |
| 59 // Sum Pixels |
| 60 unsigned int ReferenceAverage(const uint8_t* source, int pitch ) { |
| 61 unsigned int average = 0; |
| 62 for (int h = 0; h < 8; ++h) |
| 63 for (int w = 0; w < 8; ++w) |
| 64 average += source[h * source_stride_ + w]; |
| 65 return ((average + 32) >> 6); |
| 66 } |
| 67 |
| 68 void FillConstant(uint8_t fill_constant) { |
| 69 for (int i = 0; i < width_ * height_; ++i) { |
| 70 source_data_[i] = fill_constant; |
| 71 } |
| 72 } |
| 73 |
| 74 void FillRandom() { |
| 75 for (int i = 0; i < width_ * height_; ++i) { |
| 76 source_data_[i] = rnd_.Rand8(); |
| 77 } |
| 78 } |
| 79 |
| 80 int width_, height_; |
| 81 static uint8_t* source_data_; |
| 82 int source_stride_; |
| 83 |
| 84 ACMRandom rnd_; |
| 85 }; |
| 86 typedef unsigned int (*AverageFunction)(const uint8_t* s, int pitch); |
| 87 |
| 88 typedef std::tr1::tuple<int, int, int, AverageFunction> AvgFunc; |
| 89 |
| 90 class AverageTest |
| 91 : public AverageTestBase, |
| 92 public ::testing::WithParamInterface<AvgFunc>{ |
| 93 public: |
| 94 AverageTest() : AverageTestBase(GET_PARAM(0), GET_PARAM(1)) {} |
| 95 |
| 96 protected: |
| 97 void CheckAverages() { |
| 98 unsigned int expected = ReferenceAverage(source_data_+ GET_PARAM(2), |
| 99 source_stride_); |
| 100 |
| 101 ASM_REGISTER_STATE_CHECK(GET_PARAM(3)(source_data_+ GET_PARAM(2), |
| 102 source_stride_)); |
| 103 unsigned int actual = GET_PARAM(3)(source_data_+ GET_PARAM(2), |
| 104 source_stride_); |
| 105 |
| 106 EXPECT_EQ(expected, actual); |
| 107 } |
| 108 }; |
| 109 |
| 110 |
| 111 uint8_t* AverageTestBase::source_data_ = NULL; |
| 112 |
| 113 TEST_P(AverageTest, MinValue) { |
| 114 FillConstant(0); |
| 115 CheckAverages(); |
| 116 } |
| 117 |
| 118 TEST_P(AverageTest, MaxValue) { |
| 119 FillConstant(255); |
| 120 CheckAverages(); |
| 121 } |
| 122 |
| 123 TEST_P(AverageTest, Random) { |
| 124 // The reference frame, but not the source frame, may be unaligned for |
| 125 // certain types of searches. |
| 126 for (int i = 0; i < 1000; i++) { |
| 127 FillRandom(); |
| 128 CheckAverages(); |
| 129 } |
| 130 } |
| 131 |
| 132 using std::tr1::make_tuple; |
| 133 |
| 134 INSTANTIATE_TEST_CASE_P( |
| 135 C, AverageTest, |
| 136 ::testing::Values( |
| 137 make_tuple(16, 16, 1, &vp9_avg_8x8_c))); |
| 138 |
| 139 |
| 140 #if HAVE_SSE2 |
| 141 INSTANTIATE_TEST_CASE_P( |
| 142 SSE2, AverageTest, |
| 143 ::testing::Values( |
| 144 make_tuple(16, 16, 0, &vp9_avg_8x8_sse2), |
| 145 make_tuple(16, 16, 5, &vp9_avg_8x8_sse2), |
| 146 make_tuple(32, 32, 15, &vp9_avg_8x8_sse2))); |
| 147 |
| 148 #endif |
| 149 |
| 150 } // namespace |
OLD | NEW |