omxVCM4P2_EncodeVLCZigzag_IntraDCVLC.c revision 78e52bfac041d71ce53b5b13c2abf78af742b09d
1/* 2 * Copyright (C) 2007-2008 ARM Limited 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17/** 18 * 19 * File Name: omxVCM4P2_EncodeVLCZigzag_IntraDCVLC.c 20 * OpenMAX DL: v1.0.2 21 * Revision: 9641 22 * Date: Thursday, February 7, 2008 23 * 24 * 25 * 26 * 27 * Description: 28 * Contains modules for zigzag scanning and VLC encoding 29 * for intra block. 30 * 31 */ 32 33#include "omxtypes.h" 34#include "armOMX.h" 35#include "omxVC.h" 36 37#include "armVC.h" 38#include "armCOMM_Bitstream.h" 39#include "armCOMM.h" 40#include "armVCM4P2_Huff_Tables_VLC.h" 41#include "armVCM4P2_ZigZag_Tables.h" 42 43 44 45/** 46 * Function: omxVCM4P2_EncodeVLCZigzag_IntraDCVLC (6.2.4.5.2) 47 * 48 * Description: 49 * Performs zigzag scan and VLC encoding of AC and DC coefficients for one 50 * intra block. Two versions of the function (DCVLC and ACVLC) are provided 51 * in order to support the two different methods of processing DC 52 * coefficients, as described in [ISO14496-2], subclause 7.4.1.4, "Intra DC 53 * Coefficient Decoding for the Case of Switched VLC Encoding". 54 * 55 * Input Arguments: 56 * 57 * ppBitStream - double pointer to the current byte in the bitstream 58 * pBitOffset - pointer to the bit position in the byte pointed by 59 * *ppBitStream. Valid within 0 to 7. 60 * pQDctBlkCoef - pointer to the quantized DCT coefficient 61 * predDir - AC prediction direction, which is used to decide the zigzag 62 * scan pattern; takes one of the following values: 63 * - OMX_VC_NONE - AC prediction not used. 64 * Performs classical zigzag scan. 65 * - OMX_VC_HORIZONTAL - Horizontal prediction. 66 * Performs alternate-vertical zigzag scan. 67 * - OMX_VC_VERTICAL - Vertical prediction. 68 * Performs alternate-horizontal zigzag scan. 69 * pattern - block pattern which is used to decide whether this block is 70 * encoded 71 * shortVideoHeader - binary flag indicating presence of 72 * short_video_header; escape modes 0-3 are used if 73 * shortVideoHeader==0, and escape mode 4 is used when 74 * shortVideoHeader==1. 75 * videoComp - video component type (luminance, chrominance) of the current 76 * block 77 * 78 * Output Arguments: 79 * 80 * ppBitStream - *ppBitStream is updated after the block is encoded, so 81 * that it points to the current byte in the bit stream buffer. 82 * pBitOffset - *pBitOffset is updated so that it points to the current bit 83 * position in the byte pointed by *ppBitStream. 84 * 85 * Return Value: 86 * 87 * OMX_Sts_NoErr - no error 88 * OMX_Sts_BadArgErr - Bad arguments: 89 * - At least one of the following pointers is NULL: ppBitStream, 90 * *ppBitStream, pBitOffset, pQDctBlkCoef. 91 * - *pBitOffset < 0, or *pBitOffset >7. 92 * - PredDir is not one of: OMX_VC_NONE, OMX_VC_HORIZONTAL, or 93 * OMX_VC_VERTICAL. 94 * - VideoComp is not one component of enum OMXVCM4P2VideoComponent. 95 * 96 */ 97 98OMXResult omxVCM4P2_EncodeVLCZigzag_IntraDCVLC( 99 OMX_U8 **ppBitStream, 100 OMX_INT *pBitOffset, 101 const OMX_S16 *pQDctBlkCoef, 102 OMX_U8 predDir, 103 OMX_U8 pattern, 104 OMX_INT shortVideoHeader, 105 OMXVCM4P2VideoComponent videoComp 106) 107{ 108 OMX_S16 dcValue, powOfSize; 109 OMX_U8 DCValueSize, start = 1; 110 OMX_U16 absDCValue; 111 112 /* Argument error checks */ 113 armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr); 114 armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr); 115 armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr); 116 armRetArgErrIf(pQDctBlkCoef == NULL, OMX_Sts_BadArgErr); 117 armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset >7), OMX_Sts_BadArgErr); 118 armRetArgErrIf((videoComp != OMX_VC_LUMINANCE) && (videoComp != OMX_VC_CHROMINANCE), OMX_Sts_BadArgErr); 119 armRetArgErrIf((predDir != OMX_VC_NONE) && (predDir != OMX_VC_HORIZONTAL) && (predDir != OMX_VC_VERTICAL) , OMX_Sts_BadArgErr); 120 121 if (pattern) 122 { 123 dcValue = pQDctBlkCoef[0]; 124 absDCValue = armAbs(dcValue); 125 126 /* Find the size */ 127 DCValueSize = armLogSize (absDCValue); 128 absDCValue = armAbs(dcValue); 129 130 /* Insert the code into the bitstream */ 131 if (videoComp == OMX_VC_LUMINANCE) 132 { 133 134 armPackVLC32 (ppBitStream, pBitOffset, 135 armVCM4P2_aIntraDCLumaIndex[DCValueSize]); 136 } 137 else if (videoComp == OMX_VC_CHROMINANCE) 138 { 139 140 armPackVLC32 (ppBitStream, pBitOffset, 141 armVCM4P2_aIntraDCChromaIndex[DCValueSize]); 142 } 143 144 /* Additional code generation in case of negative 145 dc value the additional */ 146 if (DCValueSize > 0) 147 { 148 if (dcValue < 0) 149 { 150 /* calulate 2 pow */ 151 powOfSize = (1 << DCValueSize); 152 153 absDCValue = absDCValue ^ (powOfSize - 1); 154 } 155 armPackBits(ppBitStream, pBitOffset, (OMX_U32)absDCValue, \ 156 DCValueSize); 157 158 if (DCValueSize > 8) 159 { 160 armPackBits(ppBitStream, pBitOffset, 1, 1); 161 } 162 } 163 } 164 165 return armVCM4P2_EncodeVLCZigzag_Intra( 166 ppBitStream, 167 pBitOffset, 168 pQDctBlkCoef, 169 predDir, 170 pattern, 171 shortVideoHeader, 172 start); 173} 174 175/* End of file */ 176