rgb2yuv
场景:RGB2YUV的有关问题
RGB2YUV的问题
我刚刚接触图形图像开发,有很多问题还比较困惑,比如RGB2YUV的问题
首先,当我降RGB数据转换为YUV数据,然后试图保存文件的时候,我必须知道写入文件的字节数, 但RGB转为YUV后,字节数肯定不一样, 那么你们是如何获得新的长度的呢?
其次,我用的这段转换代码应该是没有经过优化的,不知道你们是否试过更好的代码,请推荐
void Rgb2Yuv (unsigned srcWidth,unsigned srcHeight,const BYTE * rgb,BYTE * yuv )
{
const unsigned planeSize = srcWidth*srcHeight;
const unsigned halfWidth = srcWidth > > 1;
BYTE * yplane = yuv;
BYTE * uplane = yuv + planeSize;
BYTE * vplane = yuv + planeSize + (planeSize > > 2);
const BYTE * rgbIndex = rgb;
for (unsigned y = 0; y < srcHeight; y++)
{
BYTE * yline = yplane + (y * srcWidth);
BYTE * uline = uplane + ((y > > 1) * halfWidth);
BYTE * vline = vplane + ((y > > 1) * halfWidth);
rgbIndex = rgb + (srcWidth*(srcHeight-1-y)*3);
for (unsigned x = 0; x < srcWidth; x+=2)
{
rgbtoy(rgbIndex[0], rgbIndex[1], rgbIndex[2],*yline);
rgbIndex += 3;
yline++;
rgbtoyuv(rgbIndex[0], rgbIndex[1],
rgbIndex[2],*yline, *uline, *vline);
rgbIndex += 3;
yline++;
uline++;
vline++;
}
}
}
------解决方案--------------------
http://msdn2.microsoft.com/en-us/library/aa904813(VS.80).aspx
------解决方案--------------------
美国冈萨雷斯博士编写的跟经典的 <数字图像处理> 这本书有你想要的东西,建议先把理论看透了再用程序实现.
RGB2YUV的问题
我刚刚接触图形图像开发,有很多问题还比较困惑,比如RGB2YUV的问题
首先,当我降RGB数据转换为YUV数据,然后试图保存文件的时候,我必须知道写入文件的字节数, 但RGB转为YUV后,字节数肯定不一样, 那么你们是如何获得新的长度的呢?
其次,我用的这段转换代码应该是没有经过优化的,不知道你们是否试过更好的代码,请推荐
void Rgb2Yuv (unsigned srcWidth,unsigned srcHeight,const BYTE * rgb,BYTE * yuv )
{
const unsigned planeSize = srcWidth*srcHeight;
const unsigned halfWidth = srcWidth > > 1;
BYTE * yplane = yuv;
BYTE * uplane = yuv + planeSize;
BYTE * vplane = yuv + planeSize + (planeSize > > 2);
const BYTE * rgbIndex = rgb;
for (unsigned y = 0; y < srcHeight; y++)
{
BYTE * yline = yplane + (y * srcWidth);
BYTE * uline = uplane + ((y > > 1) * halfWidth);
BYTE * vline = vplane + ((y > > 1) * halfWidth);
rgbIndex = rgb + (srcWidth*(srcHeight-1-y)*3);
for (unsigned x = 0; x < srcWidth; x+=2)
{
rgbtoy(rgbIndex[0], rgbIndex[1], rgbIndex[2],*yline);
rgbIndex += 3;
yline++;
rgbtoyuv(rgbIndex[0], rgbIndex[1],
rgbIndex[2],*yline, *uline, *vline);
rgbIndex += 3;
yline++;
uline++;
vline++;
}
}
}
------解决方案--------------------
http://msdn2.microsoft.com/en-us/library/aa904813(VS.80).aspx
------解决方案--------------------
美国冈萨雷斯博士编写的跟经典的 <数字图像处理> 这本书有你想要的东西,建议先把理论看透了再用程序实现.