From 95a4a4f227efbb72b70553299783c3a166f02a82 Mon Sep 17 00:00:00 2001 From: Evgeni Raikhel Date: Mon, 29 Aug 2022 12:29:13 +0300 Subject: [PATCH] Fix cast/conversion issue when using mixed int/float types (cherry picked from commit 3e8b34a881ce21294ca917a05f52ff6e3c428c16) (cherry picked from commit 1f30ed7fcfb968c1309bd2f9475bc95428035edb) --- src/sensor.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sensor.cpp b/src/sensor.cpp index d7e633779e..66c8b136df 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -418,7 +418,7 @@ void log_callback_end( uint32_t fps, auto&& timestamp = fr->additional_data.timestamp; // D457 development - int expected_size; + size_t expected_size; auto&& msp = As(req_profile); if (msp) expected_size = 64;//32; // D457 - WORKAROUND - SHOULD BE REMOVED AFTER CORRECTION IN DRIVER @@ -476,8 +476,13 @@ void log_callback_end( uint32_t fps, } else { + // The calibration format Y12BPP is modified to be 32 bits instead of 24 due to an issue with MIPI driver + // and padding that occurs in transmission. + // For D4xx cameras the original 24 bit support is achieved by comparing actual vs expected size: + // when it is exactly 75% of the MIPI-generated size (24/32bpp), then 24bpp-sized image will be processed if (req_profile_base->get_format() == RS2_FORMAT_Y12I) - expected_size *= (expected_size * 3 / 4 == sizeof(byte) * f.frame_size) ? 3 / 4 : 1; + if (((expected_size>>2)*3)==sizeof(byte) * f.frame_size) + expected_size = sizeof(byte) * f.frame_size; assert(expected_size == sizeof(byte) * f.frame_size); memcpy((void*)fh->get_frame_data(), f.pixels, expected_size);