buffer.h: split out init
Change-Id: Idfbd2e01714ca9d00525c5aeba78678b43fb0287
This commit is contained in:
parent
8659764a07
commit
de4cb716ee
@ -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<T> &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<T>::max());
|
||||
return !::testing::Test::HasFailure();
|
||||
}
|
||||
|
||||
private:
|
||||
bool BufferSizesMatch(const Buffer<T> &a) const;
|
||||
|
||||
const int width_;
|
||||
@ -106,11 +103,13 @@ class Buffer {
|
||||
|
||||
template <typename T>
|
||||
T *Buffer<T>::TopLeftPixel() const {
|
||||
if (!raw_buffer_) return NULL;
|
||||
return raw_buffer_ + (top_padding_ * stride()) + left_padding_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Buffer<T>::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<T>::Set(const T value) {
|
||||
|
||||
template <typename T>
|
||||
void Buffer<T>::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<T>::Set(ACMRandom *rand_class, T (ACMRandom::*rand_func)()) {
|
||||
|
||||
template <typename T>
|
||||
void Buffer<T>::CopyFrom(const Buffer<T> &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<T>::CopyFrom(const Buffer<T> &a) {
|
||||
|
||||
template <typename T>
|
||||
void Buffer<T>::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<T>::DumpBuffer() const {
|
||||
|
||||
template <typename T>
|
||||
bool Buffer<T>::HasPadding() const {
|
||||
if (!raw_buffer_) return false;
|
||||
return top_padding_ || left_padding_ || right_padding_ || bottom_padding_;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Buffer<T>::PrintDifference(const Buffer<T> &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<T>::PrintDifference(const Buffer<T> &a) const {
|
||||
|
||||
template <typename T>
|
||||
void Buffer<T>::SetPadding(const T padding_value) {
|
||||
if (!raw_buffer_) return;
|
||||
padding_value_ = padding_value;
|
||||
|
||||
T *src = raw_buffer_;
|
||||
@ -217,6 +218,7 @@ void Buffer<T>::SetPadding(const T padding_value) {
|
||||
|
||||
template <typename T>
|
||||
bool Buffer<T>::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<T>::CheckValues(const T value) const {
|
||||
|
||||
template <typename T>
|
||||
bool Buffer<T>::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<T>::CheckPadding() const {
|
||||
|
||||
template <typename T>
|
||||
bool Buffer<T>::CheckValues(const Buffer<T> &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<T>::CheckValues(const Buffer<T> &a) const {
|
||||
|
||||
template <typename T>
|
||||
bool Buffer<T>::BufferSizesMatch(const Buffer<T> &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 "
|
||||
|
@ -80,6 +80,7 @@ TEST_P(AvgPredTest, SizeCombinations) {
|
||||
// Only the reference buffer may have a stride not equal to width.
|
||||
Buffer<uint8_t> ref =
|
||||
Buffer<uint8_t>(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<uint8_t> ref = Buffer<uint8_t>(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<uint8_t> ref =
|
||||
Buffer<uint8_t>(width, height, ref_padding ? 8 : 0);
|
||||
ASSERT_TRUE(ref.Init());
|
||||
|
||||
fill(&rnd_, pred, width, height);
|
||||
ref.Set(&rnd_, &ACMRandom::Rand8);
|
||||
|
@ -31,11 +31,11 @@ class IDCTTest : public ::testing::TestWithParam<IdctFunc> {
|
||||
UUT = GetParam();
|
||||
|
||||
input = new (std::nothrow) Buffer<int16_t>(4, 4, 0);
|
||||
ASSERT_TRUE(input != NULL);
|
||||
ASSERT_TRUE(input->Init());
|
||||
predict = new (std::nothrow) Buffer<uint8_t>(4, 4, 3);
|
||||
ASSERT_TRUE(predict != NULL);
|
||||
ASSERT_TRUE(predict->Init());
|
||||
output = new (std::nothrow) Buffer<uint8_t>(4, 4, 3);
|
||||
ASSERT_TRUE(output != NULL);
|
||||
ASSERT_TRUE(output->Init());
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
|
@ -57,12 +57,14 @@ TEST_P(VpxPostProcDownAndAcrossMbRowTest, CheckFilterOutput) {
|
||||
|
||||
// 5-tap filter needs 2 padding rows above and below the block in the input.
|
||||
Buffer<uint8_t> src_image = Buffer<uint8_t>(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<uint8_t> dst_image =
|
||||
Buffer<uint8_t>(block_width, block_height, 8, 16, 8, 8);
|
||||
ASSERT_TRUE(dst_image.Init());
|
||||
|
||||
uint8_t *const flimits =
|
||||
reinterpret_cast<uint8_t *>(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<uint8_t> src_image =
|
||||
Buffer<uint8_t>(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<uint8_t> dst_image =
|
||||
Buffer<uint8_t>(block_width, block_height, 8, 8, 16, 8);
|
||||
ASSERT_TRUE(dst_image.Init());
|
||||
Buffer<uint8_t> dst_image_ref = Buffer<uint8_t>(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<uint8_t> src = Buffer<uint8_t>(cols, rows, 8, 8, 17, 8);
|
||||
ASSERT_TRUE(src.Init());
|
||||
src.SetPadding(10);
|
||||
SetCols(src.TopLeftPixel(), rows, cols, src.stride());
|
||||
|
||||
Buffer<uint8_t> expected_output = Buffer<uint8_t>(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<uint8_t> src = Buffer<uint8_t>(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<uint8_t> src = Buffer<uint8_t>(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<uint8_t> c_mem = Buffer<uint8_t>(cols, rows, 8, 8, 17, 8);
|
||||
ASSERT_TRUE(c_mem.Init());
|
||||
Buffer<uint8_t> asm_mem = Buffer<uint8_t>(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<uint8_t> src_c = Buffer<uint8_t>(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<uint8_t> src_c = Buffer<uint8_t>(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<uint8_t> src_c = Buffer<uint8_t>(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<uint8_t> src_c = Buffer<uint8_t>(cols, rows, 8, 8, 8, 17);
|
||||
ASSERT_TRUE(src_c.Init());
|
||||
Buffer<uint8_t> src_asm = Buffer<uint8_t>(cols, rows, 8, 8, 8, 17);
|
||||
ASSERT_TRUE(src_asm.Init());
|
||||
|
||||
for (int level = 0; level < 100; level++) {
|
||||
src_c.SetPadding(10);
|
||||
|
@ -35,6 +35,7 @@ void reference_filter(const Buffer<uint8_t> &a, const Buffer<uint8_t> &b, int w,
|
||||
Buffer<unsigned int> *accumulator,
|
||||
Buffer<uint16_t> *count) {
|
||||
Buffer<int> diff_sq = Buffer<int>(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<uint8_t> a = Buffer<uint8_t>(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<uint8_t> b = Buffer<uint8_t>(width, height, 0);
|
||||
ASSERT_TRUE(b.Init());
|
||||
Buffer<unsigned int> accum_ref = Buffer<unsigned int>(width, height, 0);
|
||||
ASSERT_TRUE(accum_ref.Init());
|
||||
Buffer<unsigned int> accum_chk = Buffer<unsigned int>(width, height, 0);
|
||||
ASSERT_TRUE(accum_chk.Init());
|
||||
Buffer<uint16_t> count_ref = Buffer<uint16_t>(width, height, 0);
|
||||
ASSERT_TRUE(count_ref.Init());
|
||||
Buffer<uint16_t> count_chk = Buffer<uint16_t>(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<uint8_t> a = Buffer<uint8_t>(width, height, 8);
|
||||
ASSERT_TRUE(a.Init());
|
||||
// The second buffer must not have any border.
|
||||
Buffer<uint8_t> b = Buffer<uint8_t>(width, height, 0);
|
||||
ASSERT_TRUE(b.Init());
|
||||
Buffer<unsigned int> accum_ref = Buffer<unsigned int>(width, height, 0);
|
||||
ASSERT_TRUE(accum_ref.Init());
|
||||
Buffer<unsigned int> accum_chk = Buffer<unsigned int>(width, height, 0);
|
||||
ASSERT_TRUE(accum_chk.Init());
|
||||
Buffer<uint16_t> count_ref = Buffer<uint16_t>(width, height, 0);
|
||||
ASSERT_TRUE(count_ref.Init());
|
||||
Buffer<uint16_t> count_chk = Buffer<uint16_t>(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<uint8_t> a = Buffer<uint8_t>(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<uint8_t> b = Buffer<uint8_t>(width, height, 0);
|
||||
ASSERT_TRUE(b.Init());
|
||||
Buffer<unsigned int> accum_ref = Buffer<unsigned int>(width, height, 0);
|
||||
ASSERT_TRUE(accum_ref.Init());
|
||||
Buffer<unsigned int> accum_chk = Buffer<unsigned int>(width, height, 0);
|
||||
ASSERT_TRUE(accum_chk.Init());
|
||||
Buffer<uint16_t> count_ref = Buffer<uint16_t>(width, height, 0);
|
||||
ASSERT_TRUE(count_ref.Init());
|
||||
Buffer<uint16_t> count_chk = Buffer<uint16_t>(width, height, 0);
|
||||
ASSERT_TRUE(count_chk.Init());
|
||||
|
||||
a.Set(&rnd_, &ACMRandom::Rand8);
|
||||
b.Set(&rnd_, &ACMRandom::Rand8);
|
||||
|
Loading…
x
Reference in New Issue
Block a user