diff options
| author | Mel <einebeere@gmail.com> | 2022-10-08 03:18:18 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-08 03:18:18 +0200 |
| commit | 799c06e0387e01bdb8a10019be6192f9db00a824 (patch) | |
| tree | f590ee7cb6a6b3b191ba080ddb88199cefdba7e8 /src/Image/PPMParser.hpp | |
| parent | 56c86cefa3233bdc94aa1c62ec04dada501c1ccf (diff) | |
| download | meowcraft-799c06e0387e01bdb8a10019be6192f9db00a824.tar.zst meowcraft-799c06e0387e01bdb8a10019be6192f9db00a824.zip | |
Parse PPM images
Diffstat (limited to 'src/Image/PPMParser.hpp')
| -rw-r--r-- | src/Image/PPMParser.hpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Image/PPMParser.hpp b/src/Image/PPMParser.hpp new file mode 100644 index 0000000..7d81cb8 --- /dev/null +++ b/src/Image/PPMParser.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include <cstdint> +#include <string_view> +#include "RawImage.hpp" + +namespace MC::Image { + +class PPMParser { +public: + explicit PPMParser(std::string_view source) : m_source(source) {}; + + RawImage parse(); +private: + enum PPMType { + None, + P3, + P6 + }; + + struct PPMHeader { + PPMType type; + uint32_t width; + uint32_t height; + uint8_t max_color; + }; + + PPMHeader parse_header(); + RawImage::Pixel parse_pixel(uint8_t max_color); + uint64_t parse_sample(); + + uint64_t chomp_number(); + std::string_view chomp_part(); + + void skip_whitespace(); + void skip_comment(); + + bool is_eof(); + + std::string_view m_source; + uint64_t m_cursor = 0; +}; + +} |
