Home | History | Annotate | Download | only in src
      1 /**
      2  *
      3  * File Name:  omxVCM4P2_QuantIntra_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 Quantization
     14  *
     15  */
     16 
     17 #include "omxtypes.h"
     18 #include "armOMX.h"
     19 #include "omxVC.h"
     20 
     21 #include "armCOMM.h"
     22 /**
     23  * Function:  omxVCM4P2_QuantIntra_I   (6.2.4.4.2)
     24  *
     25  * Description:
     26  * Performs quantization on intra block coefficients. This function supports
     27  * bits_per_pixel == 8.
     28  *
     29  * Input Arguments:
     30  *
     31  *   pSrcDst - pointer to the input intra block coefficients; must be aligned
     32  *            on a 16-byte boundary.
     33  *   QP - quantization parameter (quantizer_scale).
     34  *   blockIndex - block index indicating the component type and position,
     35  *            valid in the range 0 to 5, as defined in [ISO14496-2], subclause
     36  *            6.1.3.8.
     37  *   shortVideoHeader - binary flag indicating presence of
     38  *            short_video_header; shortVideoHeader==1 selects linear intra DC
     39  *            mode, and shortVideoHeader==0 selects non linear intra DC mode.
     40  *
     41  * Output Arguments:
     42  *
     43  *   pSrcDst - pointer to the output (quantized) interblock coefficients.
     44  *            When shortVideoHeader==1, AC coefficients are saturated on the
     45  *            interval [-127, 127], and DC coefficients are saturated on the
     46  *            interval [1, 254].  When shortVideoHeader==0, AC coefficients
     47  *            are saturated on the interval [-2047, 2047].
     48  *
     49  * Return Value:
     50  *
     51  *    OMX_Sts_NoErr - no error
     52  *    OMX_Sts_BadArgErr - bad arguments:
     53  *    -    pSrcDst is NULL.
     54  *    -    blockIndex < 0 or blockIndex >= 10
     55  *    -    QP <= 0 or QP >= 32.
     56  *
     57  */
     58 
     59 OMXResult omxVCM4P2_QuantIntra_I(
     60      OMX_S16 * pSrcDst,
     61      OMX_U8 QP,
     62      OMX_INT blockIndex,
     63 	 OMX_INT shortVideoHeader
     64  )
     65 {
     66 
     67     /* Definitions and Initializations*/
     68     /* Initialized to remove compilation error */
     69     OMX_INT dcScaler = 0, coeffCount,fSign;
     70     OMX_INT maxClpAC, minClpAC;
     71 
     72     /* Argument error checks */
     73     armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
     74     armRetArgErrIf(((blockIndex < 0) || (blockIndex >= 10)), OMX_Sts_BadArgErr);
     75     armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
     76    /* One argument check is delayed until we have ascertained that  */
     77    /* pQMatrix is not NULL.                                         */
     78 
     79 
     80     /* Set the Clip Range based on SVH on/off */
     81     if(shortVideoHeader == 1)
     82     {
     83         maxClpAC = 127;
     84         minClpAC = -127;
     85         dcScaler = 8;
     86         /* Dequant the DC value, this applies to both the methods */
     87         pSrcDst[0] = armIntDivAwayFromZero (pSrcDst[0], dcScaler);
     88 
     89         /* Clip between 1 and 254 */
     90         pSrcDst[0] = (OMX_S16) armClip (1, 254, pSrcDst[0]);
     91     }
     92     else
     93     {
     94         maxClpAC = 2047;
     95         minClpAC = -2047;
     96         /* Calculate the DC scaler value */
     97         if ((blockIndex  < 4) || (blockIndex  > 5))
     98         {
     99             if (QP >= 1 && QP <= 4)
    100             {
    101                 dcScaler = 8;
    102             }
    103             else if (QP >= 5 && QP <= 8)
    104             {
    105                 dcScaler = 2 * QP;
    106             }
    107             else if (QP >= 9 && QP <= 24)
    108             {
    109                 dcScaler = QP + 8;
    110             }
    111             else
    112             {
    113                 dcScaler = (2 * QP) - 16;
    114             }
    115         }
    116         else if (blockIndex < 6)
    117         {
    118             if (QP >= 1 && QP <= 4)
    119             {
    120                 dcScaler = 8;
    121             }
    122             else if (QP >= 5 && QP <= 24)
    123             {
    124                 dcScaler = (QP + 13)/2;
    125             }
    126             else
    127             {
    128                 dcScaler = QP - 6;
    129             }
    130         }
    131 
    132         /* Dequant the DC value, this applies to both the methods */
    133         pSrcDst[0] = armIntDivAwayFromZero (pSrcDst[0], dcScaler);
    134     }
    135 
    136     /* Second Inverse quantisation method */
    137     for (coeffCount = 1; coeffCount < 64; coeffCount++)
    138     {
    139         fSign =  armSignCheck (pSrcDst[coeffCount]);
    140         pSrcDst[coeffCount] = armAbs(pSrcDst[coeffCount])/(2 * QP);
    141         pSrcDst[coeffCount] *= fSign;
    142 
    143         /* Clip */
    144         pSrcDst[coeffCount] =
    145         (OMX_S16) armClip (minClpAC, maxClpAC, pSrcDst[coeffCount]);
    146     }
    147     return OMX_Sts_NoErr;
    148 
    149 }
    150 
    151 /* End of file */
    152 
    153 
    154