From 0c262a7ea04a3d55f62216cb4a26fe32f042548d Mon Sep 17 00:00:00 2001 From: Franz Trischberger Date: Fri, 30 Nov 2018 14:31:00 +0200 Subject: [PATCH] Add new option to set a fixed size for brackets. Bracketed sets will not get computed automatically. Sets get built in order of input files. --- src/Launcher.cpp | 68 +++++++++++++++++++++++++++++------------ src/LoadSaveOptions.hpp | 3 +- 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/Launcher.cpp b/src/Launcher.cpp index a01b419..2f78433 100644 --- a/src/Launcher.cpp +++ b/src/Launcher.cpp @@ -20,8 +20,10 @@ * */ +#include #include #include +#include #include #include #include @@ -73,27 +75,44 @@ struct CoutProgressIndicator : public ProgressIndicator { list Launcher::getBracketedSets() { list result; - list> dateNames; - for (QString & name : generalOptions.fileNames) { - ImageIO::QDateInterval interval = ImageIO::getImageCreationInterval(name); - if (interval.start.isValid()) { - dateNames.emplace_back(interval, name); - } else { - // We cannot get time information, process it alone - result.push_back(generalOptions); - result.back().fileNames.clear(); - result.back().fileNames.push_back(name); + if (generalOptions.imagesPerBracket > 0) { + if (generalOptions.fileNames.size() % generalOptions.imagesPerBracket != 0) { + throw std::logic_error("Number of files not a multiple of number per bracketed set (-i)."); } - } - dateNames.sort(); - ImageIO::QDateInterval lastInterval; - for (auto & dateName : dateNames) { - if (lastInterval.start.isNull() || lastInterval.difference(dateName.first) > generalOptions.batchGap) { - result.push_back(generalOptions); - result.back().fileNames.clear(); + + while(!generalOptions.fileNames.empty()) { + LoadOptions opt = generalOptions; + auto oIt = opt.fileNames.begin(); + auto goIt = generalOptions.fileNames.begin(); + std::advance(oIt, generalOptions.imagesPerBracket); + std::advance(goIt, generalOptions.imagesPerBracket); + opt.fileNames.erase(oIt, opt.fileNames.end()); + generalOptions.fileNames.erase(generalOptions.fileNames.begin(), goIt); + result.push_back(opt); + } + } else { + list> dateNames; + for (QString & name : generalOptions.fileNames) { + ImageIO::QDateInterval interval = ImageIO::getImageCreationInterval(name); + if (interval.start.isValid()) { + dateNames.emplace_back(interval, name); + } else { + // We cannot get time information, process it alone + result.push_back(generalOptions); + result.back().fileNames.clear(); + result.back().fileNames.push_back(name); + } + } + dateNames.sort(); + ImageIO::QDateInterval lastInterval; + for (auto & dateName : dateNames) { + if (lastInterval.start.isNull() || lastInterval.difference(dateName.first) > generalOptions.batchGap) { + result.push_back(generalOptions); + result.back().fileNames.clear(); + } + result.back().fileNames.push_back(dateName.second); + lastInterval = dateName.first; } - result.back().fileNames.push_back(dateName.second); - lastInterval = dateName.first; } int setNum = 0; for (auto & i : result) { @@ -175,6 +194,15 @@ void Launcher::parseCommandLine() { generalOptions.crop = false; } else if (string("--batch") == argv[i] || string("-B") == argv[i]) { generalOptions.batch = true; + } else if (string("-i") == argv[i]) { + if(++i < argc) { + try { + int value = stoi(argv[i]); + generalOptions.imagesPerBracket = value; + } catch(std::invalid_argument & e) { + cerr << tr("Invalid %1 parameter, falling back to interval-based bracketing set creation.").arg(argv[i - 1]) << endl; + } + } } else if (string("--single") == argv[i]) { generalOptions.withSingles = true; } else if (string("--help") == argv[i]) { @@ -258,6 +286,8 @@ void Launcher::showHelp() { cout << " " << "-a " << tr("Calculates the output file name as") << " %id[-1]/%iF[0]-%in[-1].dng." << endl; cout << " " << "-B|--batch " << tr("Batch mode: Input images are automatically grouped into bracketed sets,") << endl; cout << " " << " " << tr("by comparing the creation time. Implies -a if no output file name is given.") << endl; + cout << " " << "-i NUM_IMAGES " << tr("Fixed number of images per bracket set. use together with -B.") << endl; + cout << " " << " " << tr("Creation time will be ignored.") << endl; cout << " " << "-g gap " << tr("Batch gap, maximum difference in seconds between two images of the same set.") << endl; cout << " " << "--single " << tr("Include single images in batch mode (the default is to skip them.)") << endl; cout << " " << "-b BPS " << tr("Bits per sample, can be 16, 24 or 32.") << endl; diff --git a/src/LoadSaveOptions.hpp b/src/LoadSaveOptions.hpp index 5c3db3d..7d6fce0 100644 --- a/src/LoadSaveOptions.hpp +++ b/src/LoadSaveOptions.hpp @@ -35,9 +35,10 @@ struct LoadOptions { bool useCustomWl; uint16_t customWl; bool batch; + int imagesPerBracket; double batchGap; bool withSingles; - LoadOptions() : align(true), crop(true), useCustomWl(false), customWl(16383), batch(false), batchGap(2.0), + LoadOptions() : align(true), crop(true), useCustomWl(false), customWl(16383), batch(false), imagesPerBracket(-1), batchGap(2.0), withSingles(false) {} };