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.
14 const int vp8_six_tap
[8][6] =
16 { 0, 0, 128, 0, 0, 0 }, // note that 1/8 pel positions are just as per alpha -0.5 bicubic
17 { 0, -6, 123, 12, -1, 0 },
18 { 2, -11, 108, 36, -8, 1 }, // New 1/4 pel 6 tap filter
19 { 0, -9, 93, 50, -6, 0 },
20 { 3, -16, 77, 77, -16, 3 }, // New 1/2 pel 6 tap filter
21 { 0, -6, 50, 93, -9, 0 },
22 { 1, -8, 36, 108, -11, 2 }, // New 1/4 pel 6 tap filter
23 { 0, -1, 12, 123, -6, 0 }
27 const int VP8_FILTER_WEIGHT
= 128;
28 const int VP8_FILTER_SHIFT
= 7;
29 const int vp8_bilinear_taps
[8][2] =
41 unsigned int vp8_get_mb_ss_c
46 unsigned int i
= 0, sum
= 0;
50 sum
+= (src_ptr
[i
] * src_ptr
[i
]);
60 const unsigned char *src_ptr
,
62 const unsigned char *ref_ptr
,
75 for (i
= 0; i
< h
; i
++)
77 for (j
= 0; j
< w
; j
++)
79 diff
= src_ptr
[j
] - ref_ptr
[j
];
84 src_ptr
+= source_stride
;
85 ref_ptr
+= recon_stride
;
92 const unsigned char *src_ptr
,
94 const unsigned char *ref_ptr
,
101 vp8_variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 8, 8, SSE
, Sum
);
102 return (*SSE
- (((*Sum
) * (*Sum
)) >> 6));
108 const unsigned char *src_ptr
,
110 const unsigned char *ref_ptr
,
117 vp8_variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 16, 16, SSE
, Sum
);
118 return (*SSE
- (((*Sum
) * (*Sum
)) >> 8));
124 unsigned int vp8_variance16x16_c(
125 const unsigned char *src_ptr
,
127 const unsigned char *ref_ptr
,
135 vp8_variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 16, 16, &var
, &avg
);
137 return (var
- ((avg
* avg
) >> 8));
140 unsigned int vp8_variance8x16_c(
141 const unsigned char *src_ptr
,
143 const unsigned char *ref_ptr
,
151 vp8_variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 8, 16, &var
, &avg
);
153 return (var
- ((avg
* avg
) >> 7));
156 unsigned int vp8_variance16x8_c(
157 const unsigned char *src_ptr
,
159 const unsigned char *ref_ptr
,
167 vp8_variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 16, 8, &var
, &avg
);
169 return (var
- ((avg
* avg
) >> 7));
173 unsigned int vp8_variance8x8_c(
174 const unsigned char *src_ptr
,
176 const unsigned char *ref_ptr
,
184 vp8_variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 8, 8, &var
, &avg
);
186 return (var
- ((avg
* avg
) >> 6));
189 unsigned int vp8_variance4x4_c(
190 const unsigned char *src_ptr
,
192 const unsigned char *ref_ptr
,
200 vp8_variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 4, 4, &var
, &avg
);
202 return (var
- ((avg
* avg
) >> 4));
206 unsigned int vp8_mse16x16_c(
207 const unsigned char *src_ptr
,
209 const unsigned char *ref_ptr
,
216 vp8_variance(src_ptr
, source_stride
, ref_ptr
, recon_stride
, 16, 16, &var
, &avg
);
222 /****************************************************************************
224 * ROUTINE : filter_block2d_bil_first_pass
226 * INPUTS : UINT8 *src_ptr : Pointer to source block.
227 * UINT32 src_pixels_per_line : Stride of input block.
228 * UINT32 pixel_step : Offset between filter input samples (see notes).
229 * UINT32 output_height : Input block height.
230 * UINT32 output_width : Input block width.
231 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
233 * OUTPUTS : INT32 *output_ptr : Pointer to filtered block.
237 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in
238 * either horizontal or vertical direction to produce the
239 * filtered output block. Used to implement first-pass
240 * of 2-D separable filter.
242 * SPECIAL NOTES : Produces INT32 output to retain precision for next pass.
243 * Two filter taps should sum to VP8_FILTER_WEIGHT.
244 * pixel_step defines whether the filter is applied
245 * horizontally (pixel_step=1) or vertically (pixel_step=stride).
246 * It defines the offset required to move from one input
249 ****************************************************************************/
250 void vp8e_filter_block2d_bil_first_pass
252 const unsigned char *src_ptr
,
253 unsigned short *output_ptr
,
254 unsigned int src_pixels_per_line
,
256 unsigned int output_height
,
257 unsigned int output_width
,
258 const int *vp8_filter
263 for (i
= 0; i
< output_height
; i
++)
265 for (j
= 0; j
< output_width
; j
++)
267 // Apply bilinear filter
268 output_ptr
[j
] = (((int)src_ptr
[0] * vp8_filter
[0]) +
269 ((int)src_ptr
[pixel_step
] * vp8_filter
[1]) +
270 (VP8_FILTER_WEIGHT
/ 2)) >> VP8_FILTER_SHIFT
;
275 src_ptr
+= src_pixels_per_line
- output_width
;
276 output_ptr
+= output_width
;
280 /****************************************************************************
282 * ROUTINE : filter_block2d_bil_second_pass
284 * INPUTS : INT32 *src_ptr : Pointer to source block.
285 * UINT32 src_pixels_per_line : Stride of input block.
286 * UINT32 pixel_step : Offset between filter input samples (see notes).
287 * UINT32 output_height : Input block height.
288 * UINT32 output_width : Input block width.
289 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
291 * OUTPUTS : UINT16 *output_ptr : Pointer to filtered block.
295 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in
296 * either horizontal or vertical direction to produce the
297 * filtered output block. Used to implement second-pass
298 * of 2-D separable filter.
300 * SPECIAL NOTES : Requires 32-bit input as produced by filter_block2d_bil_first_pass.
301 * Two filter taps should sum to VP8_FILTER_WEIGHT.
302 * pixel_step defines whether the filter is applied
303 * horizontally (pixel_step=1) or vertically (pixel_step=stride).
304 * It defines the offset required to move from one input
307 ****************************************************************************/
308 void vp8e_filter_block2d_bil_second_pass
310 const unsigned short *src_ptr
,
311 unsigned char *output_ptr
,
312 unsigned int src_pixels_per_line
,
313 unsigned int pixel_step
,
314 unsigned int output_height
,
315 unsigned int output_width
,
316 const int *vp8_filter
322 for (i
= 0; i
< output_height
; i
++)
324 for (j
= 0; j
< output_width
; j
++)
327 Temp
= ((int)src_ptr
[0] * vp8_filter
[0]) +
328 ((int)src_ptr
[pixel_step
] * vp8_filter
[1]) +
329 (VP8_FILTER_WEIGHT
/ 2);
330 output_ptr
[j
] = (unsigned int)(Temp
>> VP8_FILTER_SHIFT
);
335 src_ptr
+= src_pixels_per_line
- output_width
;
336 output_ptr
+= output_width
;
341 /****************************************************************************
343 * ROUTINE : filter_block2d_bil
345 * INPUTS : UINT8 *src_ptr : Pointer to source block.
346 * UINT32 src_pixels_per_line : Stride of input block.
347 * INT32 *HFilter : Array of 2 horizontal filter taps.
348 * INT32 *VFilter : Array of 2 vertical filter taps.
350 * OUTPUTS : UINT16 *output_ptr : Pointer to filtered block.
354 * FUNCTION : 2-D filters an 8x8 input block by applying a 2-tap
355 * bi-linear filter horizontally followed by a 2-tap
356 * bi-linear filter vertically on the result.
358 * SPECIAL NOTES : The intermediate horizontally filtered block must produce
359 * 1 more point than the input block in each column. This
360 * is to ensure that the 2-tap filter has one extra data-point
361 * at the top of each column so filter taps do not extend
362 * beyond data. Thus the output of the first stage filter
363 * is an 8x9 (hx_v) block.
365 ****************************************************************************/
366 void vp8e_filter_block2d_bil
368 const unsigned char *src_ptr
,
369 unsigned char *output_ptr
,
370 unsigned int src_pixels_per_line
,
376 unsigned short FData
[20*16]; // Temp data bufffer used in filtering
378 // First filter 1-D horizontally...
379 vp8e_filter_block2d_bil_first_pass(src_ptr
, FData
, src_pixels_per_line
, 1, 9, 8, HFilter
);
381 // then 1-D vertically...
382 vp8e_filter_block2d_bil_second_pass(FData
, output_ptr
, 8, 8, 8, 8, VFilter
);
387 unsigned int vp8_sub_pixel_variance4x4_c
389 const unsigned char *src_ptr
,
390 int src_pixels_per_line
,
393 const unsigned char *dst_ptr
,
394 int dst_pixels_per_line
,
398 unsigned char temp2
[20*16];
399 const int *HFilter
, *VFilter
;
400 unsigned short FData3
[5*4]; // Temp data bufffer used in filtering
402 HFilter
= vp8_bilinear_taps
[xoffset
];
403 VFilter
= vp8_bilinear_taps
[yoffset
];
405 // First filter 1d Horizontal
406 vp8e_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 5, 4, HFilter
);
408 // Now filter Verticaly
409 vp8e_filter_block2d_bil_second_pass(FData3
, temp2
, 4, 4, 4, 4, VFilter
);
411 return vp8_variance4x4_c(temp2
, 4, dst_ptr
, dst_pixels_per_line
, sse
);
415 unsigned int vp8_sub_pixel_variance8x8_c
417 const unsigned char *src_ptr
,
418 int src_pixels_per_line
,
421 const unsigned char *dst_ptr
,
422 int dst_pixels_per_line
,
426 unsigned short FData3
[9*8]; // Temp data bufffer used in filtering
427 unsigned char temp2
[20*16];
428 const int *HFilter
, *VFilter
;
430 HFilter
= vp8_bilinear_taps
[xoffset
];
431 VFilter
= vp8_bilinear_taps
[yoffset
];
433 vp8e_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 9, 8, HFilter
);
434 vp8e_filter_block2d_bil_second_pass(FData3
, temp2
, 8, 8, 8, 8, VFilter
);
436 return vp8_variance8x8_c(temp2
, 8, dst_ptr
, dst_pixels_per_line
, sse
);
439 unsigned int vp8_sub_pixel_variance16x16_c
441 const unsigned char *src_ptr
,
442 int src_pixels_per_line
,
445 const unsigned char *dst_ptr
,
446 int dst_pixels_per_line
,
450 unsigned short FData3
[17*16]; // Temp data bufffer used in filtering
451 unsigned char temp2
[20*16];
452 const int *HFilter
, *VFilter
;
454 HFilter
= vp8_bilinear_taps
[xoffset
];
455 VFilter
= vp8_bilinear_taps
[yoffset
];
457 vp8e_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 17, 16, HFilter
);
458 vp8e_filter_block2d_bil_second_pass(FData3
, temp2
, 16, 16, 16, 16, VFilter
);
460 return vp8_variance16x16_c(temp2
, 16, dst_ptr
, dst_pixels_per_line
, sse
);
464 unsigned int vp8_variance_halfpixvar16x16_h_c(
465 const unsigned char *src_ptr
,
467 const unsigned char *ref_ptr
,
471 return vp8_sub_pixel_variance16x16_c(src_ptr
, source_stride
, 4, 0,
472 ref_ptr
, recon_stride
, sse
);
476 unsigned int vp8_variance_halfpixvar16x16_v_c(
477 const unsigned char *src_ptr
,
479 const unsigned char *ref_ptr
,
483 return vp8_sub_pixel_variance16x16_c(src_ptr
, source_stride
, 0, 4,
484 ref_ptr
, recon_stride
, sse
);
488 unsigned int vp8_variance_halfpixvar16x16_hv_c(
489 const unsigned char *src_ptr
,
491 const unsigned char *ref_ptr
,
495 return vp8_sub_pixel_variance16x16_c(src_ptr
, source_stride
, 4, 4,
496 ref_ptr
, recon_stride
, sse
);
500 unsigned int vp8_sub_pixel_mse16x16_c
502 const unsigned char *src_ptr
,
503 int src_pixels_per_line
,
506 const unsigned char *dst_ptr
,
507 int dst_pixels_per_line
,
511 vp8_sub_pixel_variance16x16_c(src_ptr
, src_pixels_per_line
, xoffset
, yoffset
, dst_ptr
, dst_pixels_per_line
, sse
);
515 unsigned int vp8_sub_pixel_variance16x8_c
517 const unsigned char *src_ptr
,
518 int src_pixels_per_line
,
521 const unsigned char *dst_ptr
,
522 int dst_pixels_per_line
,
526 unsigned short FData3
[16*9]; // Temp data bufffer used in filtering
527 unsigned char temp2
[20*16];
528 const int *HFilter
, *VFilter
;
530 HFilter
= vp8_bilinear_taps
[xoffset
];
531 VFilter
= vp8_bilinear_taps
[yoffset
];
533 vp8e_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 9, 16, HFilter
);
534 vp8e_filter_block2d_bil_second_pass(FData3
, temp2
, 16, 16, 8, 16, VFilter
);
536 return vp8_variance16x8_c(temp2
, 16, dst_ptr
, dst_pixels_per_line
, sse
);
539 unsigned int vp8_sub_pixel_variance8x16_c
541 const unsigned char *src_ptr
,
542 int src_pixels_per_line
,
545 const unsigned char *dst_ptr
,
546 int dst_pixels_per_line
,
550 unsigned short FData3
[9*16]; // Temp data bufffer used in filtering
551 unsigned char temp2
[20*16];
552 const int *HFilter
, *VFilter
;
555 HFilter
= vp8_bilinear_taps
[xoffset
];
556 VFilter
= vp8_bilinear_taps
[yoffset
];
559 vp8e_filter_block2d_bil_first_pass(src_ptr
, FData3
, src_pixels_per_line
, 1, 17, 8, HFilter
);
560 vp8e_filter_block2d_bil_second_pass(FData3
, temp2
, 8, 8, 16, 8, VFilter
);
562 return vp8_variance8x16_c(temp2
, 8, dst_ptr
, dst_pixels_per_line
, sse
);