diff options
| author | Mel <einebeere@gmail.com> | 2022-10-21 01:03:18 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-21 01:03:18 +0200 |
| commit | 6ed978051668c08f5a957c97570f364dd580c807 (patch) | |
| tree | e3db93c52fcd86e26bc859d46e755290d2a7f40c /src/GFX/Image/PPMParser.hpp | |
| parent | 0464a83dfaebaa75d6e2d3b7431e84ebd83fccfd (diff) | |
| download | meowcraft-6ed978051668c08f5a957c97570f364dd580c807.tar.zst meowcraft-6ed978051668c08f5a957c97570f364dd580c807.zip | |
Namespace and Folder refactor
Diffstat (limited to 'src/GFX/Image/PPMParser.hpp')
| -rw-r--r-- | src/GFX/Image/PPMParser.hpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/GFX/Image/PPMParser.hpp b/src/GFX/Image/PPMParser.hpp new file mode 100644 index 0000000..3909cee --- /dev/null +++ b/src/GFX/Image/PPMParser.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include <cstdint> +#include <string_view> +#include "RawImage.hpp" + +namespace MC::GFX::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; +}; + +} |
