Skip to content
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

Efficiently handle 3-bytes pixel formats #743

Merged
merged 3 commits into from
Aug 19, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions rviz_common/src/rviz_common/interaction/selection_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,17 @@ void SelectionManager::unpackColors(const Ogre::PixelBox & box)
pixel_buffer_.clear();
pixel_buffer_.reserve(w * h);

for (uint32_t y = 0; y < h; ++y) {
for (uint32_t x = 0; x < w; ++x) {
uint32_t pos = (x + y * w) * 4;

uint32_t pix_val = *reinterpret_cast<uint32_t *>(static_cast<uint8_t *>(box.data) + pos);
uint32_t handle = colorToHandle(box.format, pix_val);

pixel_buffer_.push_back(handle);
size_t size = Ogre::PixelUtil::getMemorySize(1, 1, 1, box.format);

for (unsigned int y = 0; y < h; y++) {
for (unsigned int x = 0; x < w; x++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (unsigned int y = 0; y < h; y++) {
for (unsigned int x = 0; x < w; x++) {
for (uint32_t y = 0; y < h; y++) {
for (uint32_t x = 0; x < w; x++) {

(as far as I can tell, these are always uint32_t in https://github.com/OGRECave/ogre/blob/master/OgreMain/include/OgreCommon.h#L789-L791)

(it would also be awesome to use uint32_t for w and h above)

uint32_t pos = (x + y * w) * size;
uint32_t pix_val = 0;
memcpy(
reinterpret_cast<uint8_t *>(&pix_val),
reinterpret_cast<uint8_t *>(box.data + pos),
size);
pixel_buffer_.push_back(colorToHandle(box.format, pix_val));
}
}
}
Expand Down