YUV to RGB conversion. RGB file structure?

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

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

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


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

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

链接地址: http://www.djcxy.com/p/65908.html

上一篇: 从RGB到YUV没有转换

下一篇: YUV到RGB转换。 RGB文件结构?