4

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);
    }
alexander_va
  • 143
  • 7

2 Answers2

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?

James
  • 9,064
  • 3
  • 31
  • 49
  • Sorry for my slow reaction. I meant that program fails to open file. BTW, I didn't make any header for my RGB file. At link that you provided, there is a perfect image showing structure of a BMP file, unfortunately I didn't find same picture for RGB files. – alexander_va Dec 10 '12 at 17:03
  • 1
    Here is the `RGB` format. http://en.wikipedia.org/wiki/Silicon_Graphics_Image The OP could also use the Imagemagik tools to convert image files. – artless noise Mar 03 '13 at 00:19
0

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

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

jim mcnamara
  • 16,005
  • 2
  • 34
  • 51