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

📄 downconvert.inl

📁 JVT-S203 contains the JSVM 6 reference software. It corresponds to CVS tag “JSVM_5_12_1”. For obt
💻 INL
📖 第 1 页 / 共 2 页
字号:
  if(pcParameters->m_iSpatialScalabilityType <= SST_RATIO_1 && pcParameters->m_bCrop)
  {
      xCrop(psBufferY, iStrideY,
            psBufferU, iStrideU,
            psBufferV, iStrideV,
            pcParameters, bClip
            );
  }
}


__inline
void
DownConvert::xGenericUpsampleEss( short* psBufferY, int iStrideY,
                                  short* psBufferU, int iStrideU,
                                  short* psBufferV, int iStrideV,
                                  ResizeParameters* pcParameters,
                                  h264::MbDataCtrl*    pcMbDataCtrl)
{
  int iWidth=pcParameters->m_iInWidth;
  int iHeight=pcParameters->m_iInHeight;
  int width=pcParameters->m_iGlobWidth;
  int height=pcParameters->m_iGlobHeight;
  int x, y, w, h, j, i;
  short *buf1, *ptr1, *buf2, *ptr2, *tmp_buf1, *tmp_buf2;
  unsigned char *tmp_buf3;

  tmp_buf1=new short[iWidth*iHeight];
  tmp_buf2=new short[width*iHeight];
  tmp_buf3=new unsigned char[width*iHeight];
  
  memset(tmp_buf3, 4, width*iHeight);

  x=pcParameters->m_iPosX;
  y=pcParameters->m_iPosY;
  w=pcParameters->m_iOutWidth;
  h=pcParameters->m_iOutHeight;

  // luma
  buf1=buf2=psBufferY;
  ptr1=buf1;
  ptr2=tmp_buf1;
  for(j=0;j<iHeight;j++){
    for(i=0;i<iWidth;i++)ptr2[i]=ptr1[i];
    ptr2+=iWidth;
    ptr1+=iStrideY;
  }
  
  xFilterResidualHor(tmp_buf1, tmp_buf2, width,  x,  w,  iWidth, iHeight, pcMbDataCtrl, 0, 0, 0, tmp_buf3);
  for(j=0;j<height;j++){
    for(i=0;i<width;i++)buf1[i]=0;
    buf1+=iStrideY;
  }
  xFilterResidualVer(tmp_buf2, buf2, iStrideY,  x, y, w, h, width, iHeight, 0, 0, 0, tmp_buf3);

  // chroma
  width>>=1; height>>=1; x>>=1; y>>=1; w>>=1; h>>=1; iWidth>>=1; iHeight>>=1;
  // U
  buf1=buf2=psBufferU;
  ptr1=buf1;
  ptr2=tmp_buf1;
  for(j=0;j<iHeight;j++){
    for(i=0;i<iWidth;i++)ptr2[i]=ptr1[i];
    ptr2+=iWidth;
    ptr1+=iStrideU;
  }
  xFilterResidualHor(tmp_buf1, tmp_buf2, width,  x,  w, iWidth, iHeight, pcMbDataCtrl, 1, pcParameters->m_iChromaPhaseX, pcParameters->m_iBaseChromaPhaseX, tmp_buf3);
  for(j=0;j<height;j++){
    for(i=0;i<width;i++)buf1[i]=0;
    buf1+=iStrideU;
  }
  xFilterResidualVer(tmp_buf2, buf2, iStrideU,  x, y, w, h, width, iHeight, 1, pcParameters->m_iChromaPhaseY, pcParameters->m_iBaseChromaPhaseY, tmp_buf3);

  // V
  buf1=buf2=psBufferV;
  ptr1=buf1;
  ptr2=tmp_buf1;
  for(j=0;j<iHeight;j++){
    for(i=0;i<iWidth;i++)ptr2[i]=ptr1[i];
    ptr2+=iWidth;
    ptr1+=iStrideV;
  }
  xFilterResidualHor(tmp_buf1, tmp_buf2, width,  x,  w,  iWidth, iHeight, pcMbDataCtrl, 1, pcParameters->m_iChromaPhaseX, pcParameters->m_iBaseChromaPhaseX, tmp_buf3);
  for(j=0;j<height;j++){
    for(i=0;i<width;i++)buf1[i]=0;
    buf1+=iStrideU;
  }
  xFilterResidualVer(tmp_buf2, buf2, iStrideU,  x, y, w, h, width, iHeight,  1, pcParameters->m_iChromaPhaseY, pcParameters->m_iBaseChromaPhaseY, tmp_buf3);
  
  delete [] tmp_buf1;
  delete [] tmp_buf2;
  delete [] tmp_buf3;
} 

__inline
void
DownConvert::xGenericUpsampleEss( short* psBufferY, int iStrideY,
                                  short* psBufferU, int iStrideU,
                                  short* psBufferV, int iStrideV,
                                  ResizeParameters* pcParameters,
                                  bool bClip )
{
  int   min = ( bClip ?   0 : -32768 );
  int   max = ( bClip ? 255 :  32767 );

  int iInWidth = pcParameters->m_iInWidth;
  int iInHeight = pcParameters->m_iInHeight;
  int iGlobWidth = pcParameters->m_iGlobWidth;
  int iGlobHeight = pcParameters->m_iGlobHeight;
  
  //===== luma =====
  xCopyToImageBuffer  ( psBufferY, iInWidth,   iInHeight,   iStrideY );
  xUpsampling3        ( pcParameters, true);
  xCopyFromImageBuffer( psBufferY, iGlobWidth,   iGlobHeight,  iStrideY, min, max );


  // ===== parameters for chromas =====
  iInWidth    >>= 1;
  iInHeight   >>= 1;
  iGlobWidth   >>= 1;
  iGlobHeight  >>= 1;
  
  //===== chroma cb =====
  xCopyToImageBuffer  ( psBufferU, iInWidth, iInHeight, iStrideU );
  xUpsampling3        ( pcParameters, false);
  xCopyFromImageBuffer( psBufferU, iGlobWidth, iGlobHeight, iStrideU, min, max );

  //===== chroma cr =====
  xCopyToImageBuffer  ( psBufferV, iInWidth, iInHeight, iStrideV );
  xUpsampling3        ( pcParameters, false);
  xCopyFromImageBuffer( psBufferV, iGlobWidth, iGlobHeight, iStrideV, min, max ); 
} 

//JVT-S067
__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, 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 = 8;
  int iMbPerRow = wsize_in >> 4;

  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+4*(2+output_chroma_phase_shift_x)-4*(2+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
  {
    //int F = 4; 
    int G = 2, J = 1, M = 13, S = 12;
    if(output_chroma_phase_shift_x)
    {
  	  J ++;
  	  M --;
    };
    //S = M + G +  J  - F;
    unsigned short C, C1, D1;
    int D, E, q, w1;

    C = ((1<<(M+G))*wsize_in + (w>>1))/w;
    //D = ((-1)<<(G-1+J+M)) + (1<<(S-1)) - (input_chroma_phase_shift_x<<(G-2+J+M));
    D = ((-1)<<15) + (1<<11) - (input_chroma_phase_shift_x<<14);

    C1 = C<<J;
    E = 0;

    q = (C<<(J-1)) + D + (C<<(J-2))*output_chroma_phase_shift_x;
    w1 = q>>S;
    D1 = q - (w1<<S);
    E += w1;
    k = E;
    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[0] = i1; k16[0] = k; p16[0] = p;
  
    for(i = 1; i < w; i++)
    {
	  q = C1 + D1;
	  w1 = q>>S;
	  D1 = q - (w1<<S);
	  E += w1;
	  k = E;
	  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 )
      {
        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-S067
__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, 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 = 8;

  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+4*(2+output_chroma_phase_shift_y)-4*(2+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
  {
    //int F = 4;
    int G = 2, J = 1, M = 13, S = 12;
    if(output_chroma_phase_shift_y)
    {
	  J ++;
	  M --;
    };
    //S = M + G + J - F;
    unsigned short C, C1, D1;
    int D, E, q, w1;

    C = ((1<<(M+G))*hsize_in + (h>>1))/h;
    //D = ((-1)<<(G-1+J+M)) + (1<<(S-1)) - (input_chroma_phase_shift_y<<(G-2+J+M));
    D = ((-1)<<15) + (1<<11) - (input_chroma_phase_shift_y<<14);

    C1 = C<<J;
    E = 0;

    q = (C<<(J-1)) + D + (C<<(J-2))*output_chroma_phase_shift_y;
    w1 = q>>S;
    D1 = q - (w1<<S);
    E += w1;
    k = E;
    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[0] = j1; k16[0] = k; p16[0] = p;
  
    for(j = 1; j < h; j++)
    {
	  q = C1 + D1;
	  w1 = q>>S;
	  D1 = q - (w1<<S);
	  E += w1;
	  k = E;
	  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;
    }
  }

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