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

📄 vtcdec.cpp

📁 此源码是在VC平台下,实现MPEG4编解码的源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:

{
//  Int marker_bit;

  snr_image->quant     = get_param(7);
//  marker_bit = get_X_bits(1);  // 1124
 // if (marker_bit != 1)
//	  noteError("marker_bit should be one");

    {
      Int l;
      
      for (l=0; l<=mzte_codec.m_lastWvtDecompInSpaLayer[spaLayer][color];++l)
      {
	snr_image->wvtDecompNumBitPlanes[l] = get_X_bits(5);

	if (((l+1) % 4) == 0)
	  get_X_bits(1);
      }
    }
}

Void CVTCDecoder::Get_Quant_and_Max_SQBB(SNR_IMAGE *snr_image, Int spaLayer, 
				   Int color)
{
 // Int marker_bit;

  if ((color==0 && spaLayer==0) || (color>0 && spaLayer==1))
    snr_image->quant = get_param(7);

  if (color==0)
    snr_image->wvtDecompNumBitPlanes[spaLayer] = get_X_bits(5);
  else if (spaLayer)
    snr_image->wvtDecompNumBitPlanes[spaLayer-1] = get_X_bits(5);


}



Void CVTCDecoder::textureLayerDC_Dec()
{
  Int col, err;

  noteProgress("Decoding DC coefficients....");
  for (col=0; col<mzte_codec.m_iColors; col++) 
  {
    /* initilize all wavelet coefficients */
    mzte_codec.m_iCurColor=col;
    err=ztqInitDC(1, col);

    /* losslessly decoding DC coefficients */
    wavelet_dc_decode(col);

    /* dequantize DC coefficients */
    err=decIQuantizeDC(col);
  }  
  noteProgress("Completed decoding of DC coefficients.");
}


/*******************************************************
  The following two routines are for single quant 
  band by band scan order.
*******************************************************/
Void CVTCDecoder::TextureSpatialLayerSQNSC_dec(Int spa_lev)
{
  Int col;

    /* hjlee 0901 */
   SNR_IMAGE *snr_image;

  /* hjlee 0901 */
    for (col=0; col<mzte_codec.m_iColors; col++) {
      snr_image = &(mzte_codec.m_SPlayer[col].SNRlayer.snr_image);
      Get_Quant_and_Max_SQBB(snr_image,spa_lev, col);
    }
 
  for (col=0; col<mzte_codec.m_iColors; col++){
    noteProgress("Single-Quant Mode (Band by Band) - Spatial %d, SNR 0, "\
	       "Color %d",spa_lev,col); fflush(stderr);

    mzte_codec.m_iCurColor = col;
    if(spa_lev !=0 || col == 0){
      wavelet_higher_bands_decode_SQ_band(col);
      if(decIQuantizeAC_spa(spa_lev,col)) 
	errorHandler("decIQuantizeAC_spa");
    }
  }
  
} 



Void CVTCDecoder::TextureSpatialLayerSQ_dec(Int spa_lev,FILE *bitfile)
{
  Int texture_spatial_layer_start_code,texture_spatial_layer_id;
  Char fname[100]; // hjlee

  /*------- AC: Open and initialize bitstream file -------*/
  if (mzte_codec.m_iSingleBitFile==0)
  {
    sprintf(fname,mzte_codec.m_cBitFileAC,spa_lev,0);
    if ((bitfile=fopen(fname,"rb"))==NULL)
      errorHandler("Can't open file '%s' for reading.",fname);
    init_bit_packing_fp(bitfile,1);
  }
  else
    init_bit_packing_fp(bitfile,0);

  /* header info */
  texture_spatial_layer_start_code = get_X_bits(32);
  if (texture_spatial_layer_start_code != 
      TEXTURE_SPATIAL_LAYER_START_CODE)
    errorHandler("Wrong texture_spatial_layer_start_code %x.",
		 texture_spatial_layer_start_code);
  
  texture_spatial_layer_id = get_X_bits(5);
  if (texture_spatial_layer_id != spa_lev)
    errorHandler("Incorrect texture_spatial_layer_id");
  mzte_codec.m_SPlayer[0].SNR_scalability_levels = 1;

  TextureSpatialLayerSQNSC_dec(spa_lev);

  align_byte();
  if(mzte_codec.m_iSingleBitFile==0)
    fclose(bitfile);
}


Void CVTCDecoder::textureLayerSQ_Dec(FILE *bitfile)
{
  Int col, err, spa_lev;
  SNR_IMAGE *snr_image;

  noteProgress("Decoding AC coefficients - Single-Quant Mode....");
   
  /* added for compatability with MQ spatial layer flexability - ph 7/16 */
  setSpatialLayerDimsSQ(0);  // hjlee 0901
  
  /*------- AC: Set spatial and SNR levels to zero -------*/
  mzte_codec.m_iCurSpatialLev = 0;
  mzte_codec.m_iCurSNRLev = 0;
  
  for (col=0; col<mzte_codec.m_iColors; col++) 
  {     
    
    /* initialization of spatial dimensions for each color component */
    setSpatialLevelAndDimensions(0, col);
    
    /* initialize AC coefficient info */
    if ((err=ztqInitAC(1, col)))
      errorHandler("ztqInitAC");
    
    snr_image=&(mzte_codec.m_SPlayer[col].SNRlayer.snr_image);
  }
  
  
  /*------- AC: Decode and inverse quantize all color components -------*/
  if (mzte_codec.m_iScanDirection==0) /* tree-depth scan */
  {  
    /* Read quant value from bitstream */
    for(col=0;col<mzte_codec.m_iColors;col++){
      snr_image=&(mzte_codec.m_SPlayer[col].SNRlayer.snr_image);
      Get_Quant_and_Max(snr_image,0,col); // hjlee 0901
    }

    /* losslessly decoding AC coefficients */
    wavelet_higher_bands_decode_SQ_tree();
    
    for (col=0; col<mzte_codec.m_iColors; col++) 
    {  	
      /* Inverse quantize AC coefficients */
      if ((err=decIQuantizeAC(col)))
	errorHandler("decIQuantizeAC");
    }
    
  }
  else  /* SQ band by band */
  {

    /* added for compatability with MQ spatial layer flexability - ph 7/16 */
    setSpatialLayerDimsSQ(1);  // hjlee 0901

    /* Assumes all three color components have the same number of SNR
       levels */
    for (col=0; col<mzte_codec.m_iColors; col++)
      mzte_codec.m_SPlayer[col].SNR_scalability_levels = 1;

    /* Loop through spatial layers */
    for (spa_lev=0; spa_lev<mzte_codec.m_iSpatialLev; 
         spa_lev++)
    {
      for (col=0; col<mzte_codec.m_iColors; col++)
	setSpatialLevelAndDimensions(spa_lev, col);

      /*----- AC: Set global spatial layer. -----*/
      mzte_codec.m_iCurSpatialLev = spa_lev;
      
      /* Update spatial level coeff info if changing spatial levels.
         Do this for all color components */
      if (mzte_codec.m_bStartCodeEnable) {
			TextureSpatialLayerSQ_dec(spa_lev,bitfile);
      }
      else
			TextureSpatialLayerSQNSC_dec(spa_lev);
    }
  }
  
  noteProgress("Completed decoding AC coefficients - Single-Quant Mode.");
}


Void CVTCDecoder::TextureSNRLayerMQ_decode(Int spa_lev, Int snr_lev,FILE *fp)
{
  SNR_IMAGE *snr_image;
  Int col;
  Int texture_snr_layer_id;

  mzte_codec.m_iCurSpatialLev=spa_lev;

  if(mzte_codec.m_bStartCodeEnable){
    noteProgress("Decoding Multi-Quant Mode Layer with SNR start code....");
    /* header info */
    if(get_X_bits(32) != texture_snr_layer_start_code)
      errorHandler("Error in decoding texture_snr_layer_start_code");
    texture_snr_layer_id=get_X_bits(5);
  }
  else 
    noteProgress("Decoding Multi-Quant Mode Layer without SNR start code....");

  noteProgress("Multi-Quant Mode - Spatial %d, SNR %d", spa_lev,snr_lev);

  for(col=0;
      col < NCOL;
      col++)
  {        
    /* Set global color variable */
    mzte_codec.m_iCurColor = col;
    
    /* initialization of spatial dimensions for each color component  */
    setSpatialLevelAndDimensions(mzte_codec.m_iCurSpatialLev, col);
    
    snr_image=&(mzte_codec.m_SPlayer[col].SNRlayer.snr_image);

    Get_Quant_and_Max(snr_image,spa_lev,col); // hjlee 0901

    updateResidMaxAndAssignSkips(col);
    noteDebug("resid_max=%d\n",snr_image->residual_max);
  }

  wavelet_higher_bands_decode_MQ(mzte_codec.m_iScanDirection);
 
  for(col=0;
      col < NCOL;      
      col++)
  {        
    /* Set global color variable */
    mzte_codec.m_iCurColor = col;

    /* quantize and mark zerotree structure for AC coefficients */
    if (decIQuantizeAC(col))
      errorHandler("decQuantizeAndMarkAC");

    noteDebug("max_root=%d max_valz=%d max_valnz=%d max_resi=%d",
	      ROOT_MAX(col),VALZ_MAX(col),VALNZ_MAX(col),
	      RESID_MAX(col));
    
    /* Update states of ac coefficients */
    if (decUpdateStateAC(col))
      errorHandler("decUpdateStateAC");
  }
}

#define SNR_INFINITY 99

// hjlee 0901
Void CVTCDecoder::textureLayerMQ_Dec(FILE *bitfile, 
			       Int  target_spatial_levels,
			       Int  target_snr_levels,
			       FILTER **wvtfilter)

{
  Int  err, spa_lev, snr_lev, snr_scalability_levels;
  Int  texture_spatial_layer_start_code;
  Int  texture_spatial_layer_id;
  Char fname[100];

// hjlee 0901

  /* added for spatial layer flexability - ph 7/16 */
  getSpatialLayerDims();  // hjlee 0901


  /*------- AC: Initialize QList Structure -------*/
  if ((err=ztqQListInit()))
    errorHandler("Allocating memory for QList information.");

// hjlee 0901
  /* Initialize coeffs */
  setSpatialLevelAndDimensions(0,0);
  if ((err=ztqInitAC(1,0)))
    errorHandler("ztqInitAC");
  
  if (mzte_codec.m_lastWvtDecompInSpaLayer[0][1]<0)
    setSpatialLevelAndDimensions(1,1);
  else
    setSpatialLevelAndDimensions(0,1);
  if ((err=ztqInitAC(1,1)))
    errorHandler("ztqInitAC");
  
  if (mzte_codec.m_lastWvtDecompInSpaLayer[0][2]<0)
    setSpatialLevelAndDimensions(1,2);
  else
    setSpatialLevelAndDimensions(0,2);
  if ((err=ztqInitAC(1,2)))
    errorHandler("ztqInitAC");


  /* Loop through spatial layers */

⌨️ 快捷键说明

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