converted from bmp to jpg
This commit is contained in:
56
src/utils/ImagePathResolver.h
Normal file
56
src/utils/ImagePathResolver.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
namespace AssetPath {
|
||||
|
||||
inline bool fileExists(const std::string& path) {
|
||||
if (path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_IOStream* file = SDL_IOFromFile(path.c_str(), "rb");
|
||||
if (file) {
|
||||
SDL_CloseIO(file);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline std::string resolveImagePath(const std::string& originalPath) {
|
||||
if (originalPath.empty()) {
|
||||
return originalPath;
|
||||
}
|
||||
|
||||
if (fileExists(originalPath)) {
|
||||
return originalPath;
|
||||
}
|
||||
|
||||
const std::size_t dot = originalPath.find_last_of('.');
|
||||
const std::string base = (dot == std::string::npos) ? originalPath : originalPath.substr(0, dot);
|
||||
|
||||
static constexpr std::array<const char*, 5> preferredExtensions{
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".png",
|
||||
".webp",
|
||||
".bmp"
|
||||
};
|
||||
|
||||
for (const char* ext : preferredExtensions) {
|
||||
std::string candidate = base + ext;
|
||||
if (candidate == originalPath) {
|
||||
continue;
|
||||
}
|
||||
if (fileExists(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return originalPath;
|
||||
}
|
||||
|
||||
} // namespace AssetPath
|
||||
Reference in New Issue
Block a user