mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Fixed image file extension detection
Previously this would fail on `jpeg` and would detect something such as `notajpg` as `jpg`. This fixes #929.
This commit is contained in:
parent
fa1bc737d5
commit
df99d5fee2
@ -227,10 +227,10 @@ bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector
|
||||
if (!pixels.empty() && (size.x > 0) && (size.y > 0))
|
||||
{
|
||||
// Deduce the image type from its extension
|
||||
if (filename.size() > 3)
|
||||
{
|
||||
|
||||
// Extract the extension
|
||||
std::string extension = toLower(filename.substr(filename.size() - 3));
|
||||
const std::size_t dot = filename.find_last_of('.');
|
||||
const std::string extension = dot != std::string::npos ? toLower(filename.substr(dot + 1)) : "";
|
||||
|
||||
if (extension == "bmp")
|
||||
{
|
||||
@ -250,14 +250,13 @@ bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector
|
||||
if (stbi_write_png(filename.c_str(), size.x, size.y, 4, &pixels[0], 0))
|
||||
return true;
|
||||
}
|
||||
else if (extension == "jpg")
|
||||
else if (extension == "jpg" || extension == "jpeg")
|
||||
{
|
||||
// JPG format
|
||||
if (writeJpg(filename, pixels, size.x, size.y))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err() << "Failed to save image \"" << filename << "\"" << std::endl;
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user