From 72f2a3eaf54f175e6b9e3af983d4eaaaf08a023f Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 16 Aug 2021 18:39:54 +0200 Subject: [PATCH 1/3] Efficiently handle 3-bytes pixel formats Signed-off-by: ahcorde --- .../interaction/selection_manager.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/rviz_common/src/rviz_common/interaction/selection_manager.cpp b/rviz_common/src/rviz_common/interaction/selection_manager.cpp index 3bdef205e..22a28d628 100644 --- a/rviz_common/src/rviz_common/interaction/selection_manager.cpp +++ b/rviz_common/src/rviz_common/interaction/selection_manager.cpp @@ -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(static_cast(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++) { + uint32_t pos = (x + y * w) * size; + uint32_t pix_val = 0; + memcpy( + reinterpret_cast(&pix_val), + reinterpret_cast(box.data + pos), + size); + pixel_buffer_.push_back(colorToHandle(box.format, pix_val)); } } } From a2b315b3aaef916cc23732ed25f0d028fe84b626 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Tue, 17 Aug 2021 10:12:52 +0200 Subject: [PATCH 2/3] Added feedback Signed-off-by: ahcorde --- .../src/rviz_common/interaction/selection_manager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rviz_common/src/rviz_common/interaction/selection_manager.cpp b/rviz_common/src/rviz_common/interaction/selection_manager.cpp index 22a28d628..4ef7bdb14 100644 --- a/rviz_common/src/rviz_common/interaction/selection_manager.cpp +++ b/rviz_common/src/rviz_common/interaction/selection_manager.cpp @@ -261,16 +261,16 @@ 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); 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++) { + for (uint32_t y = 0; y < h; y++) { + for (uint32_t x = 0; x < w; x++) { uint32_t pos = (x + y * w) * size; uint32_t pix_val = 0; memcpy( From 679b8aff21db17a37416b953c810901e70abe933 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Tue, 17 Aug 2021 21:38:04 +0200 Subject: [PATCH 3/3] Fixed windows warnings Signed-off-by: ahcorde --- rviz_common/src/rviz_common/interaction/selection_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rviz_common/src/rviz_common/interaction/selection_manager.cpp b/rviz_common/src/rviz_common/interaction/selection_manager.cpp index 4ef7bdb14..73e589462 100644 --- a/rviz_common/src/rviz_common/interaction/selection_manager.cpp +++ b/rviz_common/src/rviz_common/interaction/selection_manager.cpp @@ -271,7 +271,7 @@ void SelectionManager::unpackColors(const Ogre::PixelBox & box) for (uint32_t y = 0; y < h; y++) { for (uint32_t x = 0; x < w; x++) { - uint32_t pos = (x + y * w) * size; + uint32_t pos = static_cast((x + y * w) * size); uint32_t pix_val = 0; memcpy( reinterpret_cast(&pix_val),