社区
图形处理/算法
帖子详情
RGB24-》uyvy的转换
沧海一朵浪
2009-06-11 04:41:51
高分求:我按照网络上的公式,算出来不对啊,请给出源码?
谢谢
...全文
115
3
打赏
收藏
RGB24-》uyvy的转换
高分求:我按照网络上的公式,算出来不对啊,请给出源码? 谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
aaaa3105563
2009-06-11
打赏
举报
回复
帮顶·
jtujtujtu
2009-06-11
打赏
举报
回复
不好意思
忘了删除个东西
公式来自于 msdn:
http://msdn2.microsoft.com/en-us/library/ms893078.aspx
//////////////////////////////////////////////////////////////////////////
// RGB2YUV
// pRGB point to the RGB data
// pYUV point to the YUV data
// width width of the picture
// height height of the picture
//////////////////////////////////////////////////////////////////////////
int RGB2YUV(void* pRGB, void* pYUV, int width, int height)
{
if (NULL == pRGB)
{
return -1;
}
unsigned char* pRGBData = (unsigned char *)pRGB;
unsigned char* pYUVData = (unsigned char *)pYUV;
if (NULL == pYUVData)
{
pYUVData = new unsigned char[width*height*2];
}
int R1, G1, B1, R2, G2, B2, Y1, U1, Y2, V1;
for (int i=0; i <height; ++i)
{
for (int j=0; j <width/2; ++j)
{
B1 = *(pRGBData+(height-i-1)*width*3+j*6);
G1 = *(pRGBData+(height-i-1)*width*3+j*6+1);
R1 = *(pRGBData+(height-i-1)*width*3+j*6+2);
B2 = *(pRGBData+(height-i-1)*width*3+j*6+3);
G2 = *(pRGBData+(height-i-1)*width*3+j*6+4);
R2 = *(pRGBData+(height-i-1)*width*3+j*6+5);
Y1 = (((66*R1+129*G1+25*B1+128)>>8) + 16) > 255 ? 255 : (((66*R1+129*G1+25*B1+128)>>8) + 16);
U1 = ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128)>255 ? 255 : ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128);
Y2 = (((66*R2+129*G2+25*B2+128)>>8) + 16)>255 ? 255 : ((66*R2+129*G2+25*B2+128)>>8) + 16;
V1 = ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128)>255 ? 255 : ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128);
*(pYUVData+i*width*2+j*4) = Y1;
*(pYUVData+i*width*2+j*4+1) = U1;
*(pYUVData+i*width*2+j*4+2) = Y2;
*(pYUVData+i*width*2+j*4+3) = V1;
}
}
return 0;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jtujtujtu/archive/2009/02/10/3874621.aspx
jtujtujtu
2009-06-11
打赏
举报
回复
公式来自于 msdn:
http://msdn2.microsoft.com/en-us/library/ms893078.aspx
//////////////////////////////////////////////////////////////////////////
// RGB2YUV
// pRGB point to the RGB data
// pYUV point to the YUV data
// width width of the picture
// height height of the picture
//////////////////////////////////////////////////////////////////////////
int RGB2YUV(void* pRGB, void* pYUV, int width, int height)
{
if (NULL == pRGB)
{
return -1;
}
unsigned char* pRGBData = (unsigned char *)pRGB;
unsigned char* pYUVData = (unsigned char *)pYUV;
if (NULL == pYUVData)
{
if (alphaYUV)
{
pYUVData = new unsigned char[width*height*3];
}
else
pYUVData = new unsigned char[width*height*2];
}
int R1, G1, B1, R2, G2, B2, Y1, U1, Y2, V1;
int alpha1, alpha2;
for (int i=0; i<height; ++i)
{
for (int j=0; j<width/2; ++j)
{
B1 = *(pRGBData+(height-i-1)*width*3+j*6);
G1 = *(pRGBData+(height-i-1)*width*3+j*6+1);
R1 = *(pRGBData+(height-i-1)*width*3+j*6+2);
B2 = *(pRGBData+(height-i-1)*width*3+j*6+3);
G2 = *(pRGBData+(height-i-1)*width*3+j*6+4);
R2 = *(pRGBData+(height-i-1)*width*3+j*6+5);
Y1 = (((66*R1+129*G1+25*B1+128)>>8) + 16) > 255 ? 255 : (((66*R1+129*G1+25*B1+128)>>8) + 16);
U1 = ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128)>255 ? 255 : ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128);
Y2 = (((66*R2+129*G2+25*B2+128)>>8) + 16)>255 ? 255 : ((66*R2+129*G2+25*B2+128)>>8) + 16;
V1 = ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128)>255 ? 255 : ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128);
*(pYUVData+i*width*2+j*4) = Y1;
*(pYUVData+i*width*2+j*4+1) = U1;
*(pYUVData+i*width*2+j*4+2) = Y2;
*(pYUVData+i*width*2+j*4+3) = V1;
}
}
return 0;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jtujtujtu/archive/2009/02/10/3874621.aspx
YUV格式学习:YUYV、YVYU、
UYVY
、VYUY格式
转换
成
RGB
24
前面文章讲过题目中的YUYV、YVYU、
UYVY
、VYUY格式,它们都是YUV422的打包格式——即在内存中,Y、U、V都是挨着排序的。它们的名称就表示了Y、U、V的顺序。像YUYV,就是Y、U、Y、V、Y、U、Y、V。在做
转换
时,就显得很容易、简单了。
YUV格式学习:YUYV、YVYU、
UYVY
、VYUY格式
转换
成
RGB
YUYV、YVYU、
UYVY
、VYUY格式,它们都是YUV422的打包格式——即在内存中,Y、U、V都是挨着排序的。它们的名称就表示了Y、U、V的顺序。像YUYV,就是Y、U、Y、V、Y、U、Y、V。在做
转换
时,就显得很容易、简单了。 因为极其相近,故在将这几种格式全部封闭到一个函数里做。代码如下: void yuv422packed_to_
rgb
24
(YUV_TYPE type, unsigned char* yuv422p, unsigned char*
rgb
, int width, int heig
VB实现
RGB
888到YUV422的
转换
从前面的bmp文件格式以及YUV的格式介绍中,我们已经知道了两种文件之间的差异。再从网上找到YUV与
RGB
之间的换算关系:Y = 0.257R + 0.504G + 0.098B + 16U = -0.148R - 0.291G + 0.439B + 128V = 0.439R - 0.368G - 0.071B + 128 好,现在准备工作已经差不多了。需要的就是整理一下
色彩空间
转换
http://blog.csdn.net/yyingwei/article/details/22649575 //以下是yv12到
RGB
24
的
转换
算法,如果是yuv420到
RGB
24
转换
,秩序u,v反过来就可以了。 //即: // unsigned char* uData = &yData[nYLen]; // unsigned char* vData = &vData[nYLen>>2]; b
FFMPEG 实现 YUV,
RGB
各种图像原始数据之间的
转换
(swscale)
FFMPEG中的swscale提供了视频原始数据(YUV420,YUV422,YUV444,
RGB
24
...)之间的
转换
,分辨率变换等操作,使用起来十分方便,在这里记录一下它的用法。 swscale主要用于在2个AVFrame之间进行
转换
。 下面来看一个视频解码的简单例子,这个程序完成了对"北京移动开发者大会茶歇视频2.flv"(其实就是优酷上的一个普通...
图形处理/算法
19,464
社区成员
50,678
社区内容
发帖
与我相关
我的任务
图形处理/算法
VC/MFC 图形处理/算法
复制链接
扫一扫
分享
社区描述
VC/MFC 图形处理/算法
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章