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 #define BLOCK_HEIGHT_WIDTH 4
15 #define VP8_FILTER_WEIGHT 128
16 #define VP8_FILTER_SHIFT 7
19 static const int bilinear_filters
[8][2] =
32 static const short sub_pel_filters
[8][6] =
35 { 0, 0, 128, 0, 0, 0 }, /* note that 1/8 pel positions are just as per alpha -0.5 bicubic */
36 { 0, -6, 123, 12, -1, 0 },
37 { 2, -11, 108, 36, -8, 1 }, /* New 1/4 pel 6 tap filter */
38 { 0, -9, 93, 50, -6, 0 },
39 { 3, -16, 77, 77, -16, 3 }, /* New 1/2 pel 6 tap filter */
40 { 0, -6, 50, 93, -9, 0 },
41 { 1, -8, 36, 108, -11, 2 }, /* New 1/4 pel 6 tap filter */
42 { 0, -1, 12, 123, -6, 0 },
48 void vp8_filter_block2d_first_pass
50 unsigned char *src_ptr
,
52 unsigned int src_pixels_per_line
,
53 unsigned int pixel_step
,
54 unsigned int output_height
,
55 unsigned int output_width
,
56 const short *vp8_filter
62 for (i
= 0; i
< output_height
; i
++)
64 for (j
= 0; j
< output_width
; j
++)
66 Temp
= ((int)src_ptr
[-2 * (int)pixel_step
] * vp8_filter
[0]) +
67 ((int)src_ptr
[-1 * (int)pixel_step
] * vp8_filter
[1]) +
68 ((int)src_ptr
[0] * vp8_filter
[2]) +
69 ((int)src_ptr
[pixel_step
] * vp8_filter
[3]) +
70 ((int)src_ptr
[2*pixel_step
] * vp8_filter
[4]) +
71 ((int)src_ptr
[3*pixel_step
] * vp8_filter
[5]) +
72 (VP8_FILTER_WEIGHT
>> 1); /* Rounding */
74 /* Normalize back to 0-255 */
75 Temp
= Temp
>> VP8_FILTER_SHIFT
;
87 src_ptr
+= src_pixels_per_line
- output_width
;
88 output_ptr
+= output_width
;
92 void vp8_filter_block2d_second_pass
95 unsigned char *output_ptr
,
97 unsigned int src_pixels_per_line
,
98 unsigned int pixel_step
,
99 unsigned int output_height
,
100 unsigned int output_width
,
101 const short *vp8_filter
107 for (i
= 0; i
< output_height
; i
++)
109 for (j
= 0; j
< output_width
; j
++)
112 Temp
= ((int)src_ptr
[-2 * (int)pixel_step
] * vp8_filter
[0]) +
113 ((int)src_ptr
[-1 * (int)pixel_step
] * vp8_filter
[1]) +
114 ((int)src_ptr
[0] * vp8_filter
[2]) +
115 ((int)src_ptr
[pixel_step
] * vp8_filter
[3]) +
116 ((int)src_ptr
[2*pixel_step
] * vp8_filter
[4]) +
117 ((int)src_ptr
[3*pixel_step
] * vp8_filter
[5]) +
118 (VP8_FILTER_WEIGHT
>> 1); /* Rounding */
120 /* Normalize back to 0-255 */
121 Temp
= Temp
>> VP8_FILTER_SHIFT
;
128 output_ptr
[j
] = (unsigned char)Temp
;
133 src_ptr
+= src_pixels_per_line
- output_width
;
134 output_ptr
+= output_pitch
;
139 void vp8_filter_block2d
141 unsigned char *src_ptr
,
142 unsigned char *output_ptr
,
143 unsigned int src_pixels_per_line
,
145 const short *HFilter
,
149 int FData
[9*4]; /* Temp data bufffer used in filtering */
151 /* First filter 1-D horizontally... */
152 vp8_filter_block2d_first_pass(src_ptr
- (2 * src_pixels_per_line
), FData
, src_pixels_per_line
, 1, 9, 4, HFilter
);
154 /* then filter verticaly... */
155 vp8_filter_block2d_second_pass(FData
+ 8, output_ptr
, output_pitch
, 4, 4, 4, 4, VFilter
);
159 void vp8_block_variation_c
161 unsigned char *src_ptr
,
162 int src_pixels_per_line
,
168 unsigned char *Ptr
= src_ptr
;
170 for (i
= 0; i
< 4; i
++)
172 for (j
= 0; j
< 4; j
++)
174 *HVar
+= abs((int)Ptr
[j
] - (int)Ptr
[j
+1]);
175 *VVar
+= abs((int)Ptr
[j
] - (int)Ptr
[j
+src_pixels_per_line
]);
178 Ptr
+= src_pixels_per_line
;
185 void vp8_sixtap_predict_c
187 unsigned char *src_ptr
,
188 int src_pixels_per_line
,
191 unsigned char *dst_ptr
,
195 const short *HFilter
;
196 const short *VFilter
;
198 HFilter
= sub_pel_filters
[xoffset
]; /* 6 tap */
199 VFilter
= sub_pel_filters
[yoffset
]; /* 6 tap */
201 vp8_filter_block2d(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
);
203 void vp8_sixtap_predict8x8_c
205 unsigned char *src_ptr
,
206 int src_pixels_per_line
,
209 unsigned char *dst_ptr
,
213 const short *HFilter
;
214 const short *VFilter
;
215 int FData
[13*16]; /* Temp data bufffer used in filtering */
217 HFilter
= sub_pel_filters
[xoffset
]; /* 6 tap */
218 VFilter
= sub_pel_filters
[yoffset
]; /* 6 tap */
220 /* First filter 1-D horizontally... */
221 vp8_filter_block2d_first_pass(src_ptr
- (2 * src_pixels_per_line
), FData
, src_pixels_per_line
, 1, 13, 8, HFilter
);
224 /* then filter verticaly... */
225 vp8_filter_block2d_second_pass(FData
+ 16, dst_ptr
, dst_pitch
, 8, 8, 8, 8, VFilter
);
229 void vp8_sixtap_predict8x4_c
231 unsigned char *src_ptr
,
232 int src_pixels_per_line
,
235 unsigned char *dst_ptr
,
239 const short *HFilter
;
240 const short *VFilter
;
241 int FData
[13*16]; /* Temp data bufffer used in filtering */
243 HFilter
= sub_pel_filters
[xoffset
]; /* 6 tap */
244 VFilter
= sub_pel_filters
[yoffset
]; /* 6 tap */
246 /* First filter 1-D horizontally... */
247 vp8_filter_block2d_first_pass(src_ptr
- (2 * src_pixels_per_line
), FData
, src_pixels_per_line
, 1, 9, 8, HFilter
);
250 /* then filter verticaly... */
251 vp8_filter_block2d_second_pass(FData
+ 16, dst_ptr
, dst_pitch
, 8, 8, 4, 8, VFilter
);
255 void vp8_sixtap_predict16x16_c
257 unsigned char *src_ptr
,
258 int src_pixels_per_line
,
261 unsigned char *dst_ptr
,
265 const short *HFilter
;
266 const short *VFilter
;
267 int FData
[21*24]; /* Temp data bufffer used in filtering */
270 HFilter
= sub_pel_filters
[xoffset
]; /* 6 tap */
271 VFilter
= sub_pel_filters
[yoffset
]; /* 6 tap */
273 /* First filter 1-D horizontally... */
274 vp8_filter_block2d_first_pass(src_ptr
- (2 * src_pixels_per_line
), FData
, src_pixels_per_line
, 1, 21, 16, HFilter
);
276 /* then filter verticaly... */
277 vp8_filter_block2d_second_pass(FData
+ 32, dst_ptr
, dst_pitch
, 16, 16, 16, 16, VFilter
);
282 /****************************************************************************
284 * ROUTINE : filter_block2d_bil_first_pass
286 * INPUTS : UINT8 *src_ptr : Pointer to source block.
287 * UINT32 src_pixels_per_line : Stride of input block.
288 * UINT32 pixel_step : Offset between filter input samples (see notes).
289 * UINT32 output_height : Input block height.
290 * UINT32 output_width : Input block width.
291 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
293 * OUTPUTS : INT32 *output_ptr : Pointer to filtered block.
297 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in
298 * either horizontal or vertical direction to produce the
299 * filtered output block. Used to implement first-pass
300 * of 2-D separable filter.
302 * SPECIAL NOTES : Produces INT32 output to retain precision for next pass.
303 * Two filter taps should sum to VP8_FILTER_WEIGHT.
304 * pixel_step defines whether the filter is applied
305 * horizontally (pixel_step=1) or vertically (pixel_step=stride).
306 * It defines the offset required to move from one input
309 ****************************************************************************/
310 void vp8_filter_block2d_bil_first_pass
312 unsigned char *src_ptr
,
313 unsigned short *output_ptr
,
314 unsigned int src_pixels_per_line
,
316 unsigned int output_height
,
317 unsigned int output_width
,
318 const int *vp8_filter
323 for (i
= 0; i
< output_height
; i
++)
325 for (j
= 0; j
< output_width
; j
++)
327 /* Apply bilinear filter */
328 output_ptr
[j
] = (((int)src_ptr
[0] * vp8_filter
[0]) +
329 ((int)src_ptr
[pixel_step
] * vp8_filter
[1]) +
330 (VP8_FILTER_WEIGHT
/ 2)) >> VP8_FILTER_SHIFT
;
335 src_ptr
+= src_pixels_per_line
- output_width
;
336 output_ptr
+= output_width
;
340 /****************************************************************************
342 * ROUTINE : filter_block2d_bil_second_pass
344 * INPUTS : INT32 *src_ptr : Pointer to source block.
345 * UINT32 src_pixels_per_line : Stride of input block.
346 * UINT32 pixel_step : Offset between filter input samples (see notes).
347 * UINT32 output_height : Input block height.
348 * UINT32 output_width : Input block width.
349 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
351 * OUTPUTS : UINT16 *output_ptr : Pointer to filtered block.
355 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in
356 * either horizontal or vertical direction to produce the
357 * filtered output block. Used to implement second-pass
358 * of 2-D separable filter.
360 * SPECIAL NOTES : Requires 32-bit input as produced by filter_block2d_bil_first_pass.
361 * Two filter taps should sum to VP8_FILTER_WEIGHT.
362 * pixel_step defines whether the filter is applied
363 * horizontally (pixel_step=1) or vertically (pixel_step=stride).
364 * It defines the offset required to move from one input
367 ****************************************************************************/
368 void vp8_filter_block2d_bil_second_pass
370 unsigned short *src_ptr
,
371 unsigned char *output_ptr
,
373 unsigned int src_pixels_per_line
,
374 unsigned int pixel_step
,
375 unsigned int output_height
,
376 unsigned int output_width
,
377 const int *vp8_filter
383 for (i
= 0; i
< output_height
; i
++)
385 for (j
= 0; j
< output_width
; j
++)
388 Temp
= ((int)src_ptr
[0] * vp8_filter
[0]) +
389 ((int)src_ptr
[pixel_step
] * vp8_filter
[1]) +
390 (VP8_FILTER_WEIGHT
/ 2);
391 output_ptr
[j
] = (unsigned int)(Temp
>> VP8_FILTER_SHIFT
);
396 src_ptr
+= src_pixels_per_line
- output_width
;
397 output_ptr
+= output_pitch
;
402 /****************************************************************************
404 * ROUTINE : filter_block2d_bil
406 * INPUTS : UINT8 *src_ptr : Pointer to source block.
407 * UINT32 src_pixels_per_line : Stride of input block.
408 * INT32 *HFilter : Array of 2 horizontal filter taps.
409 * INT32 *VFilter : Array of 2 vertical filter taps.
411 * OUTPUTS : UINT16 *output_ptr : Pointer to filtered block.
415 * FUNCTION : 2-D filters an input block by applying a 2-tap
416 * bi-linear filter horizontally followed by a 2-tap
417 * bi-linear filter vertically on the result.
419 * SPECIAL NOTES : The largest block size can be handled here is 16x16
421 ****************************************************************************/
422 void vp8_filter_block2d_bil
424 unsigned char *src_ptr
,
425 unsigned char *output_ptr
,
426 unsigned int src_pixels_per_line
,
427 unsigned int dst_pitch
,
435 unsigned short FData
[17*16]; /* Temp data bufffer used in filtering */
437 /* First filter 1-D horizontally... */
438 vp8_filter_block2d_bil_first_pass(src_ptr
, FData
, src_pixels_per_line
, 1, Height
+ 1, Width
, HFilter
);
440 /* then 1-D vertically... */
441 vp8_filter_block2d_bil_second_pass(FData
, output_ptr
, dst_pitch
, Width
, Width
, Height
, Width
, VFilter
);
445 void vp8_bilinear_predict4x4_c
447 unsigned char *src_ptr
,
448 int src_pixels_per_line
,
451 unsigned char *dst_ptr
,
458 HFilter
= bilinear_filters
[xoffset
];
459 VFilter
= bilinear_filters
[yoffset
];
463 unsigned char temp1
[16];
464 unsigned char temp2
[16];
466 bilinear_predict4x4_mmx(src_ptr
, src_pixels_per_line
, xoffset
, yoffset
, temp1
, 4);
467 vp8_filter_block2d_bil(src_ptr
, temp2
, src_pixels_per_line
, 4, HFilter
, VFilter
, 4, 4);
469 for (i
= 0; i
< 16; i
++)
471 if (temp1
[i
] != temp2
[i
])
473 bilinear_predict4x4_mmx(src_ptr
, src_pixels_per_line
, xoffset
, yoffset
, temp1
, 4);
474 vp8_filter_block2d_bil(src_ptr
, temp2
, src_pixels_per_line
, 4, HFilter
, VFilter
, 4, 4);
479 vp8_filter_block2d_bil(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
, 4, 4);
483 void vp8_bilinear_predict8x8_c
485 unsigned char *src_ptr
,
486 int src_pixels_per_line
,
489 unsigned char *dst_ptr
,
496 HFilter
= bilinear_filters
[xoffset
];
497 VFilter
= bilinear_filters
[yoffset
];
499 vp8_filter_block2d_bil(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
, 8, 8);
503 void vp8_bilinear_predict8x4_c
505 unsigned char *src_ptr
,
506 int src_pixels_per_line
,
509 unsigned char *dst_ptr
,
516 HFilter
= bilinear_filters
[xoffset
];
517 VFilter
= bilinear_filters
[yoffset
];
519 vp8_filter_block2d_bil(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
, 8, 4);
523 void vp8_bilinear_predict16x16_c
525 unsigned char *src_ptr
,
526 int src_pixels_per_line
,
529 unsigned char *dst_ptr
,
536 HFilter
= bilinear_filters
[xoffset
];
537 VFilter
= bilinear_filters
[yoffset
];
539 vp8_filter_block2d_bil(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
, 16, 16);