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

Fix Coverity issue #13526

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/proc/rotation-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,21 @@ namespace librealsense {

if (auto tgt = prepare_target_frame(f, source, tgt_type))
{
int rotated_width = ( _value == 90 || _value == -90 ) ? src.get_height() : src.get_width();
int rotated_height = ( _value == 90 || _value == -90 ) ? src.get_width() : src.get_height();

switch( bpp )
{
case 1: {
rotate_depth< 1 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ),
rotate_frame< 1 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ),
static_cast< const uint8_t * >( src.get_data() ),
rotated_height,
rotated_width );
src.get_height(),
src.get_width() );
break;
}

case 2: {
rotate_depth< 2 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ),
static_cast< const uint8_t * >( src.get_data() ),
rotated_height,
rotated_width );
rotate_frame< 2 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ),
static_cast< const uint8_t * >( src.get_data() ) ,
src.get_height(),
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved
src.get_width() );
break;
}

Expand Down Expand Up @@ -184,21 +181,24 @@ namespace librealsense {
}

template< size_t SIZE >
void rotation_filter::rotate_depth( uint8_t * const out, const uint8_t * source, int width, int height )
void rotation_filter::rotate_frame( uint8_t * const out, const uint8_t * source, int height, int width )
{
if( _value != 90 && _value != -90 && _value != 180 )
{
throw std::invalid_argument( "Invalid rotation angle. Only 90, -90, and 180 degrees are supported." );
}

int width_out = ( _value == 90 || _value == -90 ) ? height : width;
int height_out = ( _value == 90 || _value == -90 ) ? width : height;
int width_in = ( _value == 90 || _value == -90 ) ? height : width; //else rotation angle is 180
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved
int height_in = ( _value == 90 || _value == -90 ) ? width : height; //else rotation angle is 180

for( int i = 0; i < height; ++i )
int width_out = ( _value == 90 || _value == -90 ) ? _rotated_width : _rotated_height; //else rotation angle is 180
int height_out = ( _value == 90 || _value == -90 ) ? _rotated_height : _rotated_width; //else rotation angle is 180

for( int i = 0; i < width_in; ++i )
{
for( int j = 0; j < width; ++j )
for( int j = 0; j < height_in; ++j )
{
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved
size_t src_index = ( i * width + j ) * SIZE;
size_t src_index = ( i * height_in + j ) * SIZE;
size_t out_index;

if( _value == 90 )
Expand All @@ -217,7 +217,6 @@ namespace librealsense {
std::memcpy( &out[out_index], &source[src_index], SIZE );
}
}

}

}
Expand Down
2 changes: 1 addition & 1 deletion src/proc/rotation-filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace librealsense
rs2::frame prepare_target_frame(const rs2::frame& f, const rs2::frame_source& source, rs2_extension tgt_type);

template< size_t SIZE >
void rotate_depth( uint8_t * const out, const uint8_t * source, int width, int height );
void rotate_frame( uint8_t * const out, const uint8_t * source, int height, int width );

rs2::frame process_frame(const rs2::frame_source& source, const rs2::frame& f) override;

Expand Down
Loading