Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
image.hpp
Go to the documentation of this file.
1#pragma once
2
23
24#include <cstddef>
25#include <cstdint>
26#include <filesystem>
27#include <span>
28#include <vector>
29
31
32namespace orrery::viz {
33
35class Image {
36public:
40 static constexpr std::size_t kChannels = 3;
41
42 Image() = default;
43
45 Image(std::size_t width, std::size_t height);
46
47 [[nodiscard]] std::size_t width() const noexcept { return width_; }
48
49 [[nodiscard]] std::size_t height() const noexcept { return height_; }
50
52 [[nodiscard]] std::span<const std::uint8_t> pixels() const noexcept { return pixels_; }
53
54 [[nodiscard]] std::span<std::uint8_t> pixels() noexcept { return pixels_; }
55
62 void set(std::size_t x, std::size_t y, std::uint8_t red, std::uint8_t green,
63 std::uint8_t blue) noexcept;
64
71 void write_ppm(const std::filesystem::path& path) const;
72
73private:
74 std::size_t width_ = 0;
75 std::size_t height_ = 0;
76 std::vector<std::uint8_t> pixels_;
77};
78
89void tone_map_into(Image& image, std::span<const float> radiance, ToneMapping mapping,
90 bool bottom_up);
91
92} // namespace orrery::viz
A rectangle of 8-bit RGB pixels, row-major from the top left.
Definition image.hpp:35
static constexpr std::size_t kChannels
The number of bytes one pixel occupies.
Definition image.hpp:40
std::span< const std::uint8_t > pixels() const noexcept
The pixel bytes, width * height * kChannels of them.
Definition image.hpp:52
void set(std::size_t x, std::size_t y, std::uint8_t red, std::uint8_t green, std::uint8_t blue) noexcept
Write one pixel, with y counted from the top.
Image(std::size_t width, std::size_t height)
A black image of the given size.
void write_ppm(const std::filesystem::path &path) const
Write the image as binary PPM.
void tone_map_into(Image &image, std::span< const float > radiance, ToneMapping mapping, bool bottom_up)
Fill image from a buffer of linear radiance, three floats per pixel.
The two numbers that decide how bright the picture is.
Definition tone_map.hpp:56
Turning accumulated light into pixels.