implement png image loader and refactor existing loader classes

This commit is contained in:
ohyzha
2024-07-31 12:53:27 +03:00
parent 51608425c1
commit 847b8660b5
5 changed files with 108 additions and 15 deletions

View File

@@ -0,0 +1,26 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "ImageLoaderPng.hpp"
#include <Data/Containers/Array.hpp>
#include <fstream>
#include <cstring>
namespace OpenVulkano::Image
{
std::unique_ptr<Image> ImageLoaderPng::loadFromFile(const std::string& filePath)
{
std::ifstream file(filePath, std::ios::binary);
if (!file) { throw std::runtime_error("Could not open file: " + filePath); }
std::vector<uint8_t> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
return loadData(buffer.data(), static_cast<int>(buffer.size()));
}
std::unique_ptr<Image> ImageLoaderPng::loadFromMemory(const std::vector<uint8_t>& buffer)
{
return loadData(buffer.data(), static_cast<int>(buffer.size()));
}
}