26 lines
903 B
C++
26 lines
903 B
C++
/*
|
|
* 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()));
|
|
}
|
|
} |