converted from bmp to jpg

This commit is contained in:
2025-11-22 21:46:00 +01:00
parent 28dd513619
commit 77a9237e25
47 changed files with 187 additions and 112 deletions

View 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