From 459f12b6b3cdfbe6c243e04e58ac379b6c27a723 Mon Sep 17 00:00:00 2001 From: Aryan Salmanpour Date: Tue, 10 Sep 2024 16:39:38 -0400 Subject: [PATCH] Increase the output image size for rgb and rgb_planar (#54) * Increase the output image size for rgb and rgb_planar to avoi * code clean up --- samples/rocjpeg_samples_utils.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/samples/rocjpeg_samples_utils.h b/samples/rocjpeg_samples_utils.h index ab474beb1c..b53a2a8080 100644 --- a/samples/rocjpeg_samples_utils.h +++ b/samples/rocjpeg_samples_utils.h @@ -376,12 +376,12 @@ public: case ROCJPEG_OUTPUT_RGB: num_channels = 1; output_image.pitch[0] = (is_roi_valid ? roi_width : widths[0]) * 3; - channel_sizes[0] = output_image.pitch[0] * (is_roi_valid ? roi_height : heights[0]); + channel_sizes[0] = align(output_image.pitch[0] * (is_roi_valid ? roi_height : heights[0]), mem_alignment); break; case ROCJPEG_OUTPUT_RGB_PLANAR: num_channels = 3; output_image.pitch[2] = output_image.pitch[1] = output_image.pitch[0] = is_roi_valid ? roi_width : widths[0]; - channel_sizes[2] = channel_sizes[1] = channel_sizes[0] = output_image.pitch[0] * (is_roi_valid ? roi_height : heights[0]); + channel_sizes[2] = channel_sizes[1] = channel_sizes[0] = align(output_image.pitch[0] * (is_roi_valid ? roi_height : heights[0]), mem_alignment); break; default: std::cout << "Unknown output format!" << std::endl; @@ -620,6 +620,7 @@ public: } private: + static const int mem_alignment = 1024 * 1024; /** * @brief Shows the help message and exits. * @@ -645,5 +646,17 @@ private: } exit(0); } + /** + * @brief Aligns a value to a specified alignment. + * + * This function takes a value and aligns it to the specified alignment. It returns the aligned value. + * + * @param value The value to be aligned. + * @param alignment The alignment value. + * @return The aligned value. + */ + static inline int align(int value, int alignment) { + return (value + alignment - 1) & ~(alignment - 1); + } }; #endif //ROC_JPEG_SAMPLES_COMMON