implement png image loader and refactor existing loader classes
This commit is contained in:
26
openVulkanoCpp/Image/ImageLoaderPng.cpp
Normal file
26
openVulkanoCpp/Image/ImageLoaderPng.cpp
Normal 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()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user