Visual C++ .NET bug?
-
this code works if compiled with VS6, but gives wrong results with VC++.NET
int Y,U,V,R,G,B; Y = lYUVColor.rgbRed; U = lYUVColor.rgbGreen - 128; V = lYUVColor.rgbBlue - 128; R = (int)(Y + 1.403 \* V); G = (int)(Y - 0.344 \* U - 0.714 \* V); B = (int)(Y + 1.770 \* U);
replaceing the declaration of Y, everything is ok.
int U,V,R,G,B; float Y = lYUVColor.rgbRed; U = lYUVColor.rgbGreen - 128; V = lYUVColor.rgbBlue - 128; R = (int)(Y + 1.403 \* V); G = (int)(Y - 0.344 \* U - 0.714 \* V); B = (int)(Y + 1.770 \* U);
where is the bug? in the compiler or in the code?
-
this code works if compiled with VS6, but gives wrong results with VC++.NET
int Y,U,V,R,G,B; Y = lYUVColor.rgbRed; U = lYUVColor.rgbGreen - 128; V = lYUVColor.rgbBlue - 128; R = (int)(Y + 1.403 \* V); G = (int)(Y - 0.344 \* U - 0.714 \* V); B = (int)(Y + 1.770 \* U);
replaceing the declaration of Y, everything is ok.
int U,V,R,G,B; float Y = lYUVColor.rgbRed; U = lYUVColor.rgbGreen - 128; V = lYUVColor.rgbBlue - 128; R = (int)(Y + 1.403 \* V); G = (int)(Y - 0.344 \* U - 0.714 \* V); B = (int)(Y + 1.770 \* U);
where is the bug? in the compiler or in the code?
Hi,, I think the problem is in the code :(
Y + 1.403 * V Y - 0.344 * U - 0.714 * V Y + 1.770 * U
(do you write a jpeg decoder/encoder?) you use U (an int) and Y (an int) so te hole equation uses ints which means loss of accuracy (int truncates what comes after the period) so when you use Y (float) the compiler does not truncate them... -
Hi,, I think the problem is in the code :(
Y + 1.403 * V Y - 0.344 * U - 0.714 * V Y + 1.770 * U
(do you write a jpeg decoder/encoder?) you use U (an int) and Y (an int) so te hole equation uses ints which means loss of accuracy (int truncates what comes after the period) so when you use Y (float) the compiler does not truncate them...hspc wrote: do you write a jpeg decoder/encoder? it's for CxImage you'are right, but 1.403 is not an integer, so the * operator should give a floating point result, while in this case the result seems an integer. :confused: in fact, another way to fix the problem is writing the constants with the "f" suffix: 1.403f and the routine works