Skip to content

Commit

Permalink
add option to save only first frame of a multiframe image
Browse files Browse the repository at this point in the history
  • Loading branch information
kambala-decapitator committed Dec 14, 2021
1 parent dc44077 commit 4d16ae5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ int main(int argc, char* argv[])
const Options transparentColorOpts{"-t", "--transparent-color"};
const Options outDirOpts{"-o", "--out-dir"};
const Options separateDirOpts{"-d", "--separate-dir"};
const Options firstFrameOnlyOpts{"--first-frame-only"};
const Options verboseOpts{"-v", "--verbose"};
const Options treatArgsAsPositionalsOpt{"--"};
const Options supportedFormatsOpts{"-l", "--list-supported-formats"};
Expand All @@ -140,6 +141,7 @@ int main(int argc, char* argv[])
qDebug() << transparentColorOpts << " <str>\tColor to use as transparent, defaults to " << defaultTransparentColorStr.constData() << ", see QColor::setNamedColor() for full list of supported formats";
qDebug() << outDirOpts << " <directory>\tWhere to save output files, defaults to current working directory";
qDebug() << separateDirOpts << "\t\tSave multiframe images in a directory named after the input file";
qDebug() << firstFrameOnlyOpts << "\t\tSave only first frame of multiframe images, ignores" << separateDirOpts;
qDebug() << verboseOpts << "\t\t\tVerbose output";
qDebug();
qDebug() << supportedFormatsOpts << "\tPrint supported image formats";
Expand All @@ -154,6 +156,7 @@ int main(int argc, char* argv[])
auto transparentColor = defaultTransparentColor;
QString outDirPath;
auto useSeparateDir = false;
auto saveOnlyFirstFrame = false;
auto treatArgsAsPositionals = false;
auto verboseOutput = false;
auto showSupportedFormats = false;
Expand Down Expand Up @@ -208,6 +211,8 @@ int main(int argc, char* argv[])
});
else if (containsOption(separateDirOpts, argv[i]))
useSeparateDir = true;
else if (containsOption(firstFrameOnlyOpts, argv[i]))
saveOnlyFirstFrame = true;
else if (containsOption(verboseOpts, argv[i]))
verboseOutput = true;
else if (containsOption(treatArgsAsPositionalsOpt, argv[i]))
Expand Down Expand Up @@ -298,10 +303,16 @@ int main(int argc, char* argv[])
ds.skipRawData(sizeof header.terminator);
ds >> header.directions;
ds >> header.framesPerDirection;
const auto framesTotal = header.directions * header.framesPerDirection;
auto framesTotal = header.directions * header.framesPerDirection;
if (verboseOutput)
qDebug() << header.directions << "direction(s) with" << header.framesPerDirection << "frame(s) =" << framesTotal << "frames total";

if (saveOnlyFirstFrame) {
if (framesTotal > 1 && verboseOutput)
qDebug() << "saving only first frame from a multiframe image";
framesTotal = 1;
}

std::vector<uint32_t> frameIndexes;
frameIndexes.resize(framesTotal);
for (std::size_t i = 0; i < framesTotal; ++i)
Expand Down

0 comments on commit 4d16ae5

Please sign in to comment.