2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
13 #include "vp8/common/filter.h"
16 unsigned int vp8_get_mb_ss_c
21 unsigned int i
= 0, sum
= 0;
25 sum
+= (src_ptr
[i
] * src_ptr
[i
]);
35 const unsigned char *src_ptr
,
37 const unsigned char *ref_ptr
,
50 for (i
= 0; i
< h
; i
++)
52 for (j
= 0; j
< w
; j
++)
54 diff
= src_ptr
[j
] - ref_ptr
[j
];
59 src_ptr
+= source_stride
;
60 ref_ptr
+= recon_stride
;
65 unsigned int vp8_variance16x16_c(
66 const unsigned char *src_ptr
,
68 const unsigned char *ref_ptr
,
76 variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 16, 16, &var
, &avg
);
78 return (var
- ((avg
* avg
) >> 8));
81 unsigned int vp8_variance8x16_c(
82 const unsigned char *src_ptr
,
84 const unsigned char *ref_ptr
,
92 variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 8, 16, &var
, &avg
);
94 return (var
- ((avg
* avg
) >> 7));
97 unsigned int vp8_variance16x8_c(
98 const unsigned char *src_ptr
,
100 const unsigned char *ref_ptr
,
108 variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 16, 8, &var
, &avg
);
110 return (var
- ((avg
* avg
) >> 7));
114 unsigned int vp8_variance8x8_c(
115 const unsigned char *src_ptr
,
117 const unsigned char *ref_ptr
,
125 variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 8, 8, &var
, &avg
);
127 return (var
- ((avg
* avg
) >> 6));
130 unsigned int vp8_variance4x4_c(
131 const unsigned char *src_ptr
,
133 const unsigned char *ref_ptr
,
141 variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 4, 4, &var
, &avg
);
143 return (var
- ((avg
* avg
) >> 4));
147 unsigned int vp8_mse16x16_c(
148 const unsigned char *src_ptr
,
150 const unsigned char *ref_ptr
,
157 variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 16, 16, &var
, &avg
);
163 /****************************************************************************
165 * ROUTINE : filter_block2d_bil_first_pass
167 * INPUTS : UINT8 *src_ptr : Pointer to source block.
168 * UINT32 src_pixels_per_line : Stride of input block.
169 * UINT32 pixel_step : Offset between filter input samples (see notes).
170 * UINT32 output_height : Input block height.
171 * UINT32 output_width : Input block width.
172 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
174 * OUTPUTS : INT32 *output_ptr : Pointer to filtered block.
178 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in
179 * either horizontal or vertical direction to produce the
180 * filtered output block. Used to implement first-pass
181 * of 2-D separable filter.
183 * SPECIAL NOTES : Produces INT32 output to retain precision for next pass.
184 * Two filter taps should sum to VP8_FILTER_WEIGHT.
185 * pixel_step defines whether the filter is applied
186 * horizontally (pixel_step=1) or vertically (pixel_step=stride).
187 * It defines the offset required to move from one input
190 ****************************************************************************/
191 static void var_filter_block2d_bil_first_pass
193 const unsigned char *src_ptr
,
194 unsigned short *output_ptr
,
195 unsigned int src_pixels_per_line
,
197 unsigned int output_height
,
198 unsigned int output_width
,
199 const short *vp8_filter
204 for (i
= 0; i
< output_height
; i
++)
206 for (j
= 0; j
< output_width
; j
++)
208 // Apply bilinear filter
209 output_ptr
[j
] = (((int)src_ptr
[0] * vp8_filter
[0]) +
210 ((int)src_ptr
[pixel_step
] * vp8_filter
[1]) +
211 (VP8_FILTER_WEIGHT
/ 2)) >> VP8_FILTER_SHIFT
;
216 src_ptr
+= src_pixels_per_line
- output_width
;
217 output_ptr
+= output_width
;
221 /****************************************************************************
223 * ROUTINE : filter_block2d_bil_second_pass
225 * INPUTS : INT32 *src_ptr : Pointer to source block.
226 * UINT32 src_pixels_per_line : Stride of input block.
227 * UINT32 pixel_step : Offset between filter input samples (see notes).
228 * UINT32 output_height : Input block height.
229 * UINT32 output_width : Input block width.
230 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
232 * OUTPUTS : UINT16 *output_ptr : Pointer to filtered block.
236 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in
237 * either horizontal or vertical direction to produce the
238 * filtered output block. Used to implement second-pass
239 * of 2-D separable filter.
241 * SPECIAL NOTES : Requires 32-bit input as produced by filter_block2d_bil_first_pass.
242 * Two filter taps should sum to VP8_FILTER_WEIGHT.
243 * pixel_step defines whether the filter is applied
244 * horizontally (pixel_step=1) or vertically (pixel_step=stride).
245 * It defines the offset required to move from one input
248 ****************************************************************************/
249 static void var_filter_block2d_bil_second_pass
251 const unsigned short *src_ptr
,
252 unsigned char *output_ptr
,
253 unsigned int src_pixels_per_line
,
254 unsigned int pixel_step
,
255 unsigned int output_height
,
256 unsigned int output_width
,
257 const short *vp8_filter
263 for (i
= 0; i
< output_height
; i
++)
265 for (j
= 0; j
< output_width
; j
++)
268 Temp
= ((int)src_ptr
[0] * vp8_filter
[0]) +
269 ((int)src_ptr
[pixel_step
] * vp8_filter
[1]) +
270 (VP8_FILTER_WEIGHT
/ 2);
271 output_ptr
[j
] = (unsigned int)(Temp
>> VP8_FILTER_SHIFT
);
276 src_ptr
+= src_pixels_per_line
- output_width
;
277 output_ptr
+= output_width
;
282 unsigned int vp8_sub_pixel_variance4x4_c
284 const unsigned char *src_ptr
,
285 int src_pixels_per_line
,
288 const unsigned char *dst_ptr
,
289 int dst_pixels_per_line
,
293 unsigned char temp2
[20*16];
294 const short *HFilter
, *VFilter
;
295 unsigned short FData3
[5*4]; // Temp data bufffer used in filtering
297 HFilter
= vp8_bilinear_filters
[xoffset
];
298 VFilter
= vp8_bilinear_filters
[yoffset
];
300 // First filter 1d Horizontal
301 var_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 5, 4, HFilter
);
303 // Now filter Verticaly
304 var_filter_block2d_bil_second_pass(FData3
, temp2
, 4, 4, 4, 4, VFilter
);
306 return vp8_variance4x4_c(temp2
, 4, dst_ptr
, dst_pixels_per_line
, sse
);
310 unsigned int vp8_sub_pixel_variance8x8_c
312 const unsigned char *src_ptr
,
313 int src_pixels_per_line
,
316 const unsigned char *dst_ptr
,
317 int dst_pixels_per_line
,
321 unsigned short FData3
[9*8]; // Temp data bufffer used in filtering
322 unsigned char temp2
[20*16];
323 const short *HFilter
, *VFilter
;
325 HFilter
= vp8_bilinear_filters
[xoffset
];
326 VFilter
= vp8_bilinear_filters
[yoffset
];
328 var_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 9, 8, HFilter
);
329 var_filter_block2d_bil_second_pass(FData3
, temp2
, 8, 8, 8, 8, VFilter
);
331 return vp8_variance8x8_c(temp2
, 8, dst_ptr
, dst_pixels_per_line
, sse
);
334 unsigned int vp8_sub_pixel_variance16x16_c
336 const unsigned char *src_ptr
,
337 int src_pixels_per_line
,
340 const unsigned char *dst_ptr
,
341 int dst_pixels_per_line
,
345 unsigned short FData3
[17*16]; // Temp data bufffer used in filtering
346 unsigned char temp2
[20*16];
347 const short *HFilter
, *VFilter
;
349 HFilter
= vp8_bilinear_filters
[xoffset
];
350 VFilter
= vp8_bilinear_filters
[yoffset
];
352 var_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 17, 16, HFilter
);
353 var_filter_block2d_bil_second_pass(FData3
, temp2
, 16, 16, 16, 16, VFilter
);
355 return vp8_variance16x16_c(temp2
, 16, dst_ptr
, dst_pixels_per_line
, sse
);
359 unsigned int vp8_variance_halfpixvar16x16_h_c(
360 const unsigned char *src_ptr
,
362 const unsigned char *ref_ptr
,
366 return vp8_sub_pixel_variance16x16_c(src_ptr
, source_stride
, 4, 0,
367 ref_ptr
, recon_stride
, sse
);
371 unsigned int vp8_variance_halfpixvar16x16_v_c(
372 const unsigned char *src_ptr
,
374 const unsigned char *ref_ptr
,
378 return vp8_sub_pixel_variance16x16_c(src_ptr
, source_stride
, 0, 4,
379 ref_ptr
, recon_stride
, sse
);
383 unsigned int vp8_variance_halfpixvar16x16_hv_c(
384 const unsigned char *src_ptr
,
386 const unsigned char *ref_ptr
,
390 return vp8_sub_pixel_variance16x16_c(src_ptr
, source_stride
, 4, 4,
391 ref_ptr
, recon_stride
, sse
);
395 unsigned int vp8_sub_pixel_mse16x16_c
397 const unsigned char *src_ptr
,
398 int src_pixels_per_line
,
401 const unsigned char *dst_ptr
,
402 int dst_pixels_per_line
,
406 vp8_sub_pixel_variance16x16_c(src_ptr
, src_pixels_per_line
, xoffset
, yoffset
, dst_ptr
, dst_pixels_per_line
, sse
);
410 unsigned int vp8_sub_pixel_variance16x8_c
412 const unsigned char *src_ptr
,
413 int src_pixels_per_line
,
416 const unsigned char *dst_ptr
,
417 int dst_pixels_per_line
,
421 unsigned short FData3
[16*9]; // Temp data bufffer used in filtering
422 unsigned char temp2
[20*16];
423 const short *HFilter
, *VFilter
;
425 HFilter
= vp8_bilinear_filters
[xoffset
];
426 VFilter
= vp8_bilinear_filters
[yoffset
];
428 var_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 9, 16, HFilter
);
429 var_filter_block2d_bil_second_pass(FData3
, temp2
, 16, 16, 8, 16, VFilter
);
431 return vp8_variance16x8_c(temp2
, 16, dst_ptr
, dst_pixels_per_line
, sse
);
434 unsigned int vp8_sub_pixel_variance8x16_c
436 const unsigned char *src_ptr
,
437 int src_pixels_per_line
,
440 const unsigned char *dst_ptr
,
441 int dst_pixels_per_line
,
445 unsigned short FData3
[9*16]; // Temp data bufffer used in filtering
446 unsigned char temp2
[20*16];
447 const short *HFilter
, *VFilter
;
450 HFilter
= vp8_bilinear_filters
[xoffset
];
451 VFilter
= vp8_bilinear_filters
[yoffset
];
454 var_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 17, 8, HFilter
);
455 var_filter_block2d_bil_second_pass(FData3
, temp2
, 8, 8, 16, 8, VFilter
);
457 return vp8_variance8x16_c(temp2
, 8, dst_ptr
, dst_pixels_per_line
, sse
);