From c424a87a14b3f72a4b49f45bc530c13259535408 Mon Sep 17 00:00:00 2001 From: noacoohen Date: Tue, 19 Nov 2024 11:47:50 +0200 Subject: [PATCH] fix coverity issue --- src/proc/rotation-filter.cpp | 28 ++++++++++------------------ src/proc/rotation-filter.h | 2 +- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/proc/rotation-filter.cpp b/src/proc/rotation-filter.cpp index 6fe28f6a97..1f894b1a60 100644 --- a/src/proc/rotation-filter.cpp +++ b/src/proc/rotation-filter.cpp @@ -95,24 +95,17 @@ 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() ) ), - static_cast< const uint8_t * >( src.get_data() ), - rotated_height, - rotated_width ); + rotate_frame< 1 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ), + static_cast< const uint8_t * >( src.get_data() )); 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() ) ); break; } @@ -184,21 +177,21 @@ 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 ) { 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_out = ( _value == 90 || _value == -90 ) ? _rotated_width : _rotated_height; + int height_out = ( _value == 90 || _value == -90 ) ? _rotated_height : _rotated_width; - for( int i = 0; i < height; ++i ) + for( int i = 0; i < _rotated_width; ++i ) { - for( int j = 0; j < width; ++j ) + for( int j = 0; j < _rotated_height; ++j ) { - size_t src_index = ( i * width + j ) * SIZE; + size_t src_index = ( i * _rotated_height + j ) * SIZE; size_t out_index; if( _value == 90 ) @@ -217,7 +210,6 @@ namespace librealsense { std::memcpy( &out[out_index], &source[src_index], SIZE ); } } - } } diff --git a/src/proc/rotation-filter.h b/src/proc/rotation-filter.h index fa841b2d58..3030fc314b 100644 --- a/src/proc/rotation-filter.h +++ b/src/proc/rotation-filter.h @@ -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 ); rs2::frame process_frame(const rs2::frame_source& source, const rs2::frame& f) override;