omxVCM4P10_TransformDequantLumaDCFromPair.c revision 78e52bfac041d71ce53b5b13c2abf78af742b09d
178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar/*
278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Copyright (C) 2007-2008 ARM Limited
378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Licensed under the Apache License, Version 2.0 (the "License");
578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * you may not use this file except in compliance with the License.
678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * You may obtain a copy of the License at
778e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
878e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *      http://www.apache.org/licenses/LICENSE-2.0
978e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
1078e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Unless required by applicable law or agreed to in writing, software
1178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * distributed under the License is distributed on an "AS IS" BASIS,
1278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * See the License for the specific language governing permissions and
1478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * limitations under the License.
1578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
1678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar */
170c1bc742181ded4930842b46e9507372f0b1b963James Dong/* ----------------------------------------------------------------
180c1bc742181ded4930842b46e9507372f0b1b963James Dong *
190c1bc742181ded4930842b46e9507372f0b1b963James Dong *
200c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name:  omxVCM4P10_TransformDequantLumaDCFromPair.c
210c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2
220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision:   9641
230c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date:       Thursday, February 7, 2008
240c1bc742181ded4930842b46e9507372f0b1b963James Dong *
250c1bc742181ded4930842b46e9507372f0b1b963James Dong *
260c1bc742181ded4930842b46e9507372f0b1b963James Dong *
270c1bc742181ded4930842b46e9507372f0b1b963James Dong *
280c1bc742181ded4930842b46e9507372f0b1b963James Dong * H.264 inverse quantize and transform module
290c1bc742181ded4930842b46e9507372f0b1b963James Dong *
300c1bc742181ded4930842b46e9507372f0b1b963James Dong */
310c1bc742181ded4930842b46e9507372f0b1b963James Dong
320c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
330c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h"
340c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h"
350c1bc742181ded4930842b46e9507372f0b1b963James Dong
360c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h"
370c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h"
380c1bc742181ded4930842b46e9507372f0b1b963James Dong
390c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
400c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
410c1bc742181ded4930842b46e9507372f0b1b963James Dong * Dequantize Luma DC block
420c1bc742181ded4930842b46e9507372f0b1b963James Dong */
430c1bc742181ded4930842b46e9507372f0b1b963James Dong
440c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void DequantLumaDC4x4(
450c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S16* pDst,
460c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT QP
470c1bc742181ded4930842b46e9507372f0b1b963James Dong)
480c1bc742181ded4930842b46e9507372f0b1b963James Dong{
490c1bc742181ded4930842b46e9507372f0b1b963James Dong    int Shift = (QP/6)-2 ;
500c1bc742181ded4930842b46e9507372f0b1b963James Dong    int Scale = armVCM4P10_VMatrix[QP%6][0];
510c1bc742181ded4930842b46e9507372f0b1b963James Dong    int i, Round, Value;
520c1bc742181ded4930842b46e9507372f0b1b963James Dong
530c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (Shift >= 0)
540c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
550c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i=0; i<16; i++)
560c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
570c1bc742181ded4930842b46e9507372f0b1b963James Dong            Value = (pDst[i] * Scale) << Shift;
580c1bc742181ded4930842b46e9507372f0b1b963James Dong            pDst[i] = (OMX_S16)Value;
590c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
600c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
610c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
620c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
630c1bc742181ded4930842b46e9507372f0b1b963James Dong        Shift = -Shift;;
640c1bc742181ded4930842b46e9507372f0b1b963James Dong        Round = 1<<(Shift-1);
650c1bc742181ded4930842b46e9507372f0b1b963James Dong
660c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i=0; i<16; i++)
670c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
680c1bc742181ded4930842b46e9507372f0b1b963James Dong            Value = (pDst[i] * Scale + Round) >> Shift;
690c1bc742181ded4930842b46e9507372f0b1b963James Dong            pDst[i] = (OMX_S16)Value;
700c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
710c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
720c1bc742181ded4930842b46e9507372f0b1b963James Dong}
730c1bc742181ded4930842b46e9507372f0b1b963James Dong
740c1bc742181ded4930842b46e9507372f0b1b963James Dong
750c1bc742181ded4930842b46e9507372f0b1b963James Dong
760c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
770c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
780c1bc742181ded4930842b46e9507372f0b1b963James Dong * Inverse Transform DC 4x4 Coefficients
790c1bc742181ded4930842b46e9507372f0b1b963James Dong */
800c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void InvTransformDC4x4(OMX_S16* pData)
810c1bc742181ded4930842b46e9507372f0b1b963James Dong{
820c1bc742181ded4930842b46e9507372f0b1b963James Dong    int i;
830c1bc742181ded4930842b46e9507372f0b1b963James Dong
840c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Transform rows */
850c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i=0; i<16; i+=4)
860c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
870c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c0 = pData[i+0];
880c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c1 = pData[i+1];
890c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c2 = pData[i+2];
900c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c3 = pData[i+3];
910c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+0] = (OMX_S16)(c0+c1+c2+c3);
920c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+1] = (OMX_S16)(c0+c1-c2-c3);
930c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+2] = (OMX_S16)(c0-c1-c2+c3);
940c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+3] = (OMX_S16)(c0-c1+c2-c3);
950c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
960c1bc742181ded4930842b46e9507372f0b1b963James Dong
970c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Transform columns */
980c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i=0; i<4; i++)
990c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c0 = pData[i+0];
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c1 = pData[i+4];
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c2 = pData[i+8];
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong        int c3 = pData[i+12];
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+0] = (OMX_S16)(c0+c1+c2+c3);
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+4] = (OMX_S16)(c0+c1-c2-c3);
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+8] = (OMX_S16)(c0-c1-c2+c3);
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong        pData[i+12] = (OMX_S16)(c0-c1+c2-c3);
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function:  omxVCM4P10_TransformDequantLumaDCFromPair   (6.3.4.2.1)
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong * Reconstructs the 4x4 LumaDC block from the coefficient-position pair
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong * buffer, performs integer inverse, and dequantization for 4x4 LumaDC
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong * coefficients, and updates the pair buffer pointer to the next non-empty
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong * block.
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong * Input Arguments:
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppSrc - Double pointer to residual coefficient-position pair buffer
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong *            output by CALVC decoding
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong *   QP - Quantization parameter QpY
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong * Output Arguments:
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppSrc - *ppSrc is updated to the start of next non empty block
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pDst - Pointer to the reconstructed 4x4 LumaDC coefficients buffer; must
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong *            be aligned on a 8-byte boundary.
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_NoErr, if the function runs without error.
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs:
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    ppSrc or pDst is NULL.
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    pDst is not 8 byte aligned.
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    QP is not in the range of [0-51].
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong */
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong
1420c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult omxVCM4P10_TransformDequantLumaDCFromPair(
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong     const OMX_U8 **ppSrc,
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S16* pDst,
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT QP
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong )
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong{
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(ppSrc  == NULL,           OMX_Sts_BadArgErr);
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*ppSrc == NULL,           OMX_Sts_BadArgErr);
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(armNot8ByteAligned(pDst), OMX_Sts_BadArgErr);
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(QP<0,                     OMX_Sts_BadArgErr);
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(QP>51,                    OMX_Sts_BadArgErr);
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong    armVCM4P10_UnpackBlock4x4(ppSrc, pDst);
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*InvTransformDequantLumaDC4x4(pDst, QP);*/
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong    InvTransformDC4x4(pDst);
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong    DequantLumaDC4x4(pDst, QP);
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong    return OMX_Sts_NoErr;
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong/* End of file */
164