summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/on2/h264dec/omxdl/reference/vc/m4p10/src/omxVCM4P10_TransformDequantLumaDCFromPair.c
blob: 16c8be1b08722f062391ffdc2d56ea13021cb68b (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
147
148
/* ----------------------------------------------------------------
 *
 * 
 * File Name:  omxVCM4P10_TransformDequantLumaDCFromPair.c
 * OpenMAX DL: v1.0.2
 * Revision:   9641
 * Date:       Thursday, February 7, 2008
 * 
 * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
 * 
 * 
 *
 * H.264 inverse quantize and transform module
 * 
 */
 
#include "omxtypes.h"
#include "armOMX.h"
#include "omxVC.h"

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

/*
 * Description:
 * Dequantize Luma DC block
 */

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

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

        for (i=0; i<16; i++)
        {
            Value = (pDst[i] * Scale + Round) >> Shift;
            pDst[i] = (OMX_S16)Value;
        }
    }
}

 

/*
 * Description:
 * Inverse Transform DC 4x4 Coefficients
 */
static void InvTransformDC4x4(OMX_S16* pData)
{
    int i;

    /* Transform rows */
    for (i=0; i<16; i+=4)
    {
        int c0 = pData[i+0];
        int c1 = pData[i+1];
        int c2 = pData[i+2];
        int c3 = pData[i+3];
        pData[i+0] = (OMX_S16)(c0+c1+c2+c3);
        pData[i+1] = (OMX_S16)(c0+c1-c2-c3);
        pData[i+2] = (OMX_S16)(c0-c1-c2+c3);
        pData[i+3] = (OMX_S16)(c0-c1+c2-c3);
    }

    /* Transform columns */
    for (i=0; i<4; i++)
    {
        int c0 = pData[i+0];
        int c1 = pData[i+4];
        int c2 = pData[i+8];
        int c3 = pData[i+12];
        pData[i+0] = (OMX_S16)(c0+c1+c2+c3);
        pData[i+4] = (OMX_S16)(c0+c1-c2-c3);
        pData[i+8] = (OMX_S16)(c0-c1-c2+c3);
        pData[i+12] = (OMX_S16)(c0-c1+c2-c3);
    }
}


/**
 * Function:  omxVCM4P10_TransformDequantLumaDCFromPair   (6.3.4.2.1)
 *
 * Description:
 * Reconstructs the 4x4 LumaDC block from the coefficient-position pair 
 * buffer, performs integer inverse, and dequantization for 4x4 LumaDC 
 * coefficients, and updates the pair buffer pointer to the next non-empty 
 * block. 
 *
 * Input Arguments:
 *   
 *   ppSrc - Double pointer to residual coefficient-position pair buffer 
 *            output by CALVC decoding 
 *   QP - Quantization parameter QpY 
 *
 * Output Arguments:
 *   
 *   ppSrc - *ppSrc is updated to the start of next non empty block 
 *   pDst - Pointer to the reconstructed 4x4 LumaDC coefficients buffer; must 
 *            be aligned on a 8-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 8 byte aligned. 
 *    -    QP is not in the range of [0-51]. 
 *
 */

OMXResult omxVCM4P10_TransformDequantLumaDCFromPair(
     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(armNot8ByteAligned(pDst), OMX_Sts_BadArgErr);
    armRetArgErrIf(QP<0,                     OMX_Sts_BadArgErr);
    armRetArgErrIf(QP>51,                    OMX_Sts_BadArgErr);

    armVCM4P10_UnpackBlock4x4(ppSrc, pDst);
    /*InvTransformDequantLumaDC4x4(pDst, QP);*/
    InvTransformDC4x4(pDst);
    DequantLumaDC4x4(pDst, QP);

    return OMX_Sts_NoErr;
}

/* End of file */