问题
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