omxVCM4P2_QuantInvIntra_I.c revision 78e52bfac041d71ce53b5b13c2abf78af742b09d
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_QuantInvIntra_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 intra inverse 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_QuantInvIntra_I   (6.2.5.3.2)
40 *
41 * Description:
42 * Performs the second inverse quantization mode on an intra/inter coded
43 * block. Supports bits_per_pixel = 8. The output coefficients are clipped to
44 * the range [-2048, 2047].
45 *
46 * Input Arguments:
47 *
48 *   pSrcDst - pointer to the input (quantized) intra/inter block; must be
49 *            aligned on a 16-byte boundary.
50 *   QP - quantization parameter (quantizer_scale)
51 *   videoComp - video component type of the current block. Takes one of the
52 *            following flags: OMX_VC_LUMINANCE, OMX_VC_CHROMINANCE (intra
53 *            version only).
54 *   shortVideoHeader - binary flag indicating presence of short_video_header
55 *            (intra version only).
56 *
57 * Output Arguments:
58 *
59 *   pSrcDst - pointer to the output (dequantized) intra/inter block
60 *
61 * Return Value:
62 *
63 *    OMX_Sts_NoErr - no error
64 *    OMX_Sts_BadArgErr - bad arguments; one or more of the following is
65 *              true:
66 *    -    pSrcDst is NULL
67 *    -    QP <= 0 or QP >=31
68 *    -    videoComp is neither OMX_VC_LUMINANCE nor OMX_VC_CHROMINANCE.
69 *
70 */
71
72OMXResult omxVCM4P2_QuantInvIntra_I(
73     OMX_S16 * pSrcDst,
74     OMX_INT QP,
75     OMXVCM4P2VideoComponent videoComp,
76	 OMX_INT shortVideoHeader
77)
78{
79
80    /* Initialized to remove compilation error */
81    OMX_INT dcScaler = 0, coeffCount, Sign;
82
83    /* Argument error checks */
84    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
85    armRetArgErrIf(((QP <= 0) || (QP >= 32)), OMX_Sts_BadArgErr);
86	armRetArgErrIf(((videoComp != OMX_VC_LUMINANCE) && (videoComp != OMX_VC_CHROMINANCE)), OMX_Sts_BadArgErr);
87
88    /* Calculate the DC scaler value */
89
90    /* linear intra DC mode */
91    if(shortVideoHeader)
92    {
93        dcScaler = 8;
94    }
95    /* nonlinear intra DC mode */
96    else
97    {
98
99        if (videoComp == OMX_VC_LUMINANCE)
100        {
101            if (QP >= 1 && QP <= 4)
102            {
103                dcScaler = 8;
104            }
105            else if (QP >= 5 && QP <= 8)
106            {
107                dcScaler = 2 * QP;
108            }
109            else if (QP >= 9 && QP <= 24)
110            {
111                dcScaler = QP + 8;
112            }
113            else
114            {
115                dcScaler = (2 * QP) - 16;
116            }
117        }
118
119        else if (videoComp == OMX_VC_CHROMINANCE)
120        {
121            if (QP >= 1 && QP <= 4)
122            {
123                dcScaler = 8;
124            }
125            else if (QP >= 5 && QP <= 24)
126            {
127                dcScaler = (QP + 13)/2;
128            }
129            else
130            {
131                dcScaler = QP - 6;
132            }
133        }
134    }
135    /* Dequant the DC value, this applies to both the methods */
136    pSrcDst[0] = pSrcDst[0] * dcScaler;
137
138    /* Saturate */
139    pSrcDst[0] = armClip (-2048, 2047, pSrcDst[0]);
140
141    /* Second Inverse quantisation method */
142    for (coeffCount = 1; coeffCount < 64; coeffCount++)
143    {
144        /* check sign */
145        Sign =  armSignCheck (pSrcDst[coeffCount]);
146
147        if (QP & 0x1)
148        {
149            pSrcDst[coeffCount] = (2* armAbs(pSrcDst[coeffCount]) + 1) * QP;
150            pSrcDst[coeffCount] *= Sign;
151        }
152        else
153        {
154            pSrcDst[coeffCount] =
155                                (2* armAbs(pSrcDst[coeffCount]) + 1) * QP - 1;
156            pSrcDst[coeffCount] *= Sign;
157        }
158
159        /* Saturate */
160        pSrcDst[coeffCount] = armClip (-2048, 2047, pSrcDst[coeffCount]);
161    }
162    return OMX_Sts_NoErr;
163
164}
165
166/* End of file */
167
168
169