Skip to content

Commit

Permalink
librealsense::copy -> std::memcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Oct 14, 2023
1 parent cfd2d73 commit 3899ff0
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/ds/d400/d400-private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down
4 changes: 3 additions & 1 deletion src/ds/d500/d500-private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ds::d500_rgb_calibration_table&>(*table), intrinsics);

Expand Down
4 changes: 2 additions & 2 deletions src/ds/ds-calib-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/ds/ds-private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 10 additions & 8 deletions src/hw-monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 );
}
}

Expand All @@ -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
Expand Down Expand Up @@ -182,8 +182,10 @@ namespace librealsense
if( !newCommand.require_response )
return std::vector<uint8_t>();

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?
Expand Down Expand Up @@ -243,15 +245,15 @@ 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
{
std::vector<unsigned char> 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;
}
}
4 changes: 3 additions & 1 deletion src/hw-monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "uvc-sensor.h"
#include <mutex>
#include "platform/command-transfer.h"
#include <string>


namespace librealsense
{
Expand Down Expand Up @@ -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 );
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/mf/mf-uvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/proc/color-formats-converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1093,7 +1093,7 @@ namespace librealsense
auto in = reinterpret_cast<const uint8_t *>(source);
auto out = reinterpret_cast<uint8_t *>(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]);
Expand Down
6 changes: 3 additions & 3 deletions src/proc/depth-formats-converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/proc/motion-transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/proc/rotation-transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include <fstream>
#include <cmath>

#include "core/streaming.h"
#include "../include/librealsense2/hpp/rs_processing.hpp"
#include <librealsense2/hpp/rs_processing.hpp>

const double SQRT_DBL_EPSILON = sqrt(std::numeric_limits<double>::epsilon());

Expand Down Expand Up @@ -220,10 +219,4 @@ namespace librealsense
{
return _callback;
}

void copy(void* dst, void const* src, size_t size)
{
auto from = reinterpret_cast<uint8_t const*>(src);
std::copy(from, from + size, reinterpret_cast<uint8_t*>(dst));
}
}
2 changes: 0 additions & 2 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ namespace librealsense
return false;
}

void copy(void* dst, void const* src, size_t size);

///////////////////////
// Logging mechanism //
///////////////////////
Expand Down

0 comments on commit 3899ff0

Please sign in to comment.