]> granicus.if.org Git - libvpx/commitdiff
Adding VP9_FILTER_BITS constant.
authorDmitry Kovalev <dkovalev@google.com>
Tue, 20 Aug 2013 07:42:25 +0000 (00:42 -0700)
committerDmitry Kovalev <dkovalev@google.com>
Tue, 20 Aug 2013 07:42:25 +0000 (00:42 -0700)
Removing VP9_FILTER_WEIGHT, VP9_FILTER_SHIFT, BLOCK_WIDTH_HEIGHT
constants. Using ROUND_POWER_OF_TWO for rounding.

Change-Id: I2e8d6858dcd600a87096138209731137d7decc24

vp9/common/vp9_convolve.c
vp9/common/vp9_convolve.h
vp9/common/vp9_filter.h
vp9/common/vp9_subpelvar.h

index ca2f83841b4b75f9e8ace3ef747b624d860e895e..4e79bbc1bc33db161e4fcf0fdc72ba1cadc37daa 100644 (file)
@@ -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 @@ static void convolve_horiz_c(const uint8_t *src, ptrdiff_t src_stride,
                              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,12 +61,12 @@ static void convolve_horiz_c(const uint8_t *src, ptrdiff_t src_stride,
     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;
@@ -85,7 +82,7 @@ static void convolve_avg_horiz_c(const uint8_t *src, ptrdiff_t src_stride,
                                  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,12 +103,13 @@ static void convolve_avg_horiz_c(const uint8_t *src, ptrdiff_t src_stride,
     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;
@@ -127,7 +125,7 @@ static void convolve_vert_c(const uint8_t *src, ptrdiff_t src_stride,
                             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,12 +146,13 @@ static void convolve_vert_c(const uint8_t *src, ptrdiff_t src_stride,
     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;
@@ -169,7 +168,7 @@ static void convolve_avg_vert_c(const uint8_t *src, ptrdiff_t src_stride,
                                 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 @@ static void convolve_avg_vert_c(const uint8_t *src, ptrdiff_t src_stride,
     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;
index 3de81119f4a6e6c4f3a4d211ff25dcc4624ca61b..9522b78bcef50048085a7fe7a2446914fe042c7b 100644 (file)
@@ -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,
index 7d7afba8131733471601f9e29a95968123a87f3e..cf5e6f117e4178eb8798948a9b37e868e162c1f4 100644 (file)
 #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)
 #define SUBPEL_SHIFTS (1 << SUBPEL_BITS)
index ad674f105cbf4f9d6b40850bfb5f1d8d0cf82d7e..78d42359b26a45c857da675374471bf63c9b773a 100644 (file)
@@ -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 @@ static void var_filter_block2d_bil_first_pass(const uint8_t *src_ptr,
 
   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 @@ static void var_filter_block2d_bil_second_pass(const uint16_t *src_ptr,
                                                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;
   }
 }