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