omxVCM4P10_DequantTransformResidualFromPairAndAdd.c revision 0c1bc742181ded4930842b46e9507372f0b1b963
1/* ----------------------------------------------------------------
2 *
3 *
4 * File Name:  omxVCM4P10_DequantTransformResidualFromPairAndAdd.c
5 * OpenMAX DL: v1.0.2
6 * Revision:   9641
7 * Date:       Thursday, February 7, 2008
8 *
9 * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
10 *
11 *
12 *
13 * H.264 inverse quantize and transform module
14 *
15 */
16
17#include "omxtypes.h"
18#include "armOMX.h"
19#include "omxVC.h"
20
21#include "armCOMM.h"
22#include "armVC.h"
23
24/*
25 * Description:
26 * Dequantize Luma AC block
27 */
28
29static void DequantLumaAC4x4(
30     OMX_S16* pSrcDst,
31     OMX_INT QP
32)
33{
34    const OMX_U8 *pVRow = &armVCM4P10_VMatrix[QP%6][0];
35    int Shift = QP / 6;
36    int i;
37    OMX_S32 Value;
38
39    for (i=0; i<16; i++)
40    {
41
42        Value = (pSrcDst[i] * pVRow[armVCM4P10_PosToVCol4x4[i]]) << Shift;
43        pSrcDst[i] = (OMX_S16)Value;
44    }
45}
46
47/**
48 * Function:  omxVCM4P10_DequantTransformResidualFromPairAndAdd   (6.3.4.2.3)
49 *
50 * Description:
51 * Reconstruct the 4x4 residual block from coefficient-position pair buffer,
52 * perform dequantization and integer inverse transformation for 4x4 block of
53 * residuals with previous intra prediction or motion compensation data, and
54 * update the pair buffer pointer to next non-empty block. If pDC == NULL,
55 * there re 16 non-zero AC coefficients at most in the packed buffer starting
56 * from 4x4 block position 0; If pDC != NULL, there re 15 non-zero AC
57 * coefficients at most in the packet buffer starting from 4x4 block position
58 * 1.
59 *
60 * Input Arguments:
61 *
62 *   ppSrc - Double pointer to residual coefficient-position pair buffer
63 *            output by CALVC decoding
64 *   pPred - Pointer to the predicted 4x4 block; must be aligned on a 4-byte
65 *            boundary
66 *   predStep - Predicted frame step size in bytes; must be a multiple of 4
67 *   dstStep - Destination frame step in bytes; must be a multiple of 4
68 *   pDC - Pointer to the DC coefficient of this block, NULL if it doesn't
69 *            exist
70 *   QP - QP Quantization parameter.  It should be QpC in chroma 4x4 block
71 *            decoding, otherwise it should be QpY.
72 *   AC - Flag indicating if at least one non-zero AC coefficient exists
73 *
74 * Output Arguments:
75 *
76 *   pDst - pointer to the reconstructed 4x4 block data; must be aligned on a
77 *            4-byte boundary
78 *
79 * Return Value:
80 *    OMX_Sts_NoErr, if the function runs without error.
81 *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs:
82 *    -    pPred or pDst is NULL.
83 *    -    pPred or pDst is not 4-byte aligned.
84 *    -    predStep or dstStep is not a multiple of 4.
85 *    -    AC !=0 and Qp is not in the range of [0-51] or ppSrc == NULL.
86 *    -    AC ==0 && pDC ==NULL.
87 *
88 */
89
90OMXResult omxVCM4P10_DequantTransformResidualFromPairAndAdd(
91     const OMX_U8 **ppSrc,
92     const OMX_U8 *pPred,
93     const OMX_S16 *pDC,
94     OMX_U8 *pDst,
95     OMX_INT predStep,
96     OMX_INT dstStep,
97     OMX_INT QP,
98     OMX_INT AC
99)
100{
101    OMX_S16 pBuffer[16+4];
102    OMX_S16 *pDelta;
103    int i,x,y;
104
105    armRetArgErrIf(pPred == NULL,            OMX_Sts_BadArgErr);
106    armRetArgErrIf(armNot4ByteAligned(pPred),OMX_Sts_BadArgErr);
107    armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
108    armRetArgErrIf(armNot4ByteAligned(pDst), OMX_Sts_BadArgErr);
109    armRetArgErrIf(predStep & 3,             OMX_Sts_BadArgErr);
110    armRetArgErrIf(dstStep & 3,              OMX_Sts_BadArgErr);
111    armRetArgErrIf(AC!=0 && (QP<0),          OMX_Sts_BadArgErr);
112    armRetArgErrIf(AC!=0 && (QP>51),         OMX_Sts_BadArgErr);
113    armRetArgErrIf(AC!=0 && ppSrc==NULL,     OMX_Sts_BadArgErr);
114    armRetArgErrIf(AC!=0 && *ppSrc==NULL,    OMX_Sts_BadArgErr);
115    armRetArgErrIf(AC==0 && pDC==NULL,       OMX_Sts_BadArgErr);
116
117    pDelta = armAlignTo8Bytes(pBuffer);
118
119    for (i=0; i<16; i++)
120    {
121        pDelta[i] = 0;
122    }
123    if (AC)
124    {
125        armVCM4P10_UnpackBlock4x4(ppSrc, pDelta);
126        DequantLumaAC4x4(pDelta, QP);
127    }
128    if (pDC)
129    {
130        pDelta[0] = pDC[0];
131    }
132    armVCM4P10_TransformResidual4x4(pDelta,pDelta);
133
134    for (y=0; y<4; y++)
135    {
136        for (x=0; x<4; x++)
137        {
138            pDst[y*dstStep+x] = (OMX_U8)armClip(0,255,pPred[y*predStep+x] + pDelta[4*y+x]);
139        }
140    }
141
142    return OMX_Sts_NoErr;
143}
144
145/* End of file */
146