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

📄 vtcdec.cpp

📁 《Visual C++小波变换技术与工程实践》靳济芳编著的光盘程序。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//Added by Sarnoff for error resilience, 3/5/99
  mzte_codec.m_usErrResiDisable=get_X_bits(1);
  h_size += 1; // added by Sharp (99/3/29)
#if 0
  if(mzte_codec.m_usErrResiDisable !=0 && mzte_codec.m_usErrResiDisable !=1)
    errorHandler("Incorrect TEXTURE_ERROR_RESILIENCE_DISABLE.");
//  align_byte(); deleted by Sharp (99/3/29)

  if(!mzte_codec.m_usErrResiDisable){
		align_byte(); // added by Sharp (99/3/29)
		prev_TU_first = prev_TU_last = prev_TU_err = -1;
		TU_first = TU_last = TU_max = TU_max_dc = 0;
	 
		get_err_resilience_header();
		if (TU_first != 0)
			errorHandler("Reading incorrect TU_first in the first packet.\n");
		if (get_X_bits(1) != 1)
			errorHandler("Reading incorrect HEC in the first packet.\n");

		if (mzte_codec.m_iScanDirection==1) /* BB */
			;
		else
			set_prev_good_TD_segment(-1,0,0);
  }
//End: added by Sarnoff for error resilience, 3/5/99
#endif

// begin: added by Sharp (99/4/7)
//  if(mzte_codec.m_usErrResiDisable) // @@@@@@@@@@@
		header_Dec_Common(wvtfilter, Image, header_size);
// end: added by Sharp (99/4/7)

	if ( mzte_codec.m_tiling_disable == 0 ){
		mzte_codec.m_iWidth = mzte_codec.m_tile_width = get_X_bits(15); // modified by Sharp (99/11/16)
		marker_bit = get_X_bits(1);
		mzte_codec.m_tile_height = mzte_codec.m_iHeight = get_X_bits(15); // modified by Sharp (99/11/16)
		marker_bit = get_X_bits(1);
		mzte_codec.m_iNumOfTile = get_X_bits(16);
		marker_bit = get_X_bits(1);
		mzte_codec.m_tiling_jump_table_enable = get_X_bits(1);
		mzte_codec.m_extension_type = 0;
		h_size += 50; // modified by Sharp (99/11/16)
/*		mzte_codec.m_iNumOfTile = mzte_codec.m_display_width/mzte_codec.m_tile_width*mzte_codec.m_display_height/mzte_codec.m_tile_height;*/
//		} deleted by Sharp (99/3/29)
		*header_size += h_size; /* by bits (not by bytes) */
	}
}
// end: modified by Sharp (99/2/16)

// begin: modified by Sharp (99/2/16)
Void CVTCDecoder::header_Dec_Common(FILTER ***wvtfilter, PICTURE **Image, Int *header_size, Int SkipShape)
{
  Int  texture_object_id;
  Int  marker_bit;
  Int  wavelet_download;
  Int  texture_object_layer_shape;
  Int  wavelet_stuffing;
  Int target_spatial_layer, target_shape_layer; //added by SL@Sarnoff (03/03/99)
  //Int  still_texture_object_start_code;
  Int i; // hjlee 0901
  FILTER **filters; // hjlee 0901
  Int  wavelet_uniform=1; // hjlee 0901
  Int  wavelet_type; // hjlee 0901
	Int h_size = 0; // added by Sharp (99/2/16)

  texture_object_id = get_X_bits(16);
  marker_bit = get_X_bits(1);

// hjlee 0901
//  wvtfilter->DWT_Type = get_X_bits(1);
//  wavelet_download = get_X_bits(1);
  mzte_codec.m_iWvtType = wavelet_type = get_X_bits(1); // hjlee 0901
  wavelet_download= mzte_codec.m_iWvtDownload = get_X_bits(1); // hjlee 0901
  mzte_codec.m_iWvtDecmpLev = get_X_bits(4); // hjlee 0901
  //added by SL to set default shape decomposition layer
  if(mzte_codec.m_iTargetShapeLev <=0) mzte_codec.m_iTargetShapeLev=mzte_codec.m_iWvtDecmpLev;
  mzte_codec.m_iScanDirection=get_X_bits(1);
  mzte_codec.m_bStartCodeEnable = get_X_bits(1);
//   mzte_codec.m_iWvtDecmpLev = get_X_bits(8);  // hjlee 0901
  texture_object_layer_shape = get_X_bits(2);
  mzte_codec.m_iQuantType = get_X_bits(2); 
  h_size += 16+1+1+1+4+1+1+2+2; // added by Sharp (99/2/16)

  if (mzte_codec.m_iQuantType==2) /* MQ */
  {
    Int i;

    mzte_codec.m_iSpatialLev = get_X_bits(4);
		h_size += 4; // added by Sharp (99/2/16)
    /* Get/Calc number decomp layers for all spatial layers */
    if (mzte_codec.m_iSpatialLev == 1)
    {
      mzte_codec.m_lastWvtDecompInSpaLayer[0][0]=mzte_codec.m_iWvtDecmpLev-1;
    }
    else if (mzte_codec.m_iSpatialLev != mzte_codec.m_iWvtDecmpLev)
    {
      mzte_codec.m_defaultSpatialScale = get_X_bits(1);
			h_size += 1; // added by Sharp (99/2/16)
      if (mzte_codec.m_defaultSpatialScale==0)
      {
	/* Fill in the luma componant of lastWvtDecompInSpaLayer. */
	for (i=0; i<mzte_codec.m_iSpatialLev-1; ++i){
	  mzte_codec.m_lastWvtDecompInSpaLayer[i][0]=get_X_bits(4);
		h_size += 4; // added by Sharp (99/2/16)
	}
	
	mzte_codec.m_lastWvtDecompInSpaLayer\
	  [mzte_codec.m_iSpatialLev-1][0]
	  =mzte_codec.m_iWvtDecmpLev-1;
      }
      else
      {
	Int sp0;

	sp0=mzte_codec.m_iWvtDecmpLev-mzte_codec.m_iSpatialLev;
	mzte_codec.m_lastWvtDecompInSpaLayer[0][0]=sp0;
	  
	for (i=1; i<mzte_codec.m_iSpatialLev; ++i)
	  mzte_codec.m_lastWvtDecompInSpaLayer[i][0]=sp0+i;
      }
    }
    else
    {
      for (i=0; i<mzte_codec.m_iSpatialLev; ++i)
	mzte_codec.m_lastWvtDecompInSpaLayer[i][0]=i;
    }
    
    /* Calculate for chroma (one less than luma) */
    for (i=0; i<mzte_codec.m_iSpatialLev; ++i)
      mzte_codec.m_lastWvtDecompInSpaLayer[i][1]
	=mzte_codec.m_lastWvtDecompInSpaLayer[i][2]
	=mzte_codec.m_lastWvtDecompInSpaLayer[i][0]-1;
  }
	// begin: added by SL@Sarnoff (03/03/99)
  if(mzte_codec.m_iQuantType!=2) {
    if(mzte_codec.m_iScanDirection) {
      mzte_codec.m_iSpatialLev = mzte_codec.m_iWvtDecmpLev;
    }
    else {
      mzte_codec.m_iSpatialLev = 1;
    }
  }
	//end: added by SL@Sarnoff (03/03/99)
// hjlee 0901
  filters = (FILTER **)malloc(sizeof(FILTER *)*mzte_codec.m_iWvtDecmpLev);
  if(filters==NULL)  
    errorHandler("Memory allocation error\n");
  if (wavelet_download == 1) {
    mzte_codec.m_iWvtUniform=wavelet_uniform = get_X_bits(1);
		h_size += 1; // added by Sharp (99/2/16)
    if(wavelet_uniform) {
      h_size += download_wavelet_filters(&(filters[0]), wavelet_type); // modified by Sharp (99/2/16)
    }
    else {
      for(i=0;i< mzte_codec.m_iWvtDecmpLev; i++) {
				h_size += download_wavelet_filters(&(filters[mzte_codec.m_iWvtDecmpLev-1-i]), wavelet_type); // modified by Sharp (99/2/16)
      }
    }
  }
  else if(wavelet_type==0){
    mzte_codec.m_iWvtType = 0;
    filters[0]=&DefaultSynthesisFilterInt;
  }
  else{
    mzte_codec.m_iWvtType = 1;
    filters[0]=&DefaultSynthesisFilterDbl;
  }
  if(wavelet_uniform) {
     for(i=1;i< mzte_codec.m_iWvtDecmpLev; i++) {
       filters[i] = filters[0];
     }
  }
  *wvtfilter = filters;


  wavelet_stuffing = get_X_bits(3);
  h_size += 3; // added by Sharp (99/2/16)

// added for FDAM1 by Samsung AIT on 2000/02/03
  if(!mzte_codec.m_usErrResiDisable && SkipShape==0){
	mzte_codec.m_usSegmentThresh=get_X_bits(16);
	marker_bit = get_X_bits(1);
	h_size += 16+1; 
  }
// ~added for FDAM1 by Samsung AIT on 2000/02/03

  if (texture_object_layer_shape==0) {
    mzte_codec.m_iAlphaChannel       = 0; 
// begin: modified by Sharp (99/5/10)
		mzte_codec.m_iPictWidth =  mzte_codec.m_iWidth = get_X_bits(15); // FPDAM : added by SAIT (99/09/03)
//    mzte_codec.m_iWidth = mzte_codec.m_display_width = get_X_bits(15); // modified by Sharp (99/2/16)
    marker_bit = get_X_bits(1);
		mzte_codec.m_iPictHeight = mzte_codec.m_iHeight = get_X_bits(15); // FPDAM : added by SAIT (99/09/03)
//    mzte_codec.m_iHeight = mzte_codec.m_display_height = get_X_bits(15); // modified by Sharp (99/2/16)
// end: modified by Sharp (99/5/10)
    marker_bit = get_X_bits(1);
		h_size += 32; // added by Sharp (99/2/16)
// FPDAM begin: added by Sharp
		mzte_codec.m_iObjectOriginX = 0;
		mzte_codec.m_iObjectOriginY = 0;
		mzte_codec.m_iObjectWidth = mzte_codec.m_display_width;
		mzte_codec.m_iObjectHeight = mzte_codec.m_display_height;
// FPDAM end: added by Sharp
  }
  else { /* Arbitrary shape header */

// FPDAM begin: modified by Sharp
    mzte_codec.m_iAlphaChannel       = 1; 
//    mzte_codec.m_iOriginX = get_X_bits(15);
    mzte_codec.m_iOriginX = mzte_codec.m_iObjectOriginX = get_X_bits(15);
    marker_bit = get_X_bits(1);
//    mzte_codec.m_iOriginY = get_X_bits(15);
    mzte_codec.m_iOriginY = mzte_codec.m_iObjectOriginY = get_X_bits(15);
    marker_bit = get_X_bits(1);
//    mzte_codec.m_iWidth = get_X_bits(15);
    mzte_codec.m_iPictWidth = mzte_codec.m_iWidth = mzte_codec.m_iObjectWidth = get_X_bits(15);
    marker_bit = get_X_bits(1);
//    mzte_codec.m_iHeight = get_X_bits(15);
    mzte_codec.m_iPictHeight = mzte_codec.m_iHeight = mzte_codec.m_iObjectHeight = get_X_bits(15);
    marker_bit = get_X_bits(1);

/* FPDAM begin: modifiedd by Samsung AIT */
/*
//    mzte_codec.m_iRealWidth = mzte_codec.m_iWidth;
    mzte_codec.m_iRealWidth = mzte_codec.m_display_width = mzte_codec.m_iWidth;
//    mzte_codec.m_iRealHeight = mzte_codec.m_iHeight;
    mzte_codec.m_iRealHeight = mzte_codec.m_display_height = mzte_codec.m_iHeight;
*/
    mzte_codec.m_iRealWidth = mzte_codec.m_display_width;
    mzte_codec.m_iRealHeight = mzte_codec.m_display_height;
    //mzte_codec.m_display_width = mzte_codec.m_iWidth;
    //mzte_codec.m_display_height = mzte_codec.m_iHeight;
/* FPDAM end: modifiedd by Samsung AIT */

		h_size += 64; // added by Sharp (99/2/16)
#ifdef	_FPDAM_DBG_
fprintf(stderr,".......mzte_codec.m_display_width=%d\n",mzte_codec.m_display_width);
fprintf(stderr,".......mzte_codec.m_display_height=%d\n",mzte_codec.m_display_height);
fprintf(stderr,".......mzte_codec.m_iObjectOriginX=%d\n",mzte_codec.m_iObjectOriginX);
fprintf(stderr,".......mzte_codec.m_iObjectOriginY=%d\n",mzte_codec.m_iObjectOriginY);
fprintf(stderr,".......mzte_codec.m_iObjectWidth=%d\n",mzte_codec.m_iObjectWidth);
fprintf(stderr,".......mzte_codec.m_iObjectHeight=%d\n",mzte_codec.m_iObjectHeight);
#endif
 
  }

// 	*header_size = h_size; /* by bits (not by bytes) */ // deleted by Sharp (99/3/29)

// FPDAM begin: added by Sharp
	if ( mzte_codec.m_tiling_disable && SkipShape == 0) {
// FPDAM end: added by Sharp

  /* decode the shape info from bitstream */
  if(mzte_codec.m_iAlphaChannel)
    noteProgress("Decoding Shape Information...");
  *Image = (PICTURE *)malloc(sizeof(PICTURE)*3);
  //begin: added by SL @Sarnoff (03/03/99)
  mzte_codec.m_iTargetSpatialLev = MIN(mzte_codec.m_iSpatialLev, mzte_codec.m_iTargetSpatialLev);
  mzte_codec.m_iTargetShapeLev = MIN(mzte_codec.m_iSpatialLev, mzte_codec.m_iTargetShapeLev);

  if(mzte_codec.m_iQuantType == 2) {
    target_spatial_layer = mzte_codec.m_iWvtDecmpLev -1-
      mzte_codec.m_lastWvtDecompInSpaLayer[mzte_codec.m_iTargetSpatialLev-1][0];
    target_shape_layer = mzte_codec.m_iWvtDecmpLev -1-
      mzte_codec.m_lastWvtDecompInSpaLayer[mzte_codec.m_iTargetShapeLev-1][0];
  }
  else {
    target_spatial_layer = mzte_codec.m_iSpatialLev - mzte_codec.m_iTargetSpatialLev; 
    target_shape_layer = mzte_codec.m_iSpatialLev - mzte_codec.m_iTargetShapeLev; 
  }
  get_virtual_mask(*Image, mzte_codec.m_iWvtDecmpLev,
		   mzte_codec.m_iWidth, mzte_codec.m_iHeight, 
		   mzte_codec.m_iAlphaChannel, mzte_codec.m_iColors,
		   &target_shape_layer,
		   mzte_codec.m_bStartCodeEnable,
		   filters); //modified by SL @Sarnoff (03/03/99)
//begin: added by SL @Sarnoff (03/03/99)	
 if(target_shape_layer > target_spatial_layer) {
    noteWarning("Shape has less spatial layers than target,\n forced to  use shape spatial layers.\n");
    if(mzte_codec.m_iQuantType == 2) {
      for(i=0;i< mzte_codec.m_iSpatialLev;i++) {
		if( mzte_codec.m_lastWvtDecompInSpaLayer[i][0] > mzte_codec.m_iWvtDecmpLev -1 - target_shape_layer){
			mzte_codec.m_iTargetSpatialLev  = i;
			mzte_codec.m_lastWvtDecompInSpaLayer[i][0] = mzte_codec.m_iWvtDecmpLev -1 - target_shape_layer;
			break;
		}
      }
    }
    else
      mzte_codec.m_iTargetSpatialLev =  mzte_codec.m_iSpatialLev - target_shape_layer;
  }
 //end: added by SL @Sarnoff (03/03/99)	

// This part is moved to texture_packet_header_Dec()
#if 0
//Added by Sarnoff for error resilience, 3/5/99
  if(!mzte_codec.m_usErrResiDisable){
	mzte_codec.m_usSegmentThresh=get_X_bits(16);
		h_size += 16; // added by Sharp (99/3/29)
		}
//End: Added by Sarnoff for error resilience, 3/5/99
#endif

// FPDAM begin: added by Sharp
	}
// FPDAM end: added by Sharp

// @@@@@@@
	if ( mzte_codec.m_tiling_disable == 0 && SkipShape == 1) {
		mzte_codec.m_iWidth = mzte_codec.m_tile_width = get_X_bits(15); // modified by Sharp (99/11/16)
		marker_bit = get_X_bits(1);
		mzte_codec.m_tile_height = mzte_codec.m_iHeight = get_X_bits(15); // modified by Sharp (99/11/16)
		marker_bit = get_X_bits(1);
		h_size += 2;
	}

 	*header_size = h_size; /* by bits (not by bytes) */ // added by Sharp (99/3/29)

}
// end: modified by Sharp (99/2/16)

/* Read quant value from bitstream */
Void CVTCDecoder::Get_Quant_and_Max(SNR_IMAGE *snr_image, Int spaLayer, Int color)


{
//  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++) 
  {

⌨️ 快捷键说明

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