omxVCM4P2_DecodeVLCZigzag_IntraDCVLC.c revision 0c1bc742181ded4930842b46e9507372f0b1b963
10c1bc742181ded4930842b46e9507372f0b1b963James Dong/** 20c1bc742181ded4930842b46e9507372f0b1b963James Dong * 30c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name: omxVCM4P2_DecodeVLCZigzag_IntraDCVLC.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 * 120c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: 130c1bc742181ded4930842b46e9507372f0b1b963James Dong * Contains modules for zigzag scanning and VLC decoding 140c1bc742181ded4930842b46e9507372f0b1b963James Dong * for intra block. 150c1bc742181ded4930842b46e9507372f0b1b963James Dong * 160c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 170c1bc742181ded4930842b46e9507372f0b1b963James Dong 180c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h" 190c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h" 200c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h" 210c1bc742181ded4930842b46e9507372f0b1b963James Dong 220c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h" 230c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM_Bitstream.h" 240c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h" 250c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVCM4P2_Huff_Tables_VLC.h" 260c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVCM4P2_ZigZag_Tables.h" 270c1bc742181ded4930842b46e9507372f0b1b963James Dong 280c1bc742181ded4930842b46e9507372f0b1b963James Dong 290c1bc742181ded4930842b46e9507372f0b1b963James Dong 300c1bc742181ded4930842b46e9507372f0b1b963James Dong 310c1bc742181ded4930842b46e9507372f0b1b963James Dong/** 320c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function: omxVCM4P2_DecodeVLCZigzag_IntraDCVLC (6.2.5.2.2) 330c1bc742181ded4930842b46e9507372f0b1b963James Dong * 340c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description: 350c1bc742181ded4930842b46e9507372f0b1b963James Dong * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 360c1bc742181ded4930842b46e9507372f0b1b963James Dong * for one intra block. Two versions of the function (DCVLC and ACVLC) are 370c1bc742181ded4930842b46e9507372f0b1b963James Dong * provided in order to support the two different methods of processing DC 380c1bc742181ded4930842b46e9507372f0b1b963James Dong * coefficients, as described in [ISO14496-2], subclause 7.4.1.4, Intra DC 390c1bc742181ded4930842b46e9507372f0b1b963James Dong * Coefficient Decoding for the Case of Switched VLC Encoding. 400c1bc742181ded4930842b46e9507372f0b1b963James Dong * 410c1bc742181ded4930842b46e9507372f0b1b963James Dong * Input Arguments: 420c1bc742181ded4930842b46e9507372f0b1b963James Dong * 430c1bc742181ded4930842b46e9507372f0b1b963James Dong * ppBitStream - pointer to the pointer to the current byte in the 440c1bc742181ded4930842b46e9507372f0b1b963James Dong * bitstream buffer 450c1bc742181ded4930842b46e9507372f0b1b963James Dong * pBitOffset - pointer to the bit position in the current byte referenced 460c1bc742181ded4930842b46e9507372f0b1b963James Dong * by *ppBitStream. The parameter *pBitOffset is valid in the 470c1bc742181ded4930842b46e9507372f0b1b963James Dong * range [0-7]. 480c1bc742181ded4930842b46e9507372f0b1b963James Dong * Bit Position in one byte: |Most Least| 490c1bc742181ded4930842b46e9507372f0b1b963James Dong * *pBitOffset |0 1 2 3 4 5 6 7| 500c1bc742181ded4930842b46e9507372f0b1b963James Dong * predDir - AC prediction direction; used to select the zigzag scan 510c1bc742181ded4930842b46e9507372f0b1b963James Dong * pattern; takes one of the following values: 520c1bc742181ded4930842b46e9507372f0b1b963James Dong * - OMX_VC_NONE - AC prediction not used; 530c1bc742181ded4930842b46e9507372f0b1b963James Dong * performs classical zigzag scan. 540c1bc742181ded4930842b46e9507372f0b1b963James Dong * - OMX_VC_HORIZONTAL - Horizontal prediction; 550c1bc742181ded4930842b46e9507372f0b1b963James Dong * performs alternate-vertical zigzag scan; 560c1bc742181ded4930842b46e9507372f0b1b963James Dong * - OMX_VC_VERTICAL - Vertical prediction; 570c1bc742181ded4930842b46e9507372f0b1b963James Dong * performs alternate-horizontal zigzag scan. 580c1bc742181ded4930842b46e9507372f0b1b963James Dong * shortVideoHeader - binary flag indicating presence of 590c1bc742181ded4930842b46e9507372f0b1b963James Dong * short_video_header; escape modes 0-3 are used if 600c1bc742181ded4930842b46e9507372f0b1b963James Dong * shortVideoHeader==0, and escape mode 4 is used when 610c1bc742181ded4930842b46e9507372f0b1b963James Dong * shortVideoHeader==1. 620c1bc742181ded4930842b46e9507372f0b1b963James Dong * videoComp - video component type (luminance or chrominance) of the 630c1bc742181ded4930842b46e9507372f0b1b963James Dong * current block 640c1bc742181ded4930842b46e9507372f0b1b963James Dong * 650c1bc742181ded4930842b46e9507372f0b1b963James Dong * Output Arguments: 660c1bc742181ded4930842b46e9507372f0b1b963James Dong * 670c1bc742181ded4930842b46e9507372f0b1b963James Dong * ppBitStream - *ppBitStream is updated after the block is decoded such 680c1bc742181ded4930842b46e9507372f0b1b963James Dong * that it points to the current byte in the bit stream buffer 690c1bc742181ded4930842b46e9507372f0b1b963James Dong * pBitOffset - *pBitOffset is updated such that it points to the current 700c1bc742181ded4930842b46e9507372f0b1b963James Dong * bit position in the byte pointed by *ppBitStream 710c1bc742181ded4930842b46e9507372f0b1b963James Dong * pDst - pointer to the coefficient buffer of current block; must be 720c1bc742181ded4930842b46e9507372f0b1b963James Dong * 4-byte aligned. 730c1bc742181ded4930842b46e9507372f0b1b963James Dong * 740c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value: 750c1bc742181ded4930842b46e9507372f0b1b963James Dong * 760c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_Sts_NoErr - no error 770c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_Sts_BadArgErr - bad arguments, if: 780c1bc742181ded4930842b46e9507372f0b1b963James Dong * - At least one of the following pointers is NULL: 790c1bc742181ded4930842b46e9507372f0b1b963James Dong * ppBitStream, *ppBitStream, pBitOffset, pDst 800c1bc742181ded4930842b46e9507372f0b1b963James Dong * - *pBitOffset exceeds [0,7] 810c1bc742181ded4930842b46e9507372f0b1b963James Dong * - preDir exceeds [0,2] 820c1bc742181ded4930842b46e9507372f0b1b963James Dong * - pDst is not 4-byte aligned 830c1bc742181ded4930842b46e9507372f0b1b963James Dong * OMX_Sts_Err - if: 840c1bc742181ded4930842b46e9507372f0b1b963James Dong * - In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 850c1bc742181ded4930842b46e9507372f0b1b963James Dong * - At least one of mark bits equals zero 860c1bc742181ded4930842b46e9507372f0b1b963James Dong * - Illegal stream encountered; code cannot be located in VLC table 870c1bc742181ded4930842b46e9507372f0b1b963James Dong * - Forbidden code encountered in the VLC FLC table. 880c1bc742181ded4930842b46e9507372f0b1b963James Dong * - The number of coefficients is greater than 64 890c1bc742181ded4930842b46e9507372f0b1b963James Dong * 900c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 910c1bc742181ded4930842b46e9507372f0b1b963James Dong 920c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult omxVCM4P2_DecodeVLCZigzag_IntraDCVLC( 930c1bc742181ded4930842b46e9507372f0b1b963James Dong const OMX_U8 ** ppBitStream, 940c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_INT * pBitOffset, 950c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_S16 * pDst, 960c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U8 predDir, 970c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_INT shortVideoHeader, 980c1bc742181ded4930842b46e9507372f0b1b963James Dong OMXVCM4P2VideoComponent videoComp 990c1bc742181ded4930842b46e9507372f0b1b963James Dong) 1000c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 1010c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Dummy initilaization to remove compilation error */ 1020c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_S8 DCValueSize = 0; 1030c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U16 powOfSize, fetchDCbits; 1040c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U8 start = 1; 1050c1bc742181ded4930842b46e9507372f0b1b963James Dong 1060c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Argument error checks */ 1070c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr); 1080c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr); 1090c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr); 1100c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr); 1110c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf(!armIs4ByteAligned(pDst), OMX_Sts_BadArgErr); 1120c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset > 7), OMX_Sts_BadArgErr); 1130c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetArgErrIf((predDir > 2), OMX_Sts_BadArgErr); 1140c1bc742181ded4930842b46e9507372f0b1b963James Dong 1150c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Insert the code into the bitstream */ 1160c1bc742181ded4930842b46e9507372f0b1b963James Dong if (videoComp == OMX_VC_LUMINANCE) 1170c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1180c1bc742181ded4930842b46e9507372f0b1b963James Dong DCValueSize = armUnPackVLC32(ppBitStream, 1190c1bc742181ded4930842b46e9507372f0b1b963James Dong pBitOffset, armVCM4P2_aIntraDCLumaIndex); 1200c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1210c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (videoComp == OMX_VC_CHROMINANCE) 1220c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1230c1bc742181ded4930842b46e9507372f0b1b963James Dong DCValueSize = armUnPackVLC32(ppBitStream, 1240c1bc742181ded4930842b46e9507372f0b1b963James Dong pBitOffset, armVCM4P2_aIntraDCChromaIndex); 1250c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1260c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetDataErrIf(DCValueSize == -1, OMX_Sts_Err); 1270c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetDataErrIf(DCValueSize > 12, OMX_Sts_Err); 1280c1bc742181ded4930842b46e9507372f0b1b963James Dong 1290c1bc742181ded4930842b46e9507372f0b1b963James Dong 1300c1bc742181ded4930842b46e9507372f0b1b963James Dong if (DCValueSize == 0) 1310c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1320c1bc742181ded4930842b46e9507372f0b1b963James Dong pDst[0] = 0; 1330c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1340c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1350c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1360c1bc742181ded4930842b46e9507372f0b1b963James Dong fetchDCbits = (OMX_U16) armGetBits(ppBitStream, pBitOffset, \ 1370c1bc742181ded4930842b46e9507372f0b1b963James Dong DCValueSize); 1380c1bc742181ded4930842b46e9507372f0b1b963James Dong 1390c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (fetchDCbits >> (DCValueSize - 1)) == 0) 1400c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1410c1bc742181ded4930842b46e9507372f0b1b963James Dong /* calulate pow */ 1420c1bc742181ded4930842b46e9507372f0b1b963James Dong powOfSize = (1 << DCValueSize); 1430c1bc742181ded4930842b46e9507372f0b1b963James Dong 1440c1bc742181ded4930842b46e9507372f0b1b963James Dong pDst[0] = (OMX_S16) (fetchDCbits ^ (powOfSize - 1)); 1450c1bc742181ded4930842b46e9507372f0b1b963James Dong pDst[0] = -pDst[0]; 1460c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1470c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1480c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1490c1bc742181ded4930842b46e9507372f0b1b963James Dong pDst[0] = fetchDCbits; 1500c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1510c1bc742181ded4930842b46e9507372f0b1b963James Dong 1520c1bc742181ded4930842b46e9507372f0b1b963James Dong if (DCValueSize > 8) 1530c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1540c1bc742181ded4930842b46e9507372f0b1b963James Dong /* reading and checking the marker bit*/ 1550c1bc742181ded4930842b46e9507372f0b1b963James Dong armRetDataErrIf (armGetBits(ppBitStream, pBitOffset, 1) == 0, \ 1560c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_Sts_Err); 1570c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1580c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1590c1bc742181ded4930842b46e9507372f0b1b963James Dong 1600c1bc742181ded4930842b46e9507372f0b1b963James Dong return armVCM4P2_DecodeVLCZigzag_Intra( 1610c1bc742181ded4930842b46e9507372f0b1b963James Dong ppBitStream, 1620c1bc742181ded4930842b46e9507372f0b1b963James Dong pBitOffset, 1630c1bc742181ded4930842b46e9507372f0b1b963James Dong pDst, 1640c1bc742181ded4930842b46e9507372f0b1b963James Dong predDir, 1650c1bc742181ded4930842b46e9507372f0b1b963James Dong shortVideoHeader, 1660c1bc742181ded4930842b46e9507372f0b1b963James Dong start); 1670c1bc742181ded4930842b46e9507372f0b1b963James Dong} 1680c1bc742181ded4930842b46e9507372f0b1b963James Dong 1690c1bc742181ded4930842b46e9507372f0b1b963James Dong/* End of file */ 1700c1bc742181ded4930842b46e9507372f0b1b963James Dong 171