1*495ae853SAndroid Build Coastguard Worker /******************************************************************************
2*495ae853SAndroid Build Coastguard Worker *
3*495ae853SAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project
4*495ae853SAndroid Build Coastguard Worker *
5*495ae853SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
6*495ae853SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
7*495ae853SAndroid Build Coastguard Worker * You may obtain a copy of the License at:
8*495ae853SAndroid Build Coastguard Worker *
9*495ae853SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
10*495ae853SAndroid Build Coastguard Worker *
11*495ae853SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
12*495ae853SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
13*495ae853SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*495ae853SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
15*495ae853SAndroid Build Coastguard Worker * limitations under the License.
16*495ae853SAndroid Build Coastguard Worker *
17*495ae853SAndroid Build Coastguard Worker *****************************************************************************
18*495ae853SAndroid Build Coastguard Worker * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*495ae853SAndroid Build Coastguard Worker */
20*495ae853SAndroid Build Coastguard Worker
21*495ae853SAndroid Build Coastguard Worker /**
22*495ae853SAndroid Build Coastguard Worker *******************************************************************************
23*495ae853SAndroid Build Coastguard Worker * @file
24*495ae853SAndroid Build Coastguard Worker * ih264e_half_pel.c
25*495ae853SAndroid Build Coastguard Worker *
26*495ae853SAndroid Build Coastguard Worker * @brief
27*495ae853SAndroid Build Coastguard Worker * This file contains functions that are used for computing subpixel planes
28*495ae853SAndroid Build Coastguard Worker *
29*495ae853SAndroid Build Coastguard Worker * @author
30*495ae853SAndroid Build Coastguard Worker * ittiam
31*495ae853SAndroid Build Coastguard Worker *
32*495ae853SAndroid Build Coastguard Worker * @par List of Functions:
33*495ae853SAndroid Build Coastguard Worker * - ih264e_sixtapfilter_horz
34*495ae853SAndroid Build Coastguard Worker * - ih264e_sixtap_filter_2dvh_vert
35*495ae853SAndroid Build Coastguard Worker *
36*495ae853SAndroid Build Coastguard Worker * @remarks
37*495ae853SAndroid Build Coastguard Worker * none
38*495ae853SAndroid Build Coastguard Worker *
39*495ae853SAndroid Build Coastguard Worker *******************************************************************************
40*495ae853SAndroid Build Coastguard Worker */
41*495ae853SAndroid Build Coastguard Worker
42*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
43*495ae853SAndroid Build Coastguard Worker /* File Includes */
44*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
45*495ae853SAndroid Build Coastguard Worker
46*495ae853SAndroid Build Coastguard Worker /* System Include Files */
47*495ae853SAndroid Build Coastguard Worker #include <stdio.h>
48*495ae853SAndroid Build Coastguard Worker #include <assert.h>
49*495ae853SAndroid Build Coastguard Worker #include <limits.h>
50*495ae853SAndroid Build Coastguard Worker
51*495ae853SAndroid Build Coastguard Worker /* User Include Files */
52*495ae853SAndroid Build Coastguard Worker #include "ih264_typedefs.h"
53*495ae853SAndroid Build Coastguard Worker
54*495ae853SAndroid Build Coastguard Worker #include "ih264_macros.h"
55*495ae853SAndroid Build Coastguard Worker #include "ih264_defs.h"
56*495ae853SAndroid Build Coastguard Worker #include "ih264_mem_fns.h"
57*495ae853SAndroid Build Coastguard Worker #include "ih264_padding.h"
58*495ae853SAndroid Build Coastguard Worker #include "ih264_intra_pred_filters.h"
59*495ae853SAndroid Build Coastguard Worker #include "ih264_inter_pred_filters.h"
60*495ae853SAndroid Build Coastguard Worker #include "ih264_deblk_edge_filters.h"
61*495ae853SAndroid Build Coastguard Worker #include "ih264_platform_macros.h"
62*495ae853SAndroid Build Coastguard Worker
63*495ae853SAndroid Build Coastguard Worker #include "ih264e_half_pel.h"
64*495ae853SAndroid Build Coastguard Worker
65*495ae853SAndroid Build Coastguard Worker
66*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
67*495ae853SAndroid Build Coastguard Worker /* Function Definitions */
68*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
69*495ae853SAndroid Build Coastguard Worker
70*495ae853SAndroid Build Coastguard Worker /**
71*495ae853SAndroid Build Coastguard Worker *******************************************************************************
72*495ae853SAndroid Build Coastguard Worker *
73*495ae853SAndroid Build Coastguard Worker * @brief
74*495ae853SAndroid Build Coastguard Worker * Interprediction luma filter for horizontal input (Filter run for width = 17
75*495ae853SAndroid Build Coastguard Worker * and height =16)
76*495ae853SAndroid Build Coastguard Worker *
77*495ae853SAndroid Build Coastguard Worker * @par Description:
78*495ae853SAndroid Build Coastguard Worker * Applies a 6 tap horizontal filter .The output is clipped to 8 bits
79*495ae853SAndroid Build Coastguard Worker * sec 8.4.2.2.1 titled "Luma sample interpolation process"
80*495ae853SAndroid Build Coastguard Worker *
81*495ae853SAndroid Build Coastguard Worker * @param[in] pu1_src
82*495ae853SAndroid Build Coastguard Worker * UWORD8 pointer to the source
83*495ae853SAndroid Build Coastguard Worker *
84*495ae853SAndroid Build Coastguard Worker * @param[out] pu1_dst
85*495ae853SAndroid Build Coastguard Worker * UWORD8 pointer to the destination
86*495ae853SAndroid Build Coastguard Worker *
87*495ae853SAndroid Build Coastguard Worker * @param[in] src_strd
88*495ae853SAndroid Build Coastguard Worker * integer source stride
89*495ae853SAndroid Build Coastguard Worker *
90*495ae853SAndroid Build Coastguard Worker * @param[in] dst_strd
91*495ae853SAndroid Build Coastguard Worker * integer destination stride
92*495ae853SAndroid Build Coastguard Worker *
93*495ae853SAndroid Build Coastguard Worker * @returns
94*495ae853SAndroid Build Coastguard Worker *
95*495ae853SAndroid Build Coastguard Worker * @remarks
96*495ae853SAndroid Build Coastguard Worker * none
97*495ae853SAndroid Build Coastguard Worker *
98*495ae853SAndroid Build Coastguard Worker *******************************************************************************
99*495ae853SAndroid Build Coastguard Worker */
ih264e_sixtapfilter_horz(UWORD8 * pu1_src,UWORD8 * pu1_dst,WORD32 src_strd,WORD32 dst_strd)100*495ae853SAndroid Build Coastguard Worker void ih264e_sixtapfilter_horz(UWORD8 *pu1_src,
101*495ae853SAndroid Build Coastguard Worker UWORD8 *pu1_dst,
102*495ae853SAndroid Build Coastguard Worker WORD32 src_strd,
103*495ae853SAndroid Build Coastguard Worker WORD32 dst_strd)
104*495ae853SAndroid Build Coastguard Worker {
105*495ae853SAndroid Build Coastguard Worker UWORD32 u4_i, u4_j;
106*495ae853SAndroid Build Coastguard Worker UWORD32 u4_w, u4_h;
107*495ae853SAndroid Build Coastguard Worker
108*495ae853SAndroid Build Coastguard Worker /* width and height of interpolation */
109*495ae853SAndroid Build Coastguard Worker u4_w = HP_PL_WD;
110*495ae853SAndroid Build Coastguard Worker u4_h = MB_SIZE;
111*495ae853SAndroid Build Coastguard Worker
112*495ae853SAndroid Build Coastguard Worker pu1_src -= 2;
113*495ae853SAndroid Build Coastguard Worker
114*495ae853SAndroid Build Coastguard Worker for (u4_i = 0; u4_i < u4_h; u4_i++)
115*495ae853SAndroid Build Coastguard Worker {
116*495ae853SAndroid Build Coastguard Worker for (u4_j = 0; u4_j < u4_w; u4_j++, pu1_dst++, pu1_src++)
117*495ae853SAndroid Build Coastguard Worker {
118*495ae853SAndroid Build Coastguard Worker WORD16 i16_temp;
119*495ae853SAndroid Build Coastguard Worker
120*495ae853SAndroid Build Coastguard Worker i16_temp = ih264_g_six_tap[0] * (*pu1_src + pu1_src[5])
121*495ae853SAndroid Build Coastguard Worker + ih264_g_six_tap[1] * (pu1_src[1] + pu1_src[4])
122*495ae853SAndroid Build Coastguard Worker + ih264_g_six_tap[2] * (pu1_src[2] + pu1_src[3]);
123*495ae853SAndroid Build Coastguard Worker
124*495ae853SAndroid Build Coastguard Worker i16_temp = (i16_temp + 16) >> 5;
125*495ae853SAndroid Build Coastguard Worker
126*495ae853SAndroid Build Coastguard Worker *pu1_dst = CLIP_U8(i16_temp);
127*495ae853SAndroid Build Coastguard Worker }
128*495ae853SAndroid Build Coastguard Worker pu1_src += src_strd - u4_w;
129*495ae853SAndroid Build Coastguard Worker pu1_dst += dst_strd - u4_w;
130*495ae853SAndroid Build Coastguard Worker }
131*495ae853SAndroid Build Coastguard Worker }
132*495ae853SAndroid Build Coastguard Worker
133*495ae853SAndroid Build Coastguard Worker /**
134*495ae853SAndroid Build Coastguard Worker *******************************************************************************
135*495ae853SAndroid Build Coastguard Worker *
136*495ae853SAndroid Build Coastguard Worker * @brief
137*495ae853SAndroid Build Coastguard Worker * This function implements a two stage cascaded six tap filter. It applies
138*495ae853SAndroid Build Coastguard Worker * the six tap filter in the vertical direction on the predictor values,
139*495ae853SAndroid Build Coastguard Worker * followed by applying the same filter in the horizontal direction on the
140*495ae853SAndroid Build Coastguard Worker * output of the first stage. The six tap filtering operation is described in
141*495ae853SAndroid Build Coastguard Worker * sec 8.4.2.2.1 titled "Luma sample interpolation process" (Filter run for
142*495ae853SAndroid Build Coastguard Worker * width = 17 and height = 17)
143*495ae853SAndroid Build Coastguard Worker *
144*495ae853SAndroid Build Coastguard Worker * @par Description:
145*495ae853SAndroid Build Coastguard Worker * The function interpolates the predictors first in the vertical direction and
146*495ae853SAndroid Build Coastguard Worker * then in the horizontal direction to output the (1/2,1/2). The output of the
147*495ae853SAndroid Build Coastguard Worker * first stage of the filter is stored in the buffer pointed to by
148*495ae853SAndroid Build Coastguard Worker * pi16_pred1(only in C) in 16 bit precision.
149*495ae853SAndroid Build Coastguard Worker *
150*495ae853SAndroid Build Coastguard Worker * @param[in] pu1_src
151*495ae853SAndroid Build Coastguard Worker * UWORD8 pointer to the source
152*495ae853SAndroid Build Coastguard Worker *
153*495ae853SAndroid Build Coastguard Worker * @param[out] pu1_dst1
154*495ae853SAndroid Build Coastguard Worker * UWORD8 pointer to the destination (Horizontal filtered output)
155*495ae853SAndroid Build Coastguard Worker *
156*495ae853SAndroid Build Coastguard Worker * @param[out] pu1_dst2
157*495ae853SAndroid Build Coastguard Worker * UWORD8 pointer to the destination (output after applying vertical filter to
158*495ae853SAndroid Build Coastguard Worker * the intermediate horizontal output)
159*495ae853SAndroid Build Coastguard Worker *
160*495ae853SAndroid Build Coastguard Worker * @param[in] src_strd
161*495ae853SAndroid Build Coastguard Worker * integer source stride
162*495ae853SAndroid Build Coastguard Worker
163*495ae853SAndroid Build Coastguard Worker * @param[in] dst_strd
164*495ae853SAndroid Build Coastguard Worker * integer destination stride of pu1_dst
165*495ae853SAndroid Build Coastguard Worker *
166*495ae853SAndroid Build Coastguard Worker * @param[in] pi4_pred
167*495ae853SAndroid Build Coastguard Worker * Pointer to 16bit intermediate buffer (used only in c)
168*495ae853SAndroid Build Coastguard Worker *
169*495ae853SAndroid Build Coastguard Worker * @param[in] i4_pred_strd
170*495ae853SAndroid Build Coastguard Worker * integer destination stride of pi16_pred1
171*495ae853SAndroid Build Coastguard Worker *
172*495ae853SAndroid Build Coastguard Worker * @returns
173*495ae853SAndroid Build Coastguard Worker *
174*495ae853SAndroid Build Coastguard Worker * @remarks
175*495ae853SAndroid Build Coastguard Worker * none
176*495ae853SAndroid Build Coastguard Worker *
177*495ae853SAndroid Build Coastguard Worker *******************************************************************************
178*495ae853SAndroid Build Coastguard Worker */
ih264e_sixtap_filter_2dvh_vert(UWORD8 * pu1_src,UWORD8 * pu1_dst1,UWORD8 * pu1_dst2,WORD32 src_strd,WORD32 dst_strd,WORD32 * pi4_pred,WORD32 i4_pred_strd)179*495ae853SAndroid Build Coastguard Worker void ih264e_sixtap_filter_2dvh_vert(UWORD8 *pu1_src,
180*495ae853SAndroid Build Coastguard Worker UWORD8 *pu1_dst1,
181*495ae853SAndroid Build Coastguard Worker UWORD8 *pu1_dst2,
182*495ae853SAndroid Build Coastguard Worker WORD32 src_strd,
183*495ae853SAndroid Build Coastguard Worker WORD32 dst_strd,
184*495ae853SAndroid Build Coastguard Worker WORD32 *pi4_pred,
185*495ae853SAndroid Build Coastguard Worker WORD32 i4_pred_strd)
186*495ae853SAndroid Build Coastguard Worker {
187*495ae853SAndroid Build Coastguard Worker WORD32 row, col;
188*495ae853SAndroid Build Coastguard Worker WORD32 tmp;
189*495ae853SAndroid Build Coastguard Worker WORD32 *pi4_pred_temp = pi4_pred;
190*495ae853SAndroid Build Coastguard Worker WORD32 ht = HP_PL_HT, wd = HP_PL_WD;
191*495ae853SAndroid Build Coastguard Worker
192*495ae853SAndroid Build Coastguard Worker for (row = 0; row < ht; row++)
193*495ae853SAndroid Build Coastguard Worker {
194*495ae853SAndroid Build Coastguard Worker for (col = -2; col < wd + 3; col++)
195*495ae853SAndroid Build Coastguard Worker {
196*495ae853SAndroid Build Coastguard Worker tmp = ih264_g_six_tap[0] * (pu1_src[col - 2 * src_strd] + pu1_src[col + 3 * src_strd]) +
197*495ae853SAndroid Build Coastguard Worker ih264_g_six_tap[1] * (pu1_src[col - 1 * src_strd] + pu1_src[col + 2 * src_strd]) +
198*495ae853SAndroid Build Coastguard Worker ih264_g_six_tap[2] * (pu1_src[col] + pu1_src[col + 1 * src_strd]);
199*495ae853SAndroid Build Coastguard Worker
200*495ae853SAndroid Build Coastguard Worker pi4_pred_temp[col] = tmp;
201*495ae853SAndroid Build Coastguard Worker }
202*495ae853SAndroid Build Coastguard Worker
203*495ae853SAndroid Build Coastguard Worker pu1_src += src_strd;
204*495ae853SAndroid Build Coastguard Worker pi4_pred_temp += i4_pred_strd;
205*495ae853SAndroid Build Coastguard Worker }
206*495ae853SAndroid Build Coastguard Worker
207*495ae853SAndroid Build Coastguard Worker for (row = 0; row < ht; row++)
208*495ae853SAndroid Build Coastguard Worker {
209*495ae853SAndroid Build Coastguard Worker for (col = 0; col < wd; col++)
210*495ae853SAndroid Build Coastguard Worker {
211*495ae853SAndroid Build Coastguard Worker tmp = (pi4_pred[col - 2] + pi4_pred[col + 3]) +
212*495ae853SAndroid Build Coastguard Worker ih264_g_six_tap[1] * (pi4_pred[col - 1] + pi4_pred[col + 2]) +
213*495ae853SAndroid Build Coastguard Worker ih264_g_six_tap[2] * (pi4_pred[col] + pi4_pred[col + 1]);
214*495ae853SAndroid Build Coastguard Worker
215*495ae853SAndroid Build Coastguard Worker tmp = (tmp + 512) >> 10;
216*495ae853SAndroid Build Coastguard Worker
217*495ae853SAndroid Build Coastguard Worker pu1_dst2[col] = CLIP_U8(tmp);
218*495ae853SAndroid Build Coastguard Worker pu1_dst1[col] = CLIP_U8((pi4_pred[col] + 16) >> 5);
219*495ae853SAndroid Build Coastguard Worker }
220*495ae853SAndroid Build Coastguard Worker pi4_pred += i4_pred_strd;
221*495ae853SAndroid Build Coastguard Worker pu1_dst2 += dst_strd;
222*495ae853SAndroid Build Coastguard Worker pu1_dst1 += dst_strd;
223*495ae853SAndroid Build Coastguard Worker }
224*495ae853SAndroid Build Coastguard Worker }
225*495ae853SAndroid Build Coastguard Worker
226