Skip to content
Snippets Groups Projects
Commit ce5548e6 authored by Thomas Müller's avatar Thomas Müller
Browse files

`save_exr`: fix incorrect header

parent 5af105bd
No related branches found
No related tags found
No related merge requests found
...@@ -54,28 +54,28 @@ __global__ void interleave_and_cast_kernel(const uint32_t num_pixels, bool has_a ...@@ -54,28 +54,28 @@ __global__ void interleave_and_cast_kernel(const uint32_t num_pixels, bool has_a
*((uint64_t*)&out[i*4]) = *((uint64_t*)&rgba_out[0]); *((uint64_t*)&out[i*4]) = *((uint64_t*)&rgba_out[0]);
} }
void save_exr(const float* data, int width, int height, int nChannels, int channelStride, const char* outfilename) { void save_exr(const float* data, int width, int height, int n_channels, int channel_stride, const char* outfilename) {
EXRHeader header; EXRHeader header;
InitEXRHeader(&header); InitEXRHeader(&header);
EXRImage image; EXRImage image;
InitEXRImage(&image); InitEXRImage(&image);
image.num_channels = nChannels; image.num_channels = n_channels;
std::vector<std::vector<float>> images(nChannels); std::vector<std::vector<float>> images(n_channels);
std::vector<float*> image_ptr(nChannels); std::vector<float*> image_ptr(n_channels);
for (int i = 0; i < nChannels; ++i) { for (int i = 0; i < n_channels; ++i) {
images[i].resize(width * height); images[i].resize(width * height);
} }
for (int i = 0; i < nChannels; ++i) { for (int i = 0; i < n_channels; ++i) {
image_ptr[i] = images[nChannels - i - 1].data(); image_ptr[i] = images[n_channels - i - 1].data();
} }
for (size_t i = 0; i < (size_t)width * height; i++) { for (size_t i = 0; i < (size_t)width * height; i++) {
for (int c = 0; c < nChannels; ++c) { for (int c = 0; c < n_channels; ++c) {
images[c][i] = data[channelStride*i+c]; images[c][i] = data[channel_stride * i + c];
} }
} }
...@@ -83,18 +83,16 @@ void save_exr(const float* data, int width, int height, int nChannels, int chann ...@@ -83,18 +83,16 @@ void save_exr(const float* data, int width, int height, int nChannels, int chann
image.width = width; image.width = width;
image.height = height; image.height = height;
header.num_channels = nChannels; header.num_channels = n_channels;
header.channels = (EXRChannelInfo *)malloc(sizeof(EXRChannelInfo) * header.num_channels); header.channels = (EXRChannelInfo *)malloc(sizeof(EXRChannelInfo) * header.num_channels);
// Must be (A)BGR order, since most of EXR viewers expect this channel order. // Must be (A)BGR order, since most of EXR viewers expect this channel order.
strncpy(header.channels[0].name, "B", 255); header.channels[0].name[strlen("B")] = '\0'; const char* channel_names[] = {
if (nChannels > 1) { "R", "G", "B", "A"
strncpy(header.channels[1].name, "G", 255); header.channels[1].name[strlen("G")] = '\0'; };
}
if (nChannels > 2) { for (size_t i = 0; i < n_channels; ++i) {
strncpy(header.channels[2].name, "R", 255); header.channels[2].name[strlen("R")] = '\0'; strncpy(header.channels[i].name, channel_names[n_channels - i - 1], 255);
}
if (nChannels > 3) {
strncpy(header.channels[3].name, "A", 255); header.channels[3].name[strlen("A")] = '\0';
} }
header.pixel_types = (int *)malloc(sizeof(int) * header.num_channels); header.pixel_types = (int *)malloc(sizeof(int) * header.num_channels);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment