Values passed to the put function don't have any effect
Hello. I have this code :
that should print the value decided by the min function in a tga image file. When I open the file, all I see it is a huge black screen. You may be thinking that the values of blue,green and red are all zero but it is not the case.
With this code:
I get
If I change
to this for instance:
I receive the expected blue image.
So the three variables blue,green and red are being evaluated as 0.0f, even though they aren't, they are 0.x, 0.y, 0.z, and multiplied by 255 they end being greater than zero as I showed in the above code.
Another weird thing is that if I interrupt the program earlier, skipping lot of calculations and sending some different values of blue,green and red, 0.177, 0.555 and 0.888 respectively, it works
In some moment doing some tests I received a warning message saying something like: "left side assignment has no effect" but then It didn't show up again.
So, anyone has a clue about what might be happening ?
Many thanks.
tgaManager.fileWriter.put((unsigned char)min(blue*255.0f,255.0f)).put((unsigned char)min(green*255.0f, 255.0f)).put((unsigned char)min(red*255.0f, 255.0f));
that should print the value decided by the min function in a tga image file. When I open the file, all I see it is a huge black screen. You may be thinking that the values of blue,green and red are all zero but it is not the case.
With this code:
if (x==50 && y==50) {
cout << "Min BGR: " << endl;
cout << min (blue*255.0f,255.0f) << ' ' << min (green*255.0f,255.0f) << ' ' << min (red*255.0f,255.0f) << ' ' << x << ' ' << y << endl;
}I get
with it is anything but pure black and also it is the value that I expected for this pixel.Min BGR:
9.54167 29.9188 47.8701 50 50
If I change
tgaManager.fileWriter.put((unsigned char)min(blue*255.0f,255.0f)).put((unsigned char)min(green*255.0f, 255.0f)).put((unsigned char)min(red*255.0f, 255.0f));
to this for instance:
tgaManager.fileWriter.put((unsigned char)min(255.0f,255.0f)).put((unsigned char)min(0.0f, 0.0f)).put((unsigned char)min(0.0f, 0.0f));
I receive the expected blue image.
So the three variables blue,green and red are being evaluated as 0.0f, even though they aren't, they are 0.x, 0.y, 0.z, and multiplied by 255 they end being greater than zero as I showed in the above code.
Another weird thing is that if I interrupt the program earlier, skipping lot of calculations and sending some different values of blue,green and red, 0.177, 0.555 and 0.888 respectively, it works
In some moment doing some tests I received a warning message saying something like: "left side assignment has no effect" but then It didn't show up again.
So, anyone has a clue about what might be happening ?
Many thanks.
Comments
You've stated yourself that the values of red/green/blue in testing are all greater than 1.
if blue is always > 1, blue * 255.0f will always be larger than 255.0f. This makes your minimums return 255.0f every time. 255f casted to unsigned char is 0 on little endian systems. That is why you're getting black for everything.