omxVCM4P10_TransformDequantLumaDCFromPair.c revision 0c1bc742181ded4930842b46e9507372f0b1b963
10c1bc742181ded4930842b46e9507372f0b1b963James Dong/* ----------------------------------------------------------------
20c1bc742181ded4930842b46e9507372f0b1b963James Dong *
30c1bc742181ded4930842b46e9507372f0b1b963James Dong *
40c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name:  omxVCM4P10_TransformDequantLumaDCFromPair.c
50c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2
60c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision:   9641
70c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date:       Thursday, February 7, 2008
80c1bc742181ded4930842b46e9507372f0b1b963James Dong *
90c1bc742181ded4930842b46e9507372f0b1b963James Dong * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
100c1bc742181ded4930842b46e9507372f0b1b963James Dong *
110c1bc742181ded4930842b46e9507372f0b1b963James Dong *
120c1bc742181ded4930842b46e9507372f0b1b963James Dong *
130c1bc742181ded4930842b46e9507372f0b1b963James Dong * H.264 inverse quantize and transform module
140c1bc742181ded4930842b46e9507372f0b1b963James Dong *
150c1bc742181ded4930842b46e9507372f0b1b963James Dong */
160c1bc742181ded4930842b46e9507372f0b1b963James Dong
170c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
180c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h"
190c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h"
200c1bc742181ded4930842b46e9507372f0b1b963James Dong
210c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h"
220c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h"
230c1bc742181ded4930842b46e9507372f0b1b963James Dong
240c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
250c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
260c1bc742181ded4930842b46e9507372f0b1b963James Dong * Dequantize Luma DC block
270c1bc742181ded4930842b46e9507372f0b1b963James Dong */
280c1bc742181ded4930842b46e9507372f0b1b963James Dong
290c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void DequantLumaDC4x4(
300c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S16* pDst,
310c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT QP
320c1bc742181ded4930842b46e9507372f0b1b963James Dong)
330c1bc742181ded4930842b46e9507372f0b1b963James Dong{
340c1bc742181ded4930842b46e9507372f0b1b963James Dong    int Shift = (QP/6)-2 ;
350c1bc742181ded4930842b46e9507372f0b1b963James Dong    int Scale = armVCM4P10_VMatrix[QP%6][0];
360c1bc742181ded4930842b46e9507372f0b1b963James Dong    int i, Round, Value;
370c1bc742181ded4930842b46e9507372f0b1b963James Dong
380c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (Shift >= 0)
390c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
400c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i=0; i<16; i++)
410c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
420c1bc742181ded4930842b46e9507372f0b1b963James Dong            Value = (pDst[i] * Scale) << Shift;
430c1bc742181ded4930842b46e9507372f0b1b963James Dong            pDst[i] = (OMX_S16)Value;
440c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
450c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
460c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
470c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
480c1bc742181ded4930842b46e9507372f0b1b963James Dong        Shift = -Shift;;
490c1bc742181ded4930842b46e9507372f0b1b963James Dong        Round = 1<<(Shift-1);
500c1bc742181ded4930842b46e9507372f0b1b963James Dong
510c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i=0; i<16; i++)
520c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
530c1bc742181ded4930842b46e9507372f0b1b963James Dong            Value = (pDst[i] * Scale + Round) >> Shift;
540c1bc742181ded4930842b46e9507372f0b1b963James Dong            pDst[i] = (OMX_S16)Value;
550c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
560c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
570c1bc742181ded4930842b46e9507372f0b1b963James Dong}
580c1bc742181ded4930842b46e9507372f0b1b963James Dong
590c1bc742181ded4930842b46e9507372f0b1b963James Dong
600c1bc742181ded4930842b46e9507372f0b1b963James Dong
610c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
620c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
630c1bc742181ded4930842b46e9507372f0b1b963James Dong * Inverse Transform DC 4x4 Coefficients
640c1bc742181ded4930842b46e9507372f0b1b963James Dong */
650c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void InvTransformDC4x4(OMX_S16* pData)
660c1bc742181ded4930842b46e9507372f0b1b963James Dong{
670c1bc742181ded4930842b46e9507372f0b1b963James Dong    int i;
680c1bc742181ded4930842b46e9507372f0b1b963James Dong
690c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Transform rows */
700c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i=0; i<16; i+=4)
710c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
720c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c0 = pData[i+0];
730c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c1 = pData[i+1];
740c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c2 = pData[i+2];
750c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c3 = pData[i+3];
760c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+0] = (OMX_S16)(c0+c1+c2+c3);
770c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+1] = (OMX_S16)(c0+c1-c2-c3);
780c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+2] = (OMX_S16)(c0-c1-c2+c3);
790c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+3] = (OMX_S16)(c0-c1+c2-c3);
800c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
810c1bc742181ded4930842b46e9507372f0b1b963James Dong
820c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Transform columns */
830c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i=0; i<4; i++)
840c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
850c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c0 = pData[i+0];
860c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c1 = pData[i+4];
870c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c2 = pData[i+8];
880c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c3 = pData[i+12];
890c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+0] = (OMX_S16)(c0+c1+c2+c3);
900c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+4] = (OMX_S16)(c0+c1-c2-c3);
910c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+8] = (OMX_S16)(c0-c1-c2+c3);
920c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+12] = (OMX_S16)(c0-c1+c2-c3);
930c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
940c1bc742181ded4930842b46e9507372f0b1b963James Dong}
950c1bc742181ded4930842b46e9507372f0b1b963James Dong
960c1bc742181ded4930842b46e9507372f0b1b963James Dong
970c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
980c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function:  omxVCM4P10_TransformDequantLumaDCFromPair   (6.3.4.2.1)
990c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong * Reconstructs the 4x4 LumaDC block from the coefficient-position pair
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong * buffer, performs integer inverse, and dequantization for 4x4 LumaDC
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong * coefficients, and updates the pair buffer pointer to the next non-empty
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong * block.
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong * Input Arguments:
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppSrc - Double pointer to residual coefficient-position pair buffer
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong *            output by CALVC decoding
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong *   QP - Quantization parameter QpY
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong * Output Arguments:
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppSrc - *ppSrc is updated to the start of next non empty block
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pDst - Pointer to the reconstructed 4x4 LumaDC coefficients buffer; must
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong *            be aligned on a 8-byte boundary.
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_NoErr, if the function runs without error.
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs:
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    ppSrc or pDst is NULL.
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    pDst is not 8 byte aligned.
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    QP is not in the range of [0-51].
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong */
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong
1270c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult omxVCM4P10_TransformDequantLumaDCFromPair(
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong     const OMX_U8 **ppSrc,
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S16* pDst,
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT QP
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong )
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong{
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(ppSrc  == NULL,           OMX_Sts_BadArgErr);
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*ppSrc == NULL,           OMX_Sts_BadArgErr);
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(armNot8ByteAligned(pDst), OMX_Sts_BadArgErr);
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(QP<0,                     OMX_Sts_BadArgErr);
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(QP>51,                    OMX_Sts_BadArgErr);
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong    armVCM4P10_UnpackBlock4x4(ppSrc, pDst);
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*InvTransformDequantLumaDC4x4(pDst, QP);*/
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong    InvTransformDC4x4(pDst);
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong    DequantLumaDC4x4(pDst, QP);
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong    return OMX_Sts_NoErr;
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong/* End of file */
149