Commit 48032bfc authored by Peter de Rivaz's avatar Peter de Rivaz Committed by Deb Mukherjee

Added sse2 acceleration for highbitdepth variance

Change-Id: I446bdf3a405e4e9d2aa633d6281d66ea0cdfd79f
(cherry picked from commit d7422b2b1eb9f0011a8c379c2be680d6892b16bc)
(cherry picked from commit 6d741e4d76a7d9ece69ca117d1d9e2f9ee48ef8c)
parent 807885b5
......@@ -7,16 +7,18 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdlib.h>
#include <new>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include <cstdlib>
#include <new>
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "vpx/vpx_integer.h"
#include "./vpx_config.h"
#include "vpx/vpx_codec.h"
#include "vpx/vpx_integer.h"
#include "vpx_mem/vpx_mem.h"
#if CONFIG_VP8_ENCODER
# include "./vp8_rtcd.h"
......@@ -26,7 +28,6 @@
# include "./vp9_rtcd.h"
# include "vp9/encoder/vp9_variance.h"
#endif
#include "test/acm_random.h"
namespace {
......@@ -43,31 +44,106 @@ static unsigned int mb_ss_ref(const int16_t *src) {
return res;
}
static unsigned int variance_ref(const uint8_t *ref, const uint8_t *src,
int l2w, int l2h, unsigned int *sse_ptr) {
static unsigned int variance_ref(const uint8_t *src, const uint8_t *ref,
int l2w, int l2h, int src_stride_coeff,
int ref_stride_coeff, uint32_t *sse_ptr,
bool use_high_bit_depth_,
vpx_bit_depth_t bit_depth) {
#if CONFIG_VP9_HIGHBITDEPTH
int64_t se = 0;
uint64_t sse = 0;
const int w = 1 << l2w;
const int h = 1 << l2h;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int diff;
if (!use_high_bit_depth_) {
diff = ref[w * y * ref_stride_coeff + x] -
src[w * y * src_stride_coeff + x];
se += diff;
sse += diff * diff;
} else {
diff = CONVERT_TO_SHORTPTR(ref)[w * y * ref_stride_coeff + x] -
CONVERT_TO_SHORTPTR(src)[w * y * src_stride_coeff + x];
se += diff;
sse += diff * diff;
}
}
}
if (bit_depth > VPX_BITS_8) {
sse = ROUND_POWER_OF_TWO(sse, 2 * (bit_depth - 8));
se = ROUND_POWER_OF_TWO(se, bit_depth - 8);
}
#else
int se = 0;
unsigned int sse = 0;
const int w = 1 << l2w, h = 1 << l2h;
const int w = 1 << l2w;
const int h = 1 << l2h;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int diff = ref[w * y + x] - src[w * y + x];
int diff = ref[w * y * ref_stride_coeff + x] -
src[w * y * src_stride_coeff + x];
se += diff;
sse += diff * diff;
}
}
#endif // CONFIG_VP9_HIGHBITDEPTH
*sse_ptr = sse;
return sse - (((int64_t) se * se) >> (l2w + l2h));
}
static unsigned int subpel_variance_ref(const uint8_t *ref, const uint8_t *src,
int l2w, int l2h, int xoff, int yoff,
unsigned int *sse_ptr) {
unsigned int *sse_ptr,
bool use_high_bit_depth_,
vpx_bit_depth_t bit_depth) {
#if CONFIG_VP9_HIGHBITDEPTH
int64_t se = 0;
uint64_t sse = 0;
const int w = 1 << l2w;
const int h = 1 << l2h;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
// Bilinear interpolation at a 16th pel step.
if (!use_high_bit_depth_) {
const int a1 = ref[(w + 1) * (y + 0) + x + 0];
const int a2 = ref[(w + 1) * (y + 0) + x + 1];
const int b1 = ref[(w + 1) * (y + 1) + x + 0];
const int b2 = ref[(w + 1) * (y + 1) + x + 1];
const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
const int r = a + (((b - a) * yoff + 8) >> 4);
const int diff = r - src[w * y + x];
se += diff;
sse += diff * diff;
} else {
uint16_t *ref16 = CONVERT_TO_SHORTPTR(ref);
uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
const int a1 = ref16[(w + 1) * (y + 0) + x + 0];
const int a2 = ref16[(w + 1) * (y + 0) + x + 1];
const int b1 = ref16[(w + 1) * (y + 1) + x + 0];
const int b2 = ref16[(w + 1) * (y + 1) + x + 1];
const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
const int r = a + (((b - a) * yoff + 8) >> 4);
const int diff = r - src16[w * y + x];
se += diff;
sse += diff * diff;
}
}
}
if (bit_depth > VPX_BITS_8) {
sse = ROUND_POWER_OF_TWO(sse, 2 * (bit_depth - 8));
se = ROUND_POWER_OF_TWO(se, bit_depth - 8);
}
#else
int se = 0;
unsigned int sse = 0;
const int w = 1 << l2w, h = 1 << l2h;
const int w = 1 << l2w;
const int h = 1 << l2h;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
// bilinear interpolation at a 16th pel step
// Bilinear interpolation at a 16th pel step.
const int a1 = ref[(w + 1) * (y + 0) + x + 0];
const int a2 = ref[(w + 1) * (y + 0) + x + 1];
const int b1 = ref[(w + 1) * (y + 1) + x + 0];
......@@ -75,11 +151,12 @@ static unsigned int subpel_variance_ref(const uint8_t *ref, const uint8_t *src,
const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
const int r = a + (((b - a) * yoff + 8) >> 4);
int diff = r - src[w * y + x];
const int diff = r - src[w * y + x];
se += diff;
sse += diff * diff;
}
}
#endif // CONFIG_VP9_HIGHBITDEPTH
*sse_ptr = sse;
return sse - (((int64_t) se * se) >> (l2w + l2h));
}
......@@ -130,40 +207,74 @@ void SumOfSquaresTest::RefTest() {
template<typename VarianceFunctionType>
class VarianceTest
: public ::testing::TestWithParam<tuple<int, int, VarianceFunctionType> > {
: public ::testing::TestWithParam<tuple<int, int,
VarianceFunctionType, int> > {
public:
virtual void SetUp() {
const tuple<int, int, VarianceFunctionType>& params = this->GetParam();
const tuple<int, int, VarianceFunctionType, int>& params = this->GetParam();
log2width_ = get<0>(params);
width_ = 1 << log2width_;
log2height_ = get<1>(params);
height_ = 1 << log2height_;
variance_ = get<2>(params);
if (get<3>(params)) {
bit_depth_ = static_cast<vpx_bit_depth_t>(get<3>(params));
use_high_bit_depth_ = true;
} else {
bit_depth_ = VPX_BITS_8;
use_high_bit_depth_ = false;
}
mask_ = (1 << bit_depth_) - 1;
rnd_.Reset(ACMRandom::DeterministicSeed());
block_size_ = width_ * height_;
src_ = reinterpret_cast<uint8_t *>(vpx_memalign(16, block_size_));
ref_ = new uint8_t[block_size_];
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
src_ = reinterpret_cast<uint8_t *>(vpx_memalign(16, block_size_ * 2));
ref_ = new uint8_t[block_size_ * 2];
} else {
src_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
vpx_memalign(16, block_size_ * 2 * sizeof(uint16_t))));
ref_ = CONVERT_TO_BYTEPTR(new uint16_t[block_size_ * 2]);
}
#else
src_ = reinterpret_cast<uint8_t *>(vpx_memalign(16, block_size_ * 2));
ref_ = new uint8_t[block_size_ * 2];
#endif
ASSERT_TRUE(src_ != NULL);
ASSERT_TRUE(ref_ != NULL);
}
virtual void TearDown() {
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
vpx_free(src_);
delete[] ref_;
} else {
vpx_free(CONVERT_TO_SHORTPTR(src_));
delete[] CONVERT_TO_SHORTPTR(ref_);
}
#else
vpx_free(src_);
delete[] ref_;
#endif
libvpx_test::ClearSystemState();
}
protected:
void ZeroTest();
void RefTest();
void RefStrideTest();
void OneQuarterTest();
ACMRandom rnd_;
uint8_t* src_;
uint8_t* ref_;
uint8_t *src_;
uint8_t *ref_;
int width_, log2width_;
int height_, log2height_;
vpx_bit_depth_t bit_depth_;
int mask_;
bool use_high_bit_depth_;
int block_size_;
VarianceFunctionType variance_;
};
......@@ -171,14 +282,32 @@ class VarianceTest
template<typename VarianceFunctionType>
void VarianceTest<VarianceFunctionType>::ZeroTest() {
for (int i = 0; i <= 255; ++i) {
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
memset(src_, i, block_size_);
} else {
vpx_memset16(CONVERT_TO_SHORTPTR(src_), i << (bit_depth_ - 8),
block_size_);
}
#else
memset(src_, i, block_size_);
#endif
for (int j = 0; j <= 255; ++j) {
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
memset(ref_, j, block_size_);
} else {
vpx_memset16(CONVERT_TO_SHORTPTR(ref_), j << (bit_depth_ - 8),
block_size_);
}
#else
memset(ref_, j, block_size_);
#endif
unsigned int sse;
unsigned int var;
ASM_REGISTER_STATE_CHECK(
var = variance_(src_, width_, ref_, width_, &sse));
EXPECT_EQ(0u, var) << "src values: " << i << "ref values: " << j;
EXPECT_EQ(0u, var) << "src values: " << i << " ref values: " << j;
}
}
}
......@@ -187,15 +316,64 @@ template<typename VarianceFunctionType>
void VarianceTest<VarianceFunctionType>::RefTest() {
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < block_size_; j++) {
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
src_[j] = rnd_.Rand8();
ref_[j] = rnd_.Rand8();
} else {
CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() && mask_;
CONVERT_TO_SHORTPTR(ref_)[j] = rnd_.Rand16() && mask_;
}
#else
src_[j] = rnd_.Rand8();
ref_[j] = rnd_.Rand8();
#endif
}
unsigned int sse1, sse2;
unsigned int var1;
const int stride_coeff = 1;
ASM_REGISTER_STATE_CHECK(
var1 = variance_(src_, width_, ref_, width_, &sse1));
const unsigned int var2 = variance_ref(src_, ref_, log2width_,
log2height_, &sse2);
log2height_, stride_coeff,
stride_coeff, &sse2,
use_high_bit_depth_, bit_depth_);
EXPECT_EQ(sse1, sse2);
EXPECT_EQ(var1, var2);
}
}
template<typename VarianceFunctionType>
void VarianceTest<VarianceFunctionType>::RefStrideTest() {
for (int i = 0; i < 10; ++i) {
int ref_stride_coeff = i % 2;
int src_stride_coeff = (i >> 1) % 2;
for (int j = 0; j < block_size_; j++) {
int ref_ind = (j / width_) * ref_stride_coeff * width_ + j % width_;
int src_ind = (j / width_) * src_stride_coeff * width_ + j % width_;
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
src_[src_ind] = rnd_.Rand8();
ref_[ref_ind] = rnd_.Rand8();
} else {
CONVERT_TO_SHORTPTR(src_)[src_ind] = rnd_.Rand16() && mask_;
CONVERT_TO_SHORTPTR(ref_)[ref_ind] = rnd_.Rand16() && mask_;
}
#else
src_[src_ind] = rnd_.Rand8();
ref_[ref_ind] = rnd_.Rand8();
#endif
}
unsigned int sse1, sse2;
unsigned int var1;
ASM_REGISTER_STATE_CHECK(
var1 = variance_(src_, width_ * src_stride_coeff,
ref_, width_ * ref_stride_coeff, &sse1));
const unsigned int var2 = variance_ref(src_, ref_, log2width_,
log2height_, src_stride_coeff,
ref_stride_coeff, &sse2,
use_high_bit_depth_, bit_depth_);
EXPECT_EQ(sse1, sse2);
EXPECT_EQ(var1, var2);
}
......@@ -203,10 +381,23 @@ void VarianceTest<VarianceFunctionType>::RefTest() {
template<typename VarianceFunctionType>
void VarianceTest<VarianceFunctionType>::OneQuarterTest() {
memset(src_, 255, block_size_);
const int half = block_size_ / 2;
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
memset(src_, 255, block_size_);
memset(ref_, 255, half);
memset(ref_ + half, 0, half);
} else {
vpx_memset16(CONVERT_TO_SHORTPTR(src_), 255 << (bit_depth_ - 8),
block_size_);
vpx_memset16(CONVERT_TO_SHORTPTR(ref_), 255 << (bit_depth_ - 8), half);
vpx_memset16(CONVERT_TO_SHORTPTR(ref_) + half, 0, half);
}
#else
memset(src_, 255, block_size_);
memset(ref_, 255, half);
memset(ref_ + half, 0, half);
#endif
unsigned int sse;
unsigned int var;
ASM_REGISTER_STATE_CHECK(var = variance_(src_, width_, ref_, width_, &sse));
......@@ -264,8 +455,10 @@ void MseTest<MseFunctionType>::RefTest_mse() {
ref_[j] = rnd.Rand8();
}
unsigned int sse1, sse2;
const int stride_coeff = 1;
ASM_REGISTER_STATE_CHECK(mse_(src_, width_, ref_, width_, &sse1));
variance_ref(src_, ref_, log2width_, log2height_, &sse2);
variance_ref(src_, ref_, log2width_, log2height_, stride_coeff,
stride_coeff, &sse2, false, VPX_BITS_8);
EXPECT_EQ(sse1, sse2);
}
}
......@@ -279,9 +472,10 @@ void MseTest<MseFunctionType>::RefTest_sse() {
}
unsigned int sse2;
unsigned int var1;
ASM_REGISTER_STATE_CHECK(
var1 = mse_(src_, width_, ref_, width_));
variance_ref(src_, ref_, log2width_, log2height_, &sse2);
const int stride_coeff = 1;
ASM_REGISTER_STATE_CHECK(var1 = mse_(src_, width_, ref_, width_));
variance_ref(src_, ref_, log2width_, log2height_, stride_coeff,
stride_coeff, &sse2, false, VPX_BITS_8);
EXPECT_EQ(var1, sse2);
}
}
......@@ -308,16 +502,59 @@ void MseTest<MseFunctionType>::MaxTest_sse() {
#endif
#if CONFIG_VP9_ENCODER
unsigned int subpel_avg_variance_ref(const uint8_t *ref,
const uint8_t *src,
const uint8_t *second_pred,
int l2w, int l2h,
int xoff, int yoff,
unsigned int *sse_ptr) {
unsigned int *sse_ptr,
bool use_high_bit_depth,
vpx_bit_depth_t bit_depth) {
#if CONFIG_VP9_HIGHBITDEPTH
int64_t se = 0;
uint64_t sse = 0;
const int w = 1 << l2w;
const int h = 1 << l2h;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
// bilinear interpolation at a 16th pel step
if (!use_high_bit_depth) {
const int a1 = ref[(w + 1) * (y + 0) + x + 0];
const int a2 = ref[(w + 1) * (y + 0) + x + 1];
const int b1 = ref[(w + 1) * (y + 1) + x + 0];
const int b2 = ref[(w + 1) * (y + 1) + x + 1];
const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
const int r = a + (((b - a) * yoff + 8) >> 4);
const int diff = ((r + second_pred[w * y + x] + 1) >> 1) - src[w * y + x];
se += diff;
sse += diff * diff;
} else {
uint16_t *ref16 = CONVERT_TO_SHORTPTR(ref);
uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
uint16_t *sec16 = CONVERT_TO_SHORTPTR(second_pred);
const int a1 = ref16[(w + 1) * (y + 0) + x + 0];
const int a2 = ref16[(w + 1) * (y + 0) + x + 1];
const int b1 = ref16[(w + 1) * (y + 1) + x + 0];
const int b2 = ref16[(w + 1) * (y + 1) + x + 1];
const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
const int r = a + (((b - a) * yoff + 8) >> 4);
const int diff = ((r + sec16[w * y + x] + 1) >> 1) - src16[w * y + x];
se += diff;
sse += diff * diff;
}
}
}
if (bit_depth > 8) {
sse = ROUND_POWER_OF_TWO(sse, 2*(bit_depth-8));
se = ROUND_POWER_OF_TWO(se, bit_depth-8);
}
#else
int se = 0;
unsigned int sse = 0;
const int w = 1 << l2w, h = 1 << l2h;
const int w = 1 << l2w;
const int h = 1 << l2h;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
// bilinear interpolation at a 16th pel step
......@@ -328,11 +565,12 @@ unsigned int subpel_avg_variance_ref(const uint8_t *ref,
const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
const int r = a + (((b - a) * yoff + 8) >> 4);
int diff = ((r + second_pred[w * y + x] + 1) >> 1) - src[w * y + x];
const int diff = ((r + second_pred[w * y + x] + 1) >> 1) - src[w * y + x];
se += diff;
sse += diff * diff;
}
}
#endif // CONFIG_VP9_HIGHBITDEPTH
*sse_ptr = sse;
return sse - (((int64_t) se * se) >> (l2w + l2h));
}
......@@ -340,44 +578,84 @@ unsigned int subpel_avg_variance_ref(const uint8_t *ref,
template<typename SubpelVarianceFunctionType>
class SubpelVarianceTest
: public ::testing::TestWithParam<tuple<int, int,
SubpelVarianceFunctionType> > {
SubpelVarianceFunctionType, int> > {
public:
virtual void SetUp() {
const tuple<int, int, SubpelVarianceFunctionType>& params =
const tuple<int, int, SubpelVarianceFunctionType, int>& params =
this->GetParam();
log2width_ = get<0>(params);
width_ = 1 << log2width_;
log2height_ = get<1>(params);
height_ = 1 << log2height_;
subpel_variance_ = get<2>(params);
if (get<3>(params)) {
bit_depth_ = (vpx_bit_depth_t) get<3>(params);
use_high_bit_depth_ = true;
} else {
bit_depth_ = VPX_BITS_8;
use_high_bit_depth_ = false;
}
mask_ = (1 << bit_depth_)-1;
rnd_.Reset(ACMRandom::DeterministicSeed());
block_size_ = width_ * height_;
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
src_ = reinterpret_cast<uint8_t *>(vpx_memalign(16, block_size_));
sec_ = reinterpret_cast<uint8_t *>(vpx_memalign(16, block_size_));
ref_ = new uint8_t[block_size_ + width_ + height_ + 1];
} else {
src_ = CONVERT_TO_BYTEPTR(
reinterpret_cast<uint16_t *>(
vpx_memalign(16, block_size_*sizeof(uint16_t))));
sec_ = CONVERT_TO_BYTEPTR(
reinterpret_cast<uint16_t *>(
vpx_memalign(16, block_size_*sizeof(uint16_t))));
ref_ = CONVERT_TO_BYTEPTR(
new uint16_t[block_size_ + width_ + height_ + 1]);
}
#else
src_ = reinterpret_cast<uint8_t *>(vpx_memalign(16, block_size_));
sec_ = reinterpret_cast<uint8_t *>(vpx_memalign(16, block_size_));
ref_ = new uint8_t[block_size_ + width_ + height_ + 1];
#endif // CONFIG_VP9_HIGHBITDEPTH
ASSERT_TRUE(src_ != NULL);
ASSERT_TRUE(sec_ != NULL);
ASSERT_TRUE(ref_ != NULL);
}
virtual void TearDown() {
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
vpx_free(src_);
delete[] ref_;
vpx_free(sec_);
} else {
vpx_free(CONVERT_TO_SHORTPTR(src_));
delete[] CONVERT_TO_SHORTPTR(ref_);
vpx_free(CONVERT_TO_SHORTPTR(sec_));
}
#else
vpx_free(src_);
delete[] ref_;
vpx_free(sec_);
#endif
libvpx_test::ClearSystemState();
}
protected:
void RefTest();
void ExtremeRefTest();
ACMRandom rnd_;
uint8_t *src_;
uint8_t *ref_;
uint8_t *sec_;
bool use_high_bit_depth_;
vpx_bit_depth_t bit_depth_;
int width_, log2width_;
int height_, log2height_;
int block_size_;
int block_size_, mask_;
SubpelVarianceFunctionType subpel_variance_;
};
......@@ -385,18 +663,78 @@ template<typename SubpelVarianceFunctionType>
void SubpelVarianceTest<SubpelVarianceFunctionType>::RefTest() {
for (int x = 0; x < 16; ++x) {
for (int y = 0; y < 16; ++y) {
#if CONFIG_VP9_HIGHBITDEPTH
if (!use_high_bit_depth_) {
for (int j = 0; j < block_size_; j++) {
src_[j] = rnd_.Rand8();
}
for (int j = 0; j < block_size_ + width_ + height_ + 1; j++) {
ref_[j] = rnd_.Rand8();
}
} else {
for (int j = 0; j < block_size_; j++) {
CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask_;
}
for (int j = 0; j < block_size_ + width_ + height_ + 1; j++) {
CONVERT_TO_SHORTPTR(ref_)[j] = rnd_.Rand16() & mask_;
}
}
#else
for (int j = 0; j < block_size_; j++) {
src_[j] = rnd_.Rand8();
}
for (int j = 0; j < block_size_ + width_ + height_ + 1; j++) {
ref_[j] = rnd_.Rand8();
}
#endif // CONFIG_VP9_HIGHBITDEPTH
unsigned int sse1, sse2;
unsigned int var1;
ASM_REGISTER_STATE_CHECK(var1 = subpel_variance_(ref_, width_ + 1, x, y,
src_, width_, &sse1));
const unsigned int var2 = subpel_variance_ref(ref_, src_, log2width_,
log2height_, x, y, &sse2);
log2height_, x, y, &sse2,
use_high_bit_depth_,
bit_depth_);
EXPECT_EQ(sse1, sse2) << "at position " << x << ", " << y;
EXPECT_EQ(var1, var2) << "at position " << x << ", " << y;
}
}
}
template<typename SubpelVarianceFunctionType>
void SubpelVarianceTest<SubpelVarianceFunctionType>::ExtremeRefTest() {
// Compare against reference.
// Src: Set the first half of values to 0, the second half to the maximum.
// Ref: Set the first half of values to the maximum, the second half to 0.
for (int x = 0; x < 16; ++x) {
for (int y = 0; y < 16; ++y) {