Home | History | Annotate | Download | only in src
      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_DecodeVLCZigzag_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 decoding
     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 /**
     47  * Function:  omxVCM4P2_DecodeVLCZigzag_IntraDCVLC   (6.2.5.2.2)
     48  *
     49  * Description:
     50  * Performs VLC decoding and inverse zigzag scan of AC and DC coefficients
     51  * for one intra block.  Two versions of the function (DCVLC and ACVLC) are
     52  * provided in order to support the two different methods of processing DC
     53  * coefficients, as described in [ISO14496-2], subclause 7.4.1.4,  Intra DC
     54  * Coefficient Decoding for the Case of Switched VLC Encoding.
     55  *
     56  * Input Arguments:
     57  *
     58  *   ppBitStream - pointer to the pointer to the current byte in the
     59  *            bitstream buffer
     60  *   pBitOffset - pointer to the bit position in the current byte referenced
     61  *            by *ppBitStream.  The parameter *pBitOffset is valid in the
     62  *            range [0-7].
     63  *            Bit Position in one byte:  |Most      Least|
     64  *                    *pBitOffset        |0 1 2 3 4 5 6 7|
     65  *   predDir - AC prediction direction; used to select the zigzag scan
     66  *            pattern; takes one of the following values:
     67  *            -  OMX_VC_NONE - AC prediction not used;
     68  *                             performs classical zigzag scan.
     69  *            -  OMX_VC_HORIZONTAL - Horizontal prediction;
     70  *                             performs alternate-vertical zigzag scan;
     71  *            -  OMX_VC_VERTICAL - Vertical prediction;
     72  *                             performs alternate-horizontal zigzag scan.
     73  *   shortVideoHeader - binary flag indicating presence of
     74  *            short_video_header; escape modes 0-3 are used if
     75  *            shortVideoHeader==0, and escape mode 4 is used when
     76  *            shortVideoHeader==1.
     77  *   videoComp - video component type (luminance or chrominance) of the
     78  *            current block
     79  *
     80  * Output Arguments:
     81  *
     82  *   ppBitStream - *ppBitStream is updated after the block is decoded such
     83  *            that it points to the current byte in the bit stream buffer
     84  *   pBitOffset - *pBitOffset is updated such that it points to the current
     85  *            bit position in the byte pointed by *ppBitStream
     86  *   pDst - pointer to the coefficient buffer of current block; must be
     87  *            4-byte aligned.
     88  *
     89  * Return Value:
     90  *
     91  *    OMX_Sts_NoErr - no error
     92  *    OMX_Sts_BadArgErr - bad arguments, if:
     93  *    -    At least one of the following pointers is NULL:
     94  *         ppBitStream, *ppBitStream, pBitOffset, pDst
     95  *    -    *pBitOffset exceeds [0,7]
     96  *    -    preDir exceeds [0,2]
     97  *    -    pDst is not 4-byte aligned
     98  *    OMX_Sts_Err - if:
     99  *    -    In DecodeVLCZigzag_IntraDCVLC, dc_size > 12
    100  *    -    At least one of mark bits equals zero
    101  *    -    Illegal stream encountered; code cannot be located in VLC table
    102  *    -    Forbidden code encountered in the VLC FLC table.
    103  *    -    The number of coefficients is greater than 64
    104  *
    105  */
    106 
    107 OMXResult omxVCM4P2_DecodeVLCZigzag_IntraDCVLC(
    108      const OMX_U8 ** ppBitStream,
    109      OMX_INT * pBitOffset,
    110      OMX_S16 * pDst,
    111      OMX_U8 predDir,
    112      OMX_INT shortVideoHeader,
    113      OMXVCM4P2VideoComponent videoComp
    114 )
    115 {
    116     /* Dummy initilaization to remove compilation error */
    117     OMX_S8  DCValueSize = 0;
    118     OMX_U16 powOfSize, fetchDCbits;
    119     OMX_U8 start = 1;
    120 
    121     /* Argument error checks */
    122     armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
    123     armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
    124     armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
    125     armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
    126     armRetArgErrIf(!armIs4ByteAligned(pDst), OMX_Sts_BadArgErr);
    127     armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset > 7), OMX_Sts_BadArgErr);
    128     armRetArgErrIf((predDir > 2), OMX_Sts_BadArgErr);
    129 
    130     /* Insert the code into the bitstream */
    131     if (videoComp == OMX_VC_LUMINANCE)
    132     {
    133         DCValueSize = armUnPackVLC32(ppBitStream,
    134                             pBitOffset, armVCM4P2_aIntraDCLumaIndex);
    135     }
    136     else if (videoComp == OMX_VC_CHROMINANCE)
    137     {
    138         DCValueSize = armUnPackVLC32(ppBitStream,
    139                             pBitOffset, armVCM4P2_aIntraDCChromaIndex);
    140     }
    141     armRetDataErrIf(DCValueSize == -1, OMX_Sts_Err);
    142     armRetDataErrIf(DCValueSize > 12, OMX_Sts_Err);
    143 
    144 
    145     if (DCValueSize == 0)
    146     {
    147         pDst[0] = 0;
    148     }
    149     else
    150     {
    151         fetchDCbits = (OMX_U16) armGetBits(ppBitStream, pBitOffset, \
    152                                            DCValueSize);
    153 
    154         if ( (fetchDCbits >> (DCValueSize - 1)) == 0)
    155         {
    156             /* calulate pow */
    157             powOfSize = (1 << DCValueSize);
    158 
    159             pDst[0] =  (OMX_S16) (fetchDCbits ^ (powOfSize - 1));
    160             pDst[0] = -pDst[0];
    161         }
    162         else
    163         {
    164             pDst[0] = fetchDCbits;
    165         }
    166 
    167         if (DCValueSize > 8)
    168         {
    169             /* reading and checking the marker bit*/
    170             armRetDataErrIf (armGetBits(ppBitStream, pBitOffset, 1) == 0, \
    171                              OMX_Sts_Err);
    172         }
    173     }
    174 
    175     return armVCM4P2_DecodeVLCZigzag_Intra(
    176                 ppBitStream,
    177                 pBitOffset,
    178                 pDst,
    179                 predDir,
    180                 shortVideoHeader,
    181                 start);
    182 }
    183 
    184 /* End of file */
    185 
    186