YUV 到 RGB 的转换.RGB文件结构? [英] YUV to RGB conversion. RGB file structure?

查看:96
本文介绍了YUV 到 RGB 的转换.RGB文件结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将 YUV 文件转换为 RGB 文件时遇到问题.完成后,我无法使用 GIMP 或其他查看器打开 .rgb 文件,但我成功打开下载的 .rgb 文件.请告诉我RGB文件的结构是什么?(它是否包含标题?)是:1) 所有 R 值,然后是所有 G 值,然后是所有 B 值?2)循环(一R一G一B)*像素数?

I have a problem when converting YUV file to RGB file. When I am done I can't open .rgb file with GIMP or other viewers, but I succeed to open downloaded .rgb files. Please tell me what the structure of RGB file? (Does it contain a header?) Is it: 1) all R values, then all G values, then all B values? 2) loop (one R one G one B) * pixels count?

void convert_YUV_to_RGB (unsigned char  Y1, unsigned char  Y2, unsigned char  Y3, unsigned char  Y4, unsigned char  U, unsigned char  V) {

/*
//V1 for conversion YUV 420 -> RGB
//1.164*(Y - 16) + 1.596*(V - 128);
//1.164*(Y - 16) - 0.813*(V - 128) - 0.391*(U - 128);
//1.164*(Y - 16) + 2.018*(U - 128);
*/
rgb[rgb_counter++] = Y1 + 1.403*V;
rgb[rgb_counter++] = Y1 + -0.344 * U + -0.714 * V;      
rgb[rgb_counter++] = Y1 + 1.770 * U ;   

rgb[rgb_counter++] = Y2 + 1.403*V;
rgb[rgb_counter++] = Y2 + -0.344 * U + -0.714 * V;      
rgb[rgb_counter++] = Y2 + 1.770 * U ;   

rgb[rgb_counter++] = Y3 + 1.403*V;
rgb[rgb_counter++] = Y3 + -0.344 * U + -0.714 * V;      
rgb[rgb_counter++] = Y3 + 1.770 * U ;   

rgb[rgb_counter++] = Y4  + 1.403*V;
rgb[rgb_counter++] = Y4 + -0.344 * U + -0.714 * V;      
rgb[rgb_counter++] = Y4 + 1.770 * U ;   }


for each (int i in rgb) 
    {
        fputc(i, pRGBFile);
    }

推荐答案

您可以尝试将数据编写为 BMP 文件.IIRC,RGBs值交错;即 R1G1B1R2G2B2...RnGnBn

You could try to write the data as a BMP file. IIRC, the RGBs value are interleaved; i.e. R1G1B1R2G2B2...RnGnBn

当您说它不起作用"时,您的意思是程序无法打开文件还是颜色看起来不对?

When you say 'it doesn't work' do you mean the program fails to open the file or the colours look wrong?

这篇关于YUV 到 RGB 的转换.RGB文件结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆