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_rtcd.h"
15 DECLARE_ALIGNED(16, const short, vp8_bilinear_filters
[8][2]) =
27 DECLARE_ALIGNED(16, const short, vp8_sub_pel_filters
[8][6]) =
30 { 0, 0, 128, 0, 0, 0 }, /* note that 1/8 pel positions are just as per alpha -0.5 bicubic */
31 { 0, -6, 123, 12, -1, 0 },
32 { 2, -11, 108, 36, -8, 1 }, /* New 1/4 pel 6 tap filter */
33 { 0, -9, 93, 50, -6, 0 },
34 { 3, -16, 77, 77, -16, 3 }, /* New 1/2 pel 6 tap filter */
35 { 0, -6, 50, 93, -9, 0 },
36 { 1, -8, 36, 108, -11, 2 }, /* New 1/4 pel 6 tap filter */
37 { 0, -1, 12, 123, -6, 0 },
40 static void filter_block2d_first_pass
42 unsigned char *src_ptr
,
44 unsigned int src_pixels_per_line
,
45 unsigned int pixel_step
,
46 unsigned int output_height
,
47 unsigned int output_width
,
48 const short *vp8_filter
54 for (i
= 0; i
< output_height
; i
++)
56 for (j
= 0; j
< output_width
; j
++)
58 Temp
= ((int)src_ptr
[-2 * (int)pixel_step
] * vp8_filter
[0]) +
59 ((int)src_ptr
[-1 * (int)pixel_step
] * vp8_filter
[1]) +
60 ((int)src_ptr
[0] * vp8_filter
[2]) +
61 ((int)src_ptr
[pixel_step
] * vp8_filter
[3]) +
62 ((int)src_ptr
[2*pixel_step
] * vp8_filter
[4]) +
63 ((int)src_ptr
[3*pixel_step
] * vp8_filter
[5]) +
64 (VP8_FILTER_WEIGHT
>> 1); /* Rounding */
66 /* Normalize back to 0-255 */
67 Temp
= Temp
>> VP8_FILTER_SHIFT
;
79 src_ptr
+= src_pixels_per_line
- output_width
;
80 output_ptr
+= output_width
;
84 static void filter_block2d_second_pass
87 unsigned char *output_ptr
,
89 unsigned int src_pixels_per_line
,
90 unsigned int pixel_step
,
91 unsigned int output_height
,
92 unsigned int output_width
,
93 const short *vp8_filter
99 for (i
= 0; i
< output_height
; i
++)
101 for (j
= 0; j
< output_width
; j
++)
104 Temp
= ((int)src_ptr
[-2 * (int)pixel_step
] * vp8_filter
[0]) +
105 ((int)src_ptr
[-1 * (int)pixel_step
] * vp8_filter
[1]) +
106 ((int)src_ptr
[0] * vp8_filter
[2]) +
107 ((int)src_ptr
[pixel_step
] * vp8_filter
[3]) +
108 ((int)src_ptr
[2*pixel_step
] * vp8_filter
[4]) +
109 ((int)src_ptr
[3*pixel_step
] * vp8_filter
[5]) +
110 (VP8_FILTER_WEIGHT
>> 1); /* Rounding */
112 /* Normalize back to 0-255 */
113 Temp
= Temp
>> VP8_FILTER_SHIFT
;
120 output_ptr
[j
] = (unsigned char)Temp
;
125 src_ptr
+= src_pixels_per_line
- output_width
;
126 output_ptr
+= output_pitch
;
131 static void filter_block2d
133 unsigned char *src_ptr
,
134 unsigned char *output_ptr
,
135 unsigned int src_pixels_per_line
,
137 const short *HFilter
,
141 int FData
[9*4]; /* Temp data buffer used in filtering */
143 /* First filter 1-D horizontally... */
144 filter_block2d_first_pass(src_ptr
- (2 * src_pixels_per_line
), FData
, src_pixels_per_line
, 1, 9, 4, HFilter
);
146 /* then filter verticaly... */
147 filter_block2d_second_pass(FData
+ 8, output_ptr
, output_pitch
, 4, 4, 4, 4, VFilter
);
151 void vp8_sixtap_predict4x4_c
153 unsigned char *src_ptr
,
154 int src_pixels_per_line
,
157 unsigned char *dst_ptr
,
161 const short *HFilter
;
162 const short *VFilter
;
164 HFilter
= vp8_sub_pel_filters
[xoffset
]; /* 6 tap */
165 VFilter
= vp8_sub_pel_filters
[yoffset
]; /* 6 tap */
167 filter_block2d(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
);
169 void vp8_sixtap_predict8x8_c
171 unsigned char *src_ptr
,
172 int src_pixels_per_line
,
175 unsigned char *dst_ptr
,
179 const short *HFilter
;
180 const short *VFilter
;
181 int FData
[13*16]; /* Temp data buffer used in filtering */
183 HFilter
= vp8_sub_pel_filters
[xoffset
]; /* 6 tap */
184 VFilter
= vp8_sub_pel_filters
[yoffset
]; /* 6 tap */
186 /* First filter 1-D horizontally... */
187 filter_block2d_first_pass(src_ptr
- (2 * src_pixels_per_line
), FData
, src_pixels_per_line
, 1, 13, 8, HFilter
);
190 /* then filter verticaly... */
191 filter_block2d_second_pass(FData
+ 16, dst_ptr
, dst_pitch
, 8, 8, 8, 8, VFilter
);
195 void vp8_sixtap_predict8x4_c
197 unsigned char *src_ptr
,
198 int src_pixels_per_line
,
201 unsigned char *dst_ptr
,
205 const short *HFilter
;
206 const short *VFilter
;
207 int FData
[13*16]; /* Temp data buffer used in filtering */
209 HFilter
= vp8_sub_pel_filters
[xoffset
]; /* 6 tap */
210 VFilter
= vp8_sub_pel_filters
[yoffset
]; /* 6 tap */
212 /* First filter 1-D horizontally... */
213 filter_block2d_first_pass(src_ptr
- (2 * src_pixels_per_line
), FData
, src_pixels_per_line
, 1, 9, 8, HFilter
);
216 /* then filter verticaly... */
217 filter_block2d_second_pass(FData
+ 16, dst_ptr
, dst_pitch
, 8, 8, 4, 8, VFilter
);
221 void vp8_sixtap_predict16x16_c
223 unsigned char *src_ptr
,
224 int src_pixels_per_line
,
227 unsigned char *dst_ptr
,
231 const short *HFilter
;
232 const short *VFilter
;
233 int FData
[21*24]; /* Temp data buffer used in filtering */
236 HFilter
= vp8_sub_pel_filters
[xoffset
]; /* 6 tap */
237 VFilter
= vp8_sub_pel_filters
[yoffset
]; /* 6 tap */
239 /* First filter 1-D horizontally... */
240 filter_block2d_first_pass(src_ptr
- (2 * src_pixels_per_line
), FData
, src_pixels_per_line
, 1, 21, 16, HFilter
);
242 /* then filter verticaly... */
243 filter_block2d_second_pass(FData
+ 32, dst_ptr
, dst_pitch
, 16, 16, 16, 16, VFilter
);
248 /****************************************************************************
250 * ROUTINE : filter_block2d_bil_first_pass
252 * INPUTS : UINT8 *src_ptr : Pointer to source block.
253 * UINT32 src_stride : Stride of source block.
254 * UINT32 height : Block height.
255 * UINT32 width : Block width.
256 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
258 * OUTPUTS : INT32 *dst_ptr : Pointer to filtered block.
262 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block
263 * in the horizontal direction to produce the filtered output
264 * block. Used to implement first-pass of 2-D separable filter.
266 * SPECIAL NOTES : Produces INT32 output to retain precision for next pass.
267 * Two filter taps should sum to VP8_FILTER_WEIGHT.
269 ****************************************************************************/
270 static void filter_block2d_bil_first_pass
272 unsigned char *src_ptr
,
273 unsigned short *dst_ptr
,
274 unsigned int src_stride
,
277 const short *vp8_filter
282 for (i
= 0; i
< height
; i
++)
284 for (j
= 0; j
< width
; j
++)
286 /* Apply bilinear filter */
287 dst_ptr
[j
] = (((int)src_ptr
[0] * vp8_filter
[0]) +
288 ((int)src_ptr
[1] * vp8_filter
[1]) +
289 (VP8_FILTER_WEIGHT
/ 2)) >> VP8_FILTER_SHIFT
;
294 src_ptr
+= src_stride
- width
;
299 /****************************************************************************
301 * ROUTINE : filter_block2d_bil_second_pass
303 * INPUTS : INT32 *src_ptr : Pointer to source block.
304 * UINT32 dst_pitch : Destination block pitch.
305 * UINT32 height : Block height.
306 * UINT32 width : Block width.
307 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
309 * OUTPUTS : UINT16 *dst_ptr : Pointer to filtered block.
313 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block
314 * in the vertical direction to produce the filtered output
315 * block. Used to implement second-pass of 2-D separable filter.
317 * SPECIAL NOTES : Requires 32-bit input as produced by filter_block2d_bil_first_pass.
318 * Two filter taps should sum to VP8_FILTER_WEIGHT.
320 ****************************************************************************/
321 static void filter_block2d_bil_second_pass
323 unsigned short *src_ptr
,
324 unsigned char *dst_ptr
,
328 const short *vp8_filter
334 for (i
= 0; i
< height
; i
++)
336 for (j
= 0; j
< width
; j
++)
339 Temp
= ((int)src_ptr
[0] * vp8_filter
[0]) +
340 ((int)src_ptr
[width
] * vp8_filter
[1]) +
341 (VP8_FILTER_WEIGHT
/ 2);
342 dst_ptr
[j
] = (unsigned int)(Temp
>> VP8_FILTER_SHIFT
);
347 dst_ptr
+= dst_pitch
;
352 /****************************************************************************
354 * ROUTINE : filter_block2d_bil
356 * INPUTS : UINT8 *src_ptr : Pointer to source block.
357 * UINT32 src_pitch : Stride of source block.
358 * UINT32 dst_pitch : Stride of destination block.
359 * INT32 *HFilter : Array of 2 horizontal filter taps.
360 * INT32 *VFilter : Array of 2 vertical filter taps.
361 * INT32 Width : Block width
362 * INT32 Height : Block height
364 * OUTPUTS : UINT16 *dst_ptr : Pointer to filtered block.
368 * FUNCTION : 2-D filters an input block by applying a 2-tap
369 * bi-linear filter horizontally followed by a 2-tap
370 * bi-linear filter vertically on the result.
372 * SPECIAL NOTES : The largest block size can be handled here is 16x16
374 ****************************************************************************/
375 static void filter_block2d_bil
377 unsigned char *src_ptr
,
378 unsigned char *dst_ptr
,
379 unsigned int src_pitch
,
380 unsigned int dst_pitch
,
381 const short *HFilter
,
382 const short *VFilter
,
388 unsigned short FData
[17*16]; /* Temp data buffer used in filtering */
390 /* First filter 1-D horizontally... */
391 filter_block2d_bil_first_pass(src_ptr
, FData
, src_pitch
, Height
+ 1, Width
, HFilter
);
393 /* then 1-D vertically... */
394 filter_block2d_bil_second_pass(FData
, dst_ptr
, dst_pitch
, Height
, Width
, VFilter
);
398 void vp8_bilinear_predict4x4_c
400 unsigned char *src_ptr
,
401 int src_pixels_per_line
,
404 unsigned char *dst_ptr
,
408 const short *HFilter
;
409 const short *VFilter
;
411 HFilter
= vp8_bilinear_filters
[xoffset
];
412 VFilter
= vp8_bilinear_filters
[yoffset
];
416 unsigned char temp1
[16];
417 unsigned char temp2
[16];
419 bilinear_predict4x4_mmx(src_ptr
, src_pixels_per_line
, xoffset
, yoffset
, temp1
, 4);
420 filter_block2d_bil(src_ptr
, temp2
, src_pixels_per_line
, 4, HFilter
, VFilter
, 4, 4);
422 for (i
= 0; i
< 16; i
++)
424 if (temp1
[i
] != temp2
[i
])
426 bilinear_predict4x4_mmx(src_ptr
, src_pixels_per_line
, xoffset
, yoffset
, temp1
, 4);
427 filter_block2d_bil(src_ptr
, temp2
, src_pixels_per_line
, 4, HFilter
, VFilter
, 4, 4);
432 filter_block2d_bil(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
, 4, 4);
436 void vp8_bilinear_predict8x8_c
438 unsigned char *src_ptr
,
439 int src_pixels_per_line
,
442 unsigned char *dst_ptr
,
446 const short *HFilter
;
447 const short *VFilter
;
449 HFilter
= vp8_bilinear_filters
[xoffset
];
450 VFilter
= vp8_bilinear_filters
[yoffset
];
452 filter_block2d_bil(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
, 8, 8);
456 void vp8_bilinear_predict8x4_c
458 unsigned char *src_ptr
,
459 int src_pixels_per_line
,
462 unsigned char *dst_ptr
,
466 const short *HFilter
;
467 const short *VFilter
;
469 HFilter
= vp8_bilinear_filters
[xoffset
];
470 VFilter
= vp8_bilinear_filters
[yoffset
];
472 filter_block2d_bil(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
, 8, 4);
476 void vp8_bilinear_predict16x16_c
478 unsigned char *src_ptr
,
479 int src_pixels_per_line
,
482 unsigned char *dst_ptr
,
486 const short *HFilter
;
487 const short *VFilter
;
489 HFilter
= vp8_bilinear_filters
[xoffset
];
490 VFilter
= vp8_bilinear_filters
[yoffset
];
492 filter_block2d_bil(src_ptr
, dst_ptr
, src_pixels_per_line
, dst_pitch
, HFilter
, VFilter
, 16, 16);