|
|
|
|
@ -24,10 +24,13 @@
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <Corrade/Containers/Optional.h> |
|
|
|
|
#include <Corrade/Containers/StaticArray.h> |
|
|
|
|
#include <Corrade/PluginManager/Manager.h> |
|
|
|
|
#include <Corrade/Utility/Arguments.h> |
|
|
|
|
#include <Corrade/Utility/ConfigurationGroup.h> |
|
|
|
|
#include <Corrade/Utility/DebugStl.h> |
|
|
|
|
#include <Corrade/Utility/Directory.h> |
|
|
|
|
#include <Corrade/Utility/String.h> |
|
|
|
|
|
|
|
|
|
#include "Magnum/PixelFormat.h" |
|
|
|
|
#include "Magnum/Trade/AbstractImporter.h" |
|
|
|
|
@ -88,6 +91,33 @@ magnum-imageconverter image.jpg image.png
|
|
|
|
|
|
|
|
|
|
using namespace Magnum; |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
void setOptions(PluginManager::AbstractPlugin& plugin, const std::string& options) { |
|
|
|
|
for(const std::string& option: Utility::String::splitWithoutEmptyParts(options, ';')) { |
|
|
|
|
auto keyValue = Utility::String::partition(option, '='); |
|
|
|
|
Utility::String::trimInPlace(keyValue[0]); |
|
|
|
|
Utility::String::trimInPlace(keyValue[2]); |
|
|
|
|
|
|
|
|
|
/* Provide a warning message in case the plugin doesn't define given
|
|
|
|
|
option in its default config. The plugin is not *required* to have |
|
|
|
|
those tho (could be backward compatibility entries, for example), so |
|
|
|
|
not an error. */ |
|
|
|
|
if(!plugin.configuration().valueCount(keyValue[0])) |
|
|
|
|
Warning{} << "Option" << keyValue[0] << "not recognized by" << plugin.plugin(); |
|
|
|
|
|
|
|
|
|
/* If the option doesn't have an =, treat it as a boolean flag that's
|
|
|
|
|
set to true. While there's no similar way to do an inverse, it's |
|
|
|
|
still nicer than causing a fatal error with those. */ |
|
|
|
|
if(keyValue[1].empty()) |
|
|
|
|
plugin.configuration().setValue(keyValue[0], true); |
|
|
|
|
else |
|
|
|
|
plugin.configuration().setValue(keyValue[0], keyValue[2]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
|
Utility::Arguments args; |
|
|
|
|
args.addArgument("input").setHelp("input", "input image") |
|
|
|
|
@ -95,7 +125,15 @@ int main(int argc, char** argv) {
|
|
|
|
|
.addOption("importer", "AnyImageImporter").setHelp("importer", "image importer plugin") |
|
|
|
|
.addOption("converter", "AnyImageConverter").setHelp("converter", "image converter plugin") |
|
|
|
|
.addOption("plugin-dir").setHelp("plugin-dir", "override base plugin dir", "DIR") |
|
|
|
|
.setGlobalHelp("Converts images of different formats.") |
|
|
|
|
.addOption('i', "importer-options").setHelp("options", "configuration options to pass to the importer", "key=val,key2=val2,…") |
|
|
|
|
.addOption('c', "converter-options").setHelp("options", "configuration options to pass to the converter", "key=val,key2=val2,…") |
|
|
|
|
.addOption("raw").setHelp("raw", "treat the image as raw pixels of given format", "FORMAT") |
|
|
|
|
.setGlobalHelp(R"(Converts images of different formats. |
|
|
|
|
|
|
|
|
|
The -i / --importer-options and -c / --converter-options arguments accept a |
|
|
|
|
comma-separated list of key/value pairs to set in the importer / converter |
|
|
|
|
plugin configuration. If the = character is omitted, it's equivalent to saying |
|
|
|
|
key=true.)") |
|
|
|
|
.parse(argc, argv); |
|
|
|
|
|
|
|
|
|
/* Load importer plugin */ |
|
|
|
|
@ -112,6 +150,10 @@ int main(int argc, char** argv) {
|
|
|
|
|
Containers::Pointer<Trade::AbstractImageConverter> converter = converterManager.loadAndInstantiate(args.value("converter")); |
|
|
|
|
if(!converter) return 2; |
|
|
|
|
|
|
|
|
|
/* Set options, if passed */ |
|
|
|
|
setOptions(*importer, args.value("importer-options")); |
|
|
|
|
setOptions(*converter, args.value("converter-options")); |
|
|
|
|
|
|
|
|
|
/* Open input file */ |
|
|
|
|
Containers::Optional<Trade::ImageData2D> image; |
|
|
|
|
if(!importer->openFile(args.value("input")) || !(image = importer->image2D(0))) { |
|
|
|
|
|