diff options
Diffstat (limited to 'src/GFX/Image')
| -rw-r--r-- | src/GFX/Image/PPMParser.cpp | 2 | ||||
| -rw-r--r-- | src/GFX/Image/RawImage.cpp | 28 | ||||
| -rw-r--r-- | src/GFX/Image/RawImage.hpp | 14 |
3 files changed, 39 insertions, 5 deletions
diff --git a/src/GFX/Image/PPMParser.cpp b/src/GFX/Image/PPMParser.cpp index 31be0ab..cf1bf77 100644 --- a/src/GFX/Image/PPMParser.cpp +++ b/src/GFX/Image/PPMParser.cpp @@ -17,7 +17,7 @@ RawImage PPMParser::parse() { auto pixel_count = header.width * header.height; - RawImage image(header.width, header.height, 3); + RawImage image(header.width, header.height); for (uint64_t pixel_index = 0; pixel_index < pixel_count; pixel_index++) { RawImage::Pixel pixel = parse_pixel(header.max_color); image.add(pixel); diff --git a/src/GFX/Image/RawImage.cpp b/src/GFX/Image/RawImage.cpp index aca8fbc..1222fab 100644 --- a/src/GFX/Image/RawImage.cpp +++ b/src/GFX/Image/RawImage.cpp @@ -2,6 +2,19 @@ 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) { m_pixels.push_back(pixel); } @@ -26,4 +39,19 @@ 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) { + if (comma) { str << ", "; } + str << "{r=" << (uint)pixel.r << ", g=" << (uint)pixel.g << ", b=" << (uint)pixel.r << "}"; + comma = true; + } + str << "]"; + + return str.str(); +} + } \ No newline at end of file diff --git a/src/GFX/Image/RawImage.hpp b/src/GFX/Image/RawImage.hpp index 2b10cb0..8a837e6 100644 --- a/src/GFX/Image/RawImage.hpp +++ b/src/GFX/Image/RawImage.hpp @@ -2,19 +2,23 @@ #include <cstdint> #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), m_channels(0) {}; + RawImage() : m_pixels(), m_width(0), m_height(0) {}; - explicit RawImage(uint32_t width, uint32_t height, uint8_t channels) - : m_pixels(), m_width(width), m_height(height), m_channels(channels) { + RawImage(uint32_t width, uint32_t height) + : m_pixels(), 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; }; @@ -27,11 +31,13 @@ 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; + uint8_t m_channels = 3; }; } |
