omxVCM4P10_TransformDequantChromaDCFromPair.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 *
20 * File Name:  omxVCM4P10_TransformDequantChromaDCFromPair.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 Chroma 2x2 DC block
42 */
43
44static void DequantChromaDC2x2(
45     OMX_S16* pDst,
46     OMX_INT QP
47)
48{
49    int Shift = (QP/6)-1 ;
50    int Scale = armVCM4P10_VMatrix[QP%6][0];
51    int i, Value;
52
53    if (Shift >= 0)
54    {
55        for (i=0; i<4; i++)
56        {
57            Value = (pDst[i] * Scale) << Shift;
58            pDst[i] = (OMX_S16)Value;
59        }
60    }
61    else
62    {
63        for (i=0; i<4; i++)
64        {
65            Value = (pDst[i] * Scale) >> 1;
66            pDst[i] = (OMX_S16)Value;
67        }
68    }
69}
70
71
72/*
73 * Description:
74 * Inverse Transform DC 2x2 Coefficients
75 */
76
77static void InvTransformDC2x2(OMX_S16* pData)
78{
79    int c00 = pData[0];
80    int c01 = pData[1];
81    int c10 = pData[2];
82    int c11 = pData[3];
83
84    int d00 = c00 + c01;
85    int d01 = c00 - c01;
86    int d10 = c10 + c11;
87    int d11 = c10 - c11;
88
89    pData[0] = (OMX_S16)(d00 + d10);
90    pData[1] = (OMX_S16)(d01 + d11);
91    pData[2] = (OMX_S16)(d00 - d10);
92    pData[3] = (OMX_S16)(d01 - d11);
93}
94
95
96/**
97 * Function:  omxVCM4P10_TransformDequantChromaDCFromPair   (6.3.4.2.2)
98 *
99 * Description:
100 * Reconstruct the 2x2 ChromaDC block from coefficient-position pair buffer,
101 * perform integer inverse transformation, and dequantization for 2x2 chroma
102 * DC coefficients, and update the pair buffer pointer to next non-empty
103 * block.
104 *
105 * Input Arguments:
106 *
107 *   ppSrc - Double pointer to residual coefficient-position pair buffer
108 *            output by CALVC decoding
109 *   QP - Quantization parameter QpC
110 *
111 * Output Arguments:
112 *
113 *   ppSrc - *ppSrc is updated to the start of next non empty block
114 *   pDst - Pointer to the reconstructed 2x2 ChromaDC coefficients buffer;
115 *            must be aligned on a 4-byte boundary.
116 *
117 * Return Value:
118 *    OMX_Sts_NoErr, if the function runs without error.
119 *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs:
120 *    -    ppSrc or pDst is NULL.
121 *    -    pDst is not 4-byte aligned.
122 *    -    QP is not in the range of [0-51].
123 *
124 */
125
126OMXResult omxVCM4P10_TransformDequantChromaDCFromPair(
127     const OMX_U8 **ppSrc,
128     OMX_S16* pDst,
129     OMX_INT QP
130 )
131{
132    armRetArgErrIf(ppSrc  == NULL,           OMX_Sts_BadArgErr);
133    armRetArgErrIf(*ppSrc == NULL,           OMX_Sts_BadArgErr);
134    armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
135    armRetArgErrIf(armNot4ByteAligned(pDst), OMX_Sts_BadArgErr);
136    armRetArgErrIf(QP<0,                     OMX_Sts_BadArgErr);
137    armRetArgErrIf(QP>51,                    OMX_Sts_BadArgErr);
138
139    armVCM4P10_UnpackBlock2x2(ppSrc, pDst);
140    InvTransformDC2x2(pDst);
141    DequantChromaDC2x2(pDst, QP);
142
143    return OMX_Sts_NoErr;
144}
145
146/* End of file */
147