Skip to content

Commit 6ad9867

Browse files
committed
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.
1 parent a913a41 commit 6ad9867

File tree

2 files changed

+50
-20
lines changed

2 files changed

+50
-20
lines changed

src/Launcher.cpp

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <iostream>
2424
#include <iomanip>
25+
#include <iterator>
2526
#include <string>
2627
#include <QApplication>
2728
#include <QTranslator>
@@ -72,27 +73,44 @@ struct CoutProgressIndicator : public ProgressIndicator {
7273

7374
list<LoadOptions> Launcher::getBracketedSets() {
7475
list<LoadOptions> result;
75-
list<pair<ImageIO::QDateInterval, QString>> dateNames;
76-
for (QString & name : generalOptions.fileNames) {
77-
ImageIO::QDateInterval interval = ImageIO::getImageCreationInterval(name);
78-
if (interval.start.isValid()) {
79-
dateNames.emplace_back(interval, name);
80-
} else {
81-
// We cannot get time information, process it alone
82-
result.push_back(generalOptions);
83-
result.back().fileNames.clear();
84-
result.back().fileNames.push_back(name);
76+
if (generalOptions.imagesPerBracket > 0) {
77+
if (generalOptions.fileNames % generalOptions.imagesPerBracket != 0) {
78+
throw std::logic_error("Number of files not a multiple of number per bracketed set (-i).");
8579
}
86-
}
87-
dateNames.sort();
88-
ImageIO::QDateInterval lastInterval;
89-
for (auto & dateName : dateNames) {
90-
if (lastInterval.start.isNull() || lastInterval.difference(dateName.first) > generalOptions.batchGap) {
91-
result.push_back(generalOptions);
92-
result.back().fileNames.clear();
80+
81+
while(!generalOptions.fileNames.empty()) {
82+
LoadOptions opt = generalOptions;
83+
auto oIt = opt.fileNames.begin();
84+
auto goIt = generalOptions.fileNames.begin();
85+
std::advance(oIt, generalOptions.imagesPerBracket);
86+
std::advance(goIt, generalOptions.imagesPerBracket);
87+
opt.fileNames.erase(oIt, opt.fileNames.end());
88+
generalOptions.fileNames.erase(generalOptions.fileNames.begin(), goIt);
89+
result.push_back(opt);
90+
}
91+
} else {
92+
list<pair<ImageIO::QDateInterval, QString>> dateNames;
93+
for (QString & name : generalOptions.fileNames) {
94+
ImageIO::QDateInterval interval = ImageIO::getImageCreationInterval(name);
95+
if (interval.start.isValid()) {
96+
dateNames.emplace_back(interval, name);
97+
} else {
98+
// We cannot get time information, process it alone
99+
result.push_back(generalOptions);
100+
result.back().fileNames.clear();
101+
result.back().fileNames.push_back(name);
102+
}
103+
}
104+
dateNames.sort();
105+
ImageIO::QDateInterval lastInterval;
106+
for (auto & dateName : dateNames) {
107+
if (lastInterval.start.isNull() || lastInterval.difference(dateName.first) > generalOptions.batchGap) {
108+
result.push_back(generalOptions);
109+
result.back().fileNames.clear();
110+
}
111+
result.back().fileNames.push_back(dateName.second);
112+
lastInterval = dateName.first;
93113
}
94-
result.back().fileNames.push_back(dateName.second);
95-
lastInterval = dateName.first;
96114
}
97115
int setNum = 0;
98116
for (auto & i : result) {
@@ -174,6 +192,15 @@ void Launcher::parseCommandLine() {
174192
generalOptions.crop = false;
175193
} else if (string("--batch") == argv[i] || string("-B") == argv[i]) {
176194
generalOptions.batch = true;
195+
} else if (string("-i") == argv[i]) {
196+
if(++i < argc) {
197+
try {
198+
int value = stoi(argv[i]);
199+
generalOptions.imagesPerBracket = value;
200+
} catch(std::invalid_argument & e) {
201+
cerr << tr("Invalid %1 parameter, falling back to interval-based bracketing set creation.").arg(argv[i - 1]) << endl;
202+
}
203+
}
177204
} else if (string("--single") == argv[i]) {
178205
generalOptions.withSingles = true;
179206
} else if (string("--help") == argv[i]) {
@@ -257,6 +284,8 @@ void Launcher::showHelp() {
257284
cout << " " << "-a " << tr("Calculates the output file name as") << " %id[-1]/%iF[0]-%in[-1].dng." << endl;
258285
cout << " " << "-B|--batch " << tr("Batch mode: Input images are automatically grouped into bracketed sets,") << endl;
259286
cout << " " << " " << tr("by comparing the creation time. Implies -a if no output file name is given.") << endl;
287+
cout << " " << "-i NUM_IMAGES " << tr("Fixed number of images per bracket set. use together with -B.") << endl;
288+
cout << " " << " " << tr("Creation time will be ignored.") << endl;
260289
cout << " " << "-g gap " << tr("Batch gap, maximum difference in seconds between two images of the same set.") << endl;
261290
cout << " " << "--single " << tr("Include single images in batch mode (the default is to skip them.)") << endl;
262291
cout << " " << "-b BPS " << tr("Bits per sample, can be 16, 24 or 32.") << endl;

src/LoadSaveOptions.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ struct LoadOptions {
3535
bool useCustomWl;
3636
uint16_t customWl;
3737
bool batch;
38+
int imagesPerBracket;
3839
double batchGap;
3940
bool withSingles;
40-
LoadOptions() : align(true), crop(true), useCustomWl(false), customWl(16383), batch(false), batchGap(2.0),
41+
LoadOptions() : align(true), crop(true), useCustomWl(false), customWl(16383), batch(false), imagesPerBracket(-1), batchGap(2.0),
4142
withSingles(false) {}
4243
};
4344

0 commit comments

Comments
 (0)