Browse Source

imageconverter,sceneconverter: compact image info if possible.

If the images have all just a single level and no names, print each on
just a single line.
pull/454/head
Vladimír Vondruš 6 years ago
parent
commit
4933b48652
  1. 9
      src/Magnum/MeshTools/sceneconverter.cpp
  2. 25
      src/Magnum/Trade/Implementation/converterUtilities.h
  3. 12
      src/Magnum/Trade/imageconverter.cpp

9
src/Magnum/MeshTools/sceneconverter.cpp

@ -313,8 +313,11 @@ save its output; if no --converter is specified, AnySceneConverter is used.)")
}
}
/* In case the images have all just a single level and no names, write
them in a compact way without listing levels. */
bool compactImages = false;
Containers::Array<Trade::Implementation::ImageInfo> imageInfos =
Trade::Implementation::imageInfo(*importer, error);
Trade::Implementation::imageInfo(*importer, error, compactImages);
for(const MeshInfo& info: meshInfos) {
Debug d;
@ -356,9 +359,9 @@ save its output; if no --converter is specified, AnySceneConverter is used.)")
if(info.level == 0) {
d << "Image" << info.image << Debug::nospace << ":";
if(!info.name.empty()) d << info.name;
d << Debug::newline;
if(compactImages) d << Debug::newline;
}
d << " Level" << info.level << Debug::nospace << ":";
if(compactImages) d << " Level" << info.level << Debug::nospace << ":";
if(info.compressed) d << info.compressedFormat;
else d << info.format;
if(info.size.z()) d << info.size;

25
src/Magnum/Trade/Implementation/converterUtilities.h

@ -86,11 +86,14 @@ struct ImageInfo {
std::string name;
};
Containers::Array<ImageInfo> imageInfo(AbstractImporter& importer, bool& error) {
Containers::Array<ImageInfo> imageInfo(AbstractImporter& importer, bool& error, bool& compact) {
Containers::Array<ImageInfo> infos;
for(UnsignedInt i = 0; i != importer.image1DCount(); ++i) {
for(UnsignedInt j = 0;j != importer.image1DLevelCount(i); ++j) {
const std::string name = importer.image1DName(i);
const UnsignedInt levelCount = importer.image1DLevelCount(i);
if(!name.empty() || levelCount != 1) compact = false;
for(UnsignedInt j = 0; j != levelCount; ++j) {
Containers::Optional<Trade::ImageData1D> image = importer.image1D(i, j);
if(!image) {
error = true;
@ -107,7 +110,11 @@ Containers::Array<ImageInfo> imageInfo(AbstractImporter& importer, bool& error)
}
}
for(UnsignedInt i = 0; i != importer.image2DCount(); ++i) {
for(UnsignedInt j = 0;j != importer.image2DLevelCount(i); ++j) {
const std::string name = importer.image2DName(i);
const UnsignedInt levelCount = importer.image2DLevelCount(i);
if(!name.empty() || levelCount != 1) compact = false;
for(UnsignedInt j = 0; j != levelCount; ++j) {
Containers::Optional<Trade::ImageData2D> image = importer.image2D(i, j);
if(!image) {
error = true;
@ -120,11 +127,15 @@ Containers::Array<ImageInfo> imageInfo(AbstractImporter& importer, bool& error)
image->isCompressed() ?
image->compressedFormat() : CompressedPixelFormat{},
Vector3i::pad(image->size()),
j ? "" : importer.image2DName(i));
j ? "" : name);
}
}
for(UnsignedInt i = 0; i != importer.image3DCount(); ++i) {
for(UnsignedInt j = 0;j != importer.image3DLevelCount(i); ++j) {
const std::string name = importer.image3DName(i);
const UnsignedInt levelCount = importer.image3DLevelCount(i);
if(!name.empty() || levelCount != 1) compact = false;
for(UnsignedInt j = 0; j != levelCount; ++j) {
Containers::Optional<Trade::ImageData3D> image = importer.image3D(i, j);
if(!image) {
error = true;
@ -137,7 +148,7 @@ Containers::Array<ImageInfo> imageInfo(AbstractImporter& importer, bool& error)
image->isCompressed() ?
image->compressedFormat() : CompressedPixelFormat{},
image->size(),
j ? "" : importer.image2DName(i));
j ? "" : name);
}
}

12
src/Magnum/Trade/imageconverter.cpp

@ -239,19 +239,21 @@ key=true; configuration subgroups are delimited with /.)")
return 0;
}
/* Parse everything first to avoid errors interleaved with output */
bool error = false;
/* Parse everything first to avoid errors interleaved with output.
In case the images have all just a single level and no names,
write them in a compact way without listing levels. */
bool error = false, compact = true;
Containers::Array<Trade::Implementation::ImageInfo> infos =
Trade::Implementation::imageInfo(*importer, error);
Trade::Implementation::imageInfo(*importer, error, compact);
for(const Trade::Implementation::ImageInfo& info: infos) {
Debug d;
if(info.level == 0) {
d << "Image" << info.image << Debug::nospace << ":";
if(!info.name.empty()) d << info.name;
d << Debug::newline;
if(!compact) d << Debug::newline;
}
d << " Level" << info.level << Debug::nospace << ":";
if(!compact) d << " Level" << info.level << Debug::nospace << ":";
if(info.compressed) d << info.compressedFormat;
else d << info.format;
if(info.size.z()) d << info.size;

Loading…
Cancel
Save