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:  omxVCM4P10_TransformQuant_ChromaDC.c
20 * OpenMAX DL: v1.0.2
21 * Revision:   9641
22 * Date:       Thursday, February 7, 2008
23 *
24 *
25 *
26 * Description:
27 * This function will calculate 4x4 hadamard transform of chroma DC
28 * coefficients and quantization
29 *
30 */
31
32#include "omxtypes.h"
33#include "armOMX.h"
34#include "omxVC.h"
35
36#include "armVC.h"
37#include "armCOMM.h"
38
39/**
40 * Function:  omxVCM4P10_TransformQuant_ChromaDC   (6.3.5.6.1)
41 *
42 * Description:
43 * This function performs 2x2 Hadamard transform of chroma DC coefficients
44 * and then quantizes the coefficients.
45 *
46 * Input Arguments:
47 *
48 *   pSrcDst - Pointer to the 2x2 array of chroma DC coefficients.  8-byte
49 *            alignment required.
50 *   iQP - Quantization parameter; must be in the range [0,51].
51 *   bIntra - Indicate whether this is an INTRA block. 1-INTRA, 0-INTER
52 *
53 * Output Arguments:
54 *
55 *   pSrcDst - Pointer to transformed and quantized coefficients.  8-byte
56 *            alignment required.
57 *
58 * Return Value:
59 *
60 *    OMX_Sts_NoErr - no error
61 *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following
62 *              conditions are true:
63 *    -    at least one of the following pointers is NULL:
64 *             pSrcDst
65 *    -    pSrcDst is not aligned on an 8-byte boundary
66 *
67 */
68OMXResult omxVCM4P10_TransformQuant_ChromaDC(
69	OMX_S16* 	pSrcDst,
70	OMX_U32		iQP,
71	OMX_U8		bIntra
72)
73{
74    OMX_INT     i, j;
75    OMX_S32     m[2][2];
76    OMX_S32     Value;
77    OMX_S32     QbitsPlusOne, Two_f, MF00;
78
79    /* Check for argument error */
80    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
81    armRetArgErrIf(armNot8ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
82    armRetArgErrIf(iQP > 51, OMX_Sts_BadArgErr);
83
84    /* Hadamard Transform for 2x2 block */
85    m[0][0] = pSrcDst[0] + pSrcDst[1] +  pSrcDst[2] + pSrcDst[3];
86    m[0][1] = pSrcDst[0] - pSrcDst[1] +  pSrcDst[2] - pSrcDst[3];
87    m[1][0] = pSrcDst[0] + pSrcDst[1] -  pSrcDst[2] - pSrcDst[3];
88    m[1][1] = pSrcDst[0] - pSrcDst[1] -  pSrcDst[2] + pSrcDst[3];
89
90    /* Quantization */
91    QbitsPlusOne = ARM_M4P10_Q_OFFSET + 1 + (iQP / 6); /*floor (QP/6)*/
92    MF00 = armVCM4P10_MFMatrix [iQP % 6][0];
93
94    Two_f = (1 << QbitsPlusOne) / (bIntra ? 3 : 6); /* 3->INTRA, 6->INTER */
95
96    /* Scaling */
97    for (j = 0; j < 2; j++)
98    {
99        for (i = 0; i < 2; i++)
100        {
101            Value = (armAbs(m[j][i]) * MF00 + Two_f) >> QbitsPlusOne;
102            pSrcDst[j * 2 + i] = (OMX_S16)((m[j][i] < 0) ? -Value : Value);
103        }
104    }
105
106    return OMX_Sts_NoErr;
107}
108
109/*****************************************************************************
110 *                              END OF FILE
111 *****************************************************************************/
112
113