PNM image loader + tests
This commit is contained in:
32
openVulkanoCpp/Image/ImageLoaderPnm.hpp
Normal file
32
openVulkanoCpp/Image/ImageLoaderPnm.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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/.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Image/ImageLoader.hpp"
|
||||
|
||||
namespace OpenVulkano::Image
|
||||
{
|
||||
struct PnmHeader
|
||||
{
|
||||
char magic = 0; // 1 for P1, 2 for P2 etc
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int maxVal = 255; // Only used for formats P2, P3, P5, P6
|
||||
};
|
||||
|
||||
class ImageLoaderPnm : public IImageLoader
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<Image> loadFromFile(const std::string& filePath) override;
|
||||
std::unique_ptr<Image> loadFromMemory(const std::vector<uint8_t>& buffer) override;
|
||||
Math::Vector2i GetImageDimensions(const std::string& filename) override;
|
||||
|
||||
private:
|
||||
PnmHeader parseHeader(std::istream& stream);
|
||||
Array<uint8_t> readBinaryData(std::istream& stream, const PnmHeader& header);
|
||||
Array<uint8_t> readTextData(std::istream& stream, const PnmHeader& header);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user