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 * File Name:  omxVCM4P2_QuantInter_I.c
20 * OpenMAX DL: v1.0.2
21 * Revision:   9641
22 * Date:       Thursday, February 7, 2008
23 *
24 *
25 *
26 *
27 * Description:
28 * Contains modules for inter Quantization
29 *
30 */
31
32#include "omxtypes.h"
33#include "armOMX.h"
34#include "omxVC.h"
35
36#include "armCOMM.h"
37
38/**
39 * Function:  omxVCM4P2_QuantInter_I   (6.2.4.4.3)
40 *
41 * Description:
42 * Performs quantization on an inter coefficient block; supports
43 * bits_per_pixel == 8.
44 *
45 * Input Arguments:
46 *
47 *   pSrcDst - pointer to the input inter block coefficients; must be aligned
48 *            on a 16-byte boundary.
49 *   QP - quantization parameter (quantizer_scale)
50 *   shortVideoHeader - binary flag indicating presence of short_video_header;
51 *            shortVideoHeader==1 selects linear intra DC mode, and
52 *            shortVideoHeader==0 selects non linear intra DC mode.
53 *
54 * Output Arguments:
55 *
56 *   pSrcDst - pointer to the output (quantized) interblock coefficients.
57 *            When shortVideoHeader==1, AC coefficients are saturated on the
58 *            interval [-127, 127], and DC coefficients are saturated on the
59 *            interval [1, 254].  When shortVideoHeader==0, AC coefficients
60 *            are saturated on the interval [-2047, 2047].
61 *
62 * Return Value:
63 *
64 *    OMX_Sts_NoErr - no error
65 *    OMX_Sts_BadArgErr - bad arguments:
66 *    -    pSrcDst is NULL.
67 *    -    QP <= 0 or QP >= 32.
68 *
69 */
70
71OMXResult omxVCM4P2_QuantInter_I(
72     OMX_S16 * pSrcDst,
73     OMX_U8 QP,
74	 OMX_INT shortVideoHeader
75)
76{
77
78    /* Definitions and Initializations*/
79    OMX_INT coeffCount;
80    OMX_INT fSign;
81    OMX_INT maxClpAC = 0, minClpAC = 0;
82    OMX_INT maxClpDC = 0, minClpDC = 0;
83
84    /* Argument error checks */
85    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
86    armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
87   /* One argument check is delayed until we have ascertained that  */
88   /* pQMatrix is not NULL.                                         */
89
90    /* Set the Clip Range based on SVH on/off */
91    if(shortVideoHeader == 1)
92    {
93       maxClpDC = 254;
94       minClpDC = 1;
95       maxClpAC = 127;
96       minClpAC = -127;
97    }
98    else
99    {
100        maxClpDC = 2047;
101        minClpDC = -2047;
102        maxClpAC = 2047;
103        minClpAC = -2047;
104    }
105
106    /* Second Inverse quantisation method */
107    for (coeffCount = 0; coeffCount < 64; coeffCount++)
108    {
109        fSign =  armSignCheck (pSrcDst[coeffCount]);
110        pSrcDst[coeffCount] = (armAbs(pSrcDst[coeffCount])
111                              - (QP/2))/(2 * QP);
112        pSrcDst[coeffCount] *= fSign;
113
114        /* Clip */
115        if (coeffCount == 0)
116        {
117           pSrcDst[coeffCount] =
118           (OMX_S16) armClip (minClpDC, maxClpDC, pSrcDst[coeffCount]);
119        }
120        else
121        {
122           pSrcDst[coeffCount] =
123           (OMX_S16) armClip (minClpAC, maxClpAC, pSrcDst[coeffCount]);
124        }
125    }
126    return OMX_Sts_NoErr;
127
128}
129
130/* End of file */
131
132
133