shithub: libvpx

Download patch

ref: ce6678fdc96a9dbf8e8f134ab45d64560812edf1
parent: da1bda0fb248b5f5a31cbc07caeb3ed34a763ea2
parent: cb957c302af0995ea9ba7455b243890494ba787c
author: James Bankoski <jimbankoski@google.com>
date: Fri Jul 15 21:48:07 EDT 2016

Merge "addnoise : clear out static size for generated noise"

--- a/vp8/common/alloccommon.c
+++ b/vp8/common/alloccommon.c
@@ -32,6 +32,9 @@
 
     vpx_free(oci->pp_limits_buffer);
     oci->pp_limits_buffer = NULL;
+
+    vpx_free(oci->postproc_state.generated_noise);
+    oci->postproc_state.generated_noise = NULL;
 #endif
 
     vpx_free(oci->above_context);
--- a/vp8/common/postproc.c
+++ b/vp8/common/postproc.c
@@ -411,6 +411,16 @@
         oci->postproc_state.last_frame_valid = 1;
         return 0;
     }
+    if (flags & VP8D_ADDNOISE)
+    {
+      if (!oci->postproc_state.generated_noise)
+      {
+          oci->postproc_state.generated_noise = vpx_calloc(
+              oci->Width + 256, sizeof(*oci->postproc_state.generated_noise));
+          if (!oci->postproc_state.generated_noise)
+            return 1;
+      }
+    }
 
     /* Allocate post_proc_buffer_int if needed */
     if ((flags & VP8D_MFQE) && !oci->post_proc_buffer_int_used)
@@ -494,9 +504,8 @@
             struct postproc_state *ppstate = &oci->postproc_state;
             vp8_clear_system_state();
             sigma = noise_level + .5 + .6 * q / 63.0;
-            oci->postproc_state.clamp = vpx_setup_noise(sigma,
-                                                        ppstate->noise,
-                                                        sizeof(ppstate->noise));
+            ppstate->clamp = vpx_setup_noise(sigma, ppstate->generated_noise,
+                                             oci->Width + 256);
             ppstate->last_q = q;
             ppstate->last_noise = noise_level;
         }
@@ -503,7 +512,7 @@
 
         vpx_plane_add_noise
         (oci->post_proc_buffer.y_buffer,
-         oci->postproc_state.noise,
+         oci->postproc_state.generated_noise,
          oci->postproc_state.clamp,
          oci->postproc_state.clamp,
          oci->post_proc_buffer.y_width, oci->post_proc_buffer.y_height,
--- a/vp8/common/postproc.h
+++ b/vp8/common/postproc.h
@@ -17,10 +17,10 @@
 {
     int           last_q;
     int           last_noise;
-    int8_t        noise[3072];
     int           last_base_qindex;
     int           last_frame_valid;
     int           clamp;
+    int8_t       *generated_noise;
 };
 #include "onyxc_int.h"
 #include "ppflags.h"
--- a/vp9/common/vp9_alloccommon.c
+++ b/vp9/common/vp9_alloccommon.c
@@ -104,7 +104,9 @@
   vpx_free_frame_buffer(&cm->post_proc_buffer);
   vpx_free_frame_buffer(&cm->post_proc_buffer_int);
   vpx_free(cm->postproc_state.limits);
-  cm->postproc_state.limits = 0;
+  cm->postproc_state.limits = NULL;
+  vpx_free(cm->postproc_state.generated_noise);
+  cm->postproc_state.generated_noise = NULL;
 #else
   (void)cm;
 #endif
--- a/vp9/common/vp9_postproc.c
+++ b/vp9/common/vp9_postproc.c
@@ -379,6 +379,14 @@
     }
   }
 
+  if (flags & VP9D_ADDNOISE) {
+    if (!cm->postproc_state.generated_noise) {
+      cm->postproc_state.generated_noise = vpx_calloc(
+          cm->width + 256, sizeof(*cm->postproc_state.generated_noise));
+      if (!cm->postproc_state.generated_noise)
+        return 1;
+    }
+  }
 
   if ((flags & VP9D_MFQE) && cm->current_video_frame >= 2 &&
       ppstate->last_frame_valid && cm->bit_depth == 8 &&
@@ -420,14 +428,14 @@
       double sigma;
       vpx_clear_system_state();
       sigma = noise_level + .5 + .6 * q / 63.0;
-      ppstate->clamp = vpx_setup_noise(sigma, ppstate->noise,
-                                       sizeof(ppstate->noise));
+      ppstate->clamp = vpx_setup_noise(sigma, ppstate->generated_noise,
+                                       cm->width + 256);
       ppstate->last_q = q;
       ppstate->last_noise = noise_level;
     }
-    vpx_plane_add_noise(ppbuf->y_buffer, ppstate->noise, ppstate->clamp,
-                        ppstate->clamp, ppbuf->y_width, ppbuf->y_height,
-                        ppbuf->y_stride);
+    vpx_plane_add_noise(ppbuf->y_buffer, ppstate->generated_noise,
+                        ppstate->clamp, ppstate->clamp, ppbuf->y_width,
+                        ppbuf->y_height, ppbuf->y_stride);
   }
 
   *dest = *ppbuf;
--- a/vp9/common/vp9_postproc.h
+++ b/vp9/common/vp9_postproc.h
@@ -25,7 +25,6 @@
 struct postproc_state {
   int last_q;
   int last_noise;
-  int8_t noise[3072];
   int last_base_qindex;
   int last_frame_valid;
   MODE_INFO *prev_mip;
@@ -32,6 +31,7 @@
   MODE_INFO *prev_mi;
   int clamp;
   uint8_t *limits;
+  int8_t *generated_noise;
 };
 
 struct VP9Common;