10c1bc742181ded4930842b46e9507372f0b1b963James Dong/** 20c1bc742181ded4930842b46e9507372f0b1b963James Dong * 30c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name: omxVCM4P10_GetVLCInfo.c 40c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2 50c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision: 9641 60c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date: Thursday, February 7, 2008 70c1bc742181ded4930842b46e9507372f0b1b963James Dong * 80c1bc742181ded4930842b46e9507372f0b1b963James Dong * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved. 90c1bc742181ded4930842b46e9507372f0b1b963James Dong * 100c1bc742181ded4930842b46e9507372f0b1b963James Dong * 110c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: 120c1bc742181ded4930842b46e9507372f0b1b963James Dong * 130c1bc742181ded4930842b46e9507372f0b1b963James Dong * This function extracts run-length encoding (RLE) information 140c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 150c1bc742181ded4930842b46e9507372f0b1b963James Dong 160c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h" 170c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h" 180c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h" 190c1bc742181ded4930842b46e9507372f0b1b963James Dong 200c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h" 210c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h" 220c1bc742181ded4930842b46e9507372f0b1b963James Dong 230c1bc742181ded4930842b46e9507372f0b1b963James Dong/** 240c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: omxVCM4P10_GetVLCInfo (6.3.5.9.1) 250c1bc742181ded4930842b46e9507372f0b1b963James Dong * 260c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: 270c1bc742181ded4930842b46e9507372f0b1b963James Dong * This function extracts run-length encoding (RLE) information from the 280c1bc742181ded4930842b46e9507372f0b1b963James Dong * coefficient matrix. The results are returned in an OMXVCM4P10VLCInfo 290c1bc742181ded4930842b46e9507372f0b1b963James Dong * structure. 300c1bc742181ded4930842b46e9507372f0b1b963James Dong * 310c1bc742181ded4930842b46e9507372f0b1b963James Dong * Input Arguments: 320c1bc742181ded4930842b46e9507372f0b1b963James Dong * 330c1bc742181ded4930842b46e9507372f0b1b963James Dong * pSrcCoeff - pointer to the transform coefficient matrix. 8-byte 340c1bc742181ded4930842b46e9507372f0b1b963James Dong * alignment required. 350c1bc742181ded4930842b46e9507372f0b1b963James Dong * pScanMatrix - pointer to the scan order definition matrix. For a luma 360c1bc742181ded4930842b46e9507372f0b1b963James Dong * block the scan matrix should follow [ISO14496-10] section 8.5.4, 370c1bc742181ded4930842b46e9507372f0b1b963James Dong * and should contain the values 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 380c1bc742181ded4930842b46e9507372f0b1b963James Dong * 10, 7, 11, 14, 15. For a chroma block, the scan matrix should 390c1bc742181ded4930842b46e9507372f0b1b963James Dong * contain the values 0, 1, 2, 3. 400c1bc742181ded4930842b46e9507372f0b1b963James Dong * bAC - indicates presence of a DC coefficient; 0 = DC coefficient 410c1bc742181ded4930842b46e9507372f0b1b963James Dong * present, 1= DC coefficient absent. 420c1bc742181ded4930842b46e9507372f0b1b963James Dong * MaxNumCoef - specifies the number of coefficients contained in the 430c1bc742181ded4930842b46e9507372f0b1b963James Dong * transform coefficient matrix, pSrcCoeff. The value should be 16 440c1bc742181ded4930842b46e9507372f0b1b963James Dong * for blocks of type LUMADC, LUMAAC, LUMALEVEL, and CHROMAAC. The 450c1bc742181ded4930842b46e9507372f0b1b963James Dong * value should be 4 for blocks of type CHROMADC. 460c1bc742181ded4930842b46e9507372f0b1b963James Dong * 470c1bc742181ded4930842b46e9507372f0b1b963James Dong * Output Arguments: 480c1bc742181ded4930842b46e9507372f0b1b963James Dong * 490c1bc742181ded4930842b46e9507372f0b1b963James Dong * pDstVLCInfo - pointer to structure that stores information for 500c1bc742181ded4930842b46e9507372f0b1b963James Dong * run-length coding. 510c1bc742181ded4930842b46e9507372f0b1b963James Dong * 520c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value: 530c1bc742181ded4930842b46e9507372f0b1b963James Dong * 540c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_Sts_NoErr - no error 550c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_Sts_BadArgErr - bad arguments; returned if any of the following 560c1bc742181ded4930842b46e9507372f0b1b963James Dong * conditions are true: 570c1bc742181ded4930842b46e9507372f0b1b963James Dong * - at least one of the following pointers is NULL: 580c1bc742181ded4930842b46e9507372f0b1b963James Dong * pSrcCoeff, pScanMatrix, pDstVLCInfo 590c1bc742181ded4930842b46e9507372f0b1b963James Dong * - pSrcCoeff is not aligned on an 8-byte boundary 600c1bc742181ded4930842b46e9507372f0b1b963James Dong * 610c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 620c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult omxVCM4P10_GetVLCInfo ( 630c1bc742181ded4930842b46e9507372f0b1b963James Dong const OMX_S16* pSrcCoeff, 640c1bc742181ded4930842b46e9507372f0b1b963James Dong const OMX_U8* pScanMatrix, 650c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U8 bAC, 660c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U32 MaxNumCoef, 670c1bc742181ded4930842b46e9507372f0b1b963James Dong OMXVCM4P10VLCInfo* pDstVLCInfo 680c1bc742181ded4930842b46e9507372f0b1b963James Dong) 690c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 700c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_INT i, MinIndex; 710c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_S32 Value; 720c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U32 Mask = 4, RunBefore; 730c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_S16 *pLevel; 740c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U8 *pRun; 750c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_S16 Buf [16]; 760c1bc742181ded4930842b46e9507372f0b1b963James Dong 770c1bc742181ded4930842b46e9507372f0b1b963James Dong /* check for argument error */ 780c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(pSrcCoeff == NULL, OMX_Sts_BadArgErr) 790c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(armNot8ByteAligned(pSrcCoeff), OMX_Sts_BadArgErr) 800c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(pScanMatrix == NULL, OMX_Sts_BadArgErr) 810c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(pDstVLCInfo == NULL, OMX_Sts_BadArgErr) 820c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(bAC > 1, OMX_Sts_BadArgErr) 830c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(MaxNumCoef > 16, OMX_Sts_BadArgErr) 840c1bc742181ded4930842b46e9507372f0b1b963James Dong 850c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Initialize RLE Info structure */ 860c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uTrailing_Ones = 0; 870c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uTrailing_One_Signs = 0; 880c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uNumCoeffs = 0; 890c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uTotalZeros = 0; 900c1bc742181ded4930842b46e9507372f0b1b963James Dong 910c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < 16; i++) 920c1bc742181ded4930842b46e9507372f0b1b963James Dong { 930c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->iLevels [i] = 0; 940c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uRuns [i] = 0; 950c1bc742181ded4930842b46e9507372f0b1b963James Dong } 960c1bc742181ded4930842b46e9507372f0b1b963James Dong 970c1bc742181ded4930842b46e9507372f0b1b963James Dong MinIndex = (bAC == 0 && MaxNumCoef == 15) ? 1 : 0; 980c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = MinIndex; i < (MaxNumCoef + MinIndex); i++) 990c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1000c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Scan */ 1010c1bc742181ded4930842b46e9507372f0b1b963James Dong Buf [i - MinIndex] = pSrcCoeff [pScanMatrix [i]]; 1020c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1030c1bc742181ded4930842b46e9507372f0b1b963James Dong 1040c1bc742181ded4930842b46e9507372f0b1b963James Dong /* skip zeros at the end */ 1050c1bc742181ded4930842b46e9507372f0b1b963James Dong i = MaxNumCoef - 1; 1060c1bc742181ded4930842b46e9507372f0b1b963James Dong while (!Buf [i] && i >= 0) 1070c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1080c1bc742181ded4930842b46e9507372f0b1b963James Dong i--; 1090c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1100c1bc742181ded4930842b46e9507372f0b1b963James Dong 1110c1bc742181ded4930842b46e9507372f0b1b963James Dong if (i < 0) 1120c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1130c1bc742181ded4930842b46e9507372f0b1b963James Dong return OMX_Sts_NoErr; 1140c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1150c1bc742181ded4930842b46e9507372f0b1b963James Dong 1160c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Fill RLE Info structure */ 1170c1bc742181ded4930842b46e9507372f0b1b963James Dong pLevel = pDstVLCInfo->iLevels; 1180c1bc742181ded4930842b46e9507372f0b1b963James Dong pRun = pDstVLCInfo->uRuns; 1190c1bc742181ded4930842b46e9507372f0b1b963James Dong RunBefore = 0; 1200c1bc742181ded4930842b46e9507372f0b1b963James Dong 1210c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Handle first non zero separate */ 1220c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uNumCoeffs++; 1230c1bc742181ded4930842b46e9507372f0b1b963James Dong Value = Buf [i]; 1240c1bc742181ded4930842b46e9507372f0b1b963James Dong if (Value == 1 || Value == -1) 1250c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1260c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uTrailing_Ones++; 1270c1bc742181ded4930842b46e9507372f0b1b963James Dong 1280c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uTrailing_One_Signs |= 1290c1bc742181ded4930842b46e9507372f0b1b963James Dong Value == -1 ? Mask : 0; 1300c1bc742181ded4930842b46e9507372f0b1b963James Dong Mask >>= 1; 1310c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1320c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1330c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1340c1bc742181ded4930842b46e9507372f0b1b963James Dong Value -= (Value > 0 ? 1 : -1); 1350c1bc742181ded4930842b46e9507372f0b1b963James Dong *pLevel++ = Value; 1360c1bc742181ded4930842b46e9507372f0b1b963James Dong Mask = 0; 1370c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1380c1bc742181ded4930842b46e9507372f0b1b963James Dong 1390c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Remaining non zero */ 1400c1bc742181ded4930842b46e9507372f0b1b963James Dong while (--i >= 0) 1410c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1420c1bc742181ded4930842b46e9507372f0b1b963James Dong Value = Buf [i]; 1430c1bc742181ded4930842b46e9507372f0b1b963James Dong if (Value) 1440c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1450c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uNumCoeffs++; 1460c1bc742181ded4930842b46e9507372f0b1b963James Dong 1470c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Mask becomes zero after entering */ 1480c1bc742181ded4930842b46e9507372f0b1b963James Dong if (Mask && 1490c1bc742181ded4930842b46e9507372f0b1b963James Dong (Value == 1 || 1500c1bc742181ded4930842b46e9507372f0b1b963James Dong Value == -1)) 1510c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1520c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uTrailing_Ones++; 1530c1bc742181ded4930842b46e9507372f0b1b963James Dong 1540c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uTrailing_One_Signs |= 1550c1bc742181ded4930842b46e9507372f0b1b963James Dong Value == -1 ? Mask : 0; 1560c1bc742181ded4930842b46e9507372f0b1b963James Dong Mask >>= 1; 1570c1bc742181ded4930842b46e9507372f0b1b963James Dong *pRun++ = RunBefore; 1580c1bc742181ded4930842b46e9507372f0b1b963James Dong RunBefore = 0; 1590c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1600c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1610c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1620c1bc742181ded4930842b46e9507372f0b1b963James Dong /* If 3 trailing ones are not completed */ 1630c1bc742181ded4930842b46e9507372f0b1b963James Dong if (Mask) 1640c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1650c1bc742181ded4930842b46e9507372f0b1b963James Dong Mask = 0; 1660c1bc742181ded4930842b46e9507372f0b1b963James Dong Value -= (Value > 0 ? 1 : -1); 1670c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1680c1bc742181ded4930842b46e9507372f0b1b963James Dong *pLevel++ = Value; 1690c1bc742181ded4930842b46e9507372f0b1b963James Dong *pRun++ = RunBefore; 1700c1bc742181ded4930842b46e9507372f0b1b963James Dong RunBefore = 0; 1710c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1720c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1730c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1740c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1750c1bc742181ded4930842b46e9507372f0b1b963James Dong pDstVLCInfo->uTotalZeros++; 1760c1bc742181ded4930842b46e9507372f0b1b963James Dong RunBefore++; 1770c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1780c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1790c1bc742181ded4930842b46e9507372f0b1b963James Dong 1800c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Update last run */ 1810c1bc742181ded4930842b46e9507372f0b1b963James Dong if (RunBefore) 1820c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1830c1bc742181ded4930842b46e9507372f0b1b963James Dong *pRun++ = RunBefore; 1840c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1850c1bc742181ded4930842b46e9507372f0b1b963James Dong 1860c1bc742181ded4930842b46e9507372f0b1b963James Dong return OMX_Sts_NoErr; 1870c1bc742181ded4930842b46e9507372f0b1b963James Dong} 1880c1bc742181ded4930842b46e9507372f0b1b963James Dong 1890c1bc742181ded4930842b46e9507372f0b1b963James Dong/***************************************************************************** 1900c1bc742181ded4930842b46e9507372f0b1b963James Dong * END OF FILE 1910c1bc742181ded4930842b46e9507372f0b1b963James Dong *****************************************************************************/ 1920c1bc742181ded4930842b46e9507372f0b1b963James Dong 193