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

📄 mpeg2_vld_intra_c.c

📁 h263,jpeg,mpeg2编解码核心程序(TI DSP C64xx)
💻 C
📖 第 1 页 / 共 3 页
字号:
        t8 = SHL(word1, bptr);        t9 = SHR(word2, bptr_cmpl);                      /* unsigned shift */        top1 = t8 + t9;                Wptr++;        zzptr++;            /* -------------------------------------------------------------------- */    /*  Decode AC coefficients                                              */    /* -------------------------------------------------------------------- */        while (!eob_err)         {                    /* ---------------------------------------------------------------- */        /*  Length computation                                              */        /* ---------------------------------------------------------------- */        /* ---------------------------------------------------------------- */        /*  _lnorm returns the number of redundant sign bits in ltop0, e.g. */        /*  0001 xxxx ... xxxx returns 2, 1111 10xx ... xxxx returns 4.     */        /*  Example: top=0000 101s xxxx xxxx, then nrm=3                    */        /* ---------------------------------------------------------------- */            nrm = _lnorm(ltop0);                    /* ---------------------------------------------------------------- */        /*  get rid of the leading all 0s/1s.                               */        /*  Example: t1=0101 sxxx xxxx xxxx                                 */        /* ---------------------------------------------------------------- */            t1  = ltop0 << nrm;                              /* ---------------------------------------------------------------- */        /*  use the number of leading bits (norm) as index,                 */        /*  Example: t2= xxxx xxxx 0011 rrrr                                */        /* ---------------------------------------------------------------- */            t2  = nrm << 4;            if (intra_vlc_format==0)                t3 = &IMG_len_tbl0[t2];            else /* intra_vlc_format==1 */                t3 = &IMG_len_tbl1[t2];                    /* ---------------------------------------------------------------- */        /*  use 4 extra bits after leading bits to distinguish special      */        /*  cases (40-4=36)                                                 */        /* ---------------------------------------------------------------- */            t4  = (unsigned) (t1 >> 36);                                                         /* ---------------------------------------------------------------- */        /*  get len from table and calculate 32-len                         */         /* ---------------------------------------------------------------- */            len  = t3[t4];            len_c = 32 - len;                    /* ---------------------------------------------------------------- */        /*  now that we know the length of the current VL code we can       */        /*  advance bitstream to next one:                                  */        /*                                                                  */        /*  1. update ltop0 from ltop0 and top1                             */        /* ---------------------------------------------------------------- */            t5  = ltop0 << len;            t7  = top1 >> len_c;            top0_bk = (unsigned)(ltop0 >> 8);            ltop0 = t5 + t7;                    /* ---------------------------------------------------------------- */        /*  2. update top1 from word1 and word2 after increasing bptr by    */        /*  len.  if neccesary (i.e. if new bptr is greater than 32)        */        /*  update word1 and word2 from memory first. Don't forget that     */        /*  bptr is always relative to the next lower word boundary and     */        /*  therefore needs to be ANDed with 31 in case it become >=32.     */        /* ---------------------------------------------------------------- */            bptr += len;            test2 = (bptr >= 32);            if (test2) {                word1_rw = word1;                word1 = word2;                word2 = bsbuf[next_wptr];                next_wptr += 1;                 next_wptr &= (bsbuf_words-1);             }            bptr = bptr & 31;            bptr_cmpl = 32 - bptr;            t8 = SHL(word1, bptr);            t9 = SHR(word2, bptr_cmpl);                   /* unsigned shift */            top1 = t8 + t9;        /* ---------------------------------------------------------------- */        /*  Run-Level Decode                                                */        /* ---------------------------------------------------------------- */        /* ---------------------------------------------------------------- */        /*  check if it is an ESCAPE code which has a unique fixed length   */        /*  of 24 bits                                                      */        /* ---------------------------------------------------------------- */            test1 = len - 24;                                if (!test1)             {            /* ------------------------------------------------------------ */            /* ESCAPE code: no look up required, just extract bits: 6 bits  */            /* for ESCAPE, 6 bits for RUN, then 12 bits for LEVEL           */            /* ------------------------------------------------------------ */                run = _extu(top0_bk, 6, 26);                level = _ext(top0_bk, 12, 20);            }            else             {                rld_left = len-5;                if (len<5) rld_left=0;                                 /* -------------------------------------------------------- */                /*  last 5 bits of VLC incl. sign form 2nd part of index    */                /* -------------------------------------------------------- */                rld_index = ((len)<<5) + _extu(top0_bk, rld_left, 32-5);                if (intra_vlc_format==0)                   run_level = IMG_rld_table0[rld_index];                else /* intra_vlc_format==1 */                   run_level = IMG_rld_table1[rld_index];                                run   = run_level >> 8;                level = (char)run_level;            }                        eob_err = (run >= 64);                    /* ---------------------------------------------------------------- */        /*  Run-lengh expansion and DQ                                      */        /* ---------------------------------------------------------------- */        /* ---------------------------------------------------------------- */        /*  Dequantisation: *out_i = ((2*level + Sign(level)) * W * qscl)   */        /*  / 32. Sign(x)=-1 for x<0, 0 for x=0, +1 for x>0. Division '/':  */        /*  "Integer division with truncation of the result toward zero.    */        /*  For example, 7/4 and -7/-4 are truncated to 1 and -7/4 and      */        /*  7/-4 are truncated to -1." (MPEG-2 Standard Text)               */        /* ---------------------------------------------------------------- */            neg = (level < 0);                  f1 = 2*level;         /* ---------------------------------------------------------------- */        /*  find quantization matrix element at zigzag position and         */        /*  multiply f1 with W * qscl                                       */        /* ---------------------------------------------------------------- */            if (!eob_err)         /* prevent from accessing memory when EOB */            {                W = *(Wptr += run);                  Wptr++;                /* detect total run overrun */                eob_err = (Wptr > Wptr_end);            }                        qW = qscl * W;            f3 = f1 * qW;                    /* ---------------------------------------------------------------- */        /*  for negative numbers we first need to add 31 before dividing    */        /*  by 32 to achieve truncation towards zero as required by the     */        /*  standard.                                                       */        /* ---------------------------------------------------------------- */            if (neg) f3 += 31;                    /* ---------------------------------------------------------------- */        /*  saturate to signed 12 bit word (with /32 <-> >>5 incorporated)  */        /*  SSHL: shift left and saturate to 32 bits                        */        /* ---------------------------------------------------------------- */            f4 = _sshl(f3, 15);                        f5 = (int)(f4 >> shr);             f5 &= mask;        /* ---------------------------------------------------------------- */        /*  mismatch control: determine if sum of coefficents is odd or     */        /*  even                                                            */        /* ---------------------------------------------------------------- */            if (!eob_err)                 sum += f5;                    /* ---------------------------------------------------------------- */        /*  find un-zigzag position of DCT coefficient                      */        /* ---------------------------------------------------------------- */            if (!eob_err)         /* prevent from accessing memory when EOB */                cnum = *(zzptr += run);             zzptr++;            if (!eob_err)                 outi[block*64+cnum] = f5;                    } /* while */        /* -------------------------------------------------------------------- */    /*  mismatch control: toggle last bit of last coefficient if sum of     */    /*  coefficents is even.                                                */    /* -------------------------------------------------------------------- */        if ((sum & lsb)==0)            // 12Q4     {            outi[block*64+63] ^= lsb;  // 12Q4     }    /* -------------------------------------------------------------------- */    /*  Determine nature of fault, invalid code word or exceeding of the    */    /*  allowed total run of 64.                                            */    /* -------------------------------------------------------------------- */    fault = (run>65) || (Wptr > Wptr_end); //- Wptr_origin)>64);    if (fault) break;        } /* for */     /* -------------------------------------------------------------------- */    /*  rewind bitstream by 8 bits to convert back to 32-bit top0           */    /* -------------------------------------------------------------------- */    top0 = (unsigned) (ltop0 >> 8);     top1 = (top1 >> 8) + (unsigned)(ltop0 << 24);         bptr = bptr - 8;    if (bptr<0)    {        word2 = word1;        word1 = word1_rw;        bptr += 32;        next_wptr -= 1;        next_wptr &= (bsbuf_words-1);     }    /* -------------------------------------------------------------------- */    /*  Update bitstream variables                                          */    /* -------------------------------------------------------------------- */    Mpeg2v->next_wptr = next_wptr;     Mpeg2v->bptr      = bptr;    Mpeg2v->word1     = word1;    Mpeg2v->word2     = word2;    Mpeg2v->top0      = top0;    Mpeg2v->top1      = top1;    Mpeg2v->fault     = fault; }/* ======================================================================== *//*  End of file:  mpeg2_vld_intra_c.c                                       *//* ------------------------------------------------------------------------ *//*            Copyright (c) 2002 Texas Instruments, Incorporated.           *//*                           All Rights Reserved.                           *//* ======================================================================== */

⌨️ 快捷键说明

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