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

📄 downconvert.inl

📁 jsvm开发代码包括抽样,编码,抽取,解码等一系列功能,可以做工具或研究用
💻 INL
📖 第 1 页 / 共 4 页
字号:
    xCopyFromImageBuffer( psBufferU, iGlobWidth, iGlobHeight/2, iStrideU*2, min, max ); 
  else
  xCopyFromImageBuffer( psBufferU, iGlobWidth, iGlobHeight, iStrideU, min, max );

  if(resample_mode==1){
    xCopyToImageBuffer  ( psBufferU+iStrideU, iInWidth,   iInHeight/2,   iStrideU*2 );
    xUpsampling3        ( pcParameters, false, 8);
    xCopyFromImageBuffer( psBufferU+iStrideU, iGlobWidth,   iGlobHeight/2,  iStrideU*2, min, max );
  }

  //===== chroma cr =====
  if(resample_mode==1 || resample_mode==4 || resample_mode==7)
    xCopyToImageBuffer  ( psBufferV, iInWidth,   iInHeight/2,   iStrideV*2 );
  else if(resample_mode==5 || resample_mode==6)
    xCopyToImageBuffer  ( psBufferV+iStrideV, iInWidth,   iInHeight/2,   iStrideV*2 );
  else
  xCopyToImageBuffer  ( psBufferV, iInWidth, iInHeight, iStrideV );

  xUpsampling3        ( pcParameters, false, resample_mode);
  
  if(resample_mode>1){
    bool top_flg = (resample_mode==2 || resample_mode==4 || resample_mode==7);
    FILTER_UP_CHROMA

    xUpsampling_ver     ( iGlobWidth, iGlobHeight/2, crop_y0, crop_h, piFilter_chroma, top_flg );
  }
  
  if(resample_mode==1)
    xCopyFromImageBuffer( psBufferV, iGlobWidth, iGlobHeight/2, iStrideV*2, min, max ); 
  else
  xCopyFromImageBuffer( psBufferV, iGlobWidth, iGlobHeight, iStrideV, min, max ); 
  
  if(resample_mode==1){
    xCopyToImageBuffer  ( psBufferV+iStrideV, iInWidth,   iInHeight/2,   iStrideV*2 );
    xUpsampling3        ( pcParameters, false, 8);
    xCopyFromImageBuffer( psBufferV+iStrideV, iGlobWidth,   iGlobHeight/2,  iStrideV*2, min, max );
} 
} 





//JVT-U067
__inline
void
DownConvert::xFilterResidualHor ( short *buf_in, short *buf_out, 
                                  int width, 
                                  int x, int w, 
                                  int wsize_in, int hsize_in, 
                                  h264::MbDataCtrl*  pcMbDataCtrl, 
                                  bool chroma, bool interlace,
                                  int output_chroma_phase_shift_x, int input_chroma_phase_shift_x,
                                  unsigned char *buf_blocksize )
{
  int j, i, k, i1;
  short *ptr1, *ptr2;
  unsigned char *ptr3;
  int p, p2, p3, block = ( chroma ? 4 : 8 );
  int iMbPerRow = wsize_in >> 4;
  unsigned short deltaa, deltab;

  int *x16 = new int[w]; 
  int* k16 = new int[w]; // for relative phase shift in unit of 1/16 sample
  int* p16 = new int[w];

  if(w == wsize_in)
  {
	  for(i = 0; i < w; i++)
	  {
		  k = i*16+2*(4+output_chroma_phase_shift_x)-2*(4+input_chroma_phase_shift_x);
		  if(k<0)
		    k = 0;
		  i1 = k >> 4;
	      k -= i1 * 16;
	      p = ( k > 7 && (i1 + 1) < wsize_in ) ? ( i1 + 1 ) : i1;
	      p = p < 0 ? 0 : p;
		  x16[i] = i1; k16[i] = k; p16[i] = p;
	  }
  }
  else
  {
    deltaa = ((wsize_in<<16) + (w>>1))/w;
    if(chroma)
    {
      deltab =  ((wsize_in<<14) + (w>>1))/w;
      for(i = 0; i < w; i++)
      {
        k = ((i*deltaa + (4 + output_chroma_phase_shift_x)*(deltab>>1) + 2048)>>12) - 2*(4 + input_chroma_phase_shift_x);
        if(k<0)
          k = 0;
        i1 = k >> 4;
        k -= i1 * 16;
        p = ( k > 7 && (i1 + 1) < wsize_in ) ? ( i1 + 1 ) : i1;
        p = p < 0 ? 0 : p;
        x16[i] = i1; k16[i] = k; p16[i] = p;
      }
    }
    else
    {
      deltab = ((wsize_in<<15) + (w>>1))/w;
      for(i = 0; i < w; i++)
      {
        k = (i*deltaa + deltab - 30720)>>12;
        if(k<0)
          k = 0;
        i1 = k >> 4;
        k -= i1 * 16;
        p = ( k > 7 && (i1 + 1) < wsize_in ) ? ( i1 + 1 ) : i1;
        p = p < 0 ? 0 : p;
        x16[i] = i1; k16[i] = k; p16[i] = p;
      }
	}
  }

  for( j = 0; j < hsize_in; j++ )
  {
    ptr1 = buf_in + j * wsize_in;
    ptr2 = buf_out + j * width + x;
    ptr3 = buf_blocksize + j * width + x;
    for( i = 0; i < w; i++ )
    {
      i1 = x16[i]; k = k16[i]; p = p16[i];
#if !RESIDUAL_B8_BASED
      if( !chroma && !interlace)
      {
        const h264::MbData& rcMbData = pcMbDataCtrl->getMbData( (p>>4) + (j>>4) * iMbPerRow );
        //if( rcMbData.isIntra16x16() ) block = 16;
        //else 
        if( rcMbData.isTransformSize8x8() ) block = 8;
        else block = 4;
        ptr3[i] = (unsigned char) block;
      }
#endif
      p = p / block;
      p2 = ( i1 / block ) == p ? i1 : ( p * block );
      p3 = ( (i1+1) / block ) == p ? (i1+1) : ( p*block + (block-1) );
      ptr2[i] = (short) ( (16-k) * ptr1[p2] + k * ptr1[p3]);
    }
  }
 
  delete [] x16;
  delete [] k16;
  delete [] p16;

}

//JVT-U067
__inline
void
DownConvert::xFilterResidualVer ( short *buf_in, short *buf_out, 
                                  int width, 
                                  int x, int y, int w, int h, 
                                  int wsize_in, int hsize_in, 
                                  bool chroma, bool interlace,
                                  int output_chroma_phase_shift_y, int input_chroma_phase_shift_y,
                                  unsigned char *buf_blocksize )
{
  int j, i, k, j1;
  short *ptr1, *ptr2;
  unsigned char *ptr3;
  int p, p2, p3, block = ( chroma ? 4 : 8 );
  unsigned short deltaa, deltab;

  int* y16 = new int[h]; 
  int* k16 = new int[h]; // for relative phase shift in unit of 1/16 sample
  int* p16 = new int[h];

  if(h == hsize_in)
  {
	  for(j = 0; j < h; j++)
	  {
		  k = j*16+2*(4+output_chroma_phase_shift_y)-2*(4+input_chroma_phase_shift_y);
		  if(k<0)
		    k = 0;
	      j1 = k >> 4;
	      k -= j1 * 16;
	      p = ( k > 7 && ( j1+1 ) < hsize_in ) ? ( j1+1 ) : j1;
    	  p = p < 0 ? 0 : p;
	      y16[j] = j1; k16[j] = k; p16[j] = p;
	  }
  }
  else
  {
//TMM_INTERLACE{
		if ( hsize_in > h )
		{
			deltaa = ((hsize_in<<15) + (h>>1))/h;
			if(chroma)
			{
				deltab = ( ((hsize_in<<13) + (h>>1))/h );
				for(j = 0; j < h; j++)
				{
					k = ((j*deltaa + (4 + output_chroma_phase_shift_y)*(deltab>>1) + 1024)>>11) - 2*(4 + input_chroma_phase_shift_y);
					if(k<0)
						k = 0;
					j1 = k >> 4;
					k -= j1 * 16;
					p = ( k > 7 && ( j1+1 ) < hsize_in ) ? ( j1+1 ) : j1;
					p = p < 0 ? 0 : p;
					y16[j] = j1; k16[j] = k; p16[j] = p;
				}
			}
			else
			{
				deltab = ((hsize_in<<14) + (h>>1))/h;
				for(j = 0; j < h; j++)
				{
					k = (j*deltaa + deltab - 15360)>>11;
					if(k<0)
						k = 0;
					j1 = k >> 4;
					k -= j1 * 16;
					p = ( k > 7 && ( j1+1 ) < hsize_in ) ? ( j1+1 ) : j1;
					p = p < 0 ? 0 : p;
					y16[j] = j1; k16[j] = k; p16[j] = p;
				}
			}
		}
		else
		{
//TMM_INTERLACE}
    deltaa = ((hsize_in<<16) + (h>>1))/h;
    if(chroma)
    {
      deltab = ( ((hsize_in<<14) + (h>>1))/h );
      for(j = 0; j < h; j++)
      {
        k = ((j*deltaa + (4 + output_chroma_phase_shift_y)*(deltab>>1) + 2048)>>12) - 2*(4 + input_chroma_phase_shift_y);
        if(k<0)
          k = 0;
        j1 = k >> 4;
        k -= j1 * 16;
        p = ( k > 7 && ( j1+1 ) < hsize_in ) ? ( j1+1 ) : j1;
        p = p < 0 ? 0 : p;
        y16[j] = j1; k16[j] = k; p16[j] = p;
      }
    }
	else
    {
      deltab = ((hsize_in<<15) + (h>>1))/h;
      for(j = 0; j < h; j++)
      {
        k = (j*deltaa + deltab - 30720)>>12;
        if(k<0)
          k = 0;
        j1 = k >> 4;
        k -= j1 * 16;
        p = ( k > 7 && ( j1+1 ) < hsize_in ) ? ( j1+1 ) : j1;
        p = p < 0 ? 0 : p;
        y16[j] = j1; k16[j] = k; p16[j] = p;
      }
	}
		} //TMM_INTERLACE{}
  }

  for( i = 0; i < w; i++ )
  {
    ptr1 = buf_in + i + x;
    ptr3 = buf_blocksize + i + x;
    ptr2 = buf_out + i + x + width * y;
    for( j = 0; j < h; j++ )
    {
      j1 = y16[j]; k = k16[j]; p = p16[j];
#if !RESIDUAL_B8_BASED
      if( !chroma && !interlace)
      {
        block = ptr3[ wsize_in * p ];
      }
#endif
      p = p / block;
      p2 = ( j1/block ) == p ? j1 : ( p*block );
      p3 = ( (j1+1) / block ) == p ? (j1+1) : ( p*block + (block-1) );
      ptr2[j*width] = (Short) (( (16-k) * ptr1[wsize_in*p2] + k * ptr1[wsize_in*p3] + 128 ) >> 8);
    }
  }
  delete [] y16;
  delete [] k16;
  delete [] p16;
}

__inline
void
DownConvert::xCrop ( short* psBufferY, int iStrideY,
                     short* psBufferU, int iStrideU,
                     short* psBufferV, int iStrideV,
                     ResizeParameters* pcParameters,
                     bool bClip )
{
  int iOutWidth = pcParameters->m_iOutWidth;
  int iOutHeight = pcParameters->m_iOutHeight;
  int iPosX = pcParameters->m_iPosX;
  int iPosY = pcParameters->m_iPosY;
  int iGlobWidth = pcParameters->m_iGlobWidth;
  int iGlobHeight = pcParameters->m_iGlobHeight;

  int   min = ( bClip ?   0 : -32768 );
  int   max = ( bClip ? 255 :  32767 );
  short* ptr;

  //===== luma =====
  ptr = &psBufferY[iPosY * iStrideY + iPosX];
  xCopyToImageBuffer  ( psBufferY, iOutWidth,  iOutHeight,   iStrideY );
  xSetValue(psBufferY, iStrideY, iGlobWidth, iGlobHeight, (short)DEFAULTY);
  xCopyFromImageBuffer( ptr,                                iOutWidth,   iOutHeight,  iStrideY, min, max );

  // ===== parameters for chromas =====
  iOutWidth   >>= 1;
  iOutHeight  >>= 1;
  iPosX       >>= 1;
  iPosY       >>= 1;
  iGlobWidth  >>= 1;
  iGlobHeight >>= 1;
  
  //===== chroma cb =====
  ptr = &psBufferU[iPosY * iStrideU + iPosX];
  xCopyToImageBuffer  ( psBufferU, iOutWidth,  iOutHeight,   iStrideU );
  xSetValue(psBufferU, iStrideU, iGlobWidth, iGlobHeight, (short)DEFAULTU);
  xCopyFromImageBuffer( ptr,                                 iOutWidth, iOutHeight, iStrideU, min, max );

  //===== chroma cr =====
  ptr = &psBufferV[iPosY * iStrideV + iPosX];
  xCopyToImageBuffer  ( psBufferV, iOutWidth,  iOutHeight,   iStrideV );
  xSetValue(psBufferV, iStrideV, iGlobWidth, iGlobHeight, (short)DEFAULTV);
  xCopyFromImageBuffer( ptr,                                 iOutWidth, iOutHeight, iStrideV, min, max );
}

__inline
void
DownConvert::xCopyToImageBuffer( short*   psSrc,
                                 int      iWidth,
                                 int      iHeight,
                                 int      iStride )
{
  int* piDes = m_paiImageBuffer;

  for( int j = 0; j < iHeight; j++ )
  {
    for( int i = 0; i < iWidth;  i++ )
    {
      piDes[i] = (int)psSrc[i];
    }
    piDes += m_iImageStride;
    psSrc += iStride;
  }
}

__inline
void
DownConvert::xCopyFromImageBuffer( short*   psDes,
                                   int      iWidth,
                                   int      iHeight,
                                   int      iStride,
                                   int      imin,
                                   int      imax )
{
  int* piSrc = m_paiImageBuffer;

  for( int j = 0; j < iHeight; j++ )
  {
    for( int i = 0; i < iWidth;  i++ )
    {
      psDes[i] = (short)xClip( piSrc[i], imin, imax );
    }
    psDes += iStride;
    piSrc += m_iImageStride;
  }
}

__inline
void
DownConvert::xSetValue ( short* psBuffer, int iStride, int iWidth, int iHeight, short value )
{
  for (int y=0; y<iHeight; y++)
    for (int x=0; x<iWidth; x++)
      psBuffer[y*iStride + x] = value;
}

#endif // DOWN_CONVERT_STATIC 



⌨️ 快捷键说明

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