From: Johann Date: Tue, 6 Jun 2017 19:48:01 +0000 (-0700) Subject: buffer.h: split out init X-Git-Tag: v1.7.0~414 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=de4cb716eea72a4daf6b0aff8c3ea51890a4afba;p=libvpx buffer.h: split out init Change-Id: Idfbd2e01714ca9d00525c5aeba78678b43fb0287 --- diff --git a/test/buffer.h b/test/buffer.h index c954f439c..1fbbae1dd 100644 --- a/test/buffer.h +++ b/test/buffer.h @@ -29,16 +29,12 @@ class Buffer { int right_padding, int bottom_padding) : width_(width), height_(height), top_padding_(top_padding), left_padding_(left_padding), right_padding_(right_padding), - bottom_padding_(bottom_padding) { - Init(); - } + bottom_padding_(bottom_padding), raw_buffer_(NULL) {} Buffer(int width, int height, int padding) : width_(width), height_(height), top_padding_(padding), left_padding_(padding), right_padding_(padding), - bottom_padding_(padding) { - Init(); - } + bottom_padding_(padding), raw_buffer_(NULL) {} ~Buffer() { delete[] raw_buffer_; } @@ -75,21 +71,22 @@ class Buffer { // Compare the non-padding portion of two buffers if they are the same size. bool CheckValues(const Buffer &a) const; - private: - void Init() { - ASSERT_GT(width_, 0); - ASSERT_GT(height_, 0); - ASSERT_GE(top_padding_, 0); - ASSERT_GE(left_padding_, 0); - ASSERT_GE(right_padding_, 0); - ASSERT_GE(bottom_padding_, 0); + bool Init() { + EXPECT_GT(width_, 0); + EXPECT_GT(height_, 0); + EXPECT_GE(top_padding_, 0); + EXPECT_GE(left_padding_, 0); + EXPECT_GE(right_padding_, 0); + EXPECT_GE(bottom_padding_, 0); stride_ = left_padding_ + width_ + right_padding_; raw_size_ = stride_ * (top_padding_ + height_ + bottom_padding_); raw_buffer_ = new (std::nothrow) T[raw_size_]; - ASSERT_TRUE(raw_buffer_ != NULL); + EXPECT_TRUE(raw_buffer_ != NULL); SetPadding(std::numeric_limits::max()); + return !::testing::Test::HasFailure(); } + private: bool BufferSizesMatch(const Buffer &a) const; const int width_; @@ -106,11 +103,13 @@ class Buffer { template T *Buffer::TopLeftPixel() const { + if (!raw_buffer_) return NULL; return raw_buffer_ + (top_padding_ * stride()) + left_padding_; } template void Buffer::Set(const T value) { + if (!raw_buffer_) return; T *src = TopLeftPixel(); for (int height = 0; height < height_; ++height) { for (int width = 0; width < width_; ++width) { @@ -122,6 +121,7 @@ void Buffer::Set(const T value) { template void Buffer::Set(ACMRandom *rand_class, T (ACMRandom::*rand_func)()) { + if (!raw_buffer_) return; T *src = TopLeftPixel(); for (int height = 0; height < height_; ++height) { for (int width = 0; width < width_; ++width) { @@ -133,9 +133,8 @@ void Buffer::Set(ACMRandom *rand_class, T (ACMRandom::*rand_func)()) { template void Buffer::CopyFrom(const Buffer &a) { - if (!BufferSizesMatch(a)) { - return; - } + if (!raw_buffer_) return; + if (!BufferSizesMatch(a)) return; T *a_src = a.TopLeftPixel(); T *b_src = this->TopLeftPixel(); @@ -150,6 +149,7 @@ void Buffer::CopyFrom(const Buffer &a) { template void Buffer::DumpBuffer() const { + if (!raw_buffer_) return; for (int height = 0; height < height_ + top_padding_ + bottom_padding_; ++height) { for (int width = 0; width < stride(); ++width) { @@ -161,14 +161,14 @@ void Buffer::DumpBuffer() const { template bool Buffer::HasPadding() const { + if (!raw_buffer_) return false; return top_padding_ || left_padding_ || right_padding_ || bottom_padding_; } template void Buffer::PrintDifference(const Buffer &a) const { - if (!BufferSizesMatch(a)) { - return; - } + if (!raw_buffer_) return; + if (!BufferSizesMatch(a)) return; T *a_src = a.TopLeftPixel(); T *b_src = TopLeftPixel(); @@ -207,6 +207,7 @@ void Buffer::PrintDifference(const Buffer &a) const { template void Buffer::SetPadding(const T padding_value) { + if (!raw_buffer_) return; padding_value_ = padding_value; T *src = raw_buffer_; @@ -217,6 +218,7 @@ void Buffer::SetPadding(const T padding_value) { template bool Buffer::CheckValues(const T value) const { + if (!raw_buffer_) return false; T *src = TopLeftPixel(); for (int height = 0; height < height_; ++height) { for (int width = 0; width < width_; ++width) { @@ -231,9 +233,8 @@ bool Buffer::CheckValues(const T value) const { template bool Buffer::CheckPadding() const { - if (!HasPadding()) { - return true; - } + if (!raw_buffer_) return false; + if (!HasPadding()) return true; // Top padding. T const *top = raw_buffer_; @@ -278,9 +279,8 @@ bool Buffer::CheckPadding() const { template bool Buffer::CheckValues(const Buffer &a) const { - if (!BufferSizesMatch(a)) { - return false; - } + if (!raw_buffer_) return false; + if (!BufferSizesMatch(a)) return false; T *a_src = a.TopLeftPixel(); T *b_src = this->TopLeftPixel(); @@ -298,6 +298,7 @@ bool Buffer::CheckValues(const Buffer &a) const { template bool Buffer::BufferSizesMatch(const Buffer &a) const { + if (!raw_buffer_) return false; if (a.width_ != this->width_ || a.height_ != this->height_) { printf( "Reference buffer of size %dx%d does not match this buffer which is " diff --git a/test/comp_avg_pred_test.cc b/test/comp_avg_pred_test.cc index dce673eec..3c1d746cd 100644 --- a/test/comp_avg_pred_test.cc +++ b/test/comp_avg_pred_test.cc @@ -80,6 +80,7 @@ TEST_P(AvgPredTest, SizeCombinations) { // Only the reference buffer may have a stride not equal to width. Buffer ref = Buffer(width, height, ref_padding ? 8 : 0); + ASSERT_TRUE(ref.Init()); fill(&rnd_, pred, width, height); ref.Set(&rnd_, &ACMRandom::Rand8); @@ -98,6 +99,7 @@ TEST_P(AvgPredTest, CompareReferenceRandom) { const int width = 64; const int height = 32; Buffer ref = Buffer(width, height, 8); + ASSERT_TRUE(ref.Init()); DECLARE_ALIGNED(16, uint8_t, pred[width * height]); DECLARE_ALIGNED(16, uint8_t, avg_ref[width * height]); DECLARE_ALIGNED(16, uint8_t, avg_chk[width * height]); @@ -128,6 +130,7 @@ TEST_P(AvgPredTest, DISABLED_Speed) { const int height = 1 << height_pow; Buffer ref = Buffer(width, height, ref_padding ? 8 : 0); + ASSERT_TRUE(ref.Init()); fill(&rnd_, pred, width, height); ref.Set(&rnd_, &ACMRandom::Rand8); diff --git a/test/idct_test.cc b/test/idct_test.cc index 084b2ed0c..5936d469b 100644 --- a/test/idct_test.cc +++ b/test/idct_test.cc @@ -31,11 +31,11 @@ class IDCTTest : public ::testing::TestWithParam { UUT = GetParam(); input = new (std::nothrow) Buffer(4, 4, 0); - ASSERT_TRUE(input != NULL); + ASSERT_TRUE(input->Init()); predict = new (std::nothrow) Buffer(4, 4, 3); - ASSERT_TRUE(predict != NULL); + ASSERT_TRUE(predict->Init()); output = new (std::nothrow) Buffer(4, 4, 3); - ASSERT_TRUE(output != NULL); + ASSERT_TRUE(output->Init()); } virtual void TearDown() { diff --git a/test/pp_filter_test.cc b/test/pp_filter_test.cc index 95da09c31..b11a1ba25 100644 --- a/test/pp_filter_test.cc +++ b/test/pp_filter_test.cc @@ -57,12 +57,14 @@ TEST_P(VpxPostProcDownAndAcrossMbRowTest, CheckFilterOutput) { // 5-tap filter needs 2 padding rows above and below the block in the input. Buffer src_image = Buffer(block_width, block_height, 2); + ASSERT_TRUE(src_image.Init()); // Filter extends output block by 8 samples at left and right edges. // Though the left padding is only 8 bytes, the assembly code tries to // read 16 bytes before the pointer. Buffer dst_image = Buffer(block_width, block_height, 8, 16, 8, 8); + ASSERT_TRUE(dst_image.Init()); uint8_t *const flimits = reinterpret_cast(vpx_memalign(16, block_width)); @@ -108,6 +110,7 @@ TEST_P(VpxPostProcDownAndAcrossMbRowTest, CheckCvsAssembly) { // SSE2 reads in blocks of 16. Pad an extra 8 in case the width is not %16. Buffer src_image = Buffer(block_width, block_height, 2, 2, 10, 2); + ASSERT_TRUE(src_image.Init()); // Filter extends output block by 8 samples at left and right edges. // Though the left padding is only 8 bytes, there is 'above' padding as well @@ -116,7 +119,9 @@ TEST_P(VpxPostProcDownAndAcrossMbRowTest, CheckCvsAssembly) { // SSE2 reads in blocks of 16. Pad an extra 8 in case the width is not %16. Buffer dst_image = Buffer(block_width, block_height, 8, 8, 16, 8); + ASSERT_TRUE(dst_image.Init()); Buffer dst_image_ref = Buffer(block_width, block_height, 8); + ASSERT_TRUE(dst_image_ref.Init()); // Filter values are set in blocks of 16 for Y and 8 for U/V. Each macroblock // can have a different filter. SSE2 assembly reads flimits in blocks of 16 so @@ -197,10 +202,12 @@ TEST_P(VpxMbPostProcAcrossIpTest, CheckLowFilterOutput) { const int cols = 16; Buffer src = Buffer(cols, rows, 8, 8, 17, 8); + ASSERT_TRUE(src.Init()); src.SetPadding(10); SetCols(src.TopLeftPixel(), rows, cols, src.stride()); Buffer expected_output = Buffer(cols, rows, 0); + ASSERT_TRUE(expected_output.Init()); SetCols(expected_output.TopLeftPixel(), rows, cols, expected_output.stride()); RunFilterLevel(src.TopLeftPixel(), rows, cols, src.stride(), q2mbl(0), @@ -212,6 +219,7 @@ TEST_P(VpxMbPostProcAcrossIpTest, CheckMediumFilterOutput) { const int cols = 16; Buffer src = Buffer(cols, rows, 8, 8, 17, 8); + ASSERT_TRUE(src.Init()); src.SetPadding(10); SetCols(src.TopLeftPixel(), rows, cols, src.stride()); @@ -228,6 +236,7 @@ TEST_P(VpxMbPostProcAcrossIpTest, CheckHighFilterOutput) { const int cols = 16; Buffer src = Buffer(cols, rows, 8, 8, 17, 8); + ASSERT_TRUE(src.Init()); src.SetPadding(10); SetCols(src.TopLeftPixel(), rows, cols, src.stride()); @@ -249,7 +258,9 @@ TEST_P(VpxMbPostProcAcrossIpTest, CheckCvsAssembly) { const int cols = 16; Buffer c_mem = Buffer(cols, rows, 8, 8, 17, 8); + ASSERT_TRUE(c_mem.Init()); Buffer asm_mem = Buffer(cols, rows, 8, 8, 17, 8); + ASSERT_TRUE(asm_mem.Init()); // When level >= 100, the filter behaves the same as the level = INT_MAX // When level < 20, it behaves the same as the level = 0 @@ -305,6 +316,7 @@ TEST_P(VpxMbPostProcDownTest, CheckHighFilterOutput) { const int cols = 16; Buffer src_c = Buffer(cols, rows, 8, 8, 8, 17); + ASSERT_TRUE(src_c.Init()); src_c.SetPadding(10); SetRows(src_c.TopLeftPixel(), rows, cols, src_c.stride()); @@ -340,6 +352,7 @@ TEST_P(VpxMbPostProcDownTest, CheckMediumFilterOutput) { const int cols = 16; Buffer src_c = Buffer(cols, rows, 8, 8, 8, 17); + ASSERT_TRUE(src_c.Init()); src_c.SetPadding(10); SetRows(src_c.TopLeftPixel(), rows, cols, src_c.stride()); @@ -370,6 +383,7 @@ TEST_P(VpxMbPostProcDownTest, CheckLowFilterOutput) { const int cols = 16; Buffer src_c = Buffer(cols, rows, 8, 8, 8, 17); + ASSERT_TRUE(src_c.Init()); src_c.SetPadding(10); SetRows(src_c.TopLeftPixel(), rows, cols, src_c.stride()); @@ -392,7 +406,9 @@ TEST_P(VpxMbPostProcDownTest, CheckCvsAssembly) { rnd.Reset(ACMRandom::DeterministicSeed()); Buffer src_c = Buffer(cols, rows, 8, 8, 8, 17); + ASSERT_TRUE(src_c.Init()); Buffer src_asm = Buffer(cols, rows, 8, 8, 8, 17); + ASSERT_TRUE(src_asm.Init()); for (int level = 0; level < 100; level++) { src_c.SetPadding(10); diff --git a/test/temporal_filter_test.cc b/test/temporal_filter_test.cc index 8615ba45a..0395eb82e 100644 --- a/test/temporal_filter_test.cc +++ b/test/temporal_filter_test.cc @@ -35,6 +35,7 @@ void reference_filter(const Buffer &a, const Buffer &b, int w, Buffer *accumulator, Buffer *count) { Buffer diff_sq = Buffer(w, h, 0); + ASSERT_TRUE(diff_sq.Init()); diff_sq.Set(0); int rounding = 0; @@ -119,6 +120,7 @@ TEST_P(TemporalFilterTest, SizeCombinations) { // Depending on subsampling this function may be called with values of 8 or 16 // for width and height, in any combination. Buffer a = Buffer(16, 16, 8); + ASSERT_TRUE(a.Init()); const int filter_weight = 2; const int filter_strength = 6; @@ -127,10 +129,15 @@ TEST_P(TemporalFilterTest, SizeCombinations) { for (int height = 8; height <= 16; height += 8) { // The second buffer must not have any border. Buffer b = Buffer(width, height, 0); + ASSERT_TRUE(b.Init()); Buffer accum_ref = Buffer(width, height, 0); + ASSERT_TRUE(accum_ref.Init()); Buffer accum_chk = Buffer(width, height, 0); + ASSERT_TRUE(accum_chk.Init()); Buffer count_ref = Buffer(width, height, 0); + ASSERT_TRUE(count_ref.Init()); Buffer count_chk = Buffer(width, height, 0); + ASSERT_TRUE(count_chk.Init()); a.Set(&rnd_, &ACMRandom::Rand8); b.Set(&rnd_, &ACMRandom::Rand8); @@ -161,12 +168,18 @@ TEST_P(TemporalFilterTest, CompareReferenceRandom) { for (int width = 8; width <= 16; width += 8) { for (int height = 8; height <= 16; height += 8) { Buffer a = Buffer(width, height, 8); + ASSERT_TRUE(a.Init()); // The second buffer must not have any border. Buffer b = Buffer(width, height, 0); + ASSERT_TRUE(b.Init()); Buffer accum_ref = Buffer(width, height, 0); + ASSERT_TRUE(accum_ref.Init()); Buffer accum_chk = Buffer(width, height, 0); + ASSERT_TRUE(accum_chk.Init()); Buffer count_ref = Buffer(width, height, 0); + ASSERT_TRUE(count_ref.Init()); Buffer count_chk = Buffer(width, height, 0); + ASSERT_TRUE(count_chk.Init()); for (int filter_strength = 0; filter_strength <= 6; ++filter_strength) { for (int filter_weight = 0; filter_weight <= 2; ++filter_weight) { @@ -202,6 +215,7 @@ TEST_P(TemporalFilterTest, CompareReferenceRandom) { TEST_P(TemporalFilterTest, DISABLED_Speed) { Buffer a = Buffer(16, 16, 8); + ASSERT_TRUE(a.Init()); const int filter_weight = 2; const int filter_strength = 6; @@ -210,10 +224,15 @@ TEST_P(TemporalFilterTest, DISABLED_Speed) { for (int height = 8; height <= 16; height += 8) { // The second buffer must not have any border. Buffer b = Buffer(width, height, 0); + ASSERT_TRUE(b.Init()); Buffer accum_ref = Buffer(width, height, 0); + ASSERT_TRUE(accum_ref.Init()); Buffer accum_chk = Buffer(width, height, 0); + ASSERT_TRUE(accum_chk.Init()); Buffer count_ref = Buffer(width, height, 0); + ASSERT_TRUE(count_ref.Init()); Buffer count_chk = Buffer(width, height, 0); + ASSERT_TRUE(count_chk.Init()); a.Set(&rnd_, &ACMRandom::Rand8); b.Set(&rnd_, &ACMRandom::Rand8);