Browse Source

imageconverter: restore the --converter raw option.

Broken with 5a8d31bf68. Tests. Did I
mention I need tests for this?
pull/578/head
Vladimír Vondruš 4 years ago
parent
commit
66d29d1b53
  1. 92
      src/Magnum/Trade/imageconverter.cpp

92
src/Magnum/Trade/imageconverter.cpp

@ -965,59 +965,64 @@ no -C / --converter is specified, AnyImageConverter is used.)")
(outputDimensions == 2 && outputImages2D.front().isCompressed()) || (outputDimensions == 2 && outputImages2D.front().isCompressed()) ||
(outputDimensions == 3 && outputImages3D.front().isCompressed()); (outputDimensions == 3 && outputImages3D.front().isCompressed());
/* Load converter plugin */ /* Load converter plugin if a raw conversion is not requested */
Containers::Pointer<Trade::AbstractImageConverter> converter = converterManager.loadAndInstantiate(converterName); Containers::Pointer<Trade::AbstractImageConverter> converter;
if(!converter) { if(converterName != "raw"_s) {
Debug{} << "Available converter plugins:" << ", "_s.join(converterManager.aliasList()); if(!(converter = converterManager.loadAndInstantiate(converterName))) {
return 2; Debug{} << "Available converter plugins:" << ", "_s.join(converterManager.aliasList());
} return 2;
}
/* Set options, if passed */ /* Set options, if passed */
if(args.isSet("verbose")) converter->addFlags(Trade::ImageConverterFlag::Verbose); if(args.isSet("verbose")) converter->addFlags(Trade::ImageConverterFlag::Verbose);
if(i < args.arrayValueCount("converter-options")) if(i < args.arrayValueCount("converter-options"))
Implementation::setOptions(*converter, "AnyImageConverter", args.arrayValue("converter-options", i)); Implementation::setOptions(*converter, "AnyImageConverter", args.arrayValue("converter-options", i));
}
/* This is the last --converter (or the implicit AnyImageConverter at /* This is the last --converter (a raw output, a file-capable converter
the end), output to a file and exit the loop */ or the implicit AnyImageConverter at the end), output to a file and
if(i + 1 >= converterCount && (converter->features() & ( exit the loop */
if(i + 1 >= converterCount && (converterName == "raw"_s || (converter->features() & (
Trade::ImageConverterFeature::Convert1DToFile| Trade::ImageConverterFeature::Convert1DToFile|
Trade::ImageConverterFeature::Convert2DToFile| Trade::ImageConverterFeature::Convert2DToFile|
Trade::ImageConverterFeature::Convert3DToFile| Trade::ImageConverterFeature::Convert3DToFile|
Trade::ImageConverterFeature::ConvertCompressed1DToFile| Trade::ImageConverterFeature::ConvertCompressed1DToFile|
Trade::ImageConverterFeature::ConvertCompressed2DToFile| Trade::ImageConverterFeature::ConvertCompressed2DToFile|
Trade::ImageConverterFeature::ConvertCompressed3DToFile))) Trade::ImageConverterFeature::ConvertCompressed3DToFile))))
{ {
/* Decide what converter feature we should look for for given /* Decide what converter feature we should look for for given
dimension count. This has to be redone each iteration, as a dimension count. This has to be redone each iteration, as a
converted could have converted an uncompressed image to a converted could have converted an uncompressed image to a
compressed one and vice versa. */ compressed one and vice versa. */
Trade::ImageConverterFeatures expectedFeatures; if(converterName != "raw"_s) {
if(outputDimensions == 1) { Trade::ImageConverterFeatures expectedFeatures;
expectedFeatures = outputIsCompressed ? if(outputDimensions == 1) {
Trade::ImageConverterFeature::ConvertCompressed1DToFile : expectedFeatures = outputIsCompressed ?
Trade::ImageConverterFeature::Convert1DToFile; Trade::ImageConverterFeature::ConvertCompressed1DToFile :
} else if(outputDimensions == 2) { Trade::ImageConverterFeature::Convert1DToFile;
expectedFeatures = outputIsCompressed ? } else if(outputDimensions == 2) {
Trade::ImageConverterFeature::ConvertCompressed2DToFile : expectedFeatures = outputIsCompressed ?
Trade::ImageConverterFeature::Convert2DToFile; Trade::ImageConverterFeature::ConvertCompressed2DToFile :
} else if(outputDimensions == 3) { Trade::ImageConverterFeature::Convert2DToFile;
expectedFeatures = outputIsCompressed ? } else if(outputDimensions == 3) {
Trade::ImageConverterFeature::ConvertCompressed3DToFile : expectedFeatures = outputIsCompressed ?
Trade::ImageConverterFeature::Convert3DToFile; Trade::ImageConverterFeature::ConvertCompressed3DToFile :
} else CORRADE_INTERNAL_ASSERT_UNREACHABLE(); Trade::ImageConverterFeature::Convert3DToFile;
/** @todo use a sane flag once the feature enum is ... sane */ } else CORRADE_INTERNAL_ASSERT_UNREACHABLE();
constexpr Trade::ImageConverterFeatures ImageConverterFeatureLevels = /** @todo use a sane flag once the feature enum is ... sane */
Trade::ImageConverterFeature::ConvertLevels1DToFile & ~Trade::ImageConverterFeature::Convert1DToFile; constexpr Trade::ImageConverterFeatures ImageConverterFeatureLevels =
if(outputIsMultiLevel) expectedFeatures |= ImageConverterFeatureLevels; Trade::ImageConverterFeature::ConvertLevels1DToFile & ~Trade::ImageConverterFeature::Convert1DToFile;
if(!(converter->features() >= expectedFeatures)) { if(outputIsMultiLevel) expectedFeatures |= ImageConverterFeatureLevels;
Error err; if(!(converter->features() >= expectedFeatures)) {
err << converterName << "doesn't support"; Error err;
if(outputIsMultiLevel) err << converterName << "doesn't support";
err << "multi-level"; if(outputIsMultiLevel)
if(outputIsCompressed) err << "multi-level";
err << "compressed"; if(outputIsCompressed)
err << outputDimensions << Debug::nospace << "D image to file conversion, only" << converter->features(); err << "compressed";
return 6; err << outputDimensions << Debug::nospace << "D image to file conversion, only" << converter->features();
return 6;
}
} }
if(args.isSet("verbose")) { if(args.isSet("verbose")) {
@ -1103,6 +1108,11 @@ no -C / --converter is specified, AnyImageConverter is used.)")
/* This is not the last converter, expect that it's capable of /* This is not the last converter, expect that it's capable of
image-to-image conversion */ image-to-image conversion */
} else { } else {
if(converterName == "raw"_s) {
Error{} << "Only the very last --converter can be raw";
return 1;
}
CORRADE_INTERNAL_ASSERT(i < converterCount); CORRADE_INTERNAL_ASSERT(i < converterCount);
if(converterCount > 1 && args.isSet("verbose")) if(converterCount > 1 && args.isSet("verbose"))
Debug{} << "Processing (" << Debug::nospace << (i+1) << Debug::nospace << "/" << Debug::nospace << converterCount << Debug::nospace << ") with" << converterName << Debug::nospace << "..."; Debug{} << "Processing (" << Debug::nospace << (i+1) << Debug::nospace << "/" << Debug::nospace << converterCount << Debug::nospace << ") with" << converterName << Debug::nospace << "...";

Loading…
Cancel
Save