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

📄 decoders.c

📁 32位操作系统OS/2的MPEG播放机
💻 C
📖 第 1 页 / 共 3 页
字号:
 *      will be filled. * *-------------------------------------------------------------- */    voidinit_tables(){  extern void init_pre_idct();  init_mb_addr_inc();  init_mb_type_P();  init_mb_type_B();  init_motion_vectors();  init_pre_idct();#ifdef ANALYSIS  {    init_stats();  }#endif}/* *-------------------------------------------------------------- * * DecodeDCTDCSizeLum -- * *	Huffman Decoder for dct_dc_size_luminance; location where *      the result of decoding will be placed is passed as argument. *      The decoded values are obtained by doing a table lookup on *      dct_dc_size_luminance. * * Results: *	The decoded value for dct_dc_size_luminance or ERROR for  *      unbound values will be placed in the location specified. * * Side effects: *	Bit stream is irreversibly parsed. * *-------------------------------------------------------------- */        voiddecodeDCTDCSizeLum(value)unsigned int *value;{  unsigned int index;  show_bits7(index);    *value = dct_dc_size_luminance[index].value;  flush_bits(dct_dc_size_luminance[index].num_bits);}/* *-------------------------------------------------------------- * * DecodeDCTDCSizeChrom -- * *	Huffman Decoder for dct_dc_size_chrominance; location where *      the result of decoding will be placed is passed as argument. *      The decoded values are obtained by doing a table lookup on *      dct_dc_size_chrominance. * * Results: *	The decoded value for dct_dc_size_chrominance or ERROR for *      unbound values will be placed in the location specified. * * Side effects: *	Bit stream is irreversibly parsed. * *-------------------------------------------------------------- */    void    decodeDCTDCSizeChrom(value)unsigned int *value;{  unsigned int index;  show_bits8(index);    *value = dct_dc_size_chrominance[index].value;  flush_bits(dct_dc_size_chrominance[index].num_bits);}/* *-------------------------------------------------------------- * * decodeDCTCoeff -- * *	Huffman Decoder for dct_coeff_first and dct_coeff_next; *      locations where the results of decoding: run and level, are to *      be placed and also the type of DCT coefficients, either *      dct_coeff_first or dct_coeff_next, are being passed as argument. *       *      The decoder first examines the next 8 bits in the input stream, *      and perform according to the following cases: *       *      '0000 0000' - examine 8 more bits (i.e. 16 bits total) and *                    perform a table lookup on dct_coeff_tbl_0. *                    One more bit is then examined to determine the sign *                    of level. * *      '0000 0001' - examine 4 more bits (i.e. 12 bits total) and  *                    perform a table lookup on dct_coeff_tbl_1. *                    One more bit is then examined to determine the sign *                    of level. *       *      '0000 0010' - examine 2 more bits (i.e. 10 bits total) and *                    perform a table lookup on dct_coeff_tbl_2. *                    One more bit is then examined to determine the sign *                    of level. * *      '0000 0011' - examine 2 more bits (i.e. 10 bits total) and  *                    perform a table lookup on dct_coeff_tbl_3. *                    One more bit is then examined to determine the sign *                    of level. * *      otherwise   - perform a table lookup on dct_coeff_tbl. If the *                    value of run is not ESCAPE, extract one more bit *                    to determine the sign of level; otherwise 6 more *                    bits will be extracted to obtain the actual value  *                    of run , and then 8 or 16 bits to get the value of level. *                     *       * * Results: *	The decoded values of run and level or ERROR for unbound values *      are placed in the locations specified. * * Side effects: *	Bit stream is irreversibly parsed. * *-------------------------------------------------------------- */static voiddecodeDCTCoeff(dct_coeff_tbl, run, level)unsigned short int *dct_coeff_tbl;                                       unsigned int *run;int *level;{  unsigned int temp, index, num_bits;  unsigned int value, next32bits, flushed;  /*   * Grab the next 32 bits and use it to improve performance of   * getting the bits to parse. Thus, calls are translated as:   *   *	show_bitsX  <-->   next32bits >> (32-X)   *	get_bitsX   <-->   val = next32bits >> (32-flushed-X);   *			   flushed += X;   *			   next32bits &= bitMask[flushed];   *	flush_bitsX <-->   flushed += X;   *			   next32bits &= bitMask[flushed];   *   */  show_bits32(next32bits);  flushed = 0;  /* show_bits8(index); */  index = next32bits >> 24;  if (index > 3) {    value = dct_coeff_tbl[index];    *run = (value & RUN_MASK) >> RUN_SHIFT;    if (*run == END_OF_BLOCK) {      *level = END_OF_BLOCK;    }    else {      /* num_bits = (value & NUM_MASK) + 1; */      /* flush_bits(num_bits); */      flushed = (value & NUM_MASK) + 1;      next32bits &= bitMask[flushed];      if (*run != ESCAPE) {         *level = (value & LEVEL_MASK) >> LEVEL_SHIFT;	 /* get_bits1(value); */	 /* if (value) *level = -*level; */	 if (next32bits >> (31-flushed)) *level = -*level;	 flushed++;	 /* next32bits &= bitMask[flushed];  last op before update */       }       else {    /* *run == ESCAPE */         /* get_bits14(temp); */	 temp = next32bits >> (18-flushed);	 flushed += 14;	 next32bits &= bitMask[flushed];	 *run = temp >> 8;	 temp &= 0xff;	 if (temp == 0) {            /* get_bits8(*level); */	    *level = next32bits >> (24-flushed);	    flushed += 8;	    /* next32bits &= bitMask[flushed];  last op before update */ 	    assert(*level >= 128);	 } else if (temp != 128) {	    /* Grab sign bit */	    *level = ((int) (temp << 24)) >> 24;	 } else {            /* get_bits8(*level); */	    *level = next32bits >> (24-flushed);	    flushed += 8;	    /* next32bits &= bitMask[flushed];  last op before update */	    *level = *level - 256;	    assert(*level <= -128 && *level >= -255);	 }       }       /* Update bitstream... */       flush_bits(flushed);    }  }  else {    if (index == 2) {       /* show_bits10(index); */      index = next32bits >> 22;      value = dct_coeff_tbl_2[index & 3];    }    else if (index == 3) {       /* show_bits10(index); */      index = next32bits >> 22;      value = dct_coeff_tbl_3[index & 3];    }    else if (index) {	/* index == 1 */      /* show_bits12(index); */      index = next32bits >> 20;      value = dct_coeff_tbl_1[index & 15];    }    else {   /* index == 0 */      /* show_bits16(index); */      index = next32bits >> 16;      value = dct_coeff_tbl_0[index & 255];    }    *run = (value & RUN_MASK) >> RUN_SHIFT;    *level = (value & LEVEL_MASK) >> LEVEL_SHIFT;    /*     * Fold these operations together to make it fast...     */    /* num_bits = (value & NUM_MASK) + 1; */    /* flush_bits(num_bits); */    /* get_bits1(value); */    /* if (value) *level = -*level; */    flushed = (value & NUM_MASK) + 2;    if ((next32bits >> (32-flushed)) & 0x1) *level = -*level;    /* Update bitstream ... */    flush_bits(flushed);  }}/* *-------------------------------------------------------------- * * decodeDCTCoeffFirst -- * *	Huffman Decoder for dct_coeff_first. Locations for the *      decoded results: run and level, are being passed as *      arguments. Actual work is being done by calling DecodeDCTCoeff, *      with the table dct_coeff_first. * * Results: *	The decoded values of run and level for dct_coeff_first or *      ERROR for unbound values are placed in the locations given. * * Side effects: *	Bit stream is irreversibly parsed. * *-------------------------------------------------------------- */        voiddecodeDCTCoeffFirst(run, level)unsigned int *run;int *level;{  decodeDCTCoeff(dct_coeff_first, run, level);}/* *-------------------------------------------------------------- * * decodeDCTCoeffNext -- * *	Huffman Decoder for dct_coeff_first. Locations for the *      decoded results: run and level, are being passed as *      arguments. Actual work is being done by calling DecodeDCTCoeff, *      with the table dct_coeff_next. * * Results: *	The decoded values of run and level for dct_coeff_next or *      ERROR for unbound values are placed in the locations given. * * Side effects: *	Bit stream is irreversibly parsed. * *-------------------------------------------------------------- */ void       decodeDCTCoeffNext(run, level)unsigned int *run;int *level;{  decodeDCTCoeff(dct_coeff_next, run, level);}

⌨️ 快捷键说明

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