-
Notifications
You must be signed in to change notification settings - Fork 0
/
exrloader.cpp
36 lines (28 loc) · 1.09 KB
/
exrloader.cpp
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
// Loading an EXR file
#include "exrloader.hpp"
#include <ImathBox.h>
#include <ImfRgbaFile.h>
bool readEXR(const std::string &fileName, Imf::Array2D<Imf::Rgba> &pixels,
unsigned int &width, unsigned int &height) {
Imf::RgbaInputFile file(fileName.c_str());
Imath::Box2i dataWindow = file.header().dataWindow();
width = dataWindow.max.x - dataWindow.min.x + 1;
height = dataWindow.max.y - dataWindow.min.y + 1;
// Make sure that we can handle empty images correctly
if (width * height < 1) {
return false;
}
pixels.resizeErase(height, width);
file.setFrameBuffer(&pixels[0][0] - dataWindow.min.x - dataWindow.min.y*width, 1, width);
file.readPixels(dataWindow.min.y, dataWindow.max.y);
return true;
}
bool writeExr(const std::string &fileName, const Imf::Array2D<Imf::Rgba> &pixels,
unsigned int &width, unsigned int &height)
{
// Write output
Imf::RgbaOutputFile fileDst (fileName.c_str(), width, height, Imf::WRITE_RGBA);
fileDst.setFrameBuffer (&pixels[0][0], 1, width);
fileDst.writePixels (height);
return true;
}