From 5fbc835b4d2cd28545afd27371b7150ad13cd1b0 Mon Sep 17 00:00:00 2001 From: Aryan Salmanpour Date: Fri, 3 Oct 2025 14:02:27 -0700 Subject: [PATCH] Resolve an issue for saving decoded jpeg images (#190) * Resolve an issue for saving decoded jpeg images * update version and changelog * address review comment * clean up [ROCm/rocjpeg commit: 6ad29257da2608a74a9005a6e48da9fd7b9cf763] --- projects/rocjpeg/CHANGELOG.md | 11 +++++++++++ projects/rocjpeg/CMakeLists.txt | 2 +- projects/rocjpeg/samples/rocjpeg_samples_utils.h | 16 ++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/projects/rocjpeg/CHANGELOG.md b/projects/rocjpeg/CHANGELOG.md index 2a54375a24..3a6500445c 100644 --- a/projects/rocjpeg/CHANGELOG.md +++ b/projects/rocjpeg/CHANGELOG.md @@ -3,6 +3,17 @@ Documentation for rocJPEG is available at [https://rocm.docs.amd.com/projects/rocJPEG/en/latest/](https://rocm.docs.amd.com/projects/rocJPEG/en/latest/) +## (Unreleased) rocjpeg 1.2.0 + +## Added + +## Changed + +## Removed + +### Resolved issues +* Fixed an issue where extra padding was incorrectly included when saving decoded JPEG images to files. + ## rocjpeg 1.1.0 for ROCm 7.0.0 ## Added diff --git a/projects/rocjpeg/CMakeLists.txt b/projects/rocjpeg/CMakeLists.txt index 768c0f368d..3b8a80050e 100644 --- a/projects/rocjpeg/CMakeLists.txt +++ b/projects/rocjpeg/CMakeLists.txt @@ -42,7 +42,7 @@ endif() # rocjpeg Version # NOTE: package version and rocjpeg_version.h is generated with this version -set(VERSION "1.1.0") +set(VERSION "1.2.0") # Set Project Version and Language project(rocjpeg VERSION ${VERSION} LANGUAGES CXX) diff --git a/projects/rocjpeg/samples/rocjpeg_samples_utils.h b/projects/rocjpeg/samples/rocjpeg_samples_utils.h index 5630bb9a35..6fe4d0afa1 100644 --- a/projects/rocjpeg/samples/rocjpeg_samples_utils.h +++ b/projects/rocjpeg/samples/rocjpeg_samples_utils.h @@ -488,6 +488,7 @@ public: uint32_t widths[ROCJPEG_MAX_COMPONENT] = {}; uint32_t heights[ROCJPEG_MAX_COMPONENT] = {}; + uint32_t aliged_heights[ROCJPEG_MAX_COMPONENT] = {}; switch (output_format) { case ROCJPEG_OUTPUT_NATIVE: @@ -567,9 +568,12 @@ public: return; } - uint32_t channel0_size = output_image->pitch[0] * align(heights[0], mem_alignment); - uint32_t channel1_size = output_image->pitch[1] * align(heights[1], mem_alignment); - uint32_t channel2_size = output_image->pitch[2] * align(heights[2], mem_alignment); + aliged_heights[0] = align(heights[0], mem_alignment); + aliged_heights[1] = align(heights[1], mem_alignment); + aliged_heights[2] = align(heights[2], mem_alignment); + uint32_t channel0_size = output_image->pitch[0] * aliged_heights[0]; + uint32_t channel1_size = output_image->pitch[1] * aliged_heights[1]; + uint32_t channel2_size = output_image->pitch[2] * aliged_heights[2]; uint32_t output_image_size = channel0_size + channel1_size + channel2_size; @@ -583,7 +587,7 @@ public: fp = fopen(output_file_name.c_str(), "wb"); if (fp) { // write channel0 - if (widths[0] == output_image->pitch[0]) { + if (widths[0] == output_image->pitch[0] && heights[0] == aliged_heights[0]) { fwrite(hst_ptr, 1, channel0_size, fp); } else { for (int i = 0; i < heights[0]; i++) { @@ -595,7 +599,7 @@ public: if (channel1_size != 0 && output_image->channel[1] != nullptr) { uint8_t *channel1_hst_ptr = hst_ptr + channel0_size; CHECK_HIP(hipMemcpyDtoH((void *)channel1_hst_ptr, output_image->channel[1], channel1_size)); - if (widths[1] == output_image->pitch[1]) { + if (widths[1] == output_image->pitch[1] && heights[1] == aliged_heights[1]) { fwrite(channel1_hst_ptr, 1, channel1_size, fp); } else { for (int i = 0; i < heights[1]; i++) { @@ -608,7 +612,7 @@ public: if (channel2_size != 0 && output_image->channel[2] != nullptr) { uint8_t *channel2_hst_ptr = hst_ptr + channel0_size + channel1_size; CHECK_HIP(hipMemcpyDtoH((void *)channel2_hst_ptr, output_image->channel[2], channel2_size)); - if (widths[2] == output_image->pitch[2]) { + if (widths[2] == output_image->pitch[2] && heights[2] == aliged_heights[2]) { fwrite(channel2_hst_ptr, 1, channel2_size, fp); } else { for (int i = 0; i < heights[2]; i++) {