shithub: libvpx

Download patch

ref: 7eec1f31b50e05f6fe06bccda8db08d75a6ff0f2
parent: 8dd3bef7efb00fa3f6f219e61c72bd6b60f1fdd2
parent: e736691a6ded0baf903f20ecee32223035fe4504
author: James Bankoski <[email protected]>
date: Wed Jul 13 18:04:47 EDT 2016

Merge "postproc: noise style fixes."

--- a/test/add_noise_test.cc
+++ b/test/add_noise_test.cc
@@ -49,7 +49,7 @@
   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 @@
 
   // 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<int>(s[i]), clamp) << "i = " << i;
   }
 
   // Initialize pixels in the image to 0 and check for roll under.
@@ -95,7 +95,7 @@
 
   // 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<int>(s[i]), 255 - clamp) << "i = " << i;
   }
 
   vpx_free(s);
@@ -110,7 +110,7 @@
   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 @@
                                                  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<int>(s[i]), static_cast<int>(d[i])) << "i = " << i;
   }
 
   vpx_free(d);
--- a/vp8/common/postproc.c
+++ b/vp8/common/postproc.c
@@ -495,7 +495,7 @@
             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++)
             {
--- a/vp9/common/vp9_postproc.c
+++ b/vp9/common/vp9_postproc.c
@@ -421,7 +421,7 @@
       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++) {
--- a/vpx_dsp/add_noise.c
+++ b/vpx_dsp/add_noise.c
@@ -24,11 +24,11 @@
                            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,18 +45,16 @@
          (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;
+  int next = 0, i, j;
 
-  next = 0;
-
   // 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;
     }
@@ -63,10 +61,11 @@
   }
 
   // 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
   }
 
--- 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
 }