From c424a87a14b3f72a4b49f45bc530c13259535408 Mon Sep 17 00:00:00 2001 From: noacoohen Date: Tue, 19 Nov 2024 11:47:50 +0200 Subject: [PATCH 1/5] 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; From da07459665b0266b97feb064ae7e57526aa470bf Mon Sep 17 00:00:00 2001 From: noacoohen Date: Tue, 19 Nov 2024 15:56:39 +0200 Subject: [PATCH 2/5] fix PR comments --- src/proc/rotation-filter.cpp | 23 +++++++++++++++-------- src/proc/rotation-filter.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/proc/rotation-filter.cpp b/src/proc/rotation-filter.cpp index 1f894b1a60..ead0e5d068 100644 --- a/src/proc/rotation-filter.cpp +++ b/src/proc/rotation-filter.cpp @@ -99,13 +99,17 @@ namespace librealsense { { case 1: { rotate_frame< 1 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ), - static_cast< const uint8_t * >( src.get_data() )); + static_cast< const uint8_t * >( src.get_data() ), + src.get_height(), + src.get_width() ); break; } case 2: { rotate_frame< 2 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ), - static_cast< const uint8_t * >( src.get_data() ) ); + static_cast< const uint8_t * >( src.get_data() ) , + src.get_height(), + src.get_width() ); break; } @@ -177,21 +181,24 @@ namespace librealsense { } template< size_t SIZE > - void rotation_filter::rotate_frame( uint8_t * const out, const uint8_t * source ) + 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 ) ? _rotated_width : _rotated_height; - int height_out = ( _value == 90 || _value == -90 ) ? _rotated_height : _rotated_width; + int width_in = ( _value == 90 || _value == -90 ) ? height : width; //else rotation angle is 180 + int height_in = ( _value == 90 || _value == -90 ) ? width : height; //else rotation angle is 180 - for( int i = 0; i < _rotated_width; ++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 < _rotated_height; ++j ) + for( int j = 0; j < height_in; ++j ) { - size_t src_index = ( i * _rotated_height + j ) * SIZE; + size_t src_index = ( i * height_in + j ) * SIZE; size_t out_index; if( _value == 90 ) diff --git a/src/proc/rotation-filter.h b/src/proc/rotation-filter.h index 3030fc314b..31bf65c99d 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_frame( uint8_t * const out, const uint8_t * source ); + 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; From 6354e60fd9fd18bfb9a6450a6d85fd36a8fb9a50 Mon Sep 17 00:00:00 2001 From: noacoohen Date: Tue, 19 Nov 2024 17:00:29 +0200 Subject: [PATCH 3/5] fix PR comments --- src/proc/rotation-filter.cpp | 40 +++++++++++++++++++----------------- src/proc/rotation-filter.h | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/proc/rotation-filter.cpp b/src/proc/rotation-filter.cpp index ead0e5d068..cb9e1976d2 100644 --- a/src/proc/rotation-filter.cpp +++ b/src/proc/rotation-filter.cpp @@ -100,16 +100,16 @@ namespace librealsense { case 1: { rotate_frame< 1 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ), static_cast< const uint8_t * >( src.get_data() ), - src.get_height(), - src.get_width() ); + src.get_width(), + src.get_height() ); break; } case 2: { rotate_frame< 2 >( static_cast< uint8_t * >( const_cast< void * >( tgt.get_data() ) ), static_cast< const uint8_t * >( src.get_data() ) , - src.get_height(), - src.get_width() ); + src.get_width(), + src.get_height()); break; } @@ -181,39 +181,41 @@ namespace librealsense { } template< size_t SIZE > - void rotation_filter::rotate_frame( uint8_t * const out, const uint8_t * source, int height, int width ) + void rotation_filter::rotate_frame( uint8_t * const out, const uint8_t * source, int width, int height ) { if( _value != 90 && _value != -90 && _value != 180 ) { throw std::invalid_argument( "Invalid rotation angle. Only 90, -90, and 180 degrees are supported." ); } - int width_in = ( _value == 90 || _value == -90 ) ? height : width; //else rotation angle is 180 - int height_in = ( _value == 90 || _value == -90 ) ? width : height; //else rotation angle is 180 + // Define output dimensions + int width_out = ( _value == 180 ) ? width : height; + int height_out = ( _value == 180 ) ? height : width; - 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 ) + // Perform rotation + for( int i = 0; i < height; ++i ) { - for( int j = 0; j < height_in; ++j ) + for( int j = 0; j < width; ++j ) { - size_t src_index = ( i * height_in + j ) * SIZE; - size_t out_index; + // Calculate source index + size_t src_index = ( i * width + j ) * SIZE; + // Determine output index based on rotation angle + size_t out_index; if( _value == 90 ) { - out_index = ( j * width_out + ( width_out - i - 1 ) ) * SIZE; + out_index = ( j * height + ( height - i - 1 ) ) * SIZE; } else if( _value == -90 ) { - out_index = ( ( height_out - j - 1 ) * width_out + i ) * SIZE; + out_index = ( ( width - j - 1 ) * height + i ) * SIZE; } - else - { // 180 degrees - out_index = ( ( height_out - i - 1 ) * width_out + ( width_out - j - 1 ) ) * SIZE; + else // 180 degrees + { + out_index = ( ( height - i - 1 ) * width + ( width - j - 1 ) ) * SIZE; } + // Copy pixel data from source to destination std::memcpy( &out[out_index], &source[src_index], SIZE ); } } diff --git a/src/proc/rotation-filter.h b/src/proc/rotation-filter.h index 31bf65c99d..f5a542e21d 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_frame( uint8_t * const out, const uint8_t * source, int height, int width ); + void rotate_frame( uint8_t * const out, const uint8_t * source, int width, int height ); rs2::frame process_frame(const rs2::frame_source& source, const rs2::frame& f) override; From 6174446659103aad5edb0f3fbf9167dae5c3d4aa Mon Sep 17 00:00:00 2001 From: noacoohen Date: Tue, 19 Nov 2024 17:05:30 +0200 Subject: [PATCH 4/5] add comment --- src/proc/rotation-filter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proc/rotation-filter.cpp b/src/proc/rotation-filter.cpp index cb9e1976d2..55782f47b5 100644 --- a/src/proc/rotation-filter.cpp +++ b/src/proc/rotation-filter.cpp @@ -189,8 +189,8 @@ namespace librealsense { } // Define output dimensions - int width_out = ( _value == 180 ) ? width : height; - int height_out = ( _value == 180 ) ? height : width; + int width_out = ( _value == 180 ) ? width : height; // else 90 or -90 degrees rotation + int height_out = ( _value == 180 ) ? height : width; // else 90 or -90 degrees rotation // Perform rotation for( int i = 0; i < height; ++i ) From 9e51a1a44f0a147ed6f9975250a405614b0e5a21 Mon Sep 17 00:00:00 2001 From: noacoohen Date: Tue, 19 Nov 2024 17:08:25 +0200 Subject: [PATCH 5/5] fix PR comments --- src/proc/rotation-filter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proc/rotation-filter.cpp b/src/proc/rotation-filter.cpp index 55782f47b5..c3654280ca 100644 --- a/src/proc/rotation-filter.cpp +++ b/src/proc/rotation-filter.cpp @@ -189,8 +189,8 @@ namespace librealsense { } // Define output dimensions - int width_out = ( _value == 180 ) ? width : height; // else 90 or -90 degrees rotation - int height_out = ( _value == 180 ) ? height : width; // else 90 or -90 degrees rotation + int width_out = ( _value == 90 || _value == -90 ) ? height : width; // rotate by 180 will keep the values as is + int height_out = ( _value == 90 || _value == -90 ) ? width : height; // rotate by 180 will keep the values as is // Perform rotation for( int i = 0; i < height; ++i )