From 2612b99cc7a64d5377f59de4775a308e6cdd5706 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Tue, 20 Aug 2013 00:42:25 -0700 Subject: [PATCH] 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 --- vp9/common/vp9_convolve.c | 47 +++++++++++++++++++++++----------------------- vp9/common/vp9_convolve.h | 2 ++ vp9/common/vp9_filter.h | 5 ----- vp9/common/vp9_subpelvar.h | 23 ++++++++++------------- 4 files changed, 35 insertions(+), 42 deletions(-) diff --git a/vp9/common/vp9_convolve.c b/vp9/common/vp9_convolve.c index ca2f838..4e79bbc 100644 --- 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 @@ 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; diff --git a/vp9/common/vp9_convolve.h b/vp9/common/vp9_convolve.h index 3de8111..9522b78 100644 --- 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, diff --git a/vp9/common/vp9_filter.h b/vp9/common/vp9_filter.h index 7d7afba..cf5e6f1 100644 --- a/vp9/common/vp9_filter.h +++ b/vp9/common/vp9_filter.h @@ -12,13 +12,8 @@ #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) diff --git a/vp9/common/vp9_subpelvar.h b/vp9/common/vp9_subpelvar.h index ad674f1..78d4235 100644 --- 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 @@ 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; } } -- 2.7.4