-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.cpp
More file actions
35 lines (28 loc) · 1.14 KB
/
Copy pathImage.cpp
File metadata and controls
35 lines (28 loc) · 1.14 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
#include "Image.hpp"
namespace RayTracing {
Image::Image(unsigned int width, unsigned int height) {
this->width = width;
this->height = height;
this->image = (RGBA8 **) malloc(sizeof(RGBA8 *) * height);
for (int i = 0; i < height; i++) {
this->image[i] = (RGBA8 *) malloc(sizeof(RGBA8) * width);
}
}
RGBA8 Image::getPixel(unsigned int x, unsigned int y) {
return image[y][x];
}
void Image::setPixel(unsigned int x, unsigned int y, RGBA8 color) {
image[height - y - 1][x] = color;
// invert y axis to convert from (0,0) as bottom left (from camera) to as top left TODO find better solution
}
void Image::setPixel(unsigned int x, unsigned int y, RGBf color) {
image[height - y - 1][x] = color.toRGBA8();
// invert y axis to convert from (0,0) as bottom left (from camera) to as top left TODO find better solution
}
RGBA8 *Image::valueAt(unsigned int x, unsigned int y) {
return &image[height - y - 1][x];
}
RGBA8 &Image::operator[](unsigned int x, unsigned int y) {
return image[height - y - 1][x];
}
}