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_DequantTransformResidualFromPairAndAdd.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 AC block
420c1bc742181ded4930842b46e9507372f0b1b963James Dong */
430c1bc742181ded4930842b46e9507372f0b1b963James Dong
440c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void DequantLumaAC4x4(
450c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S16* pSrcDst,
460c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT QP
470c1bc742181ded4930842b46e9507372f0b1b963James Dong)
480c1bc742181ded4930842b46e9507372f0b1b963James Dong{
490c1bc742181ded4930842b46e9507372f0b1b963James Dong    const OMX_U8 *pVRow = &armVCM4P10_VMatrix[QP%6][0];
500c1bc742181ded4930842b46e9507372f0b1b963James Dong    int Shift = QP / 6;
510c1bc742181ded4930842b46e9507372f0b1b963James Dong    int i;
520c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S32 Value;
530c1bc742181ded4930842b46e9507372f0b1b963James Dong
540c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i=0; i<16; i++)
550c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
560c1bc742181ded4930842b46e9507372f0b1b963James Dong
570c1bc742181ded4930842b46e9507372f0b1b963James Dong        Value = (pSrcDst[i] * pVRow[armVCM4P10_PosToVCol4x4[i]]) << Shift;
580c1bc742181ded4930842b46e9507372f0b1b963James Dong        pSrcDst[i] = (OMX_S16)Value;
590c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
600c1bc742181ded4930842b46e9507372f0b1b963James Dong}
610c1bc742181ded4930842b46e9507372f0b1b963James Dong
620c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
630c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function:  omxVCM4P10_DequantTransformResidualFromPairAndAdd   (6.3.4.2.3)
640c1bc742181ded4930842b46e9507372f0b1b963James Dong *
650c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
660c1bc742181ded4930842b46e9507372f0b1b963James Dong * Reconstruct the 4x4 residual block from coefficient-position pair buffer,
670c1bc742181ded4930842b46e9507372f0b1b963James Dong * perform dequantization and integer inverse transformation for 4x4 block of
680c1bc742181ded4930842b46e9507372f0b1b963James Dong * residuals with previous intra prediction or motion compensation data, and
690c1bc742181ded4930842b46e9507372f0b1b963James Dong * update the pair buffer pointer to next non-empty block. If pDC == NULL,
700c1bc742181ded4930842b46e9507372f0b1b963James Dong * there re 16 non-zero AC coefficients at most in the packed buffer starting
710c1bc742181ded4930842b46e9507372f0b1b963James Dong * from 4x4 block position 0; If pDC != NULL, there re 15 non-zero AC
720c1bc742181ded4930842b46e9507372f0b1b963James Dong * coefficients at most in the packet buffer starting from 4x4 block position
730c1bc742181ded4930842b46e9507372f0b1b963James Dong * 1.
740c1bc742181ded4930842b46e9507372f0b1b963James Dong *
750c1bc742181ded4930842b46e9507372f0b1b963James Dong * Input Arguments:
760c1bc742181ded4930842b46e9507372f0b1b963James Dong *
770c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppSrc - Double pointer to residual coefficient-position pair buffer
780c1bc742181ded4930842b46e9507372f0b1b963James Dong *            output by CALVC decoding
790c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pPred - Pointer to the predicted 4x4 block; must be aligned on a 4-byte
800c1bc742181ded4930842b46e9507372f0b1b963James Dong *            boundary
810c1bc742181ded4930842b46e9507372f0b1b963James Dong *   predStep - Predicted frame step size in bytes; must be a multiple of 4
820c1bc742181ded4930842b46e9507372f0b1b963James Dong *   dstStep - Destination frame step in bytes; must be a multiple of 4
830c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pDC - Pointer to the DC coefficient of this block, NULL if it doesn't
840c1bc742181ded4930842b46e9507372f0b1b963James Dong *            exist
850c1bc742181ded4930842b46e9507372f0b1b963James Dong *   QP - QP Quantization parameter.  It should be QpC in chroma 4x4 block
860c1bc742181ded4930842b46e9507372f0b1b963James Dong *            decoding, otherwise it should be QpY.
870c1bc742181ded4930842b46e9507372f0b1b963James Dong *   AC - Flag indicating if at least one non-zero AC coefficient exists
880c1bc742181ded4930842b46e9507372f0b1b963James Dong *
890c1bc742181ded4930842b46e9507372f0b1b963James Dong * Output Arguments:
900c1bc742181ded4930842b46e9507372f0b1b963James Dong *
910c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pDst - pointer to the reconstructed 4x4 block data; must be aligned on a
920c1bc742181ded4930842b46e9507372f0b1b963James Dong *            4-byte boundary
930c1bc742181ded4930842b46e9507372f0b1b963James Dong *
940c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
950c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_NoErr, if the function runs without error.
960c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs:
970c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    pPred or pDst is NULL.
980c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    pPred or pDst is not 4-byte aligned.
990c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    predStep or dstStep is not a multiple of 4.
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    AC !=0 and Qp is not in the range of [0-51] or ppSrc == NULL.
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    AC ==0 && pDC ==NULL.
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong *
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong */
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong
1050c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult omxVCM4P10_DequantTransformResidualFromPairAndAdd(
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong     const OMX_U8 **ppSrc,
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong     const OMX_U8 *pPred,
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong     const OMX_S16 *pDC,
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_U8 *pDst,
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT predStep,
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT dstStep,
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT QP,
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT AC
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong)
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong{
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S16 pBuffer[16+4];
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMX_S16 *pDelta;
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong    int i,x,y;
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pPred == NULL,            OMX_Sts_BadArgErr);
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(armNot4ByteAligned(pPred),OMX_Sts_BadArgErr);
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pDst   == NULL,           OMX_Sts_BadArgErr);
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(armNot4ByteAligned(pDst), OMX_Sts_BadArgErr);
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(predStep & 3,             OMX_Sts_BadArgErr);
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(dstStep & 3,              OMX_Sts_BadArgErr);
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(AC!=0 && (QP<0),          OMX_Sts_BadArgErr);
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(AC!=0 && (QP>51),         OMX_Sts_BadArgErr);
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(AC!=0 && ppSrc==NULL,     OMX_Sts_BadArgErr);
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(AC!=0 && *ppSrc==NULL,    OMX_Sts_BadArgErr);
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(AC==0 && pDC==NULL,       OMX_Sts_BadArgErr);
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDelta = armAlignTo8Bytes(pBuffer);
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i=0; i<16; i++)
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong        pDelta[i] = 0;
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (AC)
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong        armVCM4P10_UnpackBlock4x4(ppSrc, pDelta);
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong        DequantLumaAC4x4(pDelta, QP);
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pDC)
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong        pDelta[0] = pDC[0];
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong    armVCM4P10_TransformResidual4x4(pDelta,pDelta);
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y=0; y<4; y++)
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x=0; x<4; x++)
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong            pDst[y*dstStep+x] = (OMX_U8)armClip(0,255,pPred[y*predStep+x] + pDelta[4*y+x]);
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong    return OMX_Sts_NoErr;
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong/* End of file */
161