4381
- 收藏
- 点赞
- 分享
- 举报
windows 上的 yuv 转RGB 代码
本人技术太菜,过来跟大牛学习的,那就有事没事 分享点收集的好用的东东吧
[code]#include
#include
#include
void yuvtorgb(double *, unsigned char *);
void yuv422convertrgb(unsigned char *yuv_ptr,unsigned char *rgb_ptr,int width,int height);
int main()
{
int width = 640;
int height = 480;
int framesize = width * height;
unsigned char* indata = (unsigned char*) malloc (framesize*2*sizeof(char));
unsigned char* outdata = (unsigned char*) malloc ((framesize*3+54)*sizeof(char));
FILE *in,*out;
if((in=fopen("back.yuv","rb"))==NULL)
{
printf("can't open data.yuv");
return 0;
}
if ((out = fopen("back.bmp","wb")) == NULL) {
printf("ERROR: can't write to rgb.bmp");
return 0;
}
fread(indata,framesize*2,1,in);
yuv422convertrgb (indata,outdata,width,height);
fwrite(outdata,(framesize*3+54),1,out);
fclose(out);
free(indata);
free(outdata);
return 1;
}
void yuv422convertrgb(unsigned char *yuv_ptr,unsigned char *rgb_ptr,int width,int height)
{
int i,j,k;
int framesize_rgb;
double rgb[3];
unsigned char yuv[3];
unsigned char *prgb,*pyuv;
unsigned char bmphead[] = {
0x42,0x4d,0x38,0xd2,0x0f,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
0x00,0x00,0xD0,0x02,0x00,0x00,0xe0,0x01,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00};
framesize_rgb = width * height * 3 + 54 ;
prgb = rgb_ptr;
for(i=0;i<54;i++)
*prgb++ = bmphead;
pyuv = yuv_ptr;
prgb = rgb_ptr + framesize_rgb - width * 3;
pyuv++;
for(j=0;j
{
k = 0;
for(i=1;i
{
if( k%2==0 )
{
yuv[0] = *pyuv--;
yuv[1] = *pyuv++;
yuv[2] = *(++pyuv);
pyuv++;
}
else
{
yuv[0] = *pyuv++;
yuv[1] = *pyuv--;
yuv[2] = *(--pyuv);
pyuv++;
pyuv++;
pyuv++;
}
yuvtorgb(rgb,yuv);
*prgb++ = (unsigned char )rgb[2];
*prgb++ = (unsigned char )rgb[1];
*prgb++ = (unsigned char )rgb[0];
}
prgb -= width * 3 * 2;
}
}
void yuvtorgb ( double *rgb,unsigned char *yuv)
{
int i;
rgb[0] = 1.0 * yuv[0] + 0 + 1.402 * (yuv[2] - 128); // r
rgb[1] = 1.0 * yuv[0] - 0.34413 * (yuv[1] - 128) - 0.71414 * (yuv[2]-128); // g
rgb[2] = 1.0 * yuv[0] + 1.772 * (yuv[1]-128) + 0; // b
for(i=0;i<3;i++)
{
if(rgb>255)
rgb = 255;
if(rgb<0)
rgb = 0;
}
}[/code]
[code]#include
#include
#include
void yuvtorgb(double *, unsigned char *);
void yuv422convertrgb(unsigned char *yuv_ptr,unsigned char *rgb_ptr,int width,int height);
int main()
{
int width = 640;
int height = 480;
int framesize = width * height;
unsigned char* indata = (unsigned char*) malloc (framesize*2*sizeof(char));
unsigned char* outdata = (unsigned char*) malloc ((framesize*3+54)*sizeof(char));
FILE *in,*out;
if((in=fopen("back.yuv","rb"))==NULL)
{
printf("can't open data.yuv");
return 0;
}
if ((out = fopen("back.bmp","wb")) == NULL) {
printf("ERROR: can't write to rgb.bmp");
return 0;
}
fread(indata,framesize*2,1,in);
yuv422convertrgb (indata,outdata,width,height);
fwrite(outdata,(framesize*3+54),1,out);
fclose(out);
free(indata);
free(outdata);
return 1;
}
void yuv422convertrgb(unsigned char *yuv_ptr,unsigned char *rgb_ptr,int width,int height)
{
int i,j,k;
int framesize_rgb;
double rgb[3];
unsigned char yuv[3];
unsigned char *prgb,*pyuv;
unsigned char bmphead[] = {
0x42,0x4d,0x38,0xd2,0x0f,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
0x00,0x00,0xD0,0x02,0x00,0x00,0xe0,0x01,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00};
framesize_rgb = width * height * 3 + 54 ;
prgb = rgb_ptr;
for(i=0;i<54;i++)
*prgb++ = bmphead;
pyuv = yuv_ptr;
prgb = rgb_ptr + framesize_rgb - width * 3;
pyuv++;
for(j=0;j
k = 0;
for(i=1;i
if( k%2==0 )
{
yuv[0] = *pyuv--;
yuv[1] = *pyuv++;
yuv[2] = *(++pyuv);
pyuv++;
}
else
{
yuv[0] = *pyuv++;
yuv[1] = *pyuv--;
yuv[2] = *(--pyuv);
pyuv++;
pyuv++;
pyuv++;
}
yuvtorgb(rgb,yuv);
*prgb++ = (unsigned char )rgb[2];
*prgb++ = (unsigned char )rgb[1];
*prgb++ = (unsigned char )rgb[0];
}
prgb -= width * 3 * 2;
}
}
void yuvtorgb ( double *rgb,unsigned char *yuv)
{
int i;
rgb[0] = 1.0 * yuv[0] + 0 + 1.402 * (yuv[2] - 128); // r
rgb[1] = 1.0 * yuv[0] - 0.34413 * (yuv[1] - 128) - 0.71414 * (yuv[2]-128); // g
rgb[2] = 1.0 * yuv[0] + 1.772 * (yuv[1]-128) + 0; // b
for(i=0;i<3;i++)
{
if(rgb>255)
rgb = 255;
if(rgb<0)
rgb = 0;
}
}[/code]
我来回答
回答1个
时间排序
认可量排序
认可0
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
2013-05-18 19:45:00
-
102015-12-14 11:35:36
-
2021-06-20 21:46:35
-
2021-06-20 21:45:10
-
2020-07-22 22:53:14
-
2015-05-16 14:44:08
-
2016-01-20 14:43:29
-
2016-10-27 17:50:12
-
2008-05-27 11:09:53
-
2016-11-08 10:14:09
-
2016-11-08 10:02:25
-
2008-07-18 20:42:04
-
2023-04-21 16:06:25
-
2014-12-05 13:55:19
-
2020-11-26 16:56:05
-
2018-05-04 18:18:53
-
2018-06-08 11:39:10
-
2010-06-01 23:25:04
-
2019-08-13 13:55:59
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5SS928的emmc有32GB,bootargs设置使用16GB,但是为啥能用的只有rootfs的大小
-
33SS928怎样烧写ubuntu系统
-
10ToolPlatform下载rootfs提示网络失败
-
10谁有GK7205V500的SDK
-
5Hi3516CV610 烧录不进去
-
10Hi3559AV100 芯片硬解码h265编码格式的视频时出现视频播放错误,解码错误信息 s32PackErr:码流有错
-
5海思SS928 / SD3403的sample_venc.c摄像头编码Demo中,采集到的摄像头的YUV数据在哪个相关的函数中?
-
5海鸥派openEuler无法启动网卡,连接WIFI存在问题
-
66有没有ISP相关的巨佬帮忙看看SS928对接IMX347的图像问题
-
50求助hi3559与FPGA通过SLVS-EC接口对接问题
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认