raytracer
Parallel Ray Tracer written from scratch (no graphics API).
Loading...
Searching...
No Matches
image.h
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include "util/vec3.h"
4
5namespace raytracer::common
6{
10class Image
11{
12 std::vector<Vec3> data;
13 const int width, height;
14 const int color_channels;
15 const bool is_grayscale;
16
17 void validate_dimensions(int x, int y) const;
18
19 public:
28 Image(int _width, int _height, int _channels, bool _is_grayscale);
29
35 explicit Image(const Vec3 &color);
36
44 void draw(int x, int y, const Vec3 &color);
45
53 void add_color(int x, int y, const Vec3 &color);
54
60 void generateBmp(const std::string &file_name) const;
61
67 [[nodiscard]] int get_width() const
68 {
69 return width;
70 }
71
77 [[nodiscard]] int get_height() const
78 {
79 return height;
80 }
81
87 [[nodiscard]] int get_color_channels() const
88 {
89 return color_channels;
90 }
91
97 [[nodiscard]] bool get_is_grayscale() const
98 {
99 return is_grayscale;
100 }
101
107 [[nodiscard]] const std::vector<Vec3> &get_data() const
108 {
109 return data;
110 }
111
119 [[nodiscard]] Vec3 get_color(const int x, const int y) const
120 {
121 return data[x * width + y];
122 }
123};
124} // namespace raytracer::common
const std::vector< Vec3 > & get_data() const
Definition image.h:107
void generateBmp(const std::string &file_name) const
Definition image.cpp:75
void add_color(int x, int y, const Vec3 &color)
Definition image.cpp:69
void draw(int x, int y, const Vec3 &color)
Definition image.cpp:63
int get_width() const
Definition image.h:67
bool get_is_grayscale() const
Definition image.h:97
Vec3 get_color(const int x, const int y) const
Definition image.h:119
int get_height() const
Definition image.h:77
Image(int _width, int _height, int _channels, bool _is_grayscale)
Definition image.cpp:48
int get_color_channels() const
Definition image.h:87
Definition raytracer.cpp:24
Definition vec3.h:11