Skip to content

Commit

Permalink
Add new option to set a fixed size for brackets.
Browse files Browse the repository at this point in the history
Bracketed sets will not get computed automatically.
Sets get built in order of input files.
  • Loading branch information
ff2000 committed Nov 30, 2018
1 parent a913a41 commit 6ad9867
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
67 changes: 48 additions & 19 deletions src/Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <iostream>
#include <iomanip>
#include <iterator>
#include <string>
#include <QApplication>
#include <QTranslator>
Expand Down Expand Up @@ -72,27 +73,44 @@ struct CoutProgressIndicator : public ProgressIndicator {

list<LoadOptions> Launcher::getBracketedSets() {
list<LoadOptions> result;
list<pair<ImageIO::QDateInterval, QString>> 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 % 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<pair<ImageIO::QDateInterval, QString>> 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) {
Expand Down Expand Up @@ -174,6 +192,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]) {
Expand Down Expand Up @@ -257,6 +284,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;
Expand Down
3 changes: 2 additions & 1 deletion src/LoadSaveOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
};

Expand Down

0 comments on commit 6ad9867

Please sign in to comment.