原文:http://blog.csdn.net/zhongnanjun_3/article/details/3941974
/*
R = Y + 1.4075 *(V-128)
G = Y – 0.3455 *(U –128) – 0.7169 *(V –128)
B = Y + 1.779 *(U – 128)
*/
unsigned char GetYUVR(int nY,int nU,int nV)
{
int nR; //V=nV-128
nR = nY + (nV-128)+((nV-128)*103>>8);// v + ((v * 103) >> 8);
//overflow?
if( nR > 255 )
nR = 255;
if( nR < 0 )
nR = 0;
return nR;
}
unsigned char GetYUVG(int nY,int nU,int nV)
{
int nG; //U = nU-128
nG = nY - (((nU-128)*88>>8)+((nV-128)*183>>8));//((u * 88) >> 8) +((v * 183) >> 8);
//overflow?
if( nG > 255 )
nG = 255;
if( nG < 0 )
nG = 0;
return nG;
}
unsigned char GetYUVB(int nY,int nU,int nV)
{
int nB;
nB = nY + (nU-128)+((nU-128)*198>>8);//u +( (u*198) >> 8);
//overflow?
if( nB > 255 )
nB = 255;
if( nB < 0 )
nB = 0;
return nB;
}
////////////////////////////////////////////////////////
nPixelData = ( nR&0xF8 ) | nG>>5;
SoPbSPITXByte( nPixelData);//R5G6B5 :high
nPixelData = ( nG<<3 &0xE0) | nB>>3;
SoPbSPITXByte( nPixelData );//R5G6B5 :Low
//////////////////////////////////////////////////////////
想看看彩色图片的黑白效果 看看:
nPixelData = ((* nPIC)&0xF8 )| (* nPIC)>>5 ;//R=G=B=Y:R5G6B5 :high
SoPbSPITXByte( nPixelData);//(*(unsigned char*)DataAddr);//
nPixelData = ((* nPIC)<<3 &0xE0) | (* nPIC)>>3;//Y0//R=G=B=Y:R5G6B5 :Low
SoPbSPITXByte( nPixelData );//R5G6B5 :Low