diff --git a/samples/rocjpeg_samples_utils.h b/samples/rocjpeg_samples_utils.h index ab474be..b53a2a8 100644 --- a/samples/rocjpeg_samples_utils.h +++ b/samples/rocjpeg_samples_utils.h @@ -376,12 +376,12 @@ class RocJpegUtils { 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 @@ class RocJpegUtils { } private: + static const int mem_alignment = 1024 * 1024; /** * @brief Shows the help message and exits. * @@ -645,5 +646,17 @@ class RocJpegUtils { } 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