-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.hpp
68 lines (55 loc) · 1.3 KB
/
image.hpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#include <cuda_runtime.h>
#include <vector>
#include "dataTypes.hpp"
class Image {
public:
uint width{0};
uint height{0};
std::vector<vec3> data{};
Image() = default;
Image(uint width, uint height);
Image(uint width, uint height, const std::vector<vec3>& data);
inline vec3 operator[](uint i) const {
return data[i];
}
inline vec3& operator[](uint i) {
return data[i];
}
inline vec3 operator()(vec2 uv) const {
uv = fract(uv);
uvec2 coord = vec2(uv) * vec2{width, height};
uint idx = coord.y * width + coord.x;
if (idx >= data.size()) {
return vec3(0);
}
return data[idx];
}
};
class GPUImage {
public:
const uint width{0};
const uint height{0};
// Device side pointer
vec3* data;
GPUImage() = delete;
GPUImage(const Image& image);
GPUImage(uint width, uint height);
GPUImage(uint width, uint height, vec3* data);
~GPUImage();
__device__ inline vec3 operator[](uint i) const {
return data[i];
}
__device__ inline vec3& operator[](uint i) {
return data[i];
}
__device__ inline vec3 operator()(vec2 uv) const {
uv = fract(uv);
uvec2 coord = vec2(uv) * vec2{width, height};
uint idx = coord.y * width + coord.x;
if (idx >= width * height) {
return vec3(0);
}
return data[idx];
}
};