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

📄 ztscan_enc.cpp

📁 网络MPEG4IP流媒体开发源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		{		  /* LH */		  encodeMQBlocks(h,w,n);		  		  /* HL */		  h += ac_h;		  w -= ac_w;		  encodeMQBlocks(h,w,n);		  		  /* HH */		  w += ac_w;		  encodeMQBlocks(h,w,n);		  		  /* Set h back to where it started. w is already there */		  h -= ac_h;		}    }    /* update ranges */    acH=acH2;    acW=acW2;    acW2<<=1;    acH2<<=1;    ++layer;  }  for (color=0; color<NCOL; ++color)    probModelFreeMQ(color);}/********************************************************  Function Name  -------------  static Void encode_pixel_MQ_band(Int h,Int w)  Arguments  ---------  Int h,Int w - position of a pixel in height and width    Description  -----------  Encoding the type and/or value of a coefficient, a  recursive function, multi quant mode.  Functions Called  ----------------  mzte_ac_encode_symbol()  mark_ZTR_D()  mag_sign_encode_MQ()   Return Value  ------------  None.********************************************************/ Void CVTCEncoder::encode_pixel_MQ(Int h,Int w){  Int zt_type;  /*~~~~~~~~~~~~~~~~~ zerotree descendent or skip  ~~~~~~~~~~~~~~~~~~~*/  if(coeffinfo[h][w].type==ZTR_D)    return;  /*~~~~~~~~~~~~~~ encode zero tree symbol ~~~~~~~~~~~~~~~~~~*/  if (IS_RESID(w,h,color))  {    zt_type = VAL;  }  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:    case ZTR_D:#ifdef _SHAPE_      if(coeffinfo[h][w].mask==1) /* mark ZTR-D for in-node root */#endif	mark_ZTR_D(h,w);    case IZ:      return;    case VZTR:      mark_ZTR_D(h,w);    case VAL:#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 (%d) in multi-quant encoding.", zt_type);       }}/**********************************************************************//***************       MQ TREE         ********************************//**********************************************************************//********************************************************  Function Name  -------------  static Void cachb_encode_MQ_tree()  Arguments  ---------  None.  Description  -----------  Encode AC information for all color components for spatial level.   Multiple quant, bandwise scan.  Functions Called  ----------------  clear_ZTR_D();  encode_pixel_MQ_tree()  Return Value  ------------  None.********************************************************/ // hjlee 0901Void CVTCEncoder::cachb_encode_MQ_tree(){  Int h,w, dc_h, dc_w;  /* clear the ZTR_D type from the previous pass */  for (color=0; color<NCOL; ++color)  {          coeffinfo=mzte_codec.m_SPlayer[color].coeffinfo;    height=mzte_codec.m_SPlayer[color].height;    width=mzte_codec.m_SPlayer[color].width;    clear_ZTR_D(coeffinfo, width, height);  }  for (color=0; color<NCOL; ++color)    probModelInitMQ(color);  /* ac_h, ac_w init */  dc_h=mzte_codec.m_iDCHeight;  dc_w=mzte_codec.m_iDCWidth;  for (h=0; h<dc_h; ++h)    for (w=0; w<dc_w; ++w)    {      for (color=0; color<NCOL; ++color)      {      	SNR_IMAGE *snr_image;	Int tw,sw,sh,n; // 1124		snr_image=&(mzte_codec.m_SPlayer[color].SNRlayer.snr_image);		coeffinfo=mzte_codec.m_SPlayer[color].coeffinfo;	height=mzte_codec.m_SPlayer[color].height;	width=mzte_codec.m_SPlayer[color].width;      	setProbModelsMQ(color);	/* LH */	n = 0;	for (tw=mzte_codec.m_iDCWidth; tw < width; tw<<=1)	{	  sh = h << n;	  sw = (w+dc_w) << n;	  encodeMQBlocks(sh,sw,n);	  n++;	}	/* HL */	n = 0;	for (tw=mzte_codec.m_iDCWidth; tw < width; tw<<=1)	{	  sh = (h+dc_h) << n;	  sw = w << n;	  encodeMQBlocks(sh,sw,n);	  n++;	}	/* HH */	n = 0;	for (tw=mzte_codec.m_iDCWidth; tw < width; tw<<=1)	{	  sh = (h+dc_h) << n;	  sw = (w+dc_w) << n;	  encodeMQBlocks(sh,sw,n);	  n++;	}	#if 0	encode_pixel_MQ_tree(h,w+dc_w);           /* LH */	encode_pixel_MQ_tree(h+dc_h,w);           /* HL */	encode_pixel_MQ_tree(h+dc_h,w+dc_w);      /* HH */#endif      }    }  for (color=0; color<NCOL; ++color)    probModelFreeMQ(color);}#if 0/********************************************************  Function Name  -------------  static Void encode_pixel_MQ_tree(Int h,Int w)  Arguments  ---------  Int h,Int w - position of a pixel in height and width    Description  -----------  Encoding the type and/or value of a coefficient, a  recursive function, multi quant mode.  Functions Called  ----------------  mzte_ac_encode_symbol()  mark_ZTR_D()  mag_sign_encode_MQ()   Return Value  ------------  None.********************************************************/ // hjlee 0901Void CVTCEncoder::encode_pixel_MQ_tree(Int h0,Int w0){  Int zt_type, h, w, k;  Int dcc[4]; /* Don't Code Children */  Int nSib; /* number siblings */  nSib = (h0<(mzte_codec.m_iDCHeight<<1) && w0<(mzte_codec.m_iDCWidth<<1)) ? 1 : 4;  /********************* CODE SIBLINGS *****************************/  for (k=0; k<nSib; ++k)  {    h = h0 + (k/2);    w = w0 + (k%2);    /* encode zero tree symbol */      if (IS_RESID(w,h,color))    {      zt_type = VAL;    }    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);  }}

⌨️ 快捷键说明

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