Browse Source

Any*{Importer,Converter}: lowercase() filename before recognizing suffix

pull/306/merge
Max Schwarz 7 years ago committed by Vladimír Vondruš
parent
commit
a480c70f06
  1. 8
      src/MagnumPlugins/AnyAudioImporter/AnyImporter.cpp
  2. 1
      src/MagnumPlugins/AnyAudioImporter/Test/AnyAudioImporterTest.cpp
  3. 24
      src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp
  4. 1
      src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp
  5. 58
      src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp
  6. 1
      src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp
  7. 64
      src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp
  8. 1
      src/MagnumPlugins/AnySceneImporter/Test/AnySceneImporterTest.cpp

8
src/MagnumPlugins/AnyAudioImporter/AnyImporter.cpp

@ -47,13 +47,15 @@ void AnyImporter::doClose() { _in = nullptr; }
void AnyImporter::doOpenFile(const std::string& filename) {
CORRADE_INTERNAL_ASSERT(manager());
std::string normalized = Utility::String::lowercase(filename);
/* Detect type from extension */
std::string plugin;
if(Utility::String::endsWith(filename, ".ogg"))
if(Utility::String::endsWith(normalized, ".ogg"))
plugin = "VorbisAudioImporter";
else if(Utility::String::endsWith(filename, ".wav"))
else if(Utility::String::endsWith(normalized, ".wav"))
plugin = "WavAudioImporter";
else if(Utility::String::endsWith(filename, ".flac"))
else if(Utility::String::endsWith(normalized, ".flac"))
plugin = "FlacAudioImporter";
else {
Error() << "Audio::AnyImporter::openFile(): cannot determine type of file" << filename;

1
src/MagnumPlugins/AnyAudioImporter/Test/AnyAudioImporterTest.cpp

@ -59,6 +59,7 @@ constexpr struct {
const char* plugin;
} DetectData[]{
{"OGG", "thunder.ogg", "VorbisAudioImporter"},
{"OGG uppercase", "YELL.OGG", "VorbisAudioImporter"},
{"FLAC", "symphony.flac", "FlacAudioImporter"}
};

24
src/MagnumPlugins/AnyImageConverter/AnyImageConverter.cpp

@ -46,24 +46,26 @@ auto AnyImageConverter::doFeatures() const -> Features {
bool AnyImageConverter::doExportToFile(const ImageView2D& image, const std::string& filename) {
CORRADE_INTERNAL_ASSERT(manager());
std::string normalized = Utility::String::lowercase(filename);
/* Detect type from extension */
std::string plugin;
if(Utility::String::endsWith(filename, ".bmp"))
if(Utility::String::endsWith(normalized, ".bmp"))
plugin = "BmpImageConverter";
else if(Utility::String::endsWith(filename, ".exr"))
else if(Utility::String::endsWith(normalized, ".exr"))
plugin = "OpenExrImageConverter";
else if(Utility::String::endsWith(filename, ".hdr"))
else if(Utility::String::endsWith(normalized, ".hdr"))
plugin = "HdrImageConverter";
else if(Utility::String::endsWith(filename, ".jpg") ||
Utility::String::endsWith(filename, ".jpeg") ||
Utility::String::endsWith(filename, ".jpe"))
else if(Utility::String::endsWith(normalized, ".jpg") ||
Utility::String::endsWith(normalized, ".jpeg") ||
Utility::String::endsWith(normalized, ".jpe"))
plugin = "JpegImageConverter";
else if(Utility::String::endsWith(filename, ".png"))
else if(Utility::String::endsWith(normalized, ".png"))
plugin = "PngImageConverter";
else if(Utility::String::endsWith(filename, ".tga") ||
Utility::String::endsWith(filename, ".vda") ||
Utility::String::endsWith(filename, ".icb") ||
Utility::String::endsWith(filename, ".vst"))
else if(Utility::String::endsWith(normalized, ".tga") ||
Utility::String::endsWith(normalized, ".vda") ||
Utility::String::endsWith(normalized, ".icb") ||
Utility::String::endsWith(normalized, ".vst"))
plugin = "TgaImageConverter";
else {
Error() << "Trade::AnyImageConverter::exportToFile(): cannot determine type of file" << filename;

1
src/MagnumPlugins/AnyImageConverter/Test/AnyImageConverterTest.cpp

@ -66,6 +66,7 @@ constexpr struct {
{"HDR", "file.hdr", "HdrImageConverter"},
{"JPEG", "file.jpg", "JpegImageConverter"},
{"JPEG weird extension", "file.jpe", "JpegImageConverter"},
{"JPEG uppercase", "output.JPG", "JpegImageConverter"},
{"PNG", "file.png", "PngImageConverter"}
};

58
src/MagnumPlugins/AnyImageImporter/AnyImageImporter.cpp

@ -51,54 +51,56 @@ void AnyImageImporter::doClose() {
void AnyImageImporter::doOpenFile(const std::string& filename) {
CORRADE_INTERNAL_ASSERT(manager());
std::string normalized = Utility::String::lowercase(filename);
/* Detect type from extension */
std::string plugin;
if(Utility::String::endsWith(filename, ".bmp"))
if(Utility::String::endsWith(normalized, ".bmp"))
plugin = "BmpImporter";
else if(Utility::String::endsWith(filename, ".dds"))
else if(Utility::String::endsWith(normalized, ".dds"))
plugin = "DdsImporter";
else if(Utility::String::endsWith(filename, ".exr"))
else if(Utility::String::endsWith(normalized, ".exr"))
plugin = "OpenExrImporter";
else if(Utility::String::endsWith(filename, ".gif"))
else if(Utility::String::endsWith(normalized, ".gif"))
plugin = "GifImporter";
else if(Utility::String::endsWith(filename, ".hdr"))
else if(Utility::String::endsWith(normalized, ".hdr"))
plugin = "HdrImporter";
else if(Utility::String::endsWith(filename, ".jpg") ||
Utility::String::endsWith(filename, ".jpeg") ||
Utility::String::endsWith(filename, ".jpe") )
else if(Utility::String::endsWith(normalized, ".jpg") ||
Utility::String::endsWith(normalized, ".jpeg") ||
Utility::String::endsWith(normalized, ".jpe"))
plugin = "JpegImporter";
else if(Utility::String::endsWith(filename, ".jp2"))
else if(Utility::String::endsWith(normalized, ".jp2"))
plugin = "Jpeg2000Importer";
else if(Utility::String::endsWith(filename, ".mng"))
else if(Utility::String::endsWith(normalized, ".mng"))
plugin = "MngImporter";
else if(Utility::String::endsWith(filename, ".pbm"))
else if(Utility::String::endsWith(normalized, ".pbm"))
plugin = "PbmImporter";
else if(Utility::String::endsWith(filename, ".pcx"))
else if(Utility::String::endsWith(normalized, ".pcx"))
plugin = "PcxImporter";
else if(Utility::String::endsWith(filename, ".pgm"))
else if(Utility::String::endsWith(normalized, ".pgm"))
plugin = "PgmImporter";
else if(Utility::String::endsWith(filename, ".pic"))
else if(Utility::String::endsWith(normalized, ".pic"))
plugin = "PicImporter";
else if(Utility::String::endsWith(filename, ".pnm"))
else if(Utility::String::endsWith(normalized, ".pnm"))
plugin = "PnmImporter";
else if(Utility::String::endsWith(filename, ".png"))
else if(Utility::String::endsWith(normalized, ".png"))
plugin = "PngImporter";
else if(Utility::String::endsWith(filename, ".ppm"))
else if(Utility::String::endsWith(normalized, ".ppm"))
plugin = "PpmImporter";
else if(Utility::String::endsWith(filename, ".psd"))
else if(Utility::String::endsWith(normalized, ".psd"))
plugin = "PsdImporter";
else if(Utility::String::endsWith(filename, ".sgi") ||
Utility::String::endsWith(filename, ".bw") ||
Utility::String::endsWith(filename, ".rgb") ||
Utility::String::endsWith(filename, ".rgba"))
else if(Utility::String::endsWith(normalized, ".sgi") ||
Utility::String::endsWith(normalized, ".bw") ||
Utility::String::endsWith(normalized, ".rgb") ||
Utility::String::endsWith(normalized, ".rgba"))
plugin = "SgiImporter";
else if(Utility::String::endsWith(filename, ".tif") ||
Utility::String::endsWith(filename, ".tiff"))
else if(Utility::String::endsWith(normalized, ".tif") ||
Utility::String::endsWith(normalized, ".tiff"))
plugin = "TiffImporter";
else if(Utility::String::endsWith(filename, ".tga") ||
Utility::String::endsWith(filename, ".vda") ||
Utility::String::endsWith(filename, ".icb") ||
Utility::String::endsWith(filename, ".vst"))
else if(Utility::String::endsWith(normalized, ".tga") ||
Utility::String::endsWith(normalized, ".vda") ||
Utility::String::endsWith(normalized, ".icb") ||
Utility::String::endsWith(normalized, ".vst"))
plugin = "TgaImporter";
else {
Error() << "Trade::AnyImageImporter::openFile(): cannot determine type of file" << filename;

1
src/MagnumPlugins/AnyImageImporter/Test/AnyImageImporterTest.cpp

@ -75,6 +75,7 @@ constexpr struct {
{"PNG data", "rgb.png", fileCallback, "PngImporter"},
{"JPEG", "gray.jpg", nullptr, "JpegImporter"},
{"JPEG data", "gray.jpg", fileCallback, "JpegImporter"},
{"JPEG uppercase", "uppercase.JPG", nullptr, "JpegImporter"},
{"JPEG2000", "image.jp2", nullptr, "Jpeg2000Importer"},
{"EXR", "image.exr", nullptr, "OpenExrImporter"},
{"EXR data", "image.exr", fileCallback, "OpenExrImporter"},

64
src/MagnumPlugins/AnySceneImporter/AnySceneImporter.cpp

@ -61,63 +61,65 @@ void AnySceneImporter::doClose() {
void AnySceneImporter::doOpenFile(const std::string& filename) {
CORRADE_INTERNAL_ASSERT(manager());
std::string normalized = Utility::String::lowercase(filename);
/* Detect type from extension */
std::string plugin;
if(Utility::String::endsWith(filename, ".3ds") ||
Utility::String::endsWith(filename, ".ase"))
if(Utility::String::endsWith(normalized, ".3ds") ||
Utility::String::endsWith(normalized, ".ase"))
plugin = "3dsImporter";
else if(Utility::String::endsWith(filename, ".ac"))
else if(Utility::String::endsWith(normalized, ".ac"))
plugin = "Ac3dImporter";
else if(Utility::String::endsWith(filename, ".blend"))
else if(Utility::String::endsWith(normalized, ".blend"))
plugin = "BlenderImporter";
else if(Utility::String::endsWith(filename, ".bvh"))
else if(Utility::String::endsWith(normalized, ".bvh"))
plugin = "BvhImporter";
else if(Utility::String::endsWith(filename, ".csm"))
else if(Utility::String::endsWith(normalized, ".csm"))
plugin = "CsmImporter";
else if(Utility::String::endsWith(filename, ".dae"))
else if(Utility::String::endsWith(normalized, ".dae"))
plugin = "ColladaImporter";
else if(Utility::String::endsWith(filename, ".x"))
else if(Utility::String::endsWith(normalized, ".x"))
plugin = "DirectXImporter";
else if(Utility::String::endsWith(filename, ".dxf"))
else if(Utility::String::endsWith(normalized, ".dxf"))
plugin = "DxfImporter";
else if(Utility::String::endsWith(filename, ".fbx"))
else if(Utility::String::endsWith(normalized, ".fbx"))
plugin = "FbxImporter";
else if(Utility::String::endsWith(filename, ".gltf"))
else if(Utility::String::endsWith(normalized, ".gltf"))
plugin = "GltfImporter";
else if(Utility::String::endsWith(filename, ".glb"))
else if(Utility::String::endsWith(normalized, ".glb"))
plugin = "GlbImporter";
else if(Utility::String::endsWith(filename, ".ifc"))
else if(Utility::String::endsWith(normalized, ".ifc"))
plugin = "IfcImporter";
else if(Utility::String::endsWith(filename, ".irrmesh") ||
Utility::String::endsWith(filename, ".irr"))
else if(Utility::String::endsWith(normalized, ".irrmesh") ||
Utility::String::endsWith(normalized, ".irr"))
plugin = "IrrlichtImporter";
else if(Utility::String::endsWith(filename, ".lwo") ||
Utility::String::endsWith(filename, ".lws"))
else if(Utility::String::endsWith(normalized, ".lwo") ||
Utility::String::endsWith(normalized, ".lws"))
plugin = "LightWaveImporter";
else if(Utility::String::endsWith(filename, ".lxo"))
else if(Utility::String::endsWith(normalized, ".lxo"))
plugin = "ModoImporter";
else if(Utility::String::endsWith(filename, ".ms3d"))
else if(Utility::String::endsWith(normalized, ".ms3d"))
plugin = "MilkshapeImporter";
else if(Utility::String::endsWith(filename, ".obj"))
else if(Utility::String::endsWith(normalized, ".obj"))
plugin = "ObjImporter";
else if(Utility::String::endsWith(filename, ".xml"))
else if(Utility::String::endsWith(normalized, ".xml"))
plugin = "OgreImporter";
else if(Utility::String::endsWith(filename, ".ogex"))
else if(Utility::String::endsWith(normalized, ".ogex"))
plugin = "OpenGexImporter";
else if(Utility::String::endsWith(filename, ".ply"))
else if(Utility::String::endsWith(normalized, ".ply"))
plugin = "StanfordImporter";
else if(Utility::String::endsWith(filename, ".stl"))
else if(Utility::String::endsWith(normalized, ".stl"))
plugin = "StlImporter";
else if(Utility::String::endsWith(filename, ".cob") ||
Utility::String::endsWith(filename, ".scn"))
else if(Utility::String::endsWith(normalized, ".cob") ||
Utility::String::endsWith(normalized, ".scn"))
plugin = "TrueSpaceImporter";
else if(Utility::String::endsWith(filename, ".3d"))
else if(Utility::String::endsWith(normalized, ".3d"))
plugin = "UnrealImporter";
else if(Utility::String::endsWith(filename, ".smd") ||
Utility::String::endsWith(filename, ".vta"))
else if(Utility::String::endsWith(normalized, ".smd") ||
Utility::String::endsWith(normalized, ".vta"))
plugin = "ValveImporter";
else if(Utility::String::endsWith(filename, ".xgl") ||
Utility::String::endsWith(filename, ".zgl"))
else if(Utility::String::endsWith(normalized, ".xgl") ||
Utility::String::endsWith(normalized, ".zgl"))
plugin = "XglImporter";
else {
Error() << "Trade::AnySceneImporter::openFile(): cannot determine type of file" << filename;

1
src/MagnumPlugins/AnySceneImporter/Test/AnySceneImporterTest.cpp

@ -68,6 +68,7 @@ constexpr struct {
{"glTF binary", "khronos.glb", "GlbImporter"},
{"OpenGEX", "eric.ogex", "OpenGexImporter"},
{"Stanford PLY", "bunny.ply", "StanfordImporter"},
{"Stanford PLY uppercase", "ARMADI~1.PLY", "StanfordImporter"},
{"STL", "robot.stl", "StlImporter"},
/* Not testing everything, only the most important ones */
};

Loading…
Cancel
Save