Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2007-2008 ARM Limited
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  *
     16  */
     17 /* ----------------------------------------------------------------
     18  *
     19  *
     20  * File Name:  omxVCM4P10_DequantTransformResidualFromPairAndAdd.c
     21  * OpenMAX DL: v1.0.2
     22  * Revision:   9641
     23  * Date:       Thursday, February 7, 2008
     24  *
     25  *
     26  *
     27  *
     28  * H.264 inverse quantize and transform module
     29  *
     30  */
     31 
     32 #include "omxtypes.h"
     33 #include "armOMX.h"
     34 #include "omxVC.h"
     35 
     36 #include "armCOMM.h"
     37 #include "armVC.h"
     38 
     39 /*
     40  * Description:
     41  * Dequantize Luma AC block
     42  */
     43 
     44 static void DequantLumaAC4x4(
     45      OMX_S16* pSrcDst,
     46      OMX_INT QP
     47 )
     48 {
     49     const OMX_U8 *pVRow = &armVCM4P10_VMatrix[QP%6][0];
     50     int Shift = QP / 6;
     51     int i;
     52     OMX_S32 Value;
     53 
     54     for (i=0; i<16; i++)
     55     {
     56 
     57         Value = (pSrcDst[i] * pVRow[armVCM4P10_PosToVCol4x4[i]]) << Shift;
     58         pSrcDst[i] = (OMX_S16)Value;
     59     }
     60 }
     61 
     62 /**
     63  * Function:  omxVCM4P10_DequantTransformResidualFromPairAndAdd   (6.3.4.2.3)
     64  *
     65  * Description:
     66  * Reconstruct the 4x4 residual block from coefficient-position pair buffer,
     67  * perform dequantization and integer inverse transformation for 4x4 block of
     68  * residuals with previous intra prediction or motion compensation data, and
     69  * update the pair buffer pointer to next non-empty block. If pDC == NULL,
     70  * there re 16 non-zero AC coefficients at most in the packed buffer starting
     71  * from 4x4 block position 0; If pDC != NULL, there re 15 non-zero AC
     72  * coefficients at most in the packet buffer starting from 4x4 block position
     73  * 1.
     74  *
     75  * Input Arguments:
     76  *
     77  *   ppSrc - Double pointer to residual coefficient-position pair buffer
     78  *            output by CALVC decoding
     79  *   pPred - Pointer to the predicted 4x4 block; must be aligned on a 4-byte
     80  *            boundary
     81  *   predStep - Predicted frame step size in bytes; must be a multiple of 4
     82  *   dstStep - Destination frame step in bytes; must be a multiple of 4
     83  *   pDC - Pointer to the DC coefficient of this block, NULL if it doesn't
     84  *            exist
     85  *   QP - QP Quantization parameter.  It should be QpC in chroma 4x4 block
     86  *            decoding, otherwise it should be QpY.
     87  *   AC - Flag indicating if at least one non-zero AC coefficient exists
     88  *
     89  * Output Arguments:
     90  *
     91  *   pDst - pointer to the reconstructed 4x4 block data; must be aligned on a
     92  *            4-byte boundary
     93  *
     94  * Return Value:
     95  *    OMX_Sts_NoErr, if the function runs without error.
     96  *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs:
     97  *    -    pPred or pDst is NULL.
     98  *    -    pPred or pDst is not 4-byte aligned.
     99  *    -    predStep or dstStep is not a multiple of 4.
    100  *    -    AC !=0 and Qp is not in the range of [0-51] or ppSrc == NULL.
    101  *    -    AC ==0 && pDC ==NULL.
    102  *
    103  */
    104 
    105 OMXResult omxVCM4P10_DequantTransformResidualFromPairAndAdd(
    106      const OMX_U8 **ppSrc,
    107      const OMX_U8 *pPred,
    108      const OMX_S16 *pDC,
    109      OMX_U8 *pDst,
    110      OMX_INT predStep,
    111      OMX_INT dstStep,
    112      OMX_INT QP,
    113      OMX_INT AC
    114 )
    115 {
    116     OMX_S16 pBuffer[16+4];
    117     OMX_S16 *pDelta;
    118     int i,x,y;
    119 
    120     armRetArgErrIf(pPred == NULL,            OMX_Sts_BadArgErr);
    121     armRetArgErrIf(armNot4ByteAligned(pPred),OMX_Sts_BadArgErr);
    122     armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
    123     armRetArgErrIf(armNot4ByteAligned(pDst), OMX_Sts_BadArgErr);
    124     armRetArgErrIf(predStep & 3,             OMX_Sts_BadArgErr);
    125     armRetArgErrIf(dstStep & 3,              OMX_Sts_BadArgErr);
    126     armRetArgErrIf(AC!=0 && (QP<0),          OMX_Sts_BadArgErr);
    127     armRetArgErrIf(AC!=0 && (QP>51),         OMX_Sts_BadArgErr);
    128     armRetArgErrIf(AC!=0 && ppSrc==NULL,     OMX_Sts_BadArgErr);
    129     armRetArgErrIf(AC!=0 && *ppSrc==NULL,    OMX_Sts_BadArgErr);
    130     armRetArgErrIf(AC==0 && pDC==NULL,       OMX_Sts_BadArgErr);
    131 
    132     pDelta = armAlignTo8Bytes(pBuffer);
    133 
    134     for (i=0; i<16; i++)
    135     {
    136         pDelta[i] = 0;
    137     }
    138     if (AC)
    139     {
    140         armVCM4P10_UnpackBlock4x4(ppSrc, pDelta);
    141         DequantLumaAC4x4(pDelta, QP);
    142     }
    143     if (pDC)
    144     {
    145         pDelta[0] = pDC[0];
    146     }
    147     armVCM4P10_TransformResidual4x4(pDelta,pDelta);
    148 
    149     for (y=0; y<4; y++)
    150     {
    151         for (x=0; x<4; x++)
    152         {
    153             pDst[y*dstStep+x] = (OMX_U8)armClip(0,255,pPred[y*predStep+x] + pDelta[4*y+x]);
    154         }
    155     }
    156 
    157     return OMX_Sts_NoErr;
    158 }
    159 
    160 /* End of file */
    161