-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler warning in pixel.hpp #688
Comments
The underlying channel type for grayscale pixels is a 32-bit float. If `Channel` cannot be losslessly converted to a float--for example, if it is `int`--this would generate a compiler warning. The fix here is to perform an explicit cast. Fixes boostorg#688.
After digging into this a bit more, I think the actual problem isn't the lack of a static_cast, but actually just a bug in a part of the code unrelated to my example above. If you look at the warning stack, the root of the problem is in compute_tensor_entries, a function in numeric.hpp that's only used in the harris corner example and its associated test. This code appears to be multiplying 2 16-bit shorts (producing a 32-bit integer), then assigning it to a 32-bit float grayscale pixel. Does this make sense? Shouldn't it be doing some sort of rescaling to make sure the value is between 0 and 1? |
@jsenn IIRC the values from Harris corner detector are already small. Either way, the PR from GSoC of 2021 #624 should make it clear that the image used for computations are just treated as matrix of floating point values. There is no implied or required normalization. I'm in a bit of a roaming state atm, but should be able to get the PR in merge-ready state until the end of summer. For now, if you have the time, you could try the example from there and see how it looks like. |
Thanks for the quick response @simmplecoder. Is there anything in #624 that would solve the issue with It seems to me (correct me if I'm wrong) that either:
|
Actual behavior
I get the following compiler warnings from pixel.hpp when using some gil functions:
This is in the grayscale pixel assign function, where it's assigning the int channel value directly to the float grayscale value without an explicit cast. Since not every int has a representation as a float, this is a loss of data, hence the warning. I guess the fix would be to add an explicit
static_cast<>
in there like the following?Expected behavior
No warning
C++ Minimal Working Example
Environment
Compiled in Visual Studio 2019 using MSVC with language standard set to latest (C++20).
The text was updated successfully, but these errors were encountered: