From 44f74c4958534f7484d3d47add142b85a703aad5 Mon Sep 17 00:00:00 2001 From: Aryan Salmanpour Date: Wed, 26 Jun 2024 09:00:45 -0400 Subject: [PATCH] Use the standard .yuv and .rgb file extensions when saving the decoded jpeg outputs (#34) * Use the standard .yuv and .rgb file extensions when saving the decoded jpeg outputs * modify the file description for saving --- samples/jpegDecode/jpegdecode.cpp | 2 +- .../jpegDecodeBatched/jpegdecodebatched.cpp | 2 +- .../jpegdecodemultithreads.cpp | 2 +- samples/rocjpeg_samples_utils.h | 35 ++++++++++++++++--- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/samples/jpegDecode/jpegdecode.cpp b/samples/jpegDecode/jpegdecode.cpp index d47d1aae19..7210ee3119 100644 --- a/samples/jpegDecode/jpegdecode.cpp +++ b/samples/jpegDecode/jpegdecode.cpp @@ -127,7 +127,7 @@ int main(int argc, char **argv) { if (save_images) { std::string image_save_path = output_file_path; if (is_dir) { - rocjpeg_utils.GetOutputFileExt(decode_params.output_format, base_file_name, widths[0], heights[0], image_save_path); + rocjpeg_utils.GetOutputFileExt(decode_params.output_format, base_file_name, widths[0], heights[0], subsampling, image_save_path); } rocjpeg_utils.SaveImage(image_save_path, &output_image, widths[0], heights[0], subsampling, decode_params.output_format); } diff --git a/samples/jpegDecodeBatched/jpegdecodebatched.cpp b/samples/jpegDecodeBatched/jpegdecodebatched.cpp index dcf6f20ffa..7e34aa147d 100644 --- a/samples/jpegDecodeBatched/jpegdecodebatched.cpp +++ b/samples/jpegDecodeBatched/jpegdecodebatched.cpp @@ -148,7 +148,7 @@ int main(int argc, char **argv) { for (int b = 0; b < current_batch_size; b++) { std::string image_save_path = output_file_path; if (is_dir) { - rocjpeg_utils.GetOutputFileExt(decode_params.output_format, base_file_names[b], widths[b][0], heights[b][0], image_save_path); + rocjpeg_utils.GetOutputFileExt(decode_params.output_format, base_file_names[b], widths[b][0], heights[b][0], subsamplings[b], image_save_path); } rocjpeg_utils.SaveImage(image_save_path, &output_images[b], widths[b][0], heights[b][0], subsamplings[b], decode_params.output_format); } diff --git a/samples/jpegDecodeMultiThreads/jpegdecodemultithreads.cpp b/samples/jpegDecodeMultiThreads/jpegdecodemultithreads.cpp index 27343b41ef..2871c5d11d 100644 --- a/samples/jpegDecodeMultiThreads/jpegdecodemultithreads.cpp +++ b/samples/jpegDecodeMultiThreads/jpegdecodemultithreads.cpp @@ -99,7 +99,7 @@ void ThreadFunction(std::vector& jpegFiles, RocJpegHandle rocjpeg_h if (save_images) { std::string image_save_path = output_file_path; - rocjpeg_util.GetOutputFileExt(decode_params.output_format, base_file_name, widths[0], heights[0], image_save_path); + rocjpeg_util.GetOutputFileExt(decode_params.output_format, base_file_name, widths[0], heights[0], subsampling, image_save_path); rocjpeg_util.SaveImage(image_save_path, output_image, widths[0], heights[0], subsampling, decode_params.output_format); } diff --git a/samples/rocjpeg_samples_utils.h b/samples/rocjpeg_samples_utils.h index c6ac257e77..d429325c55 100644 --- a/samples/rocjpeg_samples_utils.h +++ b/samples/rocjpeg_samples_utils.h @@ -360,32 +360,57 @@ public: * @param image_height The image height. * @param file_name_for_saving The string to store the file name for saving. */ - void GetOutputFileExt(RocJpegOutputFormat output_format, std::string &base_file_name, uint32_t image_width, uint32_t image_height, std::string &file_name_for_saving) { + void GetOutputFileExt(RocJpegOutputFormat output_format, std::string &base_file_name, uint32_t image_width, uint32_t image_height, RocJpegChromaSubsampling subsampling, std::string &file_name_for_saving) { std::string file_extension; std::string::size_type const p(base_file_name.find_last_of('.')); std::string file_name_no_ext = base_file_name.substr(0, p); + std::string format_description = ""; switch (output_format) { case ROCJPEG_OUTPUT_NATIVE: - file_extension = "native"; + file_extension = "yuv"; + switch (subsampling) { + case ROCJPEG_CSS_444: + format_description = "444"; + break; + case ROCJPEG_CSS_440: + format_description = "440"; + break; + case ROCJPEG_CSS_422: + format_description = "422_yuyv"; + break; + case ROCJPEG_CSS_420: + format_description = "nv12"; + break; + case ROCJPEG_CSS_400: + format_description = "400"; + break; + default: + std::cout << "Unknown chroma subsampling!" << std::endl; + return; + } break; case ROCJPEG_OUTPUT_YUV_PLANAR: file_extension = "yuv"; + format_description = "planar"; break; case ROCJPEG_OUTPUT_Y: - file_extension = "y"; + file_extension = "yuv"; + format_description = "400"; break; case ROCJPEG_OUTPUT_RGB: file_extension = "rgb"; + format_description = "packed"; break; case ROCJPEG_OUTPUT_RGB_PLANAR: - file_extension = "rgb_planar"; + file_extension = "rgb"; + format_description = "planar"; break; default: file_extension = ""; break; } file_name_for_saving += "//" + file_name_no_ext + "_" + std::to_string(image_width) + "x" - + std::to_string(image_height) + "." + file_extension; + + std::to_string(image_height) + "_" + format_description + "." + file_extension; } /**