-
Couldn't load subscription status.
- Fork 46
Add function for extracting single channel data from an RGB[A] image #706
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 <[email protected]>
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 like there are some test failures.
| for (unsigned int y = 0; y < height; ++y) | ||
| { | ||
| for (unsigned int x = 0; x < width; ++x) | ||
| { | ||
| // RGBA so 4 bytes per pixel, alpha fully opaque | ||
| unsigned int colorB = metalnessData8bit[y * width + x]; | ||
| unsigned int colorG = roughnessData8bit[y * width + x]; | ||
| auto baseIndex = bytesPerPixel * (y * width + x); | ||
| auto color = _img.Pixel(x, (height - y - 1)); | ||
| metalnessData[baseIndex] = color.B() * 255.0; | ||
| metalnessData[baseIndex + 1] = color.B() * 255.0; | ||
| metalnessData[baseIndex + 2] = color.B() * 255.0; | ||
| metalnessData[baseIndex] = colorB; | ||
| metalnessData[baseIndex + 1] = colorB; | ||
| metalnessData[baseIndex + 2] = colorB; | ||
| metalnessData[baseIndex + 3] = 255; | ||
| roughnessData[baseIndex] = color.G() * 255.0; | ||
| roughnessData[baseIndex + 1] = color.G() * 255.0; | ||
| roughnessData[baseIndex + 2] = color.G() * 255.0; | ||
| roughnessData[baseIndex] = colorG; | ||
| roughnessData[baseIndex + 1] = colorG; | ||
| roughnessData[baseIndex + 2] = colorG; | ||
| roughnessData[baseIndex + 3] = 255; |
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.
If we also had a Image::SetChannelData function, we can use that instead of this nested for loop and avoid unnecessary memory allocations for the temporary std::vectors. Not sure how feasible that is.
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.
Saw that there's a FreeImage_SetChannel for helping to do this. But it requires converting the data back to FIBITMAP so not sure if it's more efficient. For now, I ticketed an issue for this #708
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.
Okay, let's investigate this some other time then. I raised this just because I noticed the creation of the std::vectors was a significant part of the cost of this function, so I was hoping we would directly write to the Image object we create below.
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
|
The windows test failures look unrelated, likely a CI machine issue The macOS github action build failure seems to be affected by actions/runner-images#12912 Given that the jenkins homebrew build is green, I'll merge this PR. |
|
@Mergifyio backport gz-common6 gz-common5 |
✅ Backports have been created
|
…706) Signed-off-by: Ian Chen <[email protected]> (cherry picked from commit e481234)
…706) Signed-off-by: Ian Chen <[email protected]> (cherry picked from commit e481234) # Conflicts: # graphics/src/AssimpLoader.cc
…706) Signed-off-by: Ian Chen <[email protected]> (cherry picked from commit e481234)
…706) Signed-off-by: Ian Chen <[email protected]> (cherry picked from commit e481234) Signed-off-by: Ian Chen <[email protected]> # Conflicts: # graphics/src/AssimpLoader.cc
…706) Signed-off-by: Ian Chen <[email protected]> (cherry picked from commit e481234) Signed-off-by: Ian Chen <[email protected]> # Conflicts: # graphics/src/AssimpLoader.cc
🎉 New feature
Related to gazebosim/jetty_demo#3
Summary
Adds a new
Image::ChannelDatafunction to help extract a single channel (r, g, b, or a) from an RGB[A] image.Thanks for profiling data from @azeey, it was found when loading the Jetty demo world a big chunk of time is spend on splitting the metallic and roughness maps of glb meshes. The main cause of slow down is found to be the Image::Pixel function as the AssimpLoader iterates through every pixel in the image. With the new
Image::ChannelDatafunction, the AssimpLoader now has a faster and more efficient way of retrieving different channels of the input image.Note that the perf issue with
Image::Pixelfunction was also noticed in #699 (comment). Some changes were made to speed it up but seems like it's still not efficient. We'll need to revisit this later on.For the Jetty demo world, the speed up for splitting the channels of an image was found to be >10x. See example timings (seconds):
The load time for the demo world reduced from 42s (with gazebosim/gz-sim#3070) to 30s on my machine.
Checklist
codecheckpassed (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-byandGenerated-bymessages.