32 lines
969 B
C++
32 lines
969 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/.
|
|
*/
|
|
#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);
|
|
};
|
|
} |