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