2 #define TINYEXR_USE_STB_ZLIB 1
3 #define TINYEXR_USE_MINIZ 0
11 const std::vector<float>& data,
12 const std::filesystem::path& path)
15 InitEXRHeader(&header);
20 image.num_channels = 3;
22 std::vector<float> images[3];
23 images[0].resize(width * height);
24 images[1].resize(width * height);
25 images[2].resize(width * height);
28 for (
int i = 0; i < width * height; i++) {
29 images[0][i] = data[i];
35 image_ptr[0] = &(images[2].at(0));
36 image_ptr[1] = &(images[1].at(0));
37 image_ptr[2] = &(images[0].at(0));
39 image.images = (
unsigned char**)image_ptr;
41 image.height = height;
43 header.num_channels = 3;
44 header.channels = (EXRChannelInfo*)malloc(
sizeof(EXRChannelInfo) * header.num_channels);
46 strncpy(header.channels[0].name,
"B", 255);
47 header.channels[0].name[strlen(
"B")] =
'\0';
48 strncpy(header.channels[1].name,
"G", 255);
49 header.channels[1].name[strlen(
"G")] =
'\0';
50 strncpy(header.channels[2].name,
"R", 255);
51 header.channels[2].name[strlen(
"R")] =
'\0';
53 header.pixel_types = (
int*)malloc(
sizeof(
int) * header.num_channels);
54 header.requested_pixel_types = (
int*)malloc(
sizeof(
int) * header.num_channels);
55 for (
int i = 0; i < header.num_channels; i++) {
56 header.pixel_types[i] = TINYEXR_PIXELTYPE_FLOAT;
57 header.requested_pixel_types[i] =
58 TINYEXR_PIXELTYPE_HALF;
61 const char* err = NULL;
62 int ret = SaveEXRImageToFile(&image, &header, path.string().data(), &err);
63 if (ret != TINYEXR_SUCCESS) {
64 fprintf(stderr,
"Save EXR err: %s\n", err);
65 FreeEXRErrorMessage(err);
70 free(header.channels);
71 free(header.pixel_types);
72 free(header.requested_pixel_types);
82 const std::vector<float>& data_r,
83 const std::vector<float>& data_g,
84 const std::vector<float>& data_b,
85 const std::filesystem::path& path)
88 InitEXRHeader(&header);
93 image.num_channels = 3;
95 std::vector<float> images[3];
96 images[0].resize(width * height);
97 images[1].resize(width * height);
98 images[2].resize(width * height);
101 for (
int i = 0; i < width * height; i++) {
102 images[r][i] = data_r[i];
103 images[g][i] = data_g[i];
104 images[b][i] = data_b[i];
107 .info(
"[save r {} {}, g {} {} b {} {}]", r, images[r][0], g, images[g][0], b, images[b][0]);
109 image_ptr[0] = &(images[2].at(0));
110 image_ptr[1] = &(images[1].at(0));
111 image_ptr[2] = &(images[0].at(0));
113 image.images = (
unsigned char**)image_ptr;
115 image.height = height;
117 header.num_channels = 3;
118 header.channels = (EXRChannelInfo*)malloc(
sizeof(EXRChannelInfo) * header.num_channels);
120 strncpy(header.channels[0].name,
"B", 255);
121 header.channels[0].name[strlen(
"B")] =
'\0';
122 strncpy(header.channels[1].name,
"G", 255);
123 header.channels[1].name[strlen(
"G")] =
'\0';
124 strncpy(header.channels[2].name,
"R", 255);
125 header.channels[2].name[strlen(
"R")] =
'\0';
127 header.pixel_types = (
int*)malloc(
sizeof(
int) * header.num_channels);
128 header.requested_pixel_types = (
int*)malloc(
sizeof(
int) * header.num_channels);
129 for (
int i = 0; i < header.num_channels; i++) {
130 header.pixel_types[i] = TINYEXR_PIXELTYPE_FLOAT;
131 header.requested_pixel_types[i] =
132 TINYEXR_PIXELTYPE_HALF;
135 const char* err = NULL;
136 int ret = SaveEXRImageToFile(&image, &header, path.string().data(), &err);
137 if (ret != TINYEXR_SUCCESS) {
138 fprintf(stderr,
"Save EXR err: %s\n", err);
139 FreeEXRErrorMessage(err);
142 printf(
"Saved exr file 3 channels. [ %s ] \n", path.c_str());
144 free(header.channels);
145 free(header.pixel_types);
146 free(header.requested_pixel_types);
bool save_image_exr_3channels(size_t width, size_t height, int r, int g, int b, const std::vector< float > &data_r, const std::vector< float > &data_g, const std::vector< float > &data_b, const std::filesystem::path &path)
bool save_image_exr_red_channel(size_t width, size_t height, const std::vector< float > &data, const std::filesystem::path &path)
spdlog::logger & logger()
Retrieves the current logger.