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