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

📄 vtc_zte_ztscan_enc.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    }    else    {      Int czt_type; /* what to put on bitstream */      Int l;      l=xy2wvtDecompLev(w,h);        zt_type = coeffinfo[h][w].type;#ifdef _SHAPE_      if(coeffinfo[h][w].mask==1) /* skip out-node */  #endif      	switch(coeffinfo[h][w].state)	{	  case S_INIT:	    czt_type=zt_type;	    mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_INIT],czt_type);	    break;	  case S_ZTR:	    czt_type=zt_type;	    mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_ZTR],czt_type);	    break;	  case S_ZTR_D:	    czt_type=zt_type;	    mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_ZTR_D],czt_type);	    break;	  case S_IZ:	    czt_type = (zt_type!=IZ);	    mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_IZ],czt_type);	    break;	  case S_LINIT: 	    czt_type = (zt_type!=ZTR);	    mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_LINIT],czt_type);	    break;	  case S_LZTR:	    czt_type = (zt_type!=ZTR);	    mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_LZTR],czt_type);	    break;	  case S_LZTR_D:	    czt_type = (zt_type!=ZTR);	    mzte_ac_encode_symbol(&ace,acm_type[l][CONTEXT_LZTR_D],czt_type);	    break;	  default:	    errorHandler("Invalid state (%d) in multi-quant encoding.", 			 coeffinfo[h][w].state);	}    }        /* mark ztr_d and encode magnitudes */    switch(zt_type)    {      case ZTR:#ifdef _SHAPE_	if(coeffinfo[h][w].mask==1) {#endif	  dcc[k]=1;	  mark_ZTR_D(h,w);#ifdef _SHAPE_	}	else	  dcc[k]=0;#endif	break;      case IZ:	dcc[k]=0;	break;      case VZTR:	dcc[k]=1;	mark_ZTR_D(h,w);#ifdef _SHAPE_	if(coeffinfo[h][w].mask==1) /* only code for in-node */#endif	  mag_sign_encode_MQ(h,w);	break;      case VAL:	dcc[k]=0;#ifdef _SHAPE_	if(coeffinfo[h][w].mask==1) /* only code for in-node*/#endif	  mag_sign_encode_MQ(h,w);	break;      default:	errorHandler("Invalid type in multi quant decoding.");         }  }  /********************* CODE CHILDREN *****************************/  if (!IS_STATE_LEAF(coeffinfo[h0][w0].state))  {    Int i, j;    for (k=0; k<nSib; ++k)    {      if (dcc[k]==0)      {	h = h0 + (k/2);	w = w0 + (k%2);  		/* scan children */	i=h<<1; j=w<<1;	encode_pixel_MQ_tree(i,j);      }    }  }}#endif/********************************************************  Function Name  -------------  static Void  mag_sign_encode_MQ(Int h,Int w)  Arguments  ---------  Int h,Int w - position of a pixel  Description  -----------  Encode the value of a coefficient.  Functions Called  ----------------  mzte_ac_encode_symbol()  Return Value  ------------  None.********************************************************/ Void CVTCEncoder::mag_sign_encode_MQ(Int h,Int w){  Int val,v_sign;  Int l;  if(coeffinfo[h][w].skip)    return;      l=xy2wvtDecompLev(w,h);    if((val=coeffinfo[h][w].quantized_value)>=0)    v_sign=0;  else  {    val=-val;    v_sign=1;  }    /* code magnitude */  if (IS_RESID(w,h,color))  {    bitplane_res_encode(val,l,WVTDECOMP_RES_NUMBITPLANES(color));  }  else  {    bitplane_encode(val-1,l,WVTDECOMP_NUMBITPLANES(color,l));    mzte_ac_encode_symbol(&ace,acm_sign[l],v_sign);  }}/*************************************************************  Function Name  -------------  Void encodeBlocks()  Arguments  ---------  Int y, Int x  - Coordinate of upper left hand corner of block.  Int n - Number of 4 blocks in a side of the total block. 0 means do only    pixel at (x,y).  Void (*pixelFunc)(Int, Int) - Function to call for pixel locations.    Description  -----------  Call function pixelFunc(y,x) for all pixels (x,y) in block in band scan  manner.  Functions Called  ----------------  encodeBlocks recursively.  Return Value  ------------  None.*************************************************************/Void CVTCEncoder::encodeSQBlocks(Int y, Int x, Int n){  /* Call the encoding function for the 4 block pixels */  if (n == 0)  {    /* For checking scan-order : use 16x16 mono image       for comparison with Figure 7-38 scan order table in        document.    static Int i=4;    noteStat("%d: y=%d, x=%d\n",i++, y,x);    */    encode_pixel_SQ(y,x);  }  else  {    Int k;    --n;    k = 1<<n;    encodeSQBlocks(y,x,n);    x += k;    encodeSQBlocks(y,x,n);    x -= k;    y += k;    encodeSQBlocks(y,x,n);    x += k;    encodeSQBlocks(y,x,n);  }}/*************************************************************  Function Name  -------------  Void encodeBlocks()  Arguments  ---------  Int y, Int x  - Coordinate of upper left hand corner of block.  Int n - Number of 4 blocks in a side of the total block. 0 means do only    pixel at (x,y).  Void (*pixelFunc)(Int, Int) - Function to call for pixel locations.    Description  -----------  Call function pixelFunc(y,x) for all pixels (x,y) in block in band scan  manner.  Functions Called  ----------------  encodeBlocks recursively.  Return Value  ------------  None.*************************************************************/Void CVTCEncoder::encodeMQBlocks(Int y, Int x, Int n){  /* Call the encoding function for the 4 block pixels */  if (n == 0)  {    /* For checking scan-order : use 16x16 mono image       for comparison with Figure 7-38 scan order table in        document.    static Int i=4;    noteStat("%d: y=%d, x=%d\n",i++, y,x);    */    encode_pixel_MQ(y,x);  }  else  {    Int k;    --n;    k = 1<<n;    encodeMQBlocks(y,x,n);    x += k;    encodeMQBlocks(y,x,n);    x -= k;    y += k;    encodeMQBlocks(y,x,n);    x += k;    encodeMQBlocks(y,x,n);  }}//Added by Sarnoff for error resilience, 3/5/99/* ----------------------------------------------------------------- *//* ----------------- Error resilience related routines ------------- *//* ----------------------------------------------------------------- *//*************************************************************  Function Name  -------------  Void encodeSQBlocks_ErrResi()  Arguments  ---------  Int y, Int x  - Coordinate of upper left hand corner of block.  Int n - Number of 4 blocks in a side of the total block. 0 means do only    pixel at (x,y).  Int c - color.    Description  -----------  Call function encode_pixel_SQ for all pixels (x,y) in block in band scan  manner.  Functions Called  ----------------  encodeSQBlocks recursively.  Return Value  ------------  None.*************************************************************/Void CVTCEncoder::encodeSQBlocks_ErrResi(Int y, Int x, Int n, Int c){  /* Call the encoding function for the 4 block pixels */  if (n == 0)  {    /* For checking scan-order : use 16x16 mono image       for comparison with Figure 7-38 scan order table in        document.    static Int i=4;    noteStat("%d: y=%d, x=%d\n",i++, y,x);    */    encode_pixel_SQ(y,x);  }  else  {    Int k;    --n;    k = 1<<n;    encodeSQBlocks_ErrResi(y,x,n,c);	if (n==4)		check_segment_size(c);    x += k;    encodeSQBlocks_ErrResi(y,x,n,c);    if (n==4)		check_segment_size(c);	x -= k;    y += k;    encodeSQBlocks_ErrResi(y,x,n,c);    if (n==4)		check_segment_size(c);	x += k;    encodeSQBlocks_ErrResi(y,x,n,c);	if (n==4)		check_segment_size(c);  }}/* bbc, 11/5/98 *//* ph, 11/13/98 - added color argument for band-by-band */void CVTCEncoder::init_arith_encoder_model(Int color){  /* init arithmetic coder */  mzte_ac_encoder_init(&ace);  if(mzte_codec.m_iScanDirection ==0 ){ /* tree depth */    for (color=0; color<mzte_codec.m_iColors; color++)       probModelInitSQ(color);  }  else{  /* band-by-band */      probModelInitSQ(color); /* ph - 11/13/98 */  }}/* bbc, 11/6/98 *//* ph, 11/13/98 - added color argument for band-by-band */Void CVTCEncoder::close_arith_encoder_model(Int color, Int mode){  noteProgress("  ==>E packet [TU_%d,TU_%d], l=%d bits",TU_first,TU_last,	       packet_size+ace.bitCount+ace.followBits);  if(mzte_codec.m_iScanDirection == 0)  {    /* tree depth */    for (color=0; color<mzte_codec.m_iColors; color++)       /* close arithmetic coder */      probModelFreeSQ(color);  }  else  {      probModelFreeSQ(color); /* ph - 11/13/98 */  }      bit_stream_length=mzte_ac_encoder_done(&ace);  if(mode==1)    write_packet_header_to_file();  ace.bitCount=ace.followBits=0;   }/****************************************************//* to check if a segment in a packet has exceeded a *//* threshold. Add a marker if so. bbc, 11/6/98      *//****************************************************/Void CVTCEncoder::check_segment_size(Int col){  /* segment not long enough, bbc, 11/16/98 */  if(packet_size+ace.bitCount+ace.followBits-prev_segs_size<     (Int)mzte_codec.m_usSegmentThresh)    return;  prev_segs_size=packet_size+ace.bitCount+ace.followBits;  /* add marker, use ZTR, bbc, 11/10/98  */  mzte_ac_encode_symbol(&ace,&acmType[col][0][CONTEXT_INIT],ZTR);}/* check if end of packet is reached, bbc, 11/6/98 */Void CVTCEncoder::check_end_of_packet(Int color){  if(packet_size+ace.bitCount+ace.followBits>=	  mzte_codec.m_usPacketThresh){    /* write full packet to file, assume that output_buffer */    /* is large enough to hold the arith part without writing to file */    close_arith_encoder_model(color,1);    flush_bits();    flush_bytes();    prev_segs_size=0;  /* reset segment size */    /* start new packet */    emit_bits((UShort)0,2); /* first bit dummy, second bit HEC=0 */    packet_size=0;    if (mzte_codec.m_iScanDirection==0)      init_arith_encoder_model(color);    else    {      /* don't reinitialize if color change */      if ((TU_last-TU_max_dc+1) % mzte_codec.m_iDCHeight != 0)	  init_arith_encoder_model(color);    }    TU_first=TU_last+1;  }  TU_last++;}#ifdef _DC_PACKET_/* check if end of packet is reached, bbc, 11/18/98 */Void CVTCEncoder::check_end_of_DC_packet(int numBP){  int i;  if(packet_size+ace.bitCount+ace.followBits>=	  mzte_codec.m_usPacketThresh){    noteProgress("  ==>E packet [TU_%d,TU_%d], l=%d bits",TU_first,TU_last,		 packet_size+ace.bitCount+ace.followBits);        for (i=0; i<numBP; i++)       mzte_ac_model_done(&(acm_bpdc[i]));	mzte_ac_model_done(&acmType[color][0][CONTEXT_INIT]);    bit_stream_length=mzte_ac_encoder_done(&ace);    write_packet_header_to_file();        flush_bits();    flush_bytes();        prev_segs_size=0;  /* reset segment size */        /* start new packet */    emit_bits((UShort)0,2); /* first bit dummy, second bit HEC=0 */    packet_size=0;        mzte_ac_encoder_init(&ace);    for (i=0; i<numBP; i++) {      acm_bpdc[i].Max_frequency = Bitplane_Max_frequency;      mzte_ac_model_init(&(acm_bpdc[i]),2,NULL,ADAPT,1);    }    mzte_ac_model_init(&acmType[color][0][CONTEXT_INIT],NUMCHAR_TYPE,						NULL,ADAPT,1); /* bbc, 11/20/98 */    TU_first=TU_last+1;  }  TU_last++;}#endif /* force end of packet is reached, ph, 11/19/98 */Void CVTCEncoder::force_end_of_packet(){  flush_bits();  flush_bytes();    prev_segs_size=0;  /* reset segment size */    /* start new packet */  emit_bits((UShort)0,2); /* first bit dummy, second bit HEC=0 */  packet_size=0;  TU_first=TU_last+1;  TU_last++;}//End: Added by Sarnoff for error resilience, 3/5/99

⌨️ 快捷键说明

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