-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.h
More file actions
36 lines (31 loc) · 1.32 KB
/
Image.h
File metadata and controls
36 lines (31 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* \author Marie DARRIGOL & Anthony LEONARD & Ophélie PELLOUX-PRAYER & Olivier SOLDANO
* \project Ray-Tracing
* \file Image.h
* \brief Represents an object to store and manipulate images (used for the bump map)
*/
#pragma once
#include "Color.h"
#include <memory>
class Image
{
public:
// Constructors
Image() : w(0), h(0), pixels(nullptr) { /* empty image */ }
Image(const unsigned int _w, const unsigned int _h, const Color &c = Color(0.0f, 0.0f, 0.0f)) : w(_w), h(_h), pixels(nullptr)
{
this->pixels = shared_ptr<Color>(new Color[this->w * this->h], [](Color* p) { delete[] p; });
for (unsigned int i = 0; i < this->w * this->h; ++i) this->pixels.get()[i] = c;
}
// Operators
inline const Color& operator [] (const unsigned int i) const { return this->pixels.get()[i]; } // reading only
inline Color& operator [] (const unsigned int i) { return this->pixels.get()[i]; } // reading and writting
// Manipulations on images
inline unsigned int getWidth() const { return this->w; }
inline unsigned int getHeight() const { return this->h; }
void readPPM(const char* file);
bool isDefined() const { return pixels ? true : false; } // return true if the pointer pixels is defined
private:
unsigned int w, h; // image resolution
shared_ptr<Color> pixels; // 1D array of pixels (shared because one or several Material can use it)
};