当先锋百科网

首页 1 2 3 4 5 6 7

bool CYuvToRgb::Yuv422ToRgb ()
{
 unsigned long col,row;
 double Y,U,V;
 double red,blue,green;

 for (row=0; row<m_Height; row++)
 {
  int idx=((m_Height-row-1)*3)*m_Width;
  int rowptr=row*m_Width;

  for (col=0; col<m_Width; col++)
  {
   int colhalf=col>>1;
   Y=m_pYuvBuf[rowptr+col];
   U=m_pYuvBuf[rowptr+colhalf+m_Width*m_Height-row*m_Width/2];
   V=m_pYuvBuf[rowptr+colhalf+m_Width*m_Height-row*m_Width/2+m_Width*m_Height/2];

   red=(Y+(U-128)*1.4022)+0.5;
   green=(Y-(U-128)*0.3456-(V-128)*0.7145)+0.5;
   blue=(Y+(V-128)*1.7710)+0.5;

   if (red>255) red=255;
   else if (red<0) red=0;
   if (green>255) green=255;
   else if (green<0) green=0;
   if (blue>255) blue=255;
   else if (blue<0) blue=0;

   m_pRgbBuf[idx++]=(char)red;
   m_pRgbBuf[idx++]=(char)green;
   m_pRgbBuf[idx++]=(char)blue;
  }
 }
 return true;
}