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