migrate from std::filesystem::path to io::path (WIP)

This commit is contained in:
MihailRis
2025-01-30 22:23:13 +03:00
parent 1e22882284
commit e0314803c0
72 changed files with 1189 additions and 791 deletions
+9 -16
View File
@@ -1,6 +1,5 @@
#include "imageio.hpp"
#include <filesystem>
#include <functional>
#include <unordered_map>
@@ -8,8 +7,6 @@
#include "io/io.hpp"
#include "png.hpp"
namespace fs = std::filesystem;
using image_reader =
std::function<std::unique_ptr<ImageData>(const ubyte*, size_t)>;
using image_writer = std::function<void(const std::string&, const ImageData*)>;
@@ -30,33 +27,29 @@ bool imageio::is_write_supported(const std::string& extension) {
return writers.find(extension) != writers.end();
}
inline std::string extensionOf(const std::string& filename) {
return fs::u8path(filename).extension().u8string();
}
std::unique_ptr<ImageData> imageio::read(const fs::path& filename) {
auto found = readers.find(extensionOf(filename.u8string()));
std::unique_ptr<ImageData> imageio::read(const io::path& file) {
auto found = readers.find(file.extension());
if (found == readers.end()) {
throw std::runtime_error(
"file format is not supported (read): " + filename.u8string()
"file format is not supported (read): " + file.string()
);
}
auto bytes = io::read_bytes_buffer(filename);
auto bytes = io::read_bytes_buffer(file);
try {
return std::unique_ptr<ImageData>(found->second(bytes.data(), bytes.size()));
} catch (const std::runtime_error& err) {
throw std::runtime_error(
"could not to load image " + filename.u8string() + ": " + err.what()
"could not to load image " + file.string() + ": " + err.what()
);
}
}
void imageio::write(const std::string& filename, const ImageData* image) {
auto found = writers.find(extensionOf(filename));
void imageio::write(const io::path& file, const ImageData* image) {
auto found = writers.find(file.extension());
if (found == writers.end()) {
throw std::runtime_error(
"file format is not supported (write): " + filename
"file format is not supported (write): " + file.string()
);
}
return found->second(filename, image);
return found->second(io::resolve(file).u8string(), image);
}