@@ -49,6 +49,7 @@ int main(int argc, char **argv) {
4949 RocJpegImage output_image = {};
5050 std::vector<RocJpegImage> output_images;
5151 RocJpegDecodeParams decode_params = {};
52+ std::vector<RocJpegDecodeParams> decode_params_batch;
5253 RocJpegUtils rocjpeg_utils;
5354 std::vector<std::string> base_file_names;
5455 std::vector<RocJpegStreamHandle> rocjpeg_stream_handles_for_current_batch;
@@ -61,15 +62,11 @@ int main(int argc, char **argv) {
6162 uint64_t num_jpegs_with_unknown_subsampling = 0 ;
6263 uint64_t num_jpegs_with_unsupported_resolution = 0 ;
6364 int current_batch_size = 0 ;
64-
65- RocJpegUtils::ParseCommandLine (input_path, output_file_path, save_images, device_id, rocjpeg_backend, decode_params, nullptr , &batch_size, argc, argv);
66-
6765 bool is_roi_valid = false ;
6866 uint32_t roi_width;
6967 uint32_t roi_height;
70- roi_width = decode_params.crop_rectangle .right - decode_params.crop_rectangle .left ;
71- roi_height = decode_params.crop_rectangle .bottom - decode_params.crop_rectangle .top ;
72-
68+
69+ RocJpegUtils::ParseCommandLine (input_path, output_file_path, save_images, device_id, rocjpeg_backend, decode_params, nullptr , &batch_size, argc, argv);
7370 if (!RocJpegUtils::GetFilePaths (input_path, file_paths, is_dir, is_file)) {
7471 std::cerr << " ERROR: Failed to get input file paths!" << std::endl;
7572 return EXIT_FAILURE;
@@ -89,6 +86,7 @@ int main(int argc, char **argv) {
8986
9087 batch_images.resize (batch_size);
9188 output_images.resize (batch_size);
89+ decode_params_batch.resize (batch_size, decode_params);
9290 prior_channel_sizes.resize (batch_size, std::vector<uint32_t >(ROCJPEG_MAX_COMPONENT, 0 ));
9391 widths.resize (batch_size, std::vector<uint32_t >(ROCJPEG_MAX_COMPONENT, 0 ));
9492 heights.resize (batch_size, std::vector<uint32_t >(ROCJPEG_MAX_COMPONENT, 0 ));
@@ -134,10 +132,6 @@ int main(int argc, char **argv) {
134132
135133 CHECK_ROCJPEG (rocJpegGetImageInfo (rocjpeg_handle, rocjpeg_stream_handles[index], &num_components, &temp_subsampling, temp_widths.data (), temp_heights.data ()));
136134
137- if (roi_width > 0 && roi_height > 0 && roi_width <= widths[index][0 ] && roi_height <= heights[index][0 ]) {
138- is_roi_valid = true ;
139- }
140-
141135 rocjpeg_utils.GetChromaSubsamplingStr (temp_subsampling, chroma_sub_sampling);
142136 if (temp_widths[0 ] < 64 || temp_heights[0 ] < 64 ) {
143137 if (is_dir) {
@@ -164,7 +158,7 @@ int main(int argc, char **argv) {
164158 }
165159 }
166160
167- if (rocjpeg_utils.GetChannelPitchAndSizes (decode_params , temp_subsampling, temp_widths.data (), temp_heights.data (), num_channels, output_images[current_batch_size], channel_sizes)) {
161+ 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)) {
168162 std::cerr << " ERROR: Failed to get the channel pitch and sizes" << std::endl;
169163 return EXIT_FAILURE;
170164 }
@@ -191,7 +185,7 @@ int main(int argc, char **argv) {
191185 double time_per_batch_in_milli_sec = 0 ;
192186 if (current_batch_size > 0 ) {
193187 auto start_time = std::chrono::high_resolution_clock::now ();
194- CHECK_ROCJPEG (rocJpegDecodeBatched (rocjpeg_handle, rocjpeg_stream_handles_for_current_batch.data (), current_batch_size, &decode_params , output_images.data ()));
188+ CHECK_ROCJPEG (rocJpegDecodeBatched (rocjpeg_handle, rocjpeg_stream_handles_for_current_batch.data (), current_batch_size, decode_params_batch. data () , output_images.data ()));
195189 auto end_time = std::chrono::high_resolution_clock::now ();
196190 time_per_batch_in_milli_sec = std::chrono::duration<double , std::milli>(end_time - start_time).count ();
197191 }
@@ -207,12 +201,15 @@ int main(int argc, char **argv) {
207201 for (int b = 0 ; b < current_batch_size; b++) {
208202 std::string image_save_path = output_file_path;
209203 // if ROI is present, need to pass roi_width and roi_height
204+ roi_width = decode_params_batch[b].crop_rectangle .right - decode_params_batch[b].crop_rectangle .left ;
205+ roi_height = decode_params_batch[b].crop_rectangle .bottom - decode_params_batch[b].crop_rectangle .top ;
206+ is_roi_valid = (roi_width > 0 && roi_height > 0 && roi_width <= widths[b][0 ] && roi_height <= heights[b][0 ]) ? true : false ;
210207 uint32_t width = is_roi_valid ? roi_width : widths[b][0 ];
211208 uint32_t height = is_roi_valid ? roi_height : heights[b][0 ];
212209 if (is_dir) {
213- rocjpeg_utils.GetOutputFileExt (decode_params .output_format , base_file_names[b], width, height, subsamplings[b], image_save_path);
210+ rocjpeg_utils.GetOutputFileExt (decode_params_batch[b] .output_format , base_file_names[b], width, height, subsamplings[b], image_save_path);
214211 }
215- rocjpeg_utils.SaveImage (image_save_path, &output_images[b], width, height, subsamplings[b], decode_params .output_format );
212+ rocjpeg_utils.SaveImage (image_save_path, &output_images[b], width, height, subsamplings[b], decode_params_batch[b] .output_format );
216213 }
217214 }
218215
0 commit comments