Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Ronald S. Bultje | 4cca47b | 2012-12-18 15:31:19 -0800 | [diff] [blame] | 11 | #ifndef VP9_COMMON_VP9_SUBPELVAR_H_ |
| 12 | #define VP9_COMMON_VP9_SUBPELVAR_H_ |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 13 | |
Dmitry Kovalev | 2612b99 | 2013-08-20 00:42:25 -0700 | [diff] [blame] | 14 | #include "vp9/common/vp9_common.h" |
| 15 | #include "vp9/common/vp9_convolve.h" |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 16 | |
Ronald S. Bultje | 4cca47b | 2012-12-18 15:31:19 -0800 | [diff] [blame] | 17 | static void variance(const uint8_t *src_ptr, |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 18 | int source_stride, |
Ronald S. Bultje | 4cca47b | 2012-12-18 15:31:19 -0800 | [diff] [blame] | 19 | const uint8_t *ref_ptr, |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 20 | int recon_stride, |
| 21 | int w, |
| 22 | int h, |
| 23 | unsigned int *sse, |
| 24 | int *sum) { |
| 25 | int i, j; |
| 26 | int diff; |
| 27 | |
| 28 | *sum = 0; |
| 29 | *sse = 0; |
| 30 | |
| 31 | for (i = 0; i < h; i++) { |
| 32 | for (j = 0; j < w; j++) { |
| 33 | diff = src_ptr[j] - ref_ptr[j]; |
| 34 | *sum += diff; |
| 35 | *sse += diff * diff; |
| 36 | } |
| 37 | |
| 38 | src_ptr += source_stride; |
| 39 | ref_ptr += recon_stride; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /**************************************************************************** |
| 44 | * |
| 45 | * ROUTINE : filter_block2d_bil_first_pass |
| 46 | * |
John Koleszar | 1306ba7 | 2012-12-14 12:35:33 -0800 | [diff] [blame] | 47 | * INPUTS : uint8_t *src_ptr : Pointer to source block. |
| 48 | * uint32_t src_pixels_per_line : Stride of input block. |
| 49 | * uint32_t pixel_step : Offset between filter input samples (see notes). |
| 50 | * uint32_t output_height : Input block height. |
| 51 | * uint32_t output_width : Input block width. |
| 52 | * int32_t *vp9_filter : Array of 2 bi-linear filter taps. |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 53 | * |
John Koleszar | 1306ba7 | 2012-12-14 12:35:33 -0800 | [diff] [blame] | 54 | * OUTPUTS : int32_t *output_ptr : Pointer to filtered block. |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 55 | * |
| 56 | * RETURNS : void |
| 57 | * |
| 58 | * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in |
| 59 | * either horizontal or vertical direction to produce the |
| 60 | * filtered output block. Used to implement first-pass |
| 61 | * of 2-D separable filter. |
| 62 | * |
John Koleszar | 1306ba7 | 2012-12-14 12:35:33 -0800 | [diff] [blame] | 63 | * SPECIAL NOTES : Produces int32_t output to retain precision for next pass. |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 64 | * Two filter taps should sum to VP9_FILTER_WEIGHT. |
| 65 | * pixel_step defines whether the filter is applied |
| 66 | * horizontally (pixel_step=1) or vertically (pixel_step=stride). |
| 67 | * It defines the offset required to move from one input |
| 68 | * to the next. |
| 69 | * |
| 70 | ****************************************************************************/ |
Ronald S. Bultje | 4cca47b | 2012-12-18 15:31:19 -0800 | [diff] [blame] | 71 | static void var_filter_block2d_bil_first_pass(const uint8_t *src_ptr, |
| 72 | uint16_t *output_ptr, |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 73 | unsigned int src_pixels_per_line, |
| 74 | int pixel_step, |
| 75 | unsigned int output_height, |
| 76 | unsigned int output_width, |
Ronald S. Bultje | 4cca47b | 2012-12-18 15:31:19 -0800 | [diff] [blame] | 77 | const int16_t *vp9_filter) { |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 78 | unsigned int i, j; |
| 79 | |
| 80 | for (i = 0; i < output_height; i++) { |
| 81 | for (j = 0; j < output_width; j++) { |
Dmitry Kovalev | 2612b99 | 2013-08-20 00:42:25 -0700 | [diff] [blame] | 82 | output_ptr[j] = ROUND_POWER_OF_TWO((int)src_ptr[0] * vp9_filter[0] + |
| 83 | (int)src_ptr[pixel_step] * vp9_filter[1], |
| 84 | VP9_FILTER_BITS); |
| 85 | |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 86 | src_ptr++; |
| 87 | } |
| 88 | |
| 89 | // Next row... |
| 90 | src_ptr += src_pixels_per_line - output_width; |
| 91 | output_ptr += output_width; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /**************************************************************************** |
| 96 | * |
| 97 | * ROUTINE : filter_block2d_bil_second_pass |
| 98 | * |
John Koleszar | 1306ba7 | 2012-12-14 12:35:33 -0800 | [diff] [blame] | 99 | * INPUTS : int32_t *src_ptr : Pointer to source block. |
| 100 | * uint32_t src_pixels_per_line : Stride of input block. |
| 101 | * uint32_t pixel_step : Offset between filter input samples (see notes). |
| 102 | * uint32_t output_height : Input block height. |
| 103 | * uint32_t output_width : Input block width. |
| 104 | * int32_t *vp9_filter : Array of 2 bi-linear filter taps. |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 105 | * |
John Koleszar | 1306ba7 | 2012-12-14 12:35:33 -0800 | [diff] [blame] | 106 | * OUTPUTS : uint16_t *output_ptr : Pointer to filtered block. |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 107 | * |
| 108 | * RETURNS : void |
| 109 | * |
| 110 | * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in |
| 111 | * either horizontal or vertical direction to produce the |
| 112 | * filtered output block. Used to implement second-pass |
| 113 | * of 2-D separable filter. |
| 114 | * |
| 115 | * SPECIAL NOTES : Requires 32-bit input as produced by filter_block2d_bil_first_pass. |
| 116 | * Two filter taps should sum to VP9_FILTER_WEIGHT. |
| 117 | * pixel_step defines whether the filter is applied |
| 118 | * horizontally (pixel_step=1) or vertically (pixel_step=stride). |
| 119 | * It defines the offset required to move from one input |
| 120 | * to the next. |
| 121 | * |
| 122 | ****************************************************************************/ |
Ronald S. Bultje | 4cca47b | 2012-12-18 15:31:19 -0800 | [diff] [blame] | 123 | static void var_filter_block2d_bil_second_pass(const uint16_t *src_ptr, |
| 124 | uint8_t *output_ptr, |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 125 | unsigned int src_pixels_per_line, |
| 126 | unsigned int pixel_step, |
| 127 | unsigned int output_height, |
| 128 | unsigned int output_width, |
Ronald S. Bultje | 4cca47b | 2012-12-18 15:31:19 -0800 | [diff] [blame] | 129 | const int16_t *vp9_filter) { |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 130 | unsigned int i, j; |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 131 | |
| 132 | for (i = 0; i < output_height; i++) { |
| 133 | for (j = 0; j < output_width; j++) { |
Dmitry Kovalev | 2612b99 | 2013-08-20 00:42:25 -0700 | [diff] [blame] | 134 | output_ptr[j] = ROUND_POWER_OF_TWO((int)src_ptr[0] * vp9_filter[0] + |
| 135 | (int)src_ptr[pixel_step] * vp9_filter[1], |
| 136 | VP9_FILTER_BITS); |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 137 | src_ptr++; |
| 138 | } |
| 139 | |
Dmitry Kovalev | 2612b99 | 2013-08-20 00:42:25 -0700 | [diff] [blame] | 140 | src_ptr += src_pixels_per_line - output_width; |
Yaowu Xu | acadcec | 2012-11-06 15:17:20 -0800 | [diff] [blame] | 141 | output_ptr += output_width; |
| 142 | } |
| 143 | } |
| 144 | |
Ronald S. Bultje | 4cca47b | 2012-12-18 15:31:19 -0800 | [diff] [blame] | 145 | #endif // VP9_COMMON_VP9_SUBPELVAR_H_ |