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

📄 huffdec2.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 3 页
字号:
                           hEpInfo );          BsPutBit(gc_streamCh, ltmp, ATKLOCBITS);        }      }    }    break;  case LONG_START_SEQUENCE:    for (bd = 1; bd <= max_band; bd++) {      for (wd = 0; wd < 2; wd++) {        natks = GetBits ( ADJUST_NUM,                           NATKSBITS,                          hResilience,                          hVm,                           hEpInfo );        BsPutBit(gc_streamCh, natks, NATKSBITS);        for (ad = 0; ad < natks; ad++) {          ltmp = GetBits ( ALEVCODE,                           IDGAINBITS,                           hResilience,                           hVm,                            hEpInfo );          BsPutBit(gc_streamCh, ltmp, IDGAINBITS);          if (wd == 0) {            ltmp = GetBits ( ALOCCODE,                              ATKLOCBITS_START_A,                             hResilience,                             hVm,                              hEpInfo );            BsPutBit(gc_streamCh, ltmp, ATKLOCBITS_START_A);          }          else {            ltmp = GetBits ( ALOCCODE,                              ATKLOCBITS_START_B,                             hResilience,                             hVm,                              hEpInfo );            BsPutBit(gc_streamCh, ltmp, ATKLOCBITS_START_B);          }        }      }    }    break;  case EIGHT_SHORT_SEQUENCE:    for (bd = 1; bd <= max_band; bd++) {      for (wd = 0; wd < 8; wd++) {        natks = GetBits (  ADJUST_NUM,                            NATKSBITS,                           hResilience,                           hVm,                            hEpInfo );        BsPutBit(gc_streamCh, natks, NATKSBITS);        for (ad = 0; ad < natks; ad++) {          ltmp = GetBits ( ALEVCODE,                            IDGAINBITS,                           hResilience,                           hVm,                            hEpInfo );          BsPutBit(gc_streamCh, ltmp, IDGAINBITS);          ltmp = GetBits (  ALOCCODE,                             ATKLOCBITS_SHORT,                            hResilience,                            hVm,                             hEpInfo );          BsPutBit(gc_streamCh, ltmp, ATKLOCBITS_SHORT);        }      }    }    break;  case LONG_STOP_SEQUENCE:    for (bd = 1; bd <= max_band; bd++) {      for (wd = 0; wd < 2; wd++) {        natks = GetBits (  ADJUST_NUM,                            NATKSBITS,                           hResilience,                           hVm,                            hEpInfo );        BsPutBit(gc_streamCh, natks, NATKSBITS);        for (ad = 0; ad < natks; ad++) {          ltmp = GetBits ( ALEVCODE,                            IDGAINBITS,                           hResilience,                           hVm,                            hEpInfo );          BsPutBit(gc_streamCh, ltmp, IDGAINBITS);          if (wd == 0) {            ltmp = GetBits ( ALOCCODE,                              ATKLOCBITS_STOP_A,                             hResilience,                             hVm,                              hEpInfo );            BsPutBit(gc_streamCh, ltmp, ATKLOCBITS_STOP_A);          }          else {            ltmp = GetBits ( ALOCCODE,                             ATKLOCBITS_STOP_B,                             hResilience,                             hVm,                              hEpInfo );            BsPutBit(gc_streamCh, ltmp, ATKLOCBITS_STOP_B);          }        }      }    }    break;  default:    return  -1;  }  return gc_streamCh->currentBit - loc;}#endif /*SRS*//* * read the codebook and boundaries */static int huffcb ( byte*              sect,                     Info               info,                    int*               sectbits,                     int                tot_sfb,                     int                sfb_per_sbk,                     byte               max_sfb,                    unsigned char      numGroups,                    HANDLE_HCR         hHcrInfo,                    HANDLE_RESILIENCE  hResilience,                    HANDLE_BUFFER      hVm,                    HANDLE_EP_INFO     hEpInfo,                    HANDLE_CONCEALMENT hConcealment){  int            nsect;  int            n;  int            nrSfb;  int            bits;  int            len;  unsigned char  group = 0;  unsigned char  currentMaxSfb;  unsigned short vcb11Flag;  unsigned short index;  unsigned short nrOfCodewords = 0;  unsigned short dim;  if (debug['s']) {    printf("total sfb %d\n", tot_sfb);    printf("   sect    top     cb\n");  }  bits = sectbits[0];  len = (1 << bits) - 1;  nsect = 0;  nrSfb = 0;  index = 0;  while ( ( nrSfb < tot_sfb ) && ( nsect < tot_sfb ) ) {    currentMaxSfb = sfb_per_sbk * group + max_sfb;    vcb11Flag = 0; /* virtual codebooks flag is false */      *sect = GetBits ( SECT_CB,                         LEN_CB,                        hResilience,                        hVm,                         hEpInfo );            hConcealment = hConcealment;      n = GetBits ( SECT_LEN_INCR,                     bits,                    hResilience,                    hVm,                     hEpInfo );    while ( n == len && nrSfb < currentMaxSfb ) { /* changed from < tot_sfb */      nrSfb += len;      n = GetBits ( SECT_LEN_INCR,                     bits,                    hResilience,                    hVm,                     hEpInfo );    }    nrSfb += n;    sect++;    *sect = nrSfb;    sect++;    /**/    if( sect[-2] < BY4BOOKS + 1 ) {      dim = 4;    }    else {      dim = 2;    }    if ( sect[-2] ) {      if ( ! nsect ) {        nrOfCodewords = (info.bk_sfb_top[sect[-1]-1] ) / dim;      }      else {        nrOfCodewords += ( info.bk_sfb_top[sect[-1]-1] - info.bk_sfb_top[sect[-3]-1] ) / dim;      }    }    /**/    nsect++;    if (debug['s'] ) {      printf(" %6d %6d %6d %6d", nsect, sect[-1], sect[-2], info.bk_sfb_top[sect[-1]-1] );      printf("\n");    }    if ( sect[-1] > currentMaxSfb ) {        CommonExit( 2, "huffcb: group %i: nrOfScfBands (%2i) > currentMaxSfb (%2i) (huffdec2.c)",                    group, sect[-1], currentMaxSfb );    }    /* insert a zero section for regions above max_sfb for each group */    if ( sect[-1] == currentMaxSfb ) {           /* changed from ((sect[-1] % sfb_per_sbk) == max_sfb) */      nrSfb = ( sfb_per_sbk * ( group + 1 ) );    /* changed from nrSfb += (sfb_per_sbk - max_sfb) */      group++;      if ( currentMaxSfb != sfb_per_sbk * group ) { /* this inserts a section with codebook 0 */        *sect++ = 0;        *sect++ = nrSfb;        nsect++;        if (debug['s'])          printf("(%6d %6d %6d)\n", nsect, sect[-1], sect[-2]);      }    }  }  if ( nrSfb != tot_sfb ) {      CommonExit ( 2, "huffcb: nrSfb (%3hu) != totSfb (%3hu)", nrSfb, tot_sfb );    return 0;  }  if ( nsect > tot_sfb ) {      CommonExit ( 2, "huffcb: nsect (%3hu) > totSfb (%3hu)", nsect, tot_sfb );    return 0;  }  if ( max_sfb && ( group != numGroups ) ) {      CommonExit ( 2, "huffcb: group (%hu) != numGroups (%hu) (huffdec2.c)", group, numGroups );  }  return ( nsect );}static int getescape ( int                q,                       HANDLE_RESILIENCE  hResilience,                       HANDLE_HCR         hHcrInfo,                       HANDLE_BUFFER      hVm,                        HANDLE_EP_INFO     hEpInfo ){  int           i;  int           off;  int           neg;  unsigned long tmp; /*error robustness, sfr */  if ( q < 0 ) {    if ( q != -16 ) {      return ( q );    }    neg = 1;  }   else {    if ( q != +16 ) {      return ( q );    }    neg = 0;  }  for ( i = 4; ; i++ ) {      {        tmp = GetBits ( ESCAPE_BITS, 1, hResilience, hVm, hEpInfo );      }    if ( tmp == 0 ) { /* truncation condition */      break;    }    if ( i >= 12 ) {      /* if i == 12 and no escape separator has been read -> break,         because the escape word has a maximum length of Nmax + 4, with Nmax = 8 --> imax = 12 */      CommonExit(2,"getescape: escape_prefix longer than 8 bit (huffdec2.c)");      hHcrInfo = hHcrInfo; /* just to avoid compiler warning */      break;     }  }    {      off = GetBits ( ESCAPE_BITS,                       i,                      hResilience,                      hVm,                       hEpInfo );    }  i = off + (1<<i);  if(neg)    i = -i;  return i;}unsigned char  HuffSpecKernelPure ( int*               qp,                                     Hcb*               hcb,                                     Huffman*           hcw,                                     int                step,                                    HANDLE_BUFFER      hSpecData,                                    HANDLE_RESILIENCE  hResilience,                                    HANDLE_HCR         hHcrInfo,                                    HANDLE_EP_INFO     hEpInfo,                                    HANDLE_CONCEALMENT hConcealment )                   {  int            temp;  unsigned long  codewordBegin;  unsigned short codewordLength;  codewordBegin = GetReadBitCnt ( hSpecData );  temp = decode_huff_cw ( hcw,                          hResilience,                          hSpecData,                           1,                           hEpInfo );  unpack_idx(qp, temp, hcb);    if (!hcb->signed_cb)    get_sign_bits ( qp,                     step,                    hResilience,                    hSpecData,                     hEpInfo );  if ( hcw == &book11[0] ) {/*   if(codebook == ESCBOOK){ */    qp[0] = getescape ( qp[0],                        hResilience,                        hHcrInfo,                        hSpecData,                         hEpInfo);    qp[1] = getescape ( qp[1],                        hResilience,                        hHcrInfo,                        hSpecData,                         hEpInfo);  }  /* section data coding of codebook 11: checks max/min values within a SFB, if codebook 11 is used */  codewordLength = GetReadBitCnt ( hSpecData ) - codewordBegin;  return ( codewordLength );}static unsigned short HuffSpecKernelNoReordering ( int*               qp,                                                    Hcb*               hcb,                                                   Huffman*           hcw,                                                   int                step,                                                   unsigned short     codebook,                                                   HANDLE_BUFFER      hSpecData,                                                   HANDLE_RESILIENCE  hResilience,                                                   HANDLE_HCR         hHcrInfo,                                                   HANDLE_EP_INFO     hEpInfo,                                                   HANDLE_CONCEALMENT hConcealment ){  unsigned short codewordLength;  codewordLength = HuffSpecKernelPure ( qp,                                         hcb,                                         hcw,                                         step,                                         hSpecData,                                        hResilience,                                         hHcrInfo,                                        hEpInfo,                                        hConcealment );  return ( codewordLength );}static unsigned short HuffSpecDecDefault ( Info*              info,                                            byte*              sect,                                            int                nsect,                                            int                quant[],                                           HANDLE_BUFFER      hSpecData,                                           HANDLE_RESILIENCE  hResilience,                                           HANDLE_HCR         hHcrInfo,                                           HANDLE_EP_INFO     hEpInfo,                                           HANDLE_CONCEALMENT hConcealment ){  short*         bandp;  short*         bands;  unsigned short bottom;  unsigned short lineCnt;   unsigned short lineStart;  unsigned short sectionCnt;  unsigned short sfbCnt;  unsigned short step;  unsigned short stop;  unsigned short codebook;  unsigned short top;  int*           qp;      /* probably could be short */  Hcb*           hcb;  Huffman*       hcw;  unsigned short codewordLength;  unsigned short lengthOfLongestCodeword = 0;  bands = info->bk_sfb_top;  bottom = 0;  lineCnt = 0;  bandp = bands;  for( sectionCnt = nsect; sectionCnt; sectionCnt-- ) {    codebook = sect[0];  /* codebook for this section */    top   = sect[1];    sect += 2;    if ( codebook == BOOKSCL ) {        CommonExit ( 2, "HuffspecDecDefault: book %d: invalid book (huffdec2.c, HuffSpecDecDefault())", BOOKSCL );    }    if( ( codebook == ZERO_HCB ) ||        ( codebook == NOISE_HCB ) ||        ( codebook == INTENSITY_HCB ) ||        ( codebook == INTENSITY_HCB2 ) ) {      bandp = bands+top;      lineCnt = bandp[-1];      bottom = top;      continue;    }    if(codebook < BY4BOOKS+1)      step = 4;    else       step = 2;    hcb       = &book[codebook];    hcw       = hcb->hcw;    qp        = quant       + lineCnt;    hConcealment = hConcealment; /* dummy to avoid compiler warning */    lineStart = lineCnt;    for ( sfbCnt = bottom; sfbCnt < top; sfbCnt++ ) {      stop = *bandp++;      while ( lineCnt < stop ) {        codewordLength = HuffSpecKernelNoReordering ( qp,                                                       hcb,                                                       hcw,                                                       step,                                                       codebook,                                                      hSpecData,                                                      hResilience,                                                       hHcrInfo,                                                      hEpInfo,                                                      hConcealment );        lengthOfLongestCodeword = MAX ( codewordLength, lengthOfLongestCodeword );        qp       += step;        lineCnt  += step;      }       if(debug['q']){        unsigned short idx;        printf("\nsect %d %d\n", codebook, lineStart);        for (idx = lineStart; idx < lineCnt; idx += 2 )          printf("%d %d  ",quant[idx],quant[idx+1]);        printf("\n");      }    }    bottom = top;  }  return ( lengthOfLongestCodeword ); }static Float esc_iquant(int q){  if (q > 0) {    if (q < MAX_IQ_TBL) {      return((Float)iq_exp_tbl[q]);    }    else {      return(pow(q, 4./3.));    }  }  else {    q = -q;    if (q < MAX_IQ_TBL) {      return((Float)(-iq_exp_tbl[q]));    }    else {      return(-pow(q, 4./3.));    }  }} static int HuffSpecFrame ( Info*              info,                            int                nsect,                            byte*              sect,                            short*             factors,                            Float*             coef,                           HANDLE_RESILIENCE  hResilience,                           HANDLE_BUFFER      hVm,                           HANDLE_BUFFER      hHcrSpecData,                           HANDLE_HCR         hHcrInfo,                           HANDLE_EP_INFO     hEpInfo,

⌨️ 快捷键说明

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