⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 h263_vld_c.c

📁 h263,jpeg,mpeg2编解码核心程序(TI DSP C64xx)
💻 C
📖 第 1 页 / 共 3 页
字号:
/*                                                                          *//*      Run: 10 Level: 1 Code: 0010110s. This comes under Class 2 and       *//*      hence the 5 left most bits are extracted to give an index of 5      *//*      The code lengths for these class of codes is stored with an         *//*      implicit offset of 60 and hence this code's length is actually      *//*      stored at location 65. The 65 th entry from the length table is     *//*      8 and corresponds to the length of the code.                        *//*                                                                          *//*                                                                          *//*      The entries in the Zig-Zag table are expected to be in the range    *//*      0 .. 63, with no repeated entries.  The VLD starts reading the      *//*      Zig-Zag table at zz[1], and under normal circumstances will not     *//*      read past element zz[63].  However, when an invalid bitstream is    *//*      encountered, elements as high as zz[126] may be accessed.  See      *//*      the MEMORY NOTE below for more information.                         *//*                                                                          *//*  INVERSE QUANTIZATION                                                    *//*      This is specified in Section 6.2.1 where the reconstructed level    *//*      is specified as follows:                                            *//*                                                                          *//*      |REC| = Quant * (2* |Level| + 1) if Quant = 'odd'                   *//*      |REC| = Quant * (2* |Level| + 1) - 1 if Quant = 'even'              *//*                                                                          *//*      The terms are expanded out to:                                      *//*                                                                          *//*      |REC| = (Quant*2)*Level + Quant            if Quant = 'odd'         *//*      |REC| = (Quant*2)*Level + Quant - 1        if Quant = 'even'        *//*                                                                          *//*      |REC| = Q * Level + dQ                                              *//*                                                                          *//*      Note that in both cases dQ is odd.  This process for generating     *//*      dQ is sometimes referred to as "oddification", as it results in     *//*      IDCT coeffficients that are all odd.  The goal of oddification is   *//*      to reduce IDCT mismatch errors.                                     *//*                                                                          *//*  ASSUMPTIONS                                                             *//*      Speculative reads are OK.  See MEMORY NOTE below.                   *//*                                                                          *//*      Short (as in, invalid due to truncation) bitstreams are followed    *//*      by sentinel values to halt VLD with an error condition, to prevent  *//*      underflow.                                                          *//*                                                                          *//*  MEMORY NOTE                                                             *//*      The VLD routine will read up to two full words beyond the final     *//*      position of the bitstream word pointer, as part of its lookahead.   *//*      The user must ensure that two words of valid memory exist there.    *//*                                                                          *//*      Speculative reads are performed to each of the following arrays:    *//*      (Ranges are in bytes, and are inclusive.)                           *//*                                                                          *//*          Table/Array            Valid Range   Accessed Range             *//*                                                                          *//*          Zig-Zag Table            0..63           0..127                 *//*          Length Table             0..91           0..511                 *//*          Coef/Run Table           0..607          0..607                 *//*                                                                          *//*      The user should ensure that valid (eg. CPU readable) memory         *//*      exists in the required ranges past the end of each table.           *//*                                                                          *//*      Alternately, to ensure that these reads do not reduce cache         *//*      effectiveness (C6211) and do not access invalid memory, the         *//*      following table layout is recommended, as it causes all             *//*      speculative reads to land inside other valid table entries:         *//*                                                                          *//*          Bytes   0 .. 63    'zz'    Zig-Zag table                        *//*          Bytes  64 .. 159   'len'   Huffman-code Length table            *//*          Bytes 160 .. 767   'tab'   Huffman-code Coefficient/Run Table   *//*                                                                          *//*  NOTES                                                                   *//*      The input bitstream must be "word order", meaning that it is        *//*      accessed with word-wide reads.                                      *//*                                                                          *//* ------------------------------------------------------------------------ *//*            Copyright (c) 2000 Texas Instruments, Incorporated.           *//*                           All Rights Reserved.                           *//* ======================================================================== */#ifdef _TMS320C6X# define SHL(x,y) ( (x) << (y) )# define SHR(x,y) ( (x) >> (y) )#else# define SHL(x,y) ( ((y) & 32) ? 0 : ((x) << (y)) )# define SHR(x,y) ( ((y) & 32) ? 0 : ((x) >> (y)) )#endifint  h263_vld_cn(      unsigned int            *restrict *restrict bufPtr,    int                     *restrict bitPtr,    const unsigned short    *restrict tab,    const unsigned char     *restrict len,    short                   Q,    int                     dq,    const unsigned char     *restrict zz,    short                   *restrict idct,    int                     inter ){    /* ==================================================================== */    /*  unsigned               **bufPtr,   Ptr to VLD buffer word pointer.  */    /*  int                    *bitPtr,    Ptr to VLD buffer bit pointer.   */    /*  const unsigned short   *tab,       Ptr to VLC Coeff/Run table.      */    /*  const unsigned char    *len,       Ptr to VLC Length table.         */    /*  short                  Q,          Quantization value.              */    /*  int                    dq,         Quant/Mismatch control value.    */    /*  const unsigned char    *zz,        Ptr to zig-zag scan table.       */    /*  short                  *idct       8x8 IDCT Coeff block. (Output)   */    /* ==================================================================== */    unsigned                *restrict buf    = *bufPtr;    int                               bit    = *bitPtr;    const unsigned short    *restrict tab_   = &tab[176];    const unsigned char     *restrict len_   = &len[60];    const unsigned char     *restrict zz_end = &zz [63];    int                     EOB     = 0;    int                     err     = 0;    unsigned                w0 = buf[0], w1 = buf[1], w2;    unsigned                vld_buf;    unsigned                f5, f7, f9, idx, idx1, idx2, c4, nesc, nbit;    unsigned                run, last, lrl;    int                     level, sign, l_tmp, s_tmp, levelQ;    int                     dq_s;    /* -------------------------------------------------------------------- */    /*  Initialize vld_buf according to the current bit position.           */    /*  Note:  This relies on '>>' and '<<' returning 0 for shift amounts   */    /*  in the range 32..63.  We use macros to emulate this behavior on     */    /*  devices which do not behave this way.                               */    /* -------------------------------------------------------------------- */    vld_buf = SHL(w0, (32 - bit)) | SHR(w1, bit);    zz -= inter;    /* -------------------------------------------------------------------- */    /*  Main VLD processing loop.                                           */    /* -------------------------------------------------------------------- */    do    {        /* ---------------------------------------------------------------- */        /*  The VLC codes fall into several different classes.  The VLD     */        /*  attempts to isolate what VLC code it has by looking at various  */        /*  ranges of bits.  The following diagram illustrates the various  */        /*  regions of the bitstream that are extracted into different      */        /*  variables.                                                      */        /*                                                                  */        /*         3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1              */        /*         1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0              */        /*        +-------------------------------------------------        */        /*        |A B C D E F G H I J K L M N O P Q R S T U V W . . .      */        /*        +-------------------------------------------------        */        /*        |<--f5--->|   |   | |   |                                 */        /*        |<----f7----->|   | |   |                                 */        /*        |<------f9------->| |   |                                 */        /*        |<-------idx2------>|   |                                 */        /*        |<---------idx1-------->|                                 */        /*                                                                  */        /*  The length of the VLC code is determined with one pair of       */        /*  lookups.                                                        */        /*                                                                  */        /*   -- If 'f5' is less than 4, then we have a code in the range    */        /*      00000xxxxx to 00011xxxxx.  For this case, we look up the    */        /*      length at len[f9].  This lookup occurs over the range       */        /*      [0,63].                                                     */        /*                                                                  */        /*   -- If 'f5' is >= 4, we use the first 5 bits to look in the     */        /*      length table.  We look at len[60 + f5].  Since f5 >= 4,     */        /*      this lookup occurs over the range [64, 91].                 */        /*                                                                  */        /*  The Len/Run/Last lookup for VLD then proceeds as follows:       */        /*                                                                  */        /*   -- If 'f5' is less than 4, then we have a code in the range    */        /*      00000xxxxx to 00011xxxxx.                                   */        /*                                                                  */        /*       -- For 00000xxxxxxx codes, lookup tab[idx1].  Since f5     */        /*          is zero (and therefore bits A...E are zero), idx1 has   */        /*          7 significant bits.  Therefore, the lookup occurs over  */        /*          over the range [0,127].                                 */        /*                                                                  */        /*       -- For 00001xxxxx thru 00011xxxxx codes, lookup            */        /*          tab[64 + idx0].  For this range of codes, idx0 >= 64,   */        /*          and has 7 significant bits.  Therefore, the lookup      */        /*          occurs over the range [128,191].                        */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -