summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformDequantChromaDCFromPair.c
blob: dd9f5a777ffec637cde9bebf2255cba801c8918f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * Copyright (C) 2007-2008 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
/* ----------------------------------------------------------------
 *
 * 
 * File Name:  omxVCM4P10_TransformDequantChromaDCFromPair.c
 * OpenMAX DL: v1.0.2
 * Revision:   9641
 * Date:       Thursday, February 7, 2008
 * 
 * 
 * 
 *
 * H.264 inverse quantize and transform module
 * 
 */
 
#include "omxtypes.h"
#include "armOMX.h"
#include "omxVC.h"

#include "armCOMM.h"
#include "armVC.h"

/*
 * Description:
 * Dequantize Chroma 2x2 DC block
 */

static void DequantChromaDC2x2(
     OMX_S16* pDst,
     OMX_INT QP        
)
{
    int Shift = (QP/6)-1 ;
    int Scale = armVCM4P10_VMatrix[QP%6][0];
    int i, Value;

    if (Shift >= 0)
    {
        for (i=0; i<4; i++)
        {
            Value = (pDst[i] * Scale) << Shift;
            pDst[i] = (OMX_S16)Value;
        }
    }
    else
    {
        for (i=0; i<4; i++)
        {
            Value = (pDst[i] * Scale) >> 1;
            pDst[i] = (OMX_S16)Value;
        }
    }
}
 

/*
 * Description:
 * Inverse Transform DC 2x2 Coefficients
 */

static void InvTransformDC2x2(OMX_S16* pData)
{
    int c00 = pData[0];
    int c01 = pData[1];
    int c10 = pData[2];
    int c11 = pData[3];

    int d00 = c00 + c01;
    int d01 = c00 - c01;
    int d10 = c10 + c11;
    int d11 = c10 - c11;

    pData[0] = (OMX_S16)(d00 + d10);
    pData[1] = (OMX_S16)(d01 + d11);
    pData[2] = (OMX_S16)(d00 - d10);
    pData[3] = (OMX_S16)(d01 - d11);
}


/**
 * Function:  omxVCM4P10_TransformDequantChromaDCFromPair   (6.3.4.2.2)
 *
 * Description:
 * Reconstruct the 2x2 ChromaDC block from coefficient-position pair buffer, 
 * perform integer inverse transformation, and dequantization for 2x2 chroma 
 * DC coefficients, and update the pair buffer pointer to next non-empty 
 * block. 
 *
 * Input Arguments:
 *   
 *   ppSrc - Double pointer to residual coefficient-position pair buffer 
 *            output by CALVC decoding 
 *   QP - Quantization parameter QpC 
 *
 * Output Arguments:
 *   
 *   ppSrc - *ppSrc is updated to the start of next non empty block 
 *   pDst - Pointer to the reconstructed 2x2 ChromaDC coefficients buffer; 
 *            must be aligned on a 4-byte boundary. 
 *
 * Return Value:
 *    OMX_Sts_NoErr, if the function runs without error.
 *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs: 
 *    -    ppSrc or pDst is NULL. 
 *    -    pDst is not 4-byte aligned. 
 *    -    QP is not in the range of [0-51]. 
 *
 */

OMXResult omxVCM4P10_TransformDequantChromaDCFromPair(
     const OMX_U8 **ppSrc,
     OMX_S16* pDst,
     OMX_INT QP        
 )
{
    armRetArgErrIf(ppSrc  == NULL,           OMX_Sts_BadArgErr);
    armRetArgErrIf(*ppSrc == NULL,           OMX_Sts_BadArgErr);
    armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
    armRetArgErrIf(armNot4ByteAligned(pDst), OMX_Sts_BadArgErr);
    armRetArgErrIf(QP<0,                     OMX_Sts_BadArgErr);
    armRetArgErrIf(QP>51,                    OMX_Sts_BadArgErr);

    armVCM4P10_UnpackBlock2x2(ppSrc, pDst);
    InvTransformDC2x2(pDst);
    DequantChromaDC2x2(pDst, QP);

    return OMX_Sts_NoErr;
}

/* End of file */