Add support for adding a new struct RocJpegDecodeParams for passing the decode parameters to rocJpegDecode API (#22)

[ROCm/rocjpeg commit: 7bdd495214]
此提交包含在:
Aryan Salmanpour
2024-05-08 11:30:36 -04:00
提交者 GitHub
父節點 37d54ad333
當前提交 f4bf8cfe17
共有 10 個檔案被更改,包括 100 行新增76 行删除
+6 -6
查看文件
@@ -44,10 +44,10 @@ int main(int argc, char **argv) {
RocJpegBackend rocjpeg_backend = ROCJPEG_BACKEND_HARDWARE;
RocJpegHandle rocjpeg_handle = nullptr;
RocJpegImage output_image = {};
RocJpegOutputFormat output_format = ROCJPEG_OUTPUT_NATIVE;
RocJpegDecodeParams decode_params = {};
RocJpegUtils rocjpeg_utils;
RocJpegUtils::ParseCommandLine(input_path, output_file_path, save_images, device_id, rocjpeg_backend, output_format, nullptr, argc, argv);
RocJpegUtils::ParseCommandLine(input_path, output_file_path, save_images, device_id, rocjpeg_backend, decode_params, nullptr, argc, argv);
if (!RocJpegUtils::GetFilePaths(input_path, file_paths, is_dir, is_file)) {
std::cerr << "ERROR: Failed to get input file paths!" << std::endl;
return EXIT_FAILURE;
@@ -97,7 +97,7 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
if (rocjpeg_utils.GetChannelPitchAndSizes(output_format, subsampling, widths, heights, num_channels, output_image, channel_sizes)) {
if (rocjpeg_utils.GetChannelPitchAndSizes(decode_params.output_format, subsampling, widths, heights, num_channels, output_image, channel_sizes)) {
std::cerr << "ERROR: Failed to get the channel pitch and sizes" << std::endl;
return EXIT_FAILURE;
}
@@ -115,7 +115,7 @@ int main(int argc, char **argv) {
std::cout << "Decoding started, please wait! ... " << std::endl;
auto start_time = std::chrono::high_resolution_clock::now();
CHECK_ROCJPEG(rocJpegDecode(rocjpeg_handle, reinterpret_cast<uint8_t*>(file_data.data()), file_size, output_format, &output_image));
CHECK_ROCJPEG(rocJpegDecode(rocjpeg_handle, reinterpret_cast<uint8_t*>(file_data.data()), file_size, &decode_params, &output_image));
auto end_time = std::chrono::high_resolution_clock::now();
double time_per_image_in_milli_sec = std::chrono::duration<double, std::milli>(end_time - start_time).count();
double image_size_in_mpixels = (static_cast<double>(widths[0]) * static_cast<double>(heights[0]) / 1000000);
@@ -124,9 +124,9 @@ int main(int argc, char **argv) {
if (save_images) {
std::string image_save_path = output_file_path;
if (is_dir) {
rocjpeg_utils.GetOutputFileExt(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], image_save_path);
}
rocjpeg_utils.SaveImage(image_save_path, &output_image, widths[0], heights[0], subsampling, output_format);
rocjpeg_utils.SaveImage(image_save_path, &output_image, widths[0], heights[0], subsampling, decode_params.output_format);
}
std::cout << "Average processing time per image (ms): " << time_per_image_in_milli_sec << std::endl;
+8 -8
查看文件
@@ -23,7 +23,7 @@ THE SOFTWARE.
#include "../rocjpeg_samples_utils.h"
void ThreadFunction(std::vector<std::string>& jpegFiles, RocJpegHandle rocjpeg_handle, RocJpegUtils rocjpeg_util, RocJpegImage *output_image, std::mutex &mutex,
RocJpegOutputFormat output_format, bool save_images, std::string &output_file_path, uint64_t *num_decoded_images, double *image_size_in_mpixels) {
RocJpegDecodeParams &decode_params, bool save_images, std::string &output_file_path, uint64_t *num_decoded_images, double *image_size_in_mpixels) {
std::vector<char> file_data;
uint8_t num_components;
@@ -76,7 +76,7 @@ void ThreadFunction(std::vector<std::string>& jpegFiles, RocJpegHandle rocjpeg_h
return;
}
if (rocjpeg_util.GetChannelPitchAndSizes(output_format, subsampling, widths, heights, num_channels, *output_image, channel_sizes)) {
if (rocjpeg_util.GetChannelPitchAndSizes(decode_params.output_format, subsampling, widths, heights, num_channels, *output_image, channel_sizes)) {
std::cerr << "ERROR: Failed to get the channel pitch and sizes" << std::endl;
return;
}
@@ -92,14 +92,14 @@ void ThreadFunction(std::vector<std::string>& jpegFiles, RocJpegHandle rocjpeg_h
}
}
CHECK_ROCJPEG(rocJpegDecode(rocjpeg_handle, reinterpret_cast<uint8_t *>(file_data.data()), file_size, output_format, output_image));
CHECK_ROCJPEG(rocJpegDecode(rocjpeg_handle, reinterpret_cast<uint8_t *>(file_data.data()), file_size, &decode_params, output_image));
*image_size_in_mpixels += (static_cast<double>(widths[0]) * static_cast<double>(heights[0]) / 1000000);
*num_decoded_images += 1;
if (save_images) {
std::string image_save_path = output_file_path;
rocjpeg_util.GetOutputFileExt(output_format, base_file_name, widths[0], heights[0], image_save_path);
rocjpeg_util.SaveImage(image_save_path, output_image, widths[0], heights[0], subsampling, output_format);
rocjpeg_util.GetOutputFileExt(decode_params.output_format, base_file_name, widths[0], heights[0], image_save_path);
rocjpeg_util.SaveImage(image_save_path, output_image, widths[0], heights[0], subsampling, decode_params.output_format);
}
for (int i = 0; i < ROCJPEG_MAX_COMPONENT; i++) {
@@ -121,7 +121,7 @@ int main(int argc, char **argv) {
bool is_file = false;
RocJpegChromaSubsampling subsampling;
RocJpegBackend rocjpeg_backend = ROCJPEG_BACKEND_HARDWARE;
RocJpegOutputFormat output_format = ROCJPEG_OUTPUT_NATIVE;
RocJpegDecodeParams decode_params = {};
std::vector<RocJpegHandle> rocjpeg_handles;
std::mutex mutex;
std::vector<uint64_t> num_decoded_images_per_thread;
@@ -130,7 +130,7 @@ int main(int argc, char **argv) {
RocJpegUtils rocjpeg_utils;
std::vector<std::thread> threads;
RocJpegUtils::ParseCommandLine(input_path, output_file_path, save_images, device_id, rocjpeg_backend, output_format, &num_threads, argc, argv);
RocJpegUtils::ParseCommandLine(input_path, output_file_path, save_images, device_id, rocjpeg_backend, decode_params, &num_threads, argc, argv);
if (!RocJpegUtils::GetFilePaths(input_path, file_paths, is_dir, is_file)) {
std::cerr << "ERROR: Failed to get input file paths!" << std::endl;
return EXIT_FAILURE;
@@ -157,7 +157,7 @@ int main(int argc, char **argv) {
std::cout << "Decoding started with " << num_threads << " threads, please wait!" << std::endl;
auto start_time = std::chrono::high_resolution_clock::now();
for (int i = 0; i < num_threads; ++i) {
threads.emplace_back(ThreadFunction, std::ref(file_paths), rocjpeg_handles[i], rocjpeg_utils, &rocjpeg_images[i], std::ref(mutex), output_format, save_images, std::ref(output_file_path),
threads.emplace_back(ThreadFunction, std::ref(file_paths), rocjpeg_handles[i], rocjpeg_utils, &rocjpeg_images[i], std::ref(mutex), std::ref(decode_params), save_images, std::ref(output_file_path),
&num_decoded_images_per_thread[i], &image_size_in_mpixels_per_thread[i]);
}
for (auto& thread : threads) {
+7 -7
查看文件
@@ -58,7 +58,7 @@ class RocJpegUtils {
public:
RocJpegUtils() {};
static void ParseCommandLine(std::string &input_path, std::string &output_file_path, bool &save_images, int &device_id,
RocJpegBackend &rocjpeg_backend, RocJpegOutputFormat &output_format, int *num_threads, int argc, char *argv[]);
RocJpegBackend &rocjpeg_backend, RocJpegDecodeParams &decode_params, int *num_threads, int argc, char *argv[]);
static bool GetFilePaths(std::string &input_path, std::vector<std::string> &file_paths, bool &is_dir, bool &is_file);
static bool InitHipDevice(int device_id);
void GetChromaSubsamplingStr(RocJpegChromaSubsampling subsampling, std::string &chroma_sub_sampling);
@@ -86,7 +86,7 @@ void RocJpegUtils::ShowHelpAndExit(const char *option, bool show_threads) {
}
void RocJpegUtils::ParseCommandLine(std::string &input_path, std::string &output_file_path, bool &save_images, int &device_id,
RocJpegBackend &rocjpeg_backend, RocJpegOutputFormat &output_format, int *num_threads, int argc, char *argv[]) {
RocJpegBackend &rocjpeg_backend, RocJpegDecodeParams &decode_params, int *num_threads, int argc, char *argv[]) {
if(argc <= 1) {
ShowHelpAndExit("", num_threads != nullptr);
}
@@ -129,15 +129,15 @@ void RocJpegUtils::ParseCommandLine(std::string &input_path, std::string &output
}
std::string selected_output_format = argv[i];
if (selected_output_format == "native") {
output_format = ROCJPEG_OUTPUT_NATIVE;
decode_params.output_format = ROCJPEG_OUTPUT_NATIVE;
} else if (selected_output_format == "yuv") {
output_format = ROCJPEG_OUTPUT_YUV_PLANAR;
decode_params.output_format = ROCJPEG_OUTPUT_YUV_PLANAR;
} else if (selected_output_format == "y") {
output_format = ROCJPEG_OUTPUT_Y;
decode_params.output_format = ROCJPEG_OUTPUT_Y;
} else if (selected_output_format == "rgb") {
output_format = ROCJPEG_OUTPUT_RGB;
decode_params.output_format = ROCJPEG_OUTPUT_RGB;
} else if (selected_output_format == "rgb_planar") {
output_format = ROCJPEG_OUTPUT_RGB_PLANAR;
decode_params.output_format = ROCJPEG_OUTPUT_RGB_PLANAR;
} else {
ShowHelpAndExit(argv[i], num_threads != nullptr);
}