1/** 2 * 3 * File Name: omxVCM4P2_DecodeVLCZigzag_IntraDCVLC.c 4 * OpenMAX DL: v1.0.2 5 * Revision: 9641 6 * Date: Thursday, February 7, 2008 7 * 8 * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved. 9 * 10 * 11 * 12 * Description: 13 * Contains modules for zigzag scanning and VLC decoding 14 * for intra block. 15 * 16 */ 17 18#include "omxtypes.h" 19#include "armOMX.h" 20#include "omxVC.h" 21 22#include "armVC.h" 23#include "armCOMM_Bitstream.h" 24#include "armCOMM.h" 25#include "armVCM4P2_Huff_Tables_VLC.h" 26#include "armVCM4P2_ZigZag_Tables.h" 27 28 29 30 31/** 32 * Function: omxVCM4P2_DecodeVLCZigzag_IntraDCVLC (6.2.5.2.2) 33 * 34 * Description: 35 * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients 36 * for one intra block. Two versions of the function (DCVLC and ACVLC) are 37 * provided in order to support the two different methods of processing DC 38 * coefficients, as described in [ISO14496-2], subclause 7.4.1.4, Intra DC 39 * Coefficient Decoding for the Case of Switched VLC Encoding. 40 * 41 * Input Arguments: 42 * 43 * ppBitStream - pointer to the pointer to the current byte in the 44 * bitstream buffer 45 * pBitOffset - pointer to the bit position in the current byte referenced 46 * by *ppBitStream. The parameter *pBitOffset is valid in the 47 * range [0-7]. 48 * Bit Position in one byte: |Most Least| 49 * *pBitOffset |0 1 2 3 4 5 6 7| 50 * predDir - AC prediction direction; used to select the zigzag scan 51 * pattern; takes one of the following values: 52 * - OMX_VC_NONE - AC prediction not used; 53 * performs classical zigzag scan. 54 * - OMX_VC_HORIZONTAL - Horizontal prediction; 55 * performs alternate-vertical zigzag scan; 56 * - OMX_VC_VERTICAL - Vertical prediction; 57 * performs alternate-horizontal zigzag scan. 58 * shortVideoHeader - binary flag indicating presence of 59 * short_video_header; escape modes 0-3 are used if 60 * shortVideoHeader==0, and escape mode 4 is used when 61 * shortVideoHeader==1. 62 * videoComp - video component type (luminance or chrominance) of the 63 * current block 64 * 65 * Output Arguments: 66 * 67 * ppBitStream - *ppBitStream is updated after the block is decoded such 68 * that it points to the current byte in the bit stream buffer 69 * pBitOffset - *pBitOffset is updated such that it points to the current 70 * bit position in the byte pointed by *ppBitStream 71 * pDst - pointer to the coefficient buffer of current block; must be 72 * 4-byte aligned. 73 * 74 * Return Value: 75 * 76 * OMX_Sts_NoErr - no error 77 * OMX_Sts_BadArgErr - bad arguments, if: 78 * - At least one of the following pointers is NULL: 79 * ppBitStream, *ppBitStream, pBitOffset, pDst 80 * - *pBitOffset exceeds [0,7] 81 * - preDir exceeds [0,2] 82 * - pDst is not 4-byte aligned 83 * OMX_Sts_Err - if: 84 * - In DecodeVLCZigzag_IntraDCVLC, dc_size > 12 85 * - At least one of mark bits equals zero 86 * - Illegal stream encountered; code cannot be located in VLC table 87 * - Forbidden code encountered in the VLC FLC table. 88 * - The number of coefficients is greater than 64 89 * 90 */ 91 92OMXResult omxVCM4P2_DecodeVLCZigzag_IntraDCVLC( 93 const OMX_U8 ** ppBitStream, 94 OMX_INT * pBitOffset, 95 OMX_S16 * pDst, 96 OMX_U8 predDir, 97 OMX_INT shortVideoHeader, 98 OMXVCM4P2VideoComponent videoComp 99) 100{ 101 /* Dummy initilaization to remove compilation error */ 102 OMX_S8 DCValueSize = 0; 103 OMX_U16 powOfSize, fetchDCbits; 104 OMX_U8 start = 1; 105 106 /* Argument error checks */ 107 armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr); 108 armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr); 109 armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr); 110 armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr); 111 armRetArgErrIf(!armIs4ByteAligned(pDst), OMX_Sts_BadArgErr); 112 armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset > 7), OMX_Sts_BadArgErr); 113 armRetArgErrIf((predDir > 2), OMX_Sts_BadArgErr); 114 115 /* Insert the code into the bitstream */ 116 if (videoComp == OMX_VC_LUMINANCE) 117 { 118 DCValueSize = armUnPackVLC32(ppBitStream, 119 pBitOffset, armVCM4P2_aIntraDCLumaIndex); 120 } 121 else if (videoComp == OMX_VC_CHROMINANCE) 122 { 123 DCValueSize = armUnPackVLC32(ppBitStream, 124 pBitOffset, armVCM4P2_aIntraDCChromaIndex); 125 } 126 armRetDataErrIf(DCValueSize == -1, OMX_Sts_Err); 127 armRetDataErrIf(DCValueSize > 12, OMX_Sts_Err); 128 129 130 if (DCValueSize == 0) 131 { 132 pDst[0] = 0; 133 } 134 else 135 { 136 fetchDCbits = (OMX_U16) armGetBits(ppBitStream, pBitOffset, \ 137 DCValueSize); 138 139 if ( (fetchDCbits >> (DCValueSize - 1)) == 0) 140 { 141 /* calulate pow */ 142 powOfSize = (1 << DCValueSize); 143 144 pDst[0] = (OMX_S16) (fetchDCbits ^ (powOfSize - 1)); 145 pDst[0] = -pDst[0]; 146 } 147 else 148 { 149 pDst[0] = fetchDCbits; 150 } 151 152 if (DCValueSize > 8) 153 { 154 /* reading and checking the marker bit*/ 155 armRetDataErrIf (armGetBits(ppBitStream, pBitOffset, 1) == 0, \ 156 OMX_Sts_Err); 157 } 158 } 159 160 return armVCM4P2_DecodeVLCZigzag_Intra( 161 ppBitStream, 162 pBitOffset, 163 pDst, 164 predDir, 165 shortVideoHeader, 166 start); 167} 168 169/* End of file */ 170 171