diff --git a/src/bin/exrmetrics/main.cpp b/src/bin/exrmetrics/main.cpp index a7d0a13b6..26d0a91d5 100644 --- a/src/bin/exrmetrics/main.cpp +++ b/src/bin/exrmetrics/main.cpp @@ -8,6 +8,8 @@ #include "ImfCompression.h" #include "ImfMisc.h" +#include "ImfThreading.h" +#include "IlmThreadPool.h" #include #include @@ -22,6 +24,7 @@ using std::endl; using std::ostream; using std::vector; using namespace Imf; +using namespace IlmThread; void usageMessage (ostream& stream, const char* program_name, bool verbose = false) @@ -41,6 +44,10 @@ usageMessage (ostream& stream, const char* program_name, bool verbose = false) " -p n part number to copy (only one part will be written to output file)\n" " default is part 0\n" "\n" + " -m set to multi-threaded (system selected thread count)\n" + " -t n use n threads for processing files\n" + " default is single / no threads\n" + "\n" " -l level set DWA or ZIP compression level\n" "\n" " -z x sets the data compression method to x\n" @@ -66,6 +73,7 @@ main (int argc, char** argv) const char* outFile = nullptr; const char* inFile = nullptr; int part = 0; + int threads = 0; float level = INFINITY; int halfMode = 0; // 0 - leave alone, 1 - just RGBA, 2 - everything Compression compression = Compression::NUM_COMPRESSION_METHODS; @@ -98,6 +106,28 @@ main (int argc, char** argv) cout << "License BSD-3-Clause" << endl; return 0; } + else if (!strcmp (argv[i], "-m")) + { + threads = -1; + i += 1; + } + else if (!strcmp (argv[i], "-t")) + { + if (i > argc - 2) + { + cerr << "Missing thread count value with -t option\n"; + return 1; + } + + threads = atoi (argv[i + 1]); + if (threads < 0) + { + cerr << "bad thread count " << argv[i + 1] << " specified to -t option\n"; + return 1; + } + + i += 2; + } else if (!strcmp (argv[i], "-z")) { if (i > argc - 2) @@ -188,6 +218,11 @@ main (int argc, char** argv) try { + if (threads < 0) + setGlobalThreadCount (ThreadPool::estimateThreadCountForFileIO ()); + else + setGlobalThreadCount (threads); + exrmetrics (inFile, outFile, part, compression, level, halfMode); } catch (std::exception& what)