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_LumaDC.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 luma DC coefficients
28 * and quantization
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 * Function:  omxVCM4P10_TransformQuant_LumaDC   (6.3.5.6.2)
41 *
42 * Description:
43 * This function performs a 4x4 Hadamard transform of luma DC coefficients
44 * and then quantizes the coefficients.
45 *
46 * Input Arguments:
47 *
48 *   pSrcDst - Pointer to the 4x4 array of luma DC coefficients.  16-byte
49 *            alignment required.
50 *   iQP - Quantization parameter; must be in the range [0,51].
51 *
52 * Output Arguments:
53 *
54 *   pSrcDst - Pointer to transformed and quantized coefficients.  16-byte
55 *             alignment required.
56 *
57 * Return Value:
58 *
59 *    OMX_Sts_NoErr - no error
60 *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following
61 *              conditions are true:
62 *    -    at least one of the following pointers is NULL: pSrcDst
63 *    -    pSrcDst is not aligned on an 16-byte boundary
64 *
65 */
66OMXResult omxVCM4P10_TransformQuant_LumaDC(
67	OMX_S16* 	pSrcDst,
68	OMX_U32		iQP
69)
70{
71    OMX_INT     i, j;
72    OMX_S32     m1[4][4], m2[4][4];
73    OMX_S32     Value;
74    OMX_U32     QbitsPlusOne, Two_f, MF;
75
76    /* Check for argument error */
77    armRetArgErrIf(pSrcDst == NULL, OMX_Sts_BadArgErr);
78    armRetArgErrIf(armNot16ByteAligned(pSrcDst), OMX_Sts_BadArgErr);
79    armRetArgErrIf(iQP > 51, OMX_Sts_BadArgErr);
80
81    /* Hadamard Transform for 4x4 block */
82    /* Horizontal Hadamard */
83    for (i = 0; i < 4; i++)
84    {
85        j = i * 4;
86
87        m1[i][0] = pSrcDst[j + 0] + pSrcDst[j + 2]; /* a+c */
88        m1[i][1] = pSrcDst[j + 1] + pSrcDst[j + 3]; /* b+d */
89        m1[i][2] = pSrcDst[j + 0] - pSrcDst[j + 2]; /* a-c */
90        m1[i][3] = pSrcDst[j + 1] - pSrcDst[j + 3]; /* b-d */
91
92        m2[i][0] = m1[i][0] + m1[i][1]; /* a+b+c+d */
93        m2[i][1] = m1[i][2] + m1[i][3]; /* a+b-c-d */
94        m2[i][2] = m1[i][2] - m1[i][3]; /* a-b-c+d */
95        m2[i][3] = m1[i][0] - m1[i][1]; /* a-b+c-d */
96
97    }
98
99    /* Vertical */
100    for (i = 0; i < 4; i++)
101    {
102        m1[0][i] = m2[0][i] + m2[2][i];
103        m1[1][i] = m2[1][i] + m2[3][i];
104        m1[2][i] = m2[0][i] - m2[2][i];
105        m1[3][i] = m2[1][i] - m2[3][i];
106
107        m2[0][i] = m1[0][i] + m1[1][i];
108        m2[1][i] = m1[2][i] + m1[3][i];
109        m2[2][i] = m1[2][i] - m1[3][i];
110        m2[3][i] = m1[0][i] - m1[1][i];
111    }
112
113
114    /* Quantization */
115    QbitsPlusOne = ARM_M4P10_Q_OFFSET + 1 + (iQP / 6); /*floor (QP/6)*/
116    Two_f = (1 << QbitsPlusOne) / 3; /* 3->INTRA, 6->INTER */
117    MF = armVCM4P10_MFMatrix [iQP % 6][0];
118
119    /* Scaling */
120    for (j = 0; j < 4; j++)
121    {
122        for (i = 0; i < 4; i++)
123        {
124            Value = (armAbs((m2[j][i]/* + 1*/) / 2) * MF + Two_f) >> QbitsPlusOne;
125            pSrcDst[j * 4 + i] = (OMX_S16)((m2[j][i] < 0) ? -Value : Value);
126        }
127    }
128    return OMX_Sts_NoErr;
129}
130
131/*****************************************************************************
132 *                              END OF FILE
133 *****************************************************************************/
134
135