求大神指教 yuv420转rgb24 存bmp图像色彩出问题 求大神指教
代码:
void ConvertYUVToRGB(unsigned char *yuv, unsigned char *rgb, int width, int height)
{
int R,G,B;
int Y,U,V;
int x,y;
int nWidth = width>>1;
unsigned char *yuv420[3];
yuv420[0] = yuv;
yuv420[1] = yuv + width*height;
yuv420[2] = yuv + width*height*5/4;
//色度信号宽度
for (y=0;y<height;y++)
{
for (x=0;x<width;x++)
{
Y = *(yuv420[0] + y*width + x);
U = *(yuv420[1] + ((y>>1)*nWidth) + (x>>1));
V = *(yuv420[2] + ((y>>1)*nWidth) + (x>>1));
B= 1.164 * (Y - 16) + 2.018 * (U - 128);
G= 1.164 * (Y - 16) - 0.38 * (U - 128) - 0.813 * (V - 128);
R= 1.164 * (Y - 16) ;
//防止越界
if (R>255)R=255;
if (R<0)R=0;
if (G>255)G=255;
if (G<0)G=0;
if (B>255)B=255;
if (B<0)B=0;
*(rgb + ((height-y-1)*width + x)*3) = R;
*(rgb + ((height-y-1)*width + x)*3 + 1) = G;
*(rgb + ((height-y-1)*width + x)*3 + 2) = B;
}
}
}