YUV to RGB conversion. RGB file structure?

♀尐吖头ヾ 提交于 2019-12-12 11:20:08

问题


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);
    }

回答1:


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?




回答2:


Try http://www.fourcc.org/rgb.php

This gives in depth structure for several flavors of rgb format.



来源:https://stackoverflow.com/questions/13753846/yuv-to-rgb-conversion-rgb-file-structure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!