Avoided unnecessary toLower string conversions
This commit is contained in:
parent
79134ba665
commit
53f7ae5d09
@ -286,34 +286,34 @@ int SoundFile::getFormatFromFilename(const std::string& filename)
|
|||||||
std::string ext = "wav";
|
std::string ext = "wav";
|
||||||
std::string::size_type pos = filename.find_last_of(".");
|
std::string::size_type pos = filename.find_last_of(".");
|
||||||
if (pos != std::string::npos)
|
if (pos != std::string::npos)
|
||||||
ext = filename.substr(pos + 1);
|
ext = toLower(filename.substr(pos + 1));
|
||||||
|
|
||||||
// Match every supported extension with its format constant
|
// Match every supported extension with its format constant
|
||||||
if (toLower(ext) == "wav" ) return SF_FORMAT_WAV;
|
if (ext == "wav" ) return SF_FORMAT_WAV;
|
||||||
if (toLower(ext) == "aif" ) return SF_FORMAT_AIFF;
|
if (ext == "aif" ) return SF_FORMAT_AIFF;
|
||||||
if (toLower(ext) == "aiff" ) return SF_FORMAT_AIFF;
|
if (ext == "aiff" ) return SF_FORMAT_AIFF;
|
||||||
if (toLower(ext) == "au" ) return SF_FORMAT_AU;
|
if (ext == "au" ) return SF_FORMAT_AU;
|
||||||
if (toLower(ext) == "raw" ) return SF_FORMAT_RAW;
|
if (ext == "raw" ) return SF_FORMAT_RAW;
|
||||||
if (toLower(ext) == "paf" ) return SF_FORMAT_PAF;
|
if (ext == "paf" ) return SF_FORMAT_PAF;
|
||||||
if (toLower(ext) == "svx" ) return SF_FORMAT_SVX;
|
if (ext == "svx" ) return SF_FORMAT_SVX;
|
||||||
if (toLower(ext) == "nist" ) return SF_FORMAT_NIST;
|
if (ext == "nist" ) return SF_FORMAT_NIST;
|
||||||
if (toLower(ext) == "voc" ) return SF_FORMAT_VOC;
|
if (ext == "voc" ) return SF_FORMAT_VOC;
|
||||||
if (toLower(ext) == "sf" ) return SF_FORMAT_IRCAM;
|
if (ext == "sf" ) return SF_FORMAT_IRCAM;
|
||||||
if (toLower(ext) == "w64" ) return SF_FORMAT_W64;
|
if (ext == "w64" ) return SF_FORMAT_W64;
|
||||||
if (toLower(ext) == "mat4" ) return SF_FORMAT_MAT4;
|
if (ext == "mat4" ) return SF_FORMAT_MAT4;
|
||||||
if (toLower(ext) == "mat5" ) return SF_FORMAT_MAT5;
|
if (ext == "mat5" ) return SF_FORMAT_MAT5;
|
||||||
if (toLower(ext) == "pvf" ) return SF_FORMAT_PVF;
|
if (ext == "pvf" ) return SF_FORMAT_PVF;
|
||||||
if (toLower(ext) == "xi" ) return SF_FORMAT_XI;
|
if (ext == "xi" ) return SF_FORMAT_XI;
|
||||||
if (toLower(ext) == "htk" ) return SF_FORMAT_HTK;
|
if (ext == "htk" ) return SF_FORMAT_HTK;
|
||||||
if (toLower(ext) == "sds" ) return SF_FORMAT_SDS;
|
if (ext == "sds" ) return SF_FORMAT_SDS;
|
||||||
if (toLower(ext) == "avr" ) return SF_FORMAT_AVR;
|
if (ext == "avr" ) return SF_FORMAT_AVR;
|
||||||
if (toLower(ext) == "sd2" ) return SF_FORMAT_SD2;
|
if (ext == "sd2" ) return SF_FORMAT_SD2;
|
||||||
if (toLower(ext) == "flac" ) return SF_FORMAT_FLAC;
|
if (ext == "flac" ) return SF_FORMAT_FLAC;
|
||||||
if (toLower(ext) == "caf" ) return SF_FORMAT_CAF;
|
if (ext == "caf" ) return SF_FORMAT_CAF;
|
||||||
if (toLower(ext) == "wve" ) return SF_FORMAT_WVE;
|
if (ext == "wve" ) return SF_FORMAT_WVE;
|
||||||
if (toLower(ext) == "ogg" ) return SF_FORMAT_OGG;
|
if (ext == "ogg" ) return SF_FORMAT_OGG;
|
||||||
if (toLower(ext) == "mpc2k") return SF_FORMAT_MPC2K;
|
if (ext == "mpc2k") return SF_FORMAT_MPC2K;
|
||||||
if (toLower(ext) == "rf64" ) return SF_FORMAT_RF64;
|
if (ext == "rf64" ) return SF_FORMAT_RF64;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -229,27 +229,27 @@ bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector
|
|||||||
if (filename.size() > 3)
|
if (filename.size() > 3)
|
||||||
{
|
{
|
||||||
// Extract the extension
|
// Extract the extension
|
||||||
std::string extension = filename.substr(filename.size() - 3);
|
std::string extension = toLower(filename.substr(filename.size() - 3));
|
||||||
|
|
||||||
if (toLower(extension) == "bmp")
|
if (extension == "bmp")
|
||||||
{
|
{
|
||||||
// BMP format
|
// BMP format
|
||||||
if (stbi_write_bmp(filename.c_str(), size.x, size.y, 4, &pixels[0]))
|
if (stbi_write_bmp(filename.c_str(), size.x, size.y, 4, &pixels[0]))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (toLower(extension) == "tga")
|
else if (extension == "tga")
|
||||||
{
|
{
|
||||||
// TGA format
|
// TGA format
|
||||||
if (stbi_write_tga(filename.c_str(), size.x, size.y, 4, &pixels[0]))
|
if (stbi_write_tga(filename.c_str(), size.x, size.y, 4, &pixels[0]))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(toLower(extension) == "png")
|
else if (extension == "png")
|
||||||
{
|
{
|
||||||
// PNG format
|
// PNG format
|
||||||
if (stbi_write_png(filename.c_str(), size.x, size.y, 4, &pixels[0], 0))
|
if (stbi_write_png(filename.c_str(), size.x, size.y, 4, &pixels[0], 0))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (toLower(extension) == "jpg")
|
else if (extension == "jpg")
|
||||||
{
|
{
|
||||||
// JPG format
|
// JPG format
|
||||||
if (writeJpg(filename, pixels, size.x, size.y))
|
if (writeJpg(filename, pixels, size.x, size.y))
|
||||||
|
Loading…
Reference in New Issue
Block a user