Home | History | Annotate | Download | only in src
      1 /**
      2  *
      3  * File Name:  omxVCM4P2_QuantInvIntra_I.c
      4  * OpenMAX DL: v1.0.2
      5  * Revision:   9641
      6  * Date:       Thursday, February 7, 2008
      7  *
      8  * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
      9  *
     10  *
     11  *
     12  * Description:
     13  * Contains modules for intra inverse Quantization
     14  *
     15  */
     16 
     17 #include "omxtypes.h"
     18 #include "armOMX.h"
     19 #include "omxVC.h"
     20 
     21 #include "armCOMM.h"
     22 
     23 /**
     24  * Function:  omxVCM4P2_QuantInvIntra_I   (6.2.5.3.2)
     25  *
     26  * Description:
     27  * Performs the second inverse quantization mode on an intra/inter coded
     28  * block. Supports bits_per_pixel = 8. The output coefficients are clipped to
     29  * the range [-2048, 2047].
     30  *
     31  * Input Arguments:
     32  *
     33  *   pSrcDst - pointer to the input (quantized) intra/inter block; must be
     34  *            aligned on a 16-byte boundary.
     35  *   QP - quantization parameter (quantizer_scale)
     36  *   videoComp - video component type of the current block. Takes one of the
     37  *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra
     38  *            version only).
     39  *   shortVideoHeader - binary flag indicating presence of short_video_header
     40  *            (intra version only).
     41  *
     42  * Output Arguments:
     43  *
     44  *   pSrcDst - pointer to the output (dequantized) intra/inter block
     45  *
     46  * Return Value:
     47  *
     48  *    OMX_Sts_NoErr - no error
     49  *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is
     50  *              true:
     51  *    -    pSrcDst is NULL
     52  *    -    QP <= 0 or QP >=31
     53  *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE.
     54  *
     55  */
     56 
     57 OMXResult omxVCM4P2_QuantInvIntra_I(
     58      OMX_S16 * pSrcDst,
     59      OMX_INT QP,
     60      OMXVCM4P2VideoComponent videoComp,
     61 	 OMX_INT shortVideoHeader
     62 )
     63 {
     64 
     65     /* Initialized to remove compilation error */
     66     OMX_INT dcScaler = 0, coeffCount, Sign;
     67 
     68     /* Argument error checks */
     69     armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
     70     armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
     71 	armRetArgErrIf(((videoComp != OMX_VC_LUMINANCE) && (videoComp != OMX_VC_CHROMINANCE)), OMX_Sts_BadArgErr);
     72 
     73     /* Calculate the DC scaler value */
     74 
     75     /* linear intra DC mode */
     76     if(shortVideoHeader)
     77     {
     78         dcScaler = 8;
     79     }
     80     /* nonlinear intra DC mode */
     81     else
     82     {
     83 
     84         if (videoComp == OMX_VC_LUMINANCE)
     85         {
     86             if (QP >= 1 && QP <= 4)
     87             {
     88                 dcScaler = 8;
     89             }
     90             else if (QP >= 5 && QP <= 8)
     91             {
     92                 dcScaler = 2 * QP;
     93             }
     94             else if (QP >= 9 && QP <= 24)
     95             {
     96                 dcScaler = QP + 8;
     97             }
     98             else
     99             {
    100                 dcScaler = (2 * QP) - 16;
    101             }
    102         }
    103 
    104         else if (videoComp == OMX_VC_CHROMINANCE)
    105         {
    106             if (QP >= 1 && QP <= 4)
    107             {
    108                 dcScaler = 8;
    109             }
    110             else if (QP >= 5 && QP <= 24)
    111             {
    112                 dcScaler = (QP + 13)/2;
    113             }
    114             else
    115             {
    116                 dcScaler = QP - 6;
    117             }
    118         }
    119     }
    120     /* Dequant the DC value, this applies to both the methods */
    121     pSrcDst[0] = pSrcDst[0] * dcScaler;
    122 
    123     /* Saturate */
    124     pSrcDst[0] = armClip (-2048, 2047, pSrcDst[0]);
    125 
    126     /* Second Inverse quantisation method */
    127     for (coeffCount = 1; coeffCount < 64; coeffCount++)
    128     {
    129         /* check sign */
    130         Sign =  armSignCheck (pSrcDst[coeffCount]);
    131 
    132         if (QP & 0x1)
    133         {
    134             pSrcDst[coeffCount] = (2* armAbs(pSrcDst[coeffCount]) + 1) * QP;
    135             pSrcDst[coeffCount] *= Sign;
    136         }
    137         else
    138         {
    139             pSrcDst[coeffCount] =
    140                                 (2* armAbs(pSrcDst[coeffCount]) + 1) * QP - 1;
    141             pSrcDst[coeffCount] *= Sign;
    142         }
    143 
    144         /* Saturate */
    145         pSrcDst[coeffCount] = armClip (-2048, 2047, pSrcDst[coeffCount]);
    146     }
    147     return OMX_Sts_NoErr;
    148 
    149 }
    150 
    151 /* End of file */
    152 
    153 
    154