Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Image.hpp
1#pragma once
2#include "Common.hpp"
3
8class Image {
9
10public:
11
13 enum class Save : uint {
14 NONE = 0,
15 FLIP = 1 << 0,
16 IGNORE_ALPHA = 1 << 1,
17 SRGB_LDR = 1 << 2
18 };
19
21 Image() = default;
22
30 Image(unsigned int awidth, unsigned int aheight, unsigned int acomponents, float value = 0.0f);
31
38 glm::vec4 & rgba(int x, int y);
39
46 glm::vec3 & rgb(int x, int y);
47
54 float & r(int x, int y);
55
62 const glm::vec4 & rgba(int x, int y) const;
63
70 const glm::vec3 & rgb(int x, int y) const;
71
78 const float & r(int x, int y) const;
79
86 glm::vec3 rgbl(float x, float y) const;
87
94 glm::vec3 rgbn(float x, float y) const;
95
102 glm::vec4 rgbal(float x, float y) const;
103
111 int load(const std::string & path, unsigned int channels, bool flip, bool externalFile);
112
118 int save(const std::string & path, Save options) const;
119
125 static bool isFloat(const std::string & path);
126
130 Image & operator=(const Image &) = delete;
131
133 Image(const Image &) = delete;
134
138 Image & operator=(Image &&) = default;
139
141 Image(Image &&) = default;
142
143 unsigned int width = 0;
144 unsigned int height = 0;
145 unsigned int components = 0;
146 std::vector<float> pixels;
147
148private:
149
155 int saveAsLDR(const std::string & path, Save options) const;
156
162 int saveAsHDR(const std::string & path, Save options) const;
163
171 int loadLDR(const std::string & path, unsigned int channels, bool flip, bool externalFile);
172
180 int loadHDR(const std::string & path, unsigned int channels, bool flip, bool externalFile);
181
182};
183
189inline int modPos(int x, int w){
190 return ((x%w)+w)%w;
191}
192
198inline Image::Save operator|( Image::Save t0, Image::Save t1) {
199 return static_cast< Image::Save>(static_cast<uint>(t0) | static_cast<uint>(t1));
200}
201
207inline bool operator&( Image::Save t0, Image::Save t1) {
208 return bool(static_cast<uint>(t0) & static_cast<uint>(t1));
209}
210
216inline Image::Save & operator|=( Image::Save & t0, Image::Save & t1) {
217 return t0 = t0 | t1;
218}
Represents an image composed of pixels with values in [0,1]. Provide image loading/saving utilities,...
Definition: Image.hpp:8
static bool isFloat(const std::string &path)
Definition: Image.cpp:122
int save(const std::string &path, Save options) const
Definition: Image.cpp:115
unsigned int components
Number of components/channels.
Definition: Image.hpp:145
float & r(int x, int y)
Definition: Image.cpp:38
Image(const Image &)=delete
glm::vec3 rgbn(float x, float y) const
Definition: Image.cpp:54
Image & operator=(const Image &)=delete
Image()=default
glm::vec4 rgbal(float x, float y) const
Definition: Image.cpp:86
Image(Image &&)=default
int load(const std::string &path, unsigned int channels, bool flip, bool externalFile)
Definition: Image.cpp:108
unsigned int height
The height of the image.
Definition: Image.hpp:144
Image & operator=(Image &&)=default
glm::vec4 & rgba(int x, int y)
Definition: Image.cpp:30
int loadHDR(const std::string &path, unsigned int channels, bool flip, bool externalFile)
Definition: Image.cpp:335
unsigned int width
The width of the image.
Definition: Image.hpp:143
std::vector< float > pixels
The pixels values of the image.
Definition: Image.hpp:146
glm::vec3 rgbl(float x, float y) const
Definition: Image.cpp:64
Save
Options for saving an image to disk.
Definition: Image.hpp:13
@ SRGB_LDR
Apply gamma sRGB correction before saving, ignored for HDR images.
@ NONE
No specific options.
@ FLIP
Flip the image vertically.
@ IGNORE_ALPHA
Force alpha to 1.
int loadLDR(const std::string &path, unsigned int channels, bool flip, bool externalFile)
Definition: Image.cpp:291
int saveAsHDR(const std::string &path, Save options) const
Definition: Image.cpp:160
int saveAsLDR(const std::string &path, Save options) const
Definition: Image.cpp:126
glm::vec3 & rgb(int x, int y)
Definition: Image.cpp:34