-
Notifications
You must be signed in to change notification settings - Fork 46
Support reading pixel values from color 16 bit images #699
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
Conversation
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, one nit and one more substantial comment on a duplicated implementation
|
||
|
||
///////////////////////////////////////////////// | ||
TEST_F(ImageTest, Color16bit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this test doesn't actually test the API that had the problematic behavior (Image.Pixel(x, y)
) or rather, it only does so in a indirect way, specifically it only tests img.MaxColor()
, which in this specific code path calls Image::Implementation::PixelIndex
which happens to be what also Pixel
would call because their logic is duplicated.
I have two alternative proposals:
- (My preference), I saw that
MaxColor
andPixel
have pretty much the same duplicated logic, which also shows in this PR's diff that has the same change implemented twice. What if we refactored so allMaxColor
does is effectively just callPixel
in a loop and we only had the logic inPixel
? - If the above is not possible, we should at least add a test for
Pixel
in these cases, so we make sure that function's implementation is correct as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep good idea, went with 1 and done in 0e307e7. I noticed that after refactoring MaxColor()
to call Pixel(...)
, the Image test took a long time to run. Turns out it's due to repeatedly calling FreeImage_GetColorType
which seems to be an expensive call. I now made it a member variable and initialize it when the image is first loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great thanks for iterating so quickly! Appreciate that we got rid of the duplicated implementation as well!
I do wish there was const-by-default throughout but it's just my Rust self talking and would explode the diff 😅, this is good to go!
@Mergifyio backport gz-common6 gz-common5 |
✅ Backports have been created
|
🎉 New feature
Closes #698
Summary
Add support for reading RGB[A] 16 bit images.
Similar to what's done in #439, this PR redirects the
Pixel(...)
function calls to use thePixelIndex(...)
function which has been extended to support 16 bit color image formats.Note: this PR does not entirely address the issue with the confusing flood of console messages about
Image coordinates out of range..
when a format is not supported, see #698 (comment). The message is changed to a more generic one, i.e.Failed to to get pixel value at..
so it does not lead the user down the wrong path. We should still tackle this issue but we can do that in a separate PR.Test it
Run the
UNIT_Image_TEST
Checklist
codecheck
passed (See contributing)Generated-by: Remove this if GenAI was not used.
Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
andGenerated-by
messages.