From 3899ff0c5065cd16dd0939f8c86e13df050065b5 Mon Sep 17 00:00:00 2001 From: Eran Date: Sat, 14 Oct 2023 14:23:34 +0300 Subject: [PATCH] librealsense::copy -> std::memcpy --- src/ds/d400/d400-private.cpp | 2 +- src/ds/d500/d500-private.cpp | 4 +++- src/ds/ds-calib-parsers.cpp | 4 ++-- src/ds/ds-private.cpp | 2 +- src/hw-monitor.cpp | 18 ++++++++++-------- src/hw-monitor.h | 4 +++- src/mf/mf-uvc.cpp | 8 ++++---- src/proc/color-formats-converter.cpp | 4 ++-- src/proc/depth-formats-converter.cpp | 6 +++--- src/proc/motion-transform.cpp | 2 +- src/proc/rotation-transform.cpp | 2 +- src/types.cpp | 9 +-------- src/types.h | 2 -- 13 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/ds/d400/d400-private.cpp b/src/ds/d400/d400-private.cpp index 86aca2f1b32..d3cb525b6df 100644 --- a/src/ds/d400/d400-private.cpp +++ b/src/ds/d400/d400-private.cpp @@ -256,7 +256,7 @@ namespace librealsense intrin(1, 1) * height / 2.f, RS2_DISTORTION_INVERSE_BROWN_CONRADY // The coefficients shall be use for undistort }; - librealsense::copy(calc_intrinsic.coeffs, table->distortion, sizeof(table->distortion)); + std::memcpy(calc_intrinsic.coeffs, table->distortion, sizeof(table->distortion)); //LOG_DEBUG(endl << array2str((float_4&)(calc_intrinsic.fx, calc_intrinsic.fy, calc_intrinsic.ppx, calc_intrinsic.ppy)) << endl); static rs2_intrinsics ref{}; diff --git a/src/ds/d500/d500-private.cpp b/src/ds/d500/d500-private.cpp index 3ab924c4fdb..0d604d77f10 100644 --- a/src/ds/d500/d500-private.cpp +++ b/src/ds/d500/d500-private.cpp @@ -228,7 +228,9 @@ namespace librealsense intrinsics.ppx = rect_params[2]; intrinsics.ppy = rect_params[3]; intrinsics.model = table->rgb_coefficients_table.distortion_model; - librealsense::copy(intrinsics.coeffs, table->rgb_coefficients_table.distortion_coeffs, sizeof(intrinsics.coeffs)); + std::memcpy( intrinsics.coeffs, + table->rgb_coefficients_table.distortion_coeffs, + sizeof( intrinsics.coeffs ) ); update_table_to_correct_fisheye_distortion(const_cast(*table), intrinsics); diff --git a/src/ds/ds-calib-parsers.cpp b/src/ds/ds-calib-parsers.cpp index ec5e6ad7cd7..aa1e478576b 100644 --- a/src/ds/ds-calib-parsers.cpp +++ b/src/ds/ds-calib-parsers.cpp @@ -189,7 +189,7 @@ namespace librealsense if (_valid_extrinsic) { // extrinsic from calibration table, by user custom calibration, The extrinsic is stored as array of floats / little-endian - librealsense::copy(&_extr, &_calib_table.module_info.dm_v2_calib_table.depth_to_imu, sizeof(rs2_extrinsics)); + std::memcpy( &_extr, &_calib_table.module_info.dm_v2_calib_table.depth_to_imu, sizeof( rs2_extrinsics ) ); } else { @@ -300,7 +300,7 @@ namespace librealsense if (_valid_extrinsic) { // only in case valid extrinsic is available in calibration data by calibration script in future or user custom calibration - librealsense::copy(&_extr, &imu_calib_table.depth_to_imu, sizeof(rs2_extrinsics)); + std::memcpy( &_extr, &imu_calib_table.depth_to_imu, sizeof( rs2_extrinsics ) ); } else { diff --git a/src/ds/ds-private.cpp b/src/ds/ds-private.cpp index ed0c8c1e378..e2beb52c39a 100644 --- a/src/ds/ds-private.cpp +++ b/src/ds/ds-private.cpp @@ -35,7 +35,7 @@ namespace librealsense intrinsics.height = height; intrinsics.width = width; - librealsense::copy(intrinsics.coeffs, table->distortion, sizeof(table->distortion)); + std::memcpy( intrinsics.coeffs, table->distortion, sizeof( table->distortion ) ); LOG_DEBUG(endl << array2str((float_4&)(intrinsics.fx, intrinsics.fy, intrinsics.ppx, intrinsics.ppy)) << endl); diff --git a/src/hw-monitor.cpp b/src/hw-monitor.cpp index d835422f18a..b24b7e62372 100644 --- a/src/hw-monitor.cpp +++ b/src/hw-monitor.cpp @@ -55,7 +55,7 @@ namespace librealsense if (dataLength) { - librealsense::copy(writePtr + cur_index, data, dataLength); + std::memcpy( writePtr + cur_index, data, dataLength ); cur_index += dataLength; } @@ -112,7 +112,7 @@ namespace librealsense // throw invalid_value_exception("bulk transfer failed - user buffer too small"); inSize = std::min(res.size(),inSize); // For D457 only - librealsense::copy(in, res.data(), inSize); + std::memcpy( in, res.data(), inSize ); } } @@ -126,10 +126,10 @@ namespace librealsense throw invalid_value_exception("received incomplete response to usb command"); details.receivedCommandDataLength -= 4; - librealsense::copy(details.receivedOpcode.data(), outputBuffer, 4); + std::memcpy( details.receivedOpcode.data(), outputBuffer, 4 ); if (details.receivedCommandDataLength > 0) - librealsense::copy(details.receivedCommandData.data(), outputBuffer + 4, details.receivedCommandDataLength); + std::memcpy( details.receivedCommandData.data(), outputBuffer + 4, details.receivedCommandDataLength ); } void hw_monitor::send_hw_monitor_command(hwmon_cmd_details& details) const @@ -182,8 +182,10 @@ namespace librealsense if( !newCommand.require_response ) return std::vector(); - librealsense::copy(newCommand.receivedOpcode, details.receivedOpcode.data(), 4); - librealsense::copy(newCommand.receivedCommandData, details.receivedCommandData.data(), details.receivedCommandDataLength); + std::memcpy( newCommand.receivedOpcode, details.receivedOpcode.data(), 4 ); + std::memcpy( newCommand.receivedCommandData, + details.receivedCommandData.data(), + details.receivedCommandDataLength ); newCommand.receivedCommandDataLength = details.receivedCommandDataLength; // endian? @@ -243,7 +245,7 @@ namespace librealsense command command(gvd_cmd); auto data = send(command); auto minSize = std::min(sz, data.size()); - librealsense::copy(gvd, data.data(), minSize); + std::memcpy( gvd, data.data(), minSize ); } bool hw_monitor::is_camera_locked(uint8_t gvd_cmd, uint32_t offset) const @@ -251,7 +253,7 @@ namespace librealsense std::vector gvd(HW_MONITOR_BUFFER_SIZE); get_gvd(gvd.size(), gvd.data(), gvd_cmd); bool value; - librealsense::copy(&value, gvd.data() + offset, 1); + std::memcpy( &value, gvd.data() + offset, 1 ); return value; } } diff --git a/src/hw-monitor.h b/src/hw-monitor.h index 1d133324e11..91611070497 100644 --- a/src/hw-monitor.h +++ b/src/hw-monitor.h @@ -6,6 +6,8 @@ #include "uvc-sensor.h" #include #include "platform/command-transfer.h" +#include + namespace librealsense { @@ -296,7 +298,7 @@ namespace librealsense require_response(cmd.require_response), receivedCommandDataLength(0) { - librealsense::copy(data, cmd.data.data(), sizeOfSendCommandData); + std::memcpy( data, cmd.data.data(), sizeOfSendCommandData ); } }; diff --git a/src/mf/mf-uvc.cpp b/src/mf/mf-uvc.cpp index da3301a45d5..68122626613 100644 --- a/src/mf/mf-uvc.cpp +++ b/src/mf/mf-uvc.cpp @@ -362,13 +362,13 @@ namespace librealsense auto pStruct = next_struct; cfg.step.resize(option_range_size); - librealsense::copy(cfg.step.data(), pStruct, field_width); + std::memcpy( cfg.step.data(), pStruct, field_width ); pStruct += length; cfg.min.resize(option_range_size); - librealsense::copy(cfg.min.data(), pStruct, field_width); + std::memcpy( cfg.min.data(), pStruct, field_width ); pStruct += length; cfg.max.resize(option_range_size); - librealsense::copy(cfg.max.data(), pStruct, field_width); + std::memcpy( cfg.max.data(), pStruct, field_width ); return; } case KSPROPERTY_MEMBER_VALUES: @@ -386,7 +386,7 @@ namespace librealsense } cfg.def.resize(option_range_size); - librealsense::copy(cfg.def.data(), next_struct, field_width); + std::memcpy( cfg.def.data(), next_struct, field_width ); } return; } diff --git a/src/proc/color-formats-converter.cpp b/src/proc/color-formats-converter.cpp index 3e32c385724..77ebea3e717 100644 --- a/src/proc/color-formats-converter.cpp +++ b/src/proc/color-formats-converter.cpp @@ -1077,7 +1077,7 @@ namespace librealsense if (uncompressed_rgb) { auto uncompressed_size = w * h * bpp; - librealsense::copy(dest[0], uncompressed_rgb, uncompressed_size); + std::memcpy( dest[0], uncompressed_rgb, uncompressed_size ); stbi_image_free(uncompressed_rgb); } else @@ -1093,7 +1093,7 @@ namespace librealsense auto in = reinterpret_cast(source); auto out = reinterpret_cast(dest[0]); - librealsense::copy(out, in, count * 3); + std::memcpy( out, in, count * 3 ); for (auto i = 0; i < count; i++) { std::swap(out[i * 3], out[i * 3 + 2]); diff --git a/src/proc/depth-formats-converter.cpp b/src/proc/depth-formats-converter.cpp index 40e6c235df8..756b3896f1f 100644 --- a/src/proc/depth-formats-converter.cpp +++ b/src/proc/depth-formats-converter.cpp @@ -22,7 +22,7 @@ namespace librealsense #else for (int i = 0; i < count; ++i) *out_ir++ = *in++ >> 2; #endif - librealsense::copy(dest[0], in, count * 2); + std::memcpy( dest[0], in, count * 2 ); } void unpack_z16_y16_from_sr300_inzi(byte * const dest[], const byte * source, int width, int height, int actual_size) @@ -36,7 +36,7 @@ namespace librealsense #else for (int i = 0; i < count; ++i) *out_ir++ = *in++ << 6; #endif - librealsense::copy(dest[0], in, count * 2); + std::memcpy( dest[0], in, count * 2 ); } void unpack_inzi(rs2_format dst_ir_format, byte * const d[], const byte * s, int width, int height, int actual_size) @@ -83,7 +83,7 @@ namespace librealsense void copy_raw10(byte * const dest[], const byte * source, int width, int height, int actual_size) { auto count = width * height; // num of pixels - librealsense::copy(dest[0], source, size_t(5.0 * (count / 4.0))); + std::memcpy( dest[0], source, size_t( 5.0 * ( count / 4.0 ) ) ); } void unpack_y10bpack(byte * const dest[], const byte * source, int width, int height, int actual_size) diff --git a/src/proc/motion-transform.cpp b/src/proc/motion-transform.cpp index edaa004ba1c..f9ef263757b 100644 --- a/src/proc/motion-transform.cpp +++ b/src/proc/motion-transform.cpp @@ -26,7 +26,7 @@ namespace librealsense res = float3{ float(hid->x), float(hid->y), float(hid->z) } *float(factor); } - librealsense::copy(dest[0], &res, sizeof(float3)); + std::memcpy( dest[0], &res, sizeof( float3 ) ); } // The Accelerometer input format: signed int 16bit. data units 1LSB=0.001g; diff --git a/src/proc/rotation-transform.cpp b/src/proc/rotation-transform.cpp index 13e8c1e057a..2780e9eac0c 100644 --- a/src/proc/rotation-transform.cpp +++ b/src/proc/rotation-transform.cpp @@ -55,7 +55,7 @@ namespace librealsense for (int j = 0; j < width; ++j) { auto out_index = (((height_out - j) * width_out) - i - 1) * SIZE; - librealsense::copy((void*)(&out[out_index]), &(source[(row_offset + j) * SIZE]), SIZE); + std::memcpy( &out[out_index], &( source[( row_offset + j ) * SIZE] ), SIZE ); } } } diff --git a/src/types.cpp b/src/types.cpp index a866eff2ed4..23bbb3cdfc7 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -9,8 +9,7 @@ #include #include -#include "core/streaming.h" -#include "../include/librealsense2/hpp/rs_processing.hpp" +#include const double SQRT_DBL_EPSILON = sqrt(std::numeric_limits::epsilon()); @@ -220,10 +219,4 @@ namespace librealsense { return _callback; } - - void copy(void* dst, void const* src, size_t size) - { - auto from = reinterpret_cast(src); - std::copy(from, from + size, reinterpret_cast(dst)); - } } diff --git a/src/types.h b/src/types.h index 0987e7d6a06..6871da5bd0d 100644 --- a/src/types.h +++ b/src/types.h @@ -174,8 +174,6 @@ namespace librealsense return false; } - void copy(void* dst, void const* src, size_t size); - /////////////////////// // Logging mechanism // ///////////////////////