Add support for multiple regions of interest (ROI) for batch JPEG decoding (#126)

Этот коммит содержится в:
Aryan Salmanpour
2025-03-05 17:06:04 -05:00
коммит произвёл GitHub
родитель 863eafcdb6
Коммит 692d4bb72c
8 изменённых файлов: 43 добавлений и 46 удалений
+11 -14
Просмотреть файл
@@ -49,6 +49,7 @@ int main(int argc, char **argv) {
RocJpegImage output_image = {};
std::vector<RocJpegImage> output_images;
RocJpegDecodeParams decode_params = {};
std::vector<RocJpegDecodeParams> decode_params_batch;
RocJpegUtils rocjpeg_utils;
std::vector<std::string> base_file_names;
std::vector<RocJpegStreamHandle> rocjpeg_stream_handles_for_current_batch;
@@ -61,15 +62,11 @@ int main(int argc, char **argv) {
uint64_t num_jpegs_with_unknown_subsampling = 0;
uint64_t num_jpegs_with_unsupported_resolution = 0;
int current_batch_size = 0;
RocJpegUtils::ParseCommandLine(input_path, output_file_path, save_images, device_id, rocjpeg_backend, decode_params, nullptr, &batch_size, argc, argv);
bool is_roi_valid = false;
uint32_t roi_width;
uint32_t roi_height;
roi_width = decode_params.crop_rectangle.right - decode_params.crop_rectangle.left;
roi_height = decode_params.crop_rectangle.bottom - decode_params.crop_rectangle.top;
RocJpegUtils::ParseCommandLine(input_path, output_file_path, save_images, device_id, rocjpeg_backend, decode_params, nullptr, &batch_size, 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;
@@ -89,6 +86,7 @@ int main(int argc, char **argv) {
batch_images.resize(batch_size);
output_images.resize(batch_size);
decode_params_batch.resize(batch_size, decode_params);
prior_channel_sizes.resize(batch_size, std::vector<uint32_t>(ROCJPEG_MAX_COMPONENT, 0));
widths.resize(batch_size, std::vector<uint32_t>(ROCJPEG_MAX_COMPONENT, 0));
heights.resize(batch_size, std::vector<uint32_t>(ROCJPEG_MAX_COMPONENT, 0));
@@ -134,10 +132,6 @@ int main(int argc, char **argv) {
CHECK_ROCJPEG(rocJpegGetImageInfo(rocjpeg_handle, rocjpeg_stream_handles[index], &num_components, &temp_subsampling, temp_widths.data(), temp_heights.data()));
if (roi_width > 0 && roi_height > 0 && roi_width <= widths[index][0] && roi_height <= heights[index][0]) {
is_roi_valid = true;
}
rocjpeg_utils.GetChromaSubsamplingStr(temp_subsampling, chroma_sub_sampling);
if (temp_widths[0] < 64 || temp_heights[0] < 64) {
if (is_dir) {
@@ -164,7 +158,7 @@ int main(int argc, char **argv) {
}
}
if (rocjpeg_utils.GetChannelPitchAndSizes(decode_params, temp_subsampling, temp_widths.data(), temp_heights.data(), num_channels, output_images[current_batch_size], channel_sizes)) {
if (rocjpeg_utils.GetChannelPitchAndSizes(decode_params_batch[index], temp_subsampling, temp_widths.data(), temp_heights.data(), num_channels, output_images[current_batch_size], channel_sizes)) {
std::cerr << "ERROR: Failed to get the channel pitch and sizes" << std::endl;
return EXIT_FAILURE;
}
@@ -191,7 +185,7 @@ int main(int argc, char **argv) {
double time_per_batch_in_milli_sec = 0;
if (current_batch_size > 0) {
auto start_time = std::chrono::high_resolution_clock::now();
CHECK_ROCJPEG(rocJpegDecodeBatched(rocjpeg_handle, rocjpeg_stream_handles_for_current_batch.data(), current_batch_size, &decode_params, output_images.data()));
CHECK_ROCJPEG(rocJpegDecodeBatched(rocjpeg_handle, rocjpeg_stream_handles_for_current_batch.data(), current_batch_size, decode_params_batch.data(), output_images.data()));
auto end_time = std::chrono::high_resolution_clock::now();
time_per_batch_in_milli_sec = std::chrono::duration<double, std::milli>(end_time - start_time).count();
}
@@ -207,12 +201,15 @@ int main(int argc, char **argv) {
for (int b = 0; b < current_batch_size; b++) {
std::string image_save_path = output_file_path;
//if ROI is present, need to pass roi_width and roi_height
roi_width = decode_params_batch[b].crop_rectangle.right - decode_params_batch[b].crop_rectangle.left;
roi_height = decode_params_batch[b].crop_rectangle.bottom - decode_params_batch[b].crop_rectangle.top;
is_roi_valid = (roi_width > 0 && roi_height > 0 && roi_width <= widths[b][0] && roi_height <= heights[b][0]) ? true : false;
uint32_t width = is_roi_valid ? roi_width : widths[b][0];
uint32_t height = is_roi_valid ? roi_height : heights[b][0];
if (is_dir) {
rocjpeg_utils.GetOutputFileExt(decode_params.output_format, base_file_names[b], width, height, subsamplings[b], image_save_path);
rocjpeg_utils.GetOutputFileExt(decode_params_batch[b].output_format, base_file_names[b], width, height, subsamplings[b], image_save_path);
}
rocjpeg_utils.SaveImage(image_save_path, &output_images[b], width, height, subsamplings[b], decode_params.output_format);
rocjpeg_utils.SaveImage(image_save_path, &output_images[b], width, height, subsamplings[b], decode_params_batch[b].output_format);
}
}