diff options
Diffstat (limited to 'src/GFX/Image')
| -rw-r--r-- | src/GFX/Image/PPMParser.cpp | 7 | ||||
| -rw-r--r-- | src/GFX/Image/PPMParser.hpp | 4 | ||||
| -rw-r--r-- | src/GFX/Image/RawImage.cpp | 24 | ||||
| -rw-r--r-- | src/GFX/Image/RawImage.hpp | 11 |
4 files changed, 11 insertions, 35 deletions
diff --git a/src/GFX/Image/PPMParser.cpp b/src/GFX/Image/PPMParser.cpp index cf1bf77..f002db8 100644 --- a/src/GFX/Image/PPMParser.cpp +++ b/src/GFX/Image/PPMParser.cpp @@ -66,7 +66,7 @@ RawImage::Pixel PPMParser::parse_pixel(uint8_t max_color) { throw std::runtime_error("Sample can not be greater than Maxval."); } - auto map_to_range = [=](uint64_t s) -> uint8_t { return (s * 255) / max_color; }; + auto map_to_range = [=](uint64_t s) -> uint8_t { return s * 255 / max_color; }; RawImage::Pixel pixel{}; pixel.r = map_to_range(r_sample); @@ -120,9 +120,8 @@ std::string_view PPMParser::chomp_part() { } void PPMParser::skip_whitespace() { - uint8_t c; while (!is_eof()) { - c = m_source[m_cursor]; + uint8_t c = m_source[m_cursor]; if (c == '#') { skip_comment(); continue; @@ -147,7 +146,7 @@ void PPMParser::skip_comment() { } } -bool PPMParser::is_eof() { +bool PPMParser::is_eof() const { return m_cursor >= m_source.size(); } diff --git a/src/GFX/Image/PPMParser.hpp b/src/GFX/Image/PPMParser.hpp index 3909cee..07ff3c2 100644 --- a/src/GFX/Image/PPMParser.hpp +++ b/src/GFX/Image/PPMParser.hpp @@ -8,7 +8,7 @@ namespace MC::GFX::Image { class PPMParser { public: - explicit PPMParser(std::string_view source) : m_source(source) {}; + explicit PPMParser(std::string_view source) : m_source(source) {} RawImage parse(); private: @@ -35,7 +35,7 @@ private: void skip_whitespace(); void skip_comment(); - bool is_eof(); + bool is_eof() const; std::string_view m_source; uint64_t m_cursor = 0; diff --git a/src/GFX/Image/RawImage.cpp b/src/GFX/Image/RawImage.cpp index 1222fab..6cb06b2 100644 --- a/src/GFX/Image/RawImage.cpp +++ b/src/GFX/Image/RawImage.cpp @@ -1,21 +1,9 @@ #include "RawImage.hpp" +#include <sstream> namespace MC::GFX::Image { -RawImage::RawImage(Util::Sampler<2, float>& sampler, uint32_t width, uint32_t height) - : m_pixels(), m_width(width), m_height(height) -{ - m_pixels.reserve(width * height); - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - auto result = sampler.sample({(float)x, (float)y}); - auto intensity = (uint8_t)(result * 255); - add({intensity, intensity, intensity}); - } - } -} - -void RawImage::add(RawImage::Pixel pixel) { +void RawImage::add(Pixel pixel) { m_pixels.push_back(pixel); } @@ -35,18 +23,14 @@ uint32_t RawImage::height() const { return m_height; } -uint8_t RawImage::channels() const { - return m_channels; -} - std::string RawImage::string() const { std::stringstream str{}; bool comma = false; str << "["; - for (const auto& pixel : m_pixels) { + for (const auto [r, g, b] : m_pixels) { if (comma) { str << ", "; } - str << "{r=" << (uint)pixel.r << ", g=" << (uint)pixel.g << ", b=" << (uint)pixel.r << "}"; + str << "{r=" << (uint)r << ", g=" << (uint)g << ", b=" << (uint)r << "}"; comma = true; } str << "]"; diff --git a/src/GFX/Image/RawImage.hpp b/src/GFX/Image/RawImage.hpp index 8a837e6..be3c83a 100644 --- a/src/GFX/Image/RawImage.hpp +++ b/src/GFX/Image/RawImage.hpp @@ -4,21 +4,17 @@ #include <cstddef> #include <string> #include <vector> -#include "../../Util/Sampler.hpp" namespace MC::GFX::Image { class RawImage { public: - RawImage() : m_pixels(), m_width(0), m_height(0) {}; + RawImage() : m_width(0), m_height(0) {} - RawImage(uint32_t width, uint32_t height) - : m_pixels(), m_width(width), m_height(height) { + RawImage(uint32_t width, uint32_t height) : m_width(width), m_height(height) { m_pixels.reserve(width * height); } - RawImage(Util::Sampler<2, float>& sampler, uint32_t width, uint32_t height); - struct Pixel { uint8_t r, g, b; }; @@ -30,14 +26,11 @@ public: uint32_t width() const; uint32_t height() const; - uint8_t channels() const; std::string string() const; private: std::vector<Pixel> m_pixels; - uint32_t m_width, m_height; - uint8_t m_channels = 3; }; } |
