shithub: libvpx

Download patch

ref: 2612b99cc7a64d5377f59de4775a308e6cdd5706
parent: c4048dbdd39dbd4763852a6d0a27f183677c4225
author: Dmitry Kovalev <dkovalev@google.com>
date: Mon Aug 19 20:42:25 EDT 2013

Adding VP9_FILTER_BITS constant.

Removing VP9_FILTER_WEIGHT, VP9_FILTER_SHIFT, BLOCK_WIDTH_HEIGHT
constants. Using ROUND_POWER_OF_TWO for rounding.

Change-Id: I2e8d6858dcd600a87096138209731137d7decc24

--- a/vp9/common/vp9_convolve.c
+++ b/vp9/common/vp9_convolve.c
@@ -17,9 +17,6 @@
 #include "vpx/vpx_integer.h"
 #include "vpx_ports/mem.h"
 
-#define VP9_FILTER_WEIGHT 128
-#define VP9_FILTER_SHIFT  7
-
 /* Assume a bank of 16 filters to choose from. There are two implementations
  * for filter wrapping behavior, since we want to be able to pick which filter
  * to start with. We could either:
@@ -43,7 +40,7 @@
                              const int16_t *filter_x0, int x_step_q4,
                              const int16_t *filter_y, int y_step_q4,
                              int w, int h, int taps) {
-  int x, y, k, sum;
+  int x, y, k;
   const int16_t *filter_x_base = filter_x0;
 
 #if ALIGN_FILTERS_256
@@ -64,13 +61,13 @@
     for (x = 0; x < w; ++x) {
       /* Per-pixel src offset */
       int src_x = (x_q4 - x0_q4) >> 4;
+      int sum = 0;
 
-      for (sum = 0, k = 0; k < taps; ++k) {
+      for (k = 0; k < taps; ++k)
         sum += src[src_x + k] * filter_x[k];
-      }
-      sum += (VP9_FILTER_WEIGHT >> 1);
-      dst[x] = clip_pixel(sum >> VP9_FILTER_SHIFT);
 
+      dst[x] = clip_pixel(ROUND_POWER_OF_TWO(sum, VP9_FILTER_BITS));
+
       /* Adjust source and filter to use for the next pixel */
       x_q4 += x_step_q4;
       filter_x = filter_x_base + (x_q4 & 0xf) * taps;
@@ -85,7 +82,7 @@
                                  const int16_t *filter_x0, int x_step_q4,
                                  const int16_t *filter_y, int y_step_q4,
                                  int w, int h, int taps) {
-  int x, y, k, sum;
+  int x, y, k;
   const int16_t *filter_x_base = filter_x0;
 
 #if ALIGN_FILTERS_256
@@ -106,13 +103,14 @@
     for (x = 0; x < w; ++x) {
       /* Per-pixel src offset */
       int src_x = (x_q4 - x0_q4) >> 4;
+      int sum = 0;
 
-      for (sum = 0, k = 0; k < taps; ++k) {
+      for (k = 0; k < taps; ++k)
         sum += src[src_x + k] * filter_x[k];
-      }
-      sum += (VP9_FILTER_WEIGHT >> 1);
-      dst[x] = (dst[x] + clip_pixel(sum >> VP9_FILTER_SHIFT) + 1) >> 1;
 
+      dst[x] = ROUND_POWER_OF_TWO(dst[x] +
+                   clip_pixel(ROUND_POWER_OF_TWO(sum, VP9_FILTER_BITS)), 1);
+
       /* Adjust source and filter to use for the next pixel */
       x_q4 += x_step_q4;
       filter_x = filter_x_base + (x_q4 & 0xf) * taps;
@@ -127,7 +125,7 @@
                             const int16_t *filter_x, int x_step_q4,
                             const int16_t *filter_y0, int y_step_q4,
                             int w, int h, int taps) {
-  int x, y, k, sum;
+  int x, y, k;
 
   const int16_t *filter_y_base = filter_y0;
 
@@ -148,13 +146,14 @@
     for (y = 0; y < h; ++y) {
       /* Per-pixel src offset */
       int src_y = (y_q4 - y0_q4) >> 4;
+      int sum = 0;
 
-      for (sum = 0, k = 0; k < taps; ++k) {
+      for (k = 0; k < taps; ++k)
         sum += src[(src_y + k) * src_stride] * filter_y[k];
-      }
-      sum += (VP9_FILTER_WEIGHT >> 1);
-      dst[y * dst_stride] = clip_pixel(sum >> VP9_FILTER_SHIFT);
 
+      dst[y * dst_stride] =
+          clip_pixel(ROUND_POWER_OF_TWO(sum, VP9_FILTER_BITS));
+
       /* Adjust source and filter to use for the next pixel */
       y_q4 += y_step_q4;
       filter_y = filter_y_base + (y_q4 & 0xf) * taps;
@@ -169,7 +168,7 @@
                                 const int16_t *filter_x, int x_step_q4,
                                 const int16_t *filter_y0, int y_step_q4,
                                 int w, int h, int taps) {
-  int x, y, k, sum;
+  int x, y, k;
 
   const int16_t *filter_y_base = filter_y0;
 
@@ -190,13 +189,13 @@
     for (y = 0; y < h; ++y) {
       /* Per-pixel src offset */
       int src_y = (y_q4 - y0_q4) >> 4;
+      int sum = 0;
 
-      for (sum = 0, k = 0; k < taps; ++k) {
+      for (k = 0; k < taps; ++k)
         sum += src[(src_y + k) * src_stride] * filter_y[k];
-      }
-      sum += (VP9_FILTER_WEIGHT >> 1);
-      dst[y * dst_stride] =
-          (dst[y * dst_stride] + clip_pixel(sum >> VP9_FILTER_SHIFT) + 1) >> 1;
+
+      dst[y * dst_stride] = ROUND_POWER_OF_TWO(dst[y * dst_stride] +
+           clip_pixel(ROUND_POWER_OF_TWO(sum, VP9_FILTER_BITS)), 1);
 
       /* Adjust source and filter to use for the next pixel */
       y_q4 += y_step_q4;
--- a/vp9/common/vp9_convolve.h
+++ b/vp9/common/vp9_convolve.h
@@ -13,6 +13,8 @@
 #include "./vpx_config.h"
 #include "vpx/vpx_integer.h"
 
+#define VP9_FILTER_BITS 7
+
 typedef void (*convolve_fn_t)(const uint8_t *src, ptrdiff_t src_stride,
                               uint8_t *dst, ptrdiff_t dst_stride,
                               const int16_t *filter_x, int x_step_q4,
--- a/vp9/common/vp9_filter.h
+++ b/vp9/common/vp9_filter.h
@@ -12,12 +12,7 @@
 #define VP9_COMMON_VP9_FILTER_H_
 
 #include "vpx_config.h"
-#include "vpx_scale/yv12config.h"
 #include "vpx/vpx_integer.h"
-
-#define BLOCK_HEIGHT_WIDTH 4
-#define VP9_FILTER_WEIGHT 128
-#define VP9_FILTER_SHIFT  7
 
 #define SUBPEL_BITS 4
 #define SUBPEL_MASK ((1 << SUBPEL_BITS) - 1)
--- a/vp9/common/vp9_subpelvar.h
+++ b/vp9/common/vp9_subpelvar.h
@@ -11,7 +11,8 @@
 #ifndef VP9_COMMON_VP9_SUBPELVAR_H_
 #define VP9_COMMON_VP9_SUBPELVAR_H_
 
-#include "vp9/common/vp9_filter.h"
+#include "vp9/common/vp9_common.h"
+#include "vp9/common/vp9_convolve.h"
 
 static void variance(const uint8_t *src_ptr,
                      int  source_stride,
@@ -78,10 +79,10 @@
 
   for (i = 0; i < output_height; i++) {
     for (j = 0; j < output_width; j++) {
-      // Apply bilinear filter
-      output_ptr[j] = (((int)src_ptr[0]          * vp9_filter[0]) +
-                       ((int)src_ptr[pixel_step] * vp9_filter[1]) +
-                       (VP9_FILTER_WEIGHT / 2)) >> VP9_FILTER_SHIFT;
+      output_ptr[j] = ROUND_POWER_OF_TWO((int)src_ptr[0] * vp9_filter[0] +
+                          (int)src_ptr[pixel_step] * vp9_filter[1],
+                          VP9_FILTER_BITS);
+
       src_ptr++;
     }
 
@@ -127,20 +128,16 @@
                                                unsigned int output_width,
                                                const int16_t *vp9_filter) {
   unsigned int  i, j;
-  int  Temp;
 
   for (i = 0; i < output_height; i++) {
     for (j = 0; j < output_width; j++) {
-      // Apply filter
-      Temp = ((int)src_ptr[0]         * vp9_filter[0]) +
-             ((int)src_ptr[pixel_step] * vp9_filter[1]) +
-             (VP9_FILTER_WEIGHT / 2);
-      output_ptr[j] = (unsigned int)(Temp >> VP9_FILTER_SHIFT);
+      output_ptr[j] = ROUND_POWER_OF_TWO((int)src_ptr[0] * vp9_filter[0] +
+                          (int)src_ptr[pixel_step] * vp9_filter[1],
+                          VP9_FILTER_BITS);
       src_ptr++;
     }
 
-    // Next row...
-    src_ptr    += src_pixels_per_line - output_width;
+    src_ptr += src_pixels_per_line - output_width;
     output_ptr += output_width;
   }
 }