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

[backport Galactic] Efficiently handle 3-bytes pixel formats (#743) #750

Merged
merged 1 commit into from Sep 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions rviz_common/src/rviz_common/interaction/selection_manager.cpp
Expand Up @@ -261,20 +261,23 @@ void SelectionManager::setHighlightRect(Ogre::Viewport * viewport, int x1, int y

void SelectionManager::unpackColors(const Ogre::PixelBox & box)
{
auto w = box.getWidth();
auto h = box.getHeight();
uint32_t w = box.getWidth();
uint32_t h = box.getHeight();

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 (uint32_t y = 0; y < h; y++) {
for (uint32_t x = 0; x < w; x++) {
uint32_t pos = static_cast<uint32_t>((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