PNM image loader + tests

This commit is contained in:
Vladyslav Baranovskyi
2024-12-24 21:54:20 +02:00
parent 4d6cba0afd
commit 7ea6edf5d0
3 changed files with 296 additions and 0 deletions

View 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);
};
}