-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlut.cpp
More file actions
51 lines (37 loc) · 1.22 KB
/
lut.cpp
File metadata and controls
51 lines (37 loc) · 1.22 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "lut.h"
#define TINYEXR_IMPLEMENTATION
#include "tinyexr.h"
int LUT::write_to_exr(const std::string& name) {
const char* err = nullptr;
int ret = SaveEXR(reinterpret_cast<const float*>(tab.data()),
static_cast<int>(width), static_cast<int>(height), 4/*rgba*/, 0, name.c_str(), &err);
if (ret != TINYEXR_SUCCESS) {
if (err) {
fprintf(stderr, "SaveEXR error: %s\n", err);
FreeEXRErrorMessage(err);
}
return -1;
}
return 0;
}
int LUT::read_from_exr(const std::string& name) {
const char* err = nullptr;
float* rgba = nullptr;
int width, height;
// Load the EXR file
int ret = LoadEXR(&rgba, &width, &height, name.c_str(), &err);
if (ret != TINYEXR_SUCCESS) {
if (err) {
std::cout << "LoadEXR error: " << err << std::endl;
FreeEXRErrorMessage(err);
}
return -1;
}
this->width = static_cast<size_t>(width);
this->height = static_cast<size_t>(height);
tab.resize(this->width * this->height * 4); // Assuming 4 channels (RGBA)
std::memcpy(tab.data(), rgba, tab.size() * sizeof(float));
// Free the memory allocated by TinyEXR
free(rgba);
return 0;
}