2016-05-04 01:23:06 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
#include <math.h>
|
|
|
|
#include "test/clear_system_state.h"
|
|
|
|
#include "test/register_state_check.h"
|
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
|
|
|
#include "./vpx_dsp_rtcd.h"
|
|
|
|
#include "vpx/vpx_integer.h"
|
2016-07-13 16:35:25 +02:00
|
|
|
#include "vpx_dsp/postproc.h"
|
2016-05-04 01:23:06 +02:00
|
|
|
#include "vpx_mem/vpx_mem.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-07-15 17:27:34 +02:00
|
|
|
static const int kNoiseSize = 3072;
|
|
|
|
|
2016-05-04 01:23:06 +02:00
|
|
|
// TODO(jimbankoski): make width and height integers not unsigned.
|
2016-07-15 17:27:34 +02:00
|
|
|
typedef void (*AddNoiseFunc)(uint8_t *start, const int8_t *noise,
|
|
|
|
int blackclamp, int whiteclamp,
|
|
|
|
int width, int height, int pitch);
|
2016-05-04 01:23:06 +02:00
|
|
|
|
|
|
|
class AddNoiseTest
|
|
|
|
: public ::testing::TestWithParam<AddNoiseFunc> {
|
|
|
|
public:
|
|
|
|
virtual void TearDown() {
|
|
|
|
libvpx_test::ClearSystemState();
|
|
|
|
}
|
|
|
|
virtual ~AddNoiseTest() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
double stddev6(char a, char b, char c, char d, char e, char f) {
|
|
|
|
const double n = (a + b + c + d + e + f) / 6.0;
|
|
|
|
const double v = ((a - n) * (a - n) + (b - n) * (b - n) + (c - n) * (c - n) +
|
|
|
|
(d - n) * (d - n) + (e - n) * (e - n) + (f - n) * (f - n)) /
|
|
|
|
6.0;
|
|
|
|
return sqrt(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(AddNoiseTest, CheckNoiseAdded) {
|
|
|
|
const int width = 64;
|
|
|
|
const int height = 64;
|
|
|
|
const int image_size = width * height;
|
2016-07-15 17:27:34 +02:00
|
|
|
int8_t noise[kNoiseSize];
|
|
|
|
const int clamp = vpx_setup_noise(4.4, noise, kNoiseSize);
|
|
|
|
uint8_t *const s = reinterpret_cast<uint8_t *>(vpx_calloc(image_size,
|
|
|
|
sizeof(*s)));
|
|
|
|
ASSERT_TRUE(s != NULL);
|
|
|
|
memset(s, 99, image_size * sizeof(*s));
|
2016-05-04 01:23:06 +02:00
|
|
|
|
2016-07-15 17:27:34 +02:00
|
|
|
ASM_REGISTER_STATE_CHECK(GetParam()(s, noise, clamp, clamp,
|
|
|
|
width, height, width));
|
2016-05-04 01:23:06 +02:00
|
|
|
|
|
|
|
// Check to make sure we don't end up having either the same or no added
|
|
|
|
// noise either vertically or horizontally.
|
|
|
|
for (int i = 0; i < image_size - 6 * width - 6; ++i) {
|
|
|
|
const double hd = stddev6(s[i] - 99, s[i + 1] - 99, s[i + 2] - 99,
|
|
|
|
s[i + 3] - 99, s[i + 4] - 99, s[i + 5] - 99);
|
|
|
|
const double vd = stddev6(s[i] - 99, s[i + width] - 99,
|
|
|
|
s[i + 2 * width] - 99, s[i + 3 * width] - 99,
|
|
|
|
s[i + 4 * width] - 99, s[i + 5 * width] - 99);
|
|
|
|
|
|
|
|
EXPECT_NE(hd, 0);
|
|
|
|
EXPECT_NE(vd, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize pixels in the image to 255 and check for roll over.
|
|
|
|
memset(s, 255, image_size);
|
|
|
|
|
2016-07-15 17:27:34 +02:00
|
|
|
ASM_REGISTER_STATE_CHECK(GetParam()(s, noise, clamp, clamp,
|
|
|
|
width, height, width));
|
2016-05-04 01:23:06 +02:00
|
|
|
|
|
|
|
// Check to make sure don't roll over.
|
|
|
|
for (int i = 0; i < image_size; ++i) {
|
2016-07-13 21:39:01 +02:00
|
|
|
EXPECT_GT(static_cast<int>(s[i]), clamp) << "i = " << i;
|
2016-05-04 01:23:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize pixels in the image to 0 and check for roll under.
|
|
|
|
memset(s, 0, image_size);
|
|
|
|
|
2016-07-15 17:27:34 +02:00
|
|
|
ASM_REGISTER_STATE_CHECK(GetParam()(s, noise, clamp, clamp,
|
|
|
|
width, height, width));
|
2016-05-04 01:23:06 +02:00
|
|
|
|
|
|
|
// Check to make sure don't roll under.
|
|
|
|
for (int i = 0; i < image_size; ++i) {
|
2016-07-13 21:39:01 +02:00
|
|
|
EXPECT_LT(static_cast<int>(s[i]), 255 - clamp) << "i = " << i;
|
2016-05-04 01:23:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
vpx_free(s);
|
|
|
|
}
|
|
|
|
|
2016-05-07 21:47:49 +02:00
|
|
|
TEST_P(AddNoiseTest, CheckCvsAssembly) {
|
2016-05-04 01:23:06 +02:00
|
|
|
const int width = 64;
|
|
|
|
const int height = 64;
|
|
|
|
const int image_size = width * height;
|
2016-07-15 17:27:34 +02:00
|
|
|
int8_t noise[kNoiseSize];
|
|
|
|
const int clamp = vpx_setup_noise(4.4, noise, kNoiseSize);
|
2016-05-04 01:23:06 +02:00
|
|
|
|
|
|
|
uint8_t *const s = reinterpret_cast<uint8_t *>(vpx_calloc(image_size, 1));
|
|
|
|
uint8_t *const d = reinterpret_cast<uint8_t *>(vpx_calloc(image_size, 1));
|
2016-07-15 17:27:34 +02:00
|
|
|
ASSERT_TRUE(s != NULL);
|
|
|
|
ASSERT_TRUE(d != NULL);
|
2016-05-04 01:23:06 +02:00
|
|
|
|
|
|
|
memset(s, 99, image_size);
|
|
|
|
memset(d, 99, image_size);
|
|
|
|
|
2016-05-07 21:47:49 +02:00
|
|
|
srand(0);
|
2016-07-15 17:27:34 +02:00
|
|
|
ASM_REGISTER_STATE_CHECK(
|
|
|
|
GetParam()(s, noise, clamp, clamp, width, height, width));
|
2016-05-07 21:47:49 +02:00
|
|
|
srand(0);
|
2016-07-15 17:27:34 +02:00
|
|
|
ASM_REGISTER_STATE_CHECK(
|
|
|
|
vpx_plane_add_noise_c(d, noise, clamp, clamp, width, height, width));
|
2016-05-04 01:23:06 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < image_size; ++i) {
|
2016-07-13 21:39:01 +02:00
|
|
|
EXPECT_EQ(static_cast<int>(s[i]), static_cast<int>(d[i])) << "i = " << i;
|
2016-05-04 01:23:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
vpx_free(d);
|
|
|
|
vpx_free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(C, AddNoiseTest,
|
|
|
|
::testing::Values(vpx_plane_add_noise_c));
|
|
|
|
|
|
|
|
#if HAVE_SSE2
|
|
|
|
INSTANTIATE_TEST_CASE_P(SSE2, AddNoiseTest,
|
|
|
|
::testing::Values(vpx_plane_add_noise_sse2));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_MSA
|
|
|
|
INSTANTIATE_TEST_CASE_P(MSA, AddNoiseTest,
|
|
|
|
::testing::Values(vpx_plane_add_noise_msa));
|
|
|
|
#endif
|
|
|
|
} // namespace
|