Quote:

Originally Posted by

It's just a rounding issue. The 601 and 709 specifications want you to round up for integers. If you do the floating point math, you'll see that Y = 63 (0x3f), Cb = 102 (0x66) and Cr = 240 (0xf0) converts to R = 235.4406, G = 16.502108 and B = 15.831311. The 16.502108 gets rounded up to 17. Here's the floating point code (for video RGB levels):

http://www.w6rz.net/yuvtorgbcalc.zip

Ron

**dr1394**It's just a rounding issue. The 601 and 709 specifications want you to round up for integers. If you do the floating point math, you'll see that Y = 63 (0x3f), Cb = 102 (0x66) and Cr = 240 (0xf0) converts to R = 235.4406, G = 16.502108 and B = 15.831311. The 16.502108 gets rounded up to 17. Here's the floating point code (for video RGB levels):

Code:

/* Converts YUV to RGB floating point */ #include #include #define TRUE 1 #define FALSE 0 /* color space conversion coefficients * for YCbCr -> RGB mapping * * entries are {crv,cbu,cgu,cgv} * * crv=(219/224)*(1-cr)/0.5 * cbu=(219/224)*(1-cb)/0.5 * cgu=(219/224)*(cb/cg)*(1-cb)/0.5 * cgv=(219/224)*(cr/cg)*(1-cr)/0.5 * * where Y=cr*R+cg*G+cb*B (cr+cg+cb=1) */ /* ITU-R BT709-5 (2002) coefficients */ /* cg = 0.7152 */ /* cb = 0.0722 */ /* cr = 0.2126 */ int main(int argc, char **argv) { int y, cr, cb; double r, g, b; if (argc != 4) { fprintf(stderr, "usage: yuvtorgbcalc \ "); exit(-1); } y = atoi(argv[1]); cb = atoi(argv[2]); cr = atoi(argv[3]); r = (double)y + 1.5396482142857 * (double)(cr - 128); g = (double)y - 0.4576750704098 * (double)(cr - 128) - 0.18314292755273 * (double)(cb - 128); b = (double)y + 1.814180357142857 * (double)(cb - 128); printf("R = %f, G = %f, B = %f\ ", r, g, b); return 0; }

Ron

It amazes me how you have some code for every question I ask.

You don't have the source for a time machine laying around do you? I was thinking I could jump forward a few weeks, ask myself all the questions I have, and then jump back to save us all some time and trouble