Home | History | Annotate | Download | only in common
      1 /******************************************************************************
      2 *
      3 * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
      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 /**
     19  *******************************************************************************
     20  * @file
     21  *  ihevc_chroma_itrans_recon.c
     22  *
     23  * @brief
     24  *  Contains function definitions for inverse transform  and reconstruction
     25  * of chroma interleaved data.
     26  *
     27  * @author
     28  *  100470
     29  *
     30  * @par List of Functions:
     31  *  - ihevc_chroma_itrans_recon_4x4()
     32  *
     33  * @remarks
     34  *  None
     35  *
     36  *******************************************************************************
     37  */
     38 
     39 #include <stdio.h>
     40 #include <string.h>
     41 #include "ihevc_typedefs.h"
     42 #include "ihevc_macros.h"
     43 #include "ihevc_platform_macros.h"
     44 #include "ihevc_defs.h"
     45 #include "ihevc_trans_tables.h"
     46 #include "ihevc_chroma_itrans_recon.h"
     47 #include "ihevc_func_selector.h"
     48 #include "ihevc_trans_macros.h"
     49 
     50 /* All the functions work one component(U or V) of interleaved data depending upon pointers passed to it */
     51 /* Data visualization */
     52 /* U V U V U V U V */
     53 /* U V U V U V U V */
     54 /* U V U V U V U V */
     55 /* U V U V U V U V */
     56 /* If the pointer points to first byte of above stream (U) , functions will operate on U component */
     57 /* If the pointer points to second byte of above stream (V) , functions will operate on V component */
     58 
     59 /**
     60  *******************************************************************************
     61  *
     62  * @brief
     63  *  This function performs Inverse transform  and reconstruction for 4x4
     64  * input block
     65  *
     66  * @par Description:
     67  *  Performs inverse transform and adds the prediction  data and clips output
     68  * to 8 bit
     69  *
     70  * @param[in] pi2_src
     71  *  Input 4x4 coefficients
     72  *
     73  * @param[in] pi2_tmp
     74  *  Temporary 4x4 buffer for storing inverse transform
     75  *  1st stage output
     76  *
     77  * @param[in] pu1_pred
     78  *  Prediction 4x4 block
     79  *
     80  * @param[out] pu1_dst
     81  *  Output 4x4 block
     82  *
     83  * @param[in] src_strd
     84  *  Input stride
     85  *
     86  * @param[in] pred_strd
     87  *  Prediction stride
     88  *
     89  * @param[in] dst_strd
     90  *  Output Stride
     91  *
     92  * @param[in] shift
     93  *  Output shift
     94  *
     95  * @param[in] zero_cols
     96  *  Zero columns in pi2_src
     97  *
     98  * @returns  Void
     99  *
    100  * @remarks
    101  *  None
    102  *
    103  *******************************************************************************
    104  */
    105 
    106 
    107 void ihevc_chroma_itrans_recon_4x4(WORD16 *pi2_src,
    108                                    WORD16 *pi2_tmp,
    109                                    UWORD8 *pu1_pred,
    110                                    UWORD8 *pu1_dst,
    111                                    WORD32 src_strd,
    112                                    WORD32 pred_strd,
    113                                    WORD32 dst_strd,
    114                                    WORD32 zero_cols,
    115                                    WORD32 zero_rows)
    116 {
    117     WORD32 j;
    118     WORD32 e[2], o[2];
    119     WORD32 add;
    120     WORD32 shift;
    121     WORD16 *pi2_tmp_orig;
    122     WORD32 trans_size;
    123     UNUSED(zero_rows);
    124     trans_size = TRANS_SIZE_4;
    125 
    126     pi2_tmp_orig = pi2_tmp;
    127 
    128     /* Inverse Transform 1st stage */
    129     shift = IT_SHIFT_STAGE_1;
    130     add = 1 << (shift - 1);
    131 
    132     for(j = 0; j < trans_size; j++)
    133     {
    134         /* Checking for Zero Cols */
    135         if((zero_cols & 1) == 1)
    136         {
    137             memset(pi2_tmp, 0, trans_size * sizeof(WORD16));
    138         }
    139         else
    140         {
    141 
    142             /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
    143             o[0] = g_ai2_ihevc_trans_4[1][0] * pi2_src[src_strd]
    144                             + g_ai2_ihevc_trans_4[3][0] * pi2_src[3 * src_strd];
    145             o[1] = g_ai2_ihevc_trans_4[1][1] * pi2_src[src_strd]
    146                             + g_ai2_ihevc_trans_4[3][1] * pi2_src[3 * src_strd];
    147             e[0] = g_ai2_ihevc_trans_4[0][0] * pi2_src[0]
    148                             + g_ai2_ihevc_trans_4[2][0] * pi2_src[2 * src_strd];
    149             e[1] = g_ai2_ihevc_trans_4[0][1] * pi2_src[0]
    150                             + g_ai2_ihevc_trans_4[2][1] * pi2_src[2 * src_strd];
    151 
    152             pi2_tmp[0] =
    153                             CLIP_S16(((e[0] + o[0] + add) >> shift));
    154             pi2_tmp[1] =
    155                             CLIP_S16(((e[1] + o[1] + add) >> shift));
    156             pi2_tmp[2] =
    157                             CLIP_S16(((e[1] - o[1] + add) >> shift));
    158             pi2_tmp[3] =
    159                             CLIP_S16(((e[0] - o[0] + add) >> shift));
    160 
    161         }
    162         pi2_src++;
    163         pi2_tmp += trans_size;
    164         zero_cols = zero_cols >> 1;
    165     }
    166 
    167     pi2_tmp = pi2_tmp_orig;
    168 
    169     /* Inverse Transform 2nd stage */
    170     shift = IT_SHIFT_STAGE_2;
    171     add = 1 << (shift - 1);
    172 
    173     for(j = 0; j < trans_size; j++)
    174     {
    175         WORD32 itrans_out;
    176         /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
    177         o[0] = g_ai2_ihevc_trans_4[1][0] * pi2_tmp[trans_size]
    178                         + g_ai2_ihevc_trans_4[3][0] * pi2_tmp[3 * trans_size];
    179         o[1] = g_ai2_ihevc_trans_4[1][1] * pi2_tmp[trans_size]
    180                         + g_ai2_ihevc_trans_4[3][1] * pi2_tmp[3 * trans_size];
    181         e[0] = g_ai2_ihevc_trans_4[0][0] * pi2_tmp[0]
    182                         + g_ai2_ihevc_trans_4[2][0] * pi2_tmp[2 * trans_size];
    183         e[1] = g_ai2_ihevc_trans_4[0][1] * pi2_tmp[0]
    184                         + g_ai2_ihevc_trans_4[2][1] * pi2_tmp[2 * trans_size];
    185 
    186         itrans_out =
    187                         CLIP_S16(((e[0] + o[0] + add) >> shift));
    188         pu1_dst[0 * 2] = CLIP_U8((itrans_out + pu1_pred[0 * 2]));
    189         itrans_out =
    190                         CLIP_S16(((e[1] + o[1] + add) >> shift));
    191         pu1_dst[1 * 2] = CLIP_U8((itrans_out + pu1_pred[1 * 2]));
    192         itrans_out =
    193                         CLIP_S16(((e[1] - o[1] + add) >> shift));
    194         pu1_dst[2 * 2] = CLIP_U8((itrans_out + pu1_pred[2 * 2]));
    195         itrans_out =
    196                         CLIP_S16(((e[0] - o[0] + add) >> shift));
    197         pu1_dst[3 * 2] = CLIP_U8((itrans_out + pu1_pred[3 * 2]));
    198 
    199         pi2_tmp++;
    200         pu1_pred += pred_strd;
    201         pu1_dst += dst_strd;
    202 
    203     }
    204 }
    205 
    206