Skip to content

Commit 4d16ae5

Browse files
add option to save only first frame of a multiframe image
1 parent dc44077 commit 4d16ae5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

main.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ int main(int argc, char* argv[])
116116
const Options transparentColorOpts{"-t", "--transparent-color"};
117117
const Options outDirOpts{"-o", "--out-dir"};
118118
const Options separateDirOpts{"-d", "--separate-dir"};
119+
const Options firstFrameOnlyOpts{"--first-frame-only"};
119120
const Options verboseOpts{"-v", "--verbose"};
120121
const Options treatArgsAsPositionalsOpt{"--"};
121122
const Options supportedFormatsOpts{"-l", "--list-supported-formats"};
@@ -140,6 +141,7 @@ int main(int argc, char* argv[])
140141
qDebug() << transparentColorOpts << " <str>\tColor to use as transparent, defaults to " << defaultTransparentColorStr.constData() << ", see QColor::setNamedColor() for full list of supported formats";
141142
qDebug() << outDirOpts << " <directory>\tWhere to save output files, defaults to current working directory";
142143
qDebug() << separateDirOpts << "\t\tSave multiframe images in a directory named after the input file";
144+
qDebug() << firstFrameOnlyOpts << "\t\tSave only first frame of multiframe images, ignores" << separateDirOpts;
143145
qDebug() << verboseOpts << "\t\t\tVerbose output";
144146
qDebug();
145147
qDebug() << supportedFormatsOpts << "\tPrint supported image formats";
@@ -154,6 +156,7 @@ int main(int argc, char* argv[])
154156
auto transparentColor = defaultTransparentColor;
155157
QString outDirPath;
156158
auto useSeparateDir = false;
159+
auto saveOnlyFirstFrame = false;
157160
auto treatArgsAsPositionals = false;
158161
auto verboseOutput = false;
159162
auto showSupportedFormats = false;
@@ -208,6 +211,8 @@ int main(int argc, char* argv[])
208211
});
209212
else if (containsOption(separateDirOpts, argv[i]))
210213
useSeparateDir = true;
214+
else if (containsOption(firstFrameOnlyOpts, argv[i]))
215+
saveOnlyFirstFrame = true;
211216
else if (containsOption(verboseOpts, argv[i]))
212217
verboseOutput = true;
213218
else if (containsOption(treatArgsAsPositionalsOpt, argv[i]))
@@ -298,10 +303,16 @@ int main(int argc, char* argv[])
298303
ds.skipRawData(sizeof header.terminator);
299304
ds >> header.directions;
300305
ds >> header.framesPerDirection;
301-
const auto framesTotal = header.directions * header.framesPerDirection;
306+
auto framesTotal = header.directions * header.framesPerDirection;
302307
if (verboseOutput)
303308
qDebug() << header.directions << "direction(s) with" << header.framesPerDirection << "frame(s) =" << framesTotal << "frames total";
304309

310+
if (saveOnlyFirstFrame) {
311+
if (framesTotal > 1 && verboseOutput)
312+
qDebug() << "saving only first frame from a multiframe image";
313+
framesTotal = 1;
314+
}
315+
305316
std::vector<uint32_t> frameIndexes;
306317
frameIndexes.resize(framesTotal);
307318
for (std::size_t i = 0; i < framesTotal; ++i)

0 commit comments

Comments
 (0)