@@ -172,8 +172,6 @@ static void collectFilenames( list<string>& inputFiles, const boost::filesystem:
172172
173173SiftJob* process_image ( const string& inputFile, PopSift& PopSift )
174174{
175- int w;
176- int h;
177175 SiftJob* job;
178176 unsigned char * image_data;
179177
@@ -197,8 +195,8 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
197195 cerr << " Failed converting image " << inputFile << " to unsigned greyscale image" << endl;
198196 exit ( -1 );
199197 }
200- w = img.Width ();
201- h = img.Height ();
198+ const auto w = img.Width ();
199+ const auto h = img.Height ();
202200 cout << " Loading " << w << " x " << h << " image " << inputFile << endl;
203201
204202 image_data = img.GetData ();
@@ -213,10 +211,11 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
213211#endif
214212 {
215213 nvtxRangePushA ( " load and convert image - pgmread" );
216-
214+ int w{};
215+ int h{};
217216 image_data = readPGMfile ( inputFile, w, h );
218- if ( image_data == 0 ) {
219- exit ( - 1 );
217+ if ( image_data == nullptr ) {
218+ exit ( EXIT_FAILURE );
220219 }
221220
222221 nvtxRangePop ( ); // "load and convert image - pgmread"
@@ -230,7 +229,7 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
230229 }
231230 else
232231 {
233- float * f_image_data = new float [w * h];
232+ auto f_image_data = new float [w * h];
234233 for ( int i=0 ; i<w*h; i++ )
235234 {
236235 f_image_data[i] = float ( image_data[i] ) / 256 .0f ;
@@ -271,8 +270,7 @@ int main(int argc, char **argv)
271270
272271 popsift::Config config;
273272 list<string> inputFiles;
274- string inputFile = " " ;
275- const char * appName = argv[0 ];
273+ string inputFile{};
276274
277275 std::cout << " PopSift version: " << POPSIFT_VERSION_STRING << std::endl;
278276
@@ -282,7 +280,7 @@ int main(int argc, char **argv)
282280 }
283281 catch (std::exception& e) {
284282 std::cout << e.what () << std::endl;
285- exit ( 1 ) ;
283+ return EXIT_FAILURE ;
286284 }
287285
288286 if ( boost::filesystem::exists ( inputFile ) ) {
@@ -291,13 +289,13 @@ int main(int argc, char **argv)
291289 collectFilenames ( inputFiles, inputFile );
292290 if ( inputFiles.empty () ) {
293291 cerr << " No files in directory, nothing to do" << endl;
294- exit ( 0 ) ;
292+ return EXIT_SUCCESS ;
295293 }
296294 } else if ( boost::filesystem::is_regular_file ( inputFile ) ) {
297295 inputFiles.push_back ( inputFile );
298296 } else {
299297 cout << " Input file is neither regular file nor directory, nothing to do" << endl;
300- exit ( - 1 ) ;
298+ return EXIT_FAILURE ;
301299 }
302300 }
303301
@@ -310,10 +308,9 @@ int main(int argc, char **argv)
310308 float_mode ? PopSift::FloatImages : PopSift::ByteImages );
311309
312310 std::queue<SiftJob*> jobs;
313- for ( auto it = inputFiles.begin (); it!=inputFiles.end (); it++ ) {
314- inputFile = it->c_str ();
315-
316- SiftJob* job = process_image ( inputFile, PopSift );
311+ for (const auto & currFile : inputFiles)
312+ {
313+ SiftJob* job = process_image ( currFile, PopSift );
317314 jobs.push ( job );
318315 }
319316
@@ -328,5 +325,7 @@ int main(int argc, char **argv)
328325 }
329326
330327 PopSift.uninit ( );
328+
329+ return EXIT_SUCCESS;
331330}
332331
0 commit comments