Browse Source

Any*{Importer,Converter}: use string view APIs for extension matching.

Now that Path is std::string-free, this is all very possible, very
convenient and very pretty.
pull/556/head
Vladimír Vondruš 4 years ago
parent
commit
3fc9028b54
  1. 31
      src/MagnumPlugins/AnyAudioImporter/AnyImporter.cpp
  2. 145
      src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp
  3. 121
      src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp
  4. 10
      src/MagnumPlugins/AnySceneConverter/AnySceneConverter.cpp
  5. 5
      src/MagnumPlugins/AnyShaderConverter/AnyConverter.cpp

31
src/MagnumPlugins/AnyAudioImporter/AnyImporter.cpp

@ -30,12 +30,15 @@
#include <Corrade/PluginManager/PluginMetadata.h> #include <Corrade/PluginManager/PluginMetadata.h>
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
#include "MagnumPlugins/Implementation/propagateConfiguration.h" #include "MagnumPlugins/Implementation/propagateConfiguration.h"
namespace Magnum { namespace Audio { namespace Magnum { namespace Audio {
using namespace Containers::Literals;
AnyImporter::AnyImporter(PluginManager::Manager<AbstractImporter>& manager): AbstractImporter{manager} {} AnyImporter::AnyImporter(PluginManager::Manager<AbstractImporter>& manager): AbstractImporter{manager} {}
AnyImporter::AnyImporter(PluginManager::AbstractManager& manager, const std::string& plugin): AbstractImporter{manager, plugin} {} AnyImporter::AnyImporter(PluginManager::AbstractManager& manager, const std::string& plugin): AbstractImporter{manager, plugin} {}
@ -51,21 +54,23 @@ void AnyImporter::doClose() { _in = nullptr; }
void AnyImporter::doOpenFile(const std::string& filename) { void AnyImporter::doOpenFile(const std::string& filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo lowercase only the extension, once Directory::split() is done */ /* We don't detect any double extensions yet, so we can normalize just the
const std::string normalized = Utility::String::lowercase(filename); extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
std::string plugin; Containers::StringView plugin;
if(Utility::String::endsWith(normalized, ".aac")) if(normalizedExtension == ".aac"_s)
plugin = "AacAudioImporter"; plugin = "AacAudioImporter"_s;
else if(Utility::String::endsWith(normalized, ".mp3")) else if(normalizedExtension == ".mp3"_s)
plugin = "Mp3AudioImporter"; plugin = "Mp3AudioImporter"_s;
else if(Utility::String::endsWith(normalized, ".ogg")) else if(normalizedExtension == ".ogg"_s)
plugin = "VorbisAudioImporter"; plugin = "VorbisAudioImporter"_s;
else if(Utility::String::endsWith(normalized, ".wav")) else if(normalizedExtension == ".wav"_s)
plugin = "WavAudioImporter"; plugin = "WavAudioImporter"_s;
else if(Utility::String::endsWith(normalized, ".flac")) else if(normalizedExtension == ".flac"_s)
plugin = "FlacAudioImporter"; plugin = "FlacAudioImporter"_s;
else { else {
Error{} << "Audio::AnyImporter::openFile(): cannot determine the format of" << filename; Error{} << "Audio::AnyImporter::openFile(): cannot determine the format of" << filename;
return; return;

145
src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp

@ -31,6 +31,7 @@
#include <Corrade/PluginManager/PluginMetadata.h> #include <Corrade/PluginManager/PluginMetadata.h>
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h> /* for PluginMetadata::name() */ #include <Corrade/Utility/DebugStl.h> /* for PluginMetadata::name() */
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
#include "Magnum/Trade/ImageData.h" #include "Magnum/Trade/ImageData.h"
@ -65,13 +66,14 @@ ImageConverterFeatures AnyImageConverter::doFeatures() const {
bool AnyImageConverter::doConvertToFile(const ImageView1D& image, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const ImageView1D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s)) if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 1D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 1D image";
@ -108,32 +110,33 @@ bool AnyImageConverter::doConvertToFile(const ImageView1D& image, const Containe
bool AnyImageConverter::doConvertToFile(const ImageView2D& image, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const ImageView2D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".bmp"_s)) if(normalizedExtension == ".bmp"_s)
plugin = "BmpImageConverter"_s; plugin = "BmpImageConverter"_s;
else if(normalized.hasSuffix(".basis"_s)) else if(normalizedExtension == ".basis"_s)
plugin = "BasisImageConverter"_s; plugin = "BasisImageConverter"_s;
else if(normalized.hasSuffix(".exr"_s)) else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImageConverter"_s; plugin = "OpenExrImageConverter"_s;
else if(normalized.hasSuffix(".hdr"_s)) else if(normalizedExtension == ".hdr"_s)
plugin = "HdrImageConverter"_s; plugin = "HdrImageConverter"_s;
else if(normalized.hasSuffix(".jpg"_s) || else if(normalizedExtension == ".jpg"_s ||
normalized.hasSuffix(".jpeg"_s) || normalizedExtension == ".jpeg"_s ||
normalized.hasSuffix(".jpe"_s)) normalizedExtension == ".jpe"_s)
plugin = "JpegImageConverter"_s; plugin = "JpegImageConverter"_s;
else if(normalized.hasSuffix(".ktx2"_s)) else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else if(normalized.hasSuffix(".png"_s)) else if(normalizedExtension == ".png"_s)
plugin = "PngImageConverter"_s; plugin = "PngImageConverter"_s;
else if(normalized.hasSuffix(".tga"_s) || else if(normalizedExtension == ".tga"_s ||
normalized.hasSuffix(".vda"_s) || normalizedExtension == ".vda"_s ||
normalized.hasSuffix(".icb"_s) || normalizedExtension == ".icb"_s ||
normalized.hasSuffix( ".vst"_s)) normalizedExtension == ".vst"_s)
plugin = "TgaImageConverter"_s; plugin = "TgaImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 2D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 2D image";
@ -170,17 +173,18 @@ bool AnyImageConverter::doConvertToFile(const ImageView2D& image, const Containe
bool AnyImageConverter::doConvertToFile(const ImageView3D& image, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const ImageView3D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".basis"_s)) if(normalizedExtension == ".basis"_s)
plugin = "BasisImageConverter"_s; plugin = "BasisImageConverter"_s;
else if(normalized.hasSuffix(".exr"_s)) else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImageConverter"_s; plugin = "OpenExrImageConverter"_s;
else if(normalized.hasSuffix(".ktx2"_s)) else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 3D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a 3D image";
@ -217,13 +221,14 @@ bool AnyImageConverter::doConvertToFile(const ImageView3D& image, const Containe
bool AnyImageConverter::doConvertToFile(const CompressedImageView1D& image, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const CompressedImageView1D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s)) if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 1D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 1D image";
@ -260,13 +265,14 @@ bool AnyImageConverter::doConvertToFile(const CompressedImageView1D& image, cons
bool AnyImageConverter::doConvertToFile(const CompressedImageView2D& image, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const CompressedImageView2D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s)) if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 2D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 2D image";
@ -303,13 +309,14 @@ bool AnyImageConverter::doConvertToFile(const CompressedImageView2D& image, cons
bool AnyImageConverter::doConvertToFile(const CompressedImageView3D& image, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const CompressedImageView3D& image, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s)) if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 3D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a compressed 3D image";
@ -346,13 +353,14 @@ bool AnyImageConverter::doConvertToFile(const CompressedImageView3D& image, cons
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView1D> imageLevels, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView1D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s)) if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 1D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 1D image";
@ -389,17 +397,18 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageV
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView2D> imageLevels, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView2D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".basis"_s)) if(normalizedExtension == ".basis"_s)
plugin = "BasisImageConverter"_s; plugin = "BasisImageConverter"_s;
else if(normalized.hasSuffix(".exr"_s)) else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImageConverter"_s; plugin = "OpenExrImageConverter"_s;
else if(normalized.hasSuffix(".ktx2"_s)) else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 2D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 2D image";
@ -436,17 +445,18 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageV
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView3D> imageLevels, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageView3D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".basis"_s)) if(normalizedExtension == ".basis"_s)
plugin = "BasisImageConverter"_s; plugin = "BasisImageConverter"_s;
else if(normalized.hasSuffix(".exr"_s)) else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImageConverter"_s; plugin = "OpenExrImageConverter"_s;
else if(normalized.hasSuffix(".ktx2"_s)) else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 3D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level 3D image";
@ -483,13 +493,14 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const ImageV
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView1D> imageLevels, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView1D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s)) if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 1D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 1D image";
@ -526,13 +537,14 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const Compre
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView2D> imageLevels, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView2D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s)) if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 2D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 2D image";
@ -569,13 +581,14 @@ bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const Compre
bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView3D> imageLevels, const Containers::StringView filename) { bool AnyImageConverter::doConvertToFile(const Containers::ArrayView<const CompressedImageView3D> imageLevels, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::String normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".ktx2"_s)) if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImageConverter"_s; plugin = "KtxImageConverter"_s;
else { else {
Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 3D image"; Error{} << "Trade::AnyImageConverter::convertToFile(): cannot determine the format of" << filename << "for a multi-level compressed 3D image";

121
src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp

@ -33,6 +33,7 @@
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
#include "Magnum/Trade/ImageData.h" #include "Magnum/Trade/ImageData.h"
@ -40,6 +41,8 @@
namespace Magnum { namespace Trade { namespace Magnum { namespace Trade {
using namespace Containers::Literals;
AnyImageImporter::AnyImageImporter(PluginManager::Manager<AbstractImporter>& manager): AbstractImporter{manager} {} AnyImageImporter::AnyImageImporter(PluginManager::Manager<AbstractImporter>& manager): AbstractImporter{manager} {}
AnyImageImporter::AnyImageImporter(PluginManager::AbstractManager& manager, const std::string& plugin): AbstractImporter{manager, plugin} {} AnyImageImporter::AnyImageImporter(PluginManager::AbstractManager& manager, const std::string& plugin): AbstractImporter{manager, plugin} {}
@ -61,65 +64,67 @@ void AnyImageImporter::doClose() {
void AnyImageImporter::doOpenFile(const std::string& filename) { void AnyImageImporter::doOpenFile(const std::string& filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo lowercase only the extension, once Directory::split() is done */ /* We don't detect any double extensions yet, so we can normalize just the
const std::string normalized = Utility::String::lowercase(filename); extension. In case we eventually might, it'd have to be split() instead
to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
std::string plugin; Containers::StringView plugin;
if(Utility::String::endsWith(normalized, ".basis")) if(normalizedExtension == ".basis"_s)
plugin = "BasisImporter"; plugin = "BasisImporter"_s;
else if(Utility::String::endsWith(normalized, ".bmp")) else if(normalizedExtension == ".bmp"_s)
plugin = "BmpImporter"; plugin = "BmpImporter"_s;
else if(Utility::String::endsWith(normalized, ".dds")) else if(normalizedExtension == ".dds"_s)
plugin = "DdsImporter"; plugin = "DdsImporter"_s;
else if(Utility::String::endsWith(normalized, ".exr")) else if(normalizedExtension == ".exr"_s)
plugin = "OpenExrImporter"; plugin = "OpenExrImporter"_s;
else if(Utility::String::endsWith(normalized, ".gif")) else if(normalizedExtension == ".gif"_s)
plugin = "GifImporter"; plugin = "GifImporter"_s;
else if(Utility::String::endsWith(normalized, ".hdr")) else if(normalizedExtension == ".hdr"_s)
plugin = "HdrImporter"; plugin = "HdrImporter"_s;
else if(Utility::String::endsWith(normalized, ".ico") || else if(normalizedExtension == ".ico"_s ||
Utility::String::endsWith(normalized, ".cur")) normalizedExtension == ".cur"_s)
plugin = "IcoImporter"; plugin = "IcoImporter"_s;
else if(Utility::String::endsWith(normalized, ".jpg") || else if(normalizedExtension == ".jpg"_s ||
Utility::String::endsWith(normalized, ".jpeg") || normalizedExtension == ".jpeg"_s ||
Utility::String::endsWith(normalized, ".jpe")) normalizedExtension == ".jpe"_s)
plugin = "JpegImporter"; plugin = "JpegImporter"_s;
else if(Utility::String::endsWith(normalized, ".jp2")) else if(normalizedExtension == ".jp2"_s)
plugin = "Jpeg2000Importer"; plugin = "Jpeg2000Importer"_s;
else if(Utility::String::endsWith(normalized, ".ktx2")) else if(normalizedExtension == ".ktx2"_s)
plugin = "KtxImporter"; plugin = "KtxImporter"_s;
else if(Utility::String::endsWith(normalized, ".mng")) else if(normalizedExtension == ".mng"_s)
plugin = "MngImporter"; plugin = "MngImporter"_s;
else if(Utility::String::endsWith(normalized, ".pbm")) else if(normalizedExtension == ".pbm"_s)
plugin = "PbmImporter"; plugin = "PbmImporter"_s;
else if(Utility::String::endsWith(normalized, ".pcx")) else if(normalizedExtension == ".pcx"_s)
plugin = "PcxImporter"; plugin = "PcxImporter"_s;
else if(Utility::String::endsWith(normalized, ".pgm")) else if(normalizedExtension == ".pgm"_s)
plugin = "PgmImporter"; plugin = "PgmImporter"_s;
else if(Utility::String::endsWith(normalized, ".pic")) else if(normalizedExtension == ".pic"_s)
plugin = "PicImporter"; plugin = "PicImporter"_s;
else if(Utility::String::endsWith(normalized, ".pnm")) else if(normalizedExtension == ".pnm"_s)
plugin = "PnmImporter"; plugin = "PnmImporter"_s;
else if(Utility::String::endsWith(normalized, ".png")) else if(normalizedExtension == ".png"_s)
plugin = "PngImporter"; plugin = "PngImporter"_s;
else if(Utility::String::endsWith(normalized, ".ppm")) else if(normalizedExtension == ".ppm"_s)
plugin = "PpmImporter"; plugin = "PpmImporter"_s;
else if(Utility::String::endsWith(normalized, ".psd")) else if(normalizedExtension == ".psd"_s)
plugin = "PsdImporter"; plugin = "PsdImporter"_s;
else if(Utility::String::endsWith(normalized, ".sgi") || else if(normalizedExtension == ".sgi"_s ||
Utility::String::endsWith(normalized, ".bw") || normalizedExtension == ".bw"_s ||
Utility::String::endsWith(normalized, ".rgb") || normalizedExtension == ".rgb"_s ||
Utility::String::endsWith(normalized, ".rgba")) normalizedExtension == ".rgba"_s)
plugin = "SgiImporter"; plugin = "SgiImporter"_s;
else if(Utility::String::endsWith(normalized, ".tif") || else if(normalizedExtension == ".tif"_s ||
Utility::String::endsWith(normalized, ".tiff")) normalizedExtension == ".tiff"_s)
plugin = "TiffImporter"; plugin = "TiffImporter"_s;
else if(Utility::String::endsWith(normalized, ".tga") || else if(normalizedExtension == ".tga"_s ||
Utility::String::endsWith(normalized, ".vda") || normalizedExtension == ".vda"_s ||
Utility::String::endsWith(normalized, ".icb") || normalizedExtension == ".icb"_s ||
Utility::String::endsWith(normalized, ".vst")) normalizedExtension == ".vst"_s)
plugin = "TgaImporter"; plugin = "TgaImporter"_s;
else { else {
Error{} << "Trade::AnyImageImporter::openFile(): cannot determine the format of" << filename; Error{} << "Trade::AnyImageImporter::openFile(): cannot determine the format of" << filename;
return; return;
@ -161,7 +166,7 @@ void AnyImageImporter::doOpenData(Containers::Array<char>&& data, DataFlags) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/* So we can use the convenient hasSuffix() API */ /* So we can use the convenient hasPrefix() API */
const Containers::ArrayView<const char> dataView = data; const Containers::ArrayView<const char> dataView = data;
const Containers::StringView dataString = dataView; const Containers::StringView dataString = dataView;

10
src/MagnumPlugins/AnySceneConverter/AnySceneConverter.cpp

@ -31,6 +31,7 @@
#include <Corrade/PluginManager/PluginMetadata.h> #include <Corrade/PluginManager/PluginMetadata.h>
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h> /* for PluginMetadata::name() */ #include <Corrade/Utility/DebugStl.h> /* for PluginMetadata::name() */
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
#include "Magnum/Trade/ImageData.h" #include "Magnum/Trade/ImageData.h"
@ -53,13 +54,14 @@ SceneConverterFeatures AnySceneConverter::doFeatures() const {
bool AnySceneConverter::doConvertToFile(const MeshData& mesh, const Containers::StringView filename) { bool AnySceneConverter::doConvertToFile(const MeshData& mesh, const Containers::StringView filename) {
CORRADE_INTERNAL_ASSERT(manager()); CORRADE_INTERNAL_ASSERT(manager());
/** @todo once Directory is std::string-free, use splitExtension(), but /* We don't detect any double extensions yet, so we can normalize just the
only if we don't detect more than one extension yet */ extension. In case we eventually might, it'd have to be split() instead
const Containers::StringView normalized = Utility::String::lowercase(filename); to save at least by normalizing just the filename and not the path. */
const Containers::String normalizedExtension = Utility::String::lowercase(Utility::Path::splitExtension(filename).second());
/* Detect the plugin from extension */ /* Detect the plugin from extension */
Containers::StringView plugin; Containers::StringView plugin;
if(normalized.hasSuffix(".ply"_s)) if(normalizedExtension == ".ply"_s)
plugin = "StanfordSceneConverter"_s; plugin = "StanfordSceneConverter"_s;
else { else {
Error{} << "Trade::AnySceneConverter::convertToFile(): cannot determine the format of" << filename; Error{} << "Trade::AnySceneConverter::convertToFile(): cannot determine the format of" << filename;

5
src/MagnumPlugins/AnyShaderConverter/AnyConverter.cpp

@ -32,6 +32,7 @@
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/DebugStl.h> /* for PluginMetadata::name() */ #include <Corrade/Utility/DebugStl.h> /* for PluginMetadata::name() */
#include <Corrade/Utility/FormatStl.h> #include <Corrade/Utility/FormatStl.h>
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
#include "MagnumPlugins/Implementation/propagateConfiguration.h" #include "MagnumPlugins/Implementation/propagateConfiguration.h"
@ -122,8 +123,8 @@ Containers::StringView stringForFormat(const Format format) {
Format formatForExtension(const char* prefix, const Containers::StringView filename) { Format formatForExtension(const char* prefix, const Containers::StringView filename) {
/* Can't reliably lowercase just the extension as we detect double /* Can't reliably lowercase just the extension as we detect double
extensions as well */ extensions as well. But we can lowercase just the filename, at least. */
const Containers::String normalized = Utility::String::lowercase(filename); const Containers::String normalized = Utility::String::lowercase(Utility::Path::split(filename).second());
/* https://github.com/KhronosGroup/SPIRV-Tools/blob/a715b1b4053519ad0f2bdb2d22ace35d35867cff/README.md#command-line-tools /* https://github.com/KhronosGroup/SPIRV-Tools/blob/a715b1b4053519ad0f2bdb2d22ace35d35867cff/README.md#command-line-tools
"It's a convention to name SPIR-V assembly and binary files with suffix "It's a convention to name SPIR-V assembly and binary files with suffix

Loading…
Cancel
Save