addnoise : clear out static size for generated noise
authorJim Bankoski <jimbankoski@google.com>
Fri, 15 Jul 2016 22:52:45 +0000 (15:52 -0700)
committerJim Bankoski <jimbankoski@google.com>
Fri, 15 Jul 2016 22:52:45 +0000 (15:52 -0700)
Change-Id: I5d4343f2da9cd4b01dd37be7a048d159fec109d1

vp8/common/alloccommon.c
vp8/common/postproc.c
vp8/common/postproc.h
vp9/common/vp9_alloccommon.c
vp9/common/vp9_postproc.c
vp9/common/vp9_postproc.h

index 8dfd4ce..b175e4a 100644 (file)
@@ -32,6 +32,9 @@ void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
 
     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);
index 5468f24..781d6f5 100644 (file)
@@ -411,6 +411,16 @@ int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t
         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,16 +504,15 @@ 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;
-            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;
         }
 
         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,
index 77c4a04..2cc1e63 100644 (file)
@@ -17,10 +17,10 @@ struct postproc_state
 {
     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"
index b4b120b..9463412 100644 (file)
@@ -104,7 +104,9 @@ void vp9_free_postproc_buffers(VP9_COMMON *cm) {
   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
index 6adaf04..4356adc 100644 (file)
@@ -378,6 +378,14 @@ int vp9_post_proc_frame(struct VP9Common *cm,
     }
   }
 
+  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 &&
@@ -419,14 +427,14 @@ int vp9_post_proc_frame(struct VP9Common *cm,
       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;
index 5a4eb8d..810ac2a 100644 (file)
@@ -25,13 +25,13 @@ extern "C" {
 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;
   MODE_INFO *prev_mi;
   int clamp;
   uint8_t *limits;
+  int8_t *generated_noise;
 };
 
 struct VP9Common;