diff --git a/test/add_noise_test.cc b/test/add_noise_test.cc index 44b8d74c6..35aaadfa7 100644 --- a/test/add_noise_test.cc +++ b/test/add_noise_test.cc @@ -49,7 +49,7 @@ TEST_P(AddNoiseTest, CheckNoiseAdded) { const int height = 64; const int image_size = width * height; char noise[3072]; - const int clamp = vpx_setup_noise(sizeof(noise), 4.4, noise); + const int clamp = vpx_setup_noise(4.4, sizeof(noise), noise); for (int i = 0; i < 16; i++) { blackclamp[i] = clamp; @@ -84,7 +84,7 @@ TEST_P(AddNoiseTest, CheckNoiseAdded) { // Check to make sure don't roll over. for (int i = 0; i < image_size; ++i) { - EXPECT_GT((int)s[i], clamp) << "i = " << i; + EXPECT_GT(static_cast(s[i]), clamp) << "i = " << i; } // Initialize pixels in the image to 0 and check for roll under. @@ -95,7 +95,7 @@ TEST_P(AddNoiseTest, CheckNoiseAdded) { // Check to make sure don't roll under. for (int i = 0; i < image_size; ++i) { - EXPECT_LT((int)s[i], 255 - clamp) << "i = " << i; + EXPECT_LT(static_cast(s[i]), 255 - clamp) << "i = " << i; } vpx_free(s); @@ -110,7 +110,7 @@ TEST_P(AddNoiseTest, CheckCvsAssembly) { const int image_size = width * height; char noise[3072]; - const int clamp = vpx_setup_noise(sizeof(noise), 4.4, noise); + const int clamp = vpx_setup_noise(4.4, sizeof(noise), noise); for (int i = 0; i < 16; i++) { blackclamp[i] = clamp; @@ -133,7 +133,7 @@ TEST_P(AddNoiseTest, CheckCvsAssembly) { width, height, width)); for (int i = 0; i < image_size; ++i) { - EXPECT_EQ((int)s[i], (int)d[i]) << "i = " << i; + EXPECT_EQ(static_cast(s[i]), static_cast(d[i])) << "i = " << i; } vpx_free(d); diff --git a/vp8/common/postproc.c b/vp8/common/postproc.c index 82b66001d..05e2bfc60 100644 --- a/vp8/common/postproc.c +++ b/vp8/common/postproc.c @@ -495,7 +495,7 @@ int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t struct postproc_state *ppstate = &oci->postproc_state; vp8_clear_system_state(); sigma = noise_level + .5 + .6 * q / 63.0; - clamp = vpx_setup_noise(sizeof(ppstate->noise), sigma, + clamp = vpx_setup_noise(sigma, sizeof(ppstate->noise), ppstate->noise); for (i = 0; i < 16; i++) { diff --git a/vp9/common/vp9_postproc.c b/vp9/common/vp9_postproc.c index 265c37fd2..a3697b9b9 100644 --- a/vp9/common/vp9_postproc.c +++ b/vp9/common/vp9_postproc.c @@ -421,7 +421,7 @@ int vp9_post_proc_frame(struct VP9Common *cm, int clamp, i; vpx_clear_system_state(); sigma = noise_level + .5 + .6 * q / 63.0; - clamp = vpx_setup_noise(sizeof(ppstate->noise), sigma, + clamp = vpx_setup_noise(sigma, sizeof(ppstate->noise), ppstate->noise); for (i = 0; i < 16; i++) { diff --git a/vpx_dsp/add_noise.c b/vpx_dsp/add_noise.c index baede2850..4ae67a813 100644 --- a/vpx_dsp/add_noise.c +++ b/vpx_dsp/add_noise.c @@ -24,11 +24,11 @@ void vpx_plane_add_noise_c(uint8_t *start, char *noise, unsigned int width, unsigned int height, int pitch) { unsigned int i, j; - for (i = 0; i < height; i++) { + for (i = 0; i < height; ++i) { uint8_t *pos = start + i * pitch; char *ref = (char *)(noise + (rand() & 0xff)); // NOLINT - for (j = 0; j < width; j++) { + for (j = 0; j < width; ++j) { int v = pos[j]; v = clamp(v - blackclamp[0], 0, 255); @@ -45,28 +45,27 @@ static double gaussian(double sigma, double mu, double x) { (exp(-(x - mu) * (x - mu) / (2 * sigma * sigma))); } -int vpx_setup_noise(int size, double sigma, char *noise) { +int vpx_setup_noise(double sigma, int size, char *noise) { char char_dist[256]; - int next, i, j; - - next = 0; + int next = 0, i, j; // set up a 256 entry lookup that matches gaussian distribution - for (i = -32; i < 32; i++) { - int a_i = (int) (0.5 + 256 * gaussian(sigma, 0, i)); + for (i = -32; i < 32; ++i) { + const int a_i = (int) (0.5 + 256 * gaussian(sigma, 0, i)); if (a_i) { - for (j = 0; j < a_i; j++) { - char_dist[next + j] = (char) (i); + for (j = 0; j < a_i; ++j) { + char_dist[next + j] = (char)i; } next = next + j; } } // Rounding error - might mean we have less than 256. - for (; next < 256; next++) + for (; next < 256; ++next) { char_dist[next] = 0; + } - for (i = 0; i < size; i++) { + for (i = 0; i < size; ++i) { noise[i] = char_dist[rand() & 0xff]; // NOLINT } diff --git a/vpx_dsp/postproc.h b/vpx_dsp/postproc.h index 389b0eed7..78d11b186 100644 --- a/vpx_dsp/postproc.h +++ b/vpx_dsp/postproc.h @@ -15,7 +15,8 @@ extern "C" { #endif -int vpx_setup_noise(int size, double sigma, char *noise); +// Fills a noise buffer with gaussian noise strength determined by sigma. +int vpx_setup_noise(double sigma, int size, char *noise); #ifdef __cplusplus }