18 #ifndef PIC_IO_EXR_HPP 19 #define PIC_IO_EXR_HPP 21 #include "../base.hpp" 23 #ifdef PIC_ENABLE_OPEN_EXR 27 #include <ImfRgbaFile.h> 28 #include <ImfStringAttribute.h> 29 #include <ImfMatrixAttribute.h> 33 #pragma comment( lib, "Iex_dll" ) 34 #pragma comment( lib, "Half_dll" ) 35 #pragma comment( lib, "IlmImf_dll" ) 36 #pragma comment( lib, "IlmThread_dll" ) 37 #pragma comment( lib, "Imath_dll" ) 38 #pragma comment( lib, "zlib" ) 54 int &channels, Imf::Rgba *pixelBuffer = NULL)
57 Imf::RgbaInputFile in(nameFile.c_str());
58 Imath::Box2i win = in.dataWindow();
60 Imath::V2i dim(win.max.x - win.min.x + 1, win.max.y - win.min.y + 1);
64 if(pixelBuffer == NULL) {
65 pixelBuffer =
new Imf::Rgba[dim.x * dim.y];
71 in.setFrameBuffer(pixelBuffer - dx - dy * dim.x, 1, dim.x);
72 in.readPixels(win.min.y, win.max.y);
80 }
catch(Iex::BaseExc &e) {
81 std::cerr << e.what() << std::endl;
97 int &height,
int &channels, Imf::Rgba *pixelBuffer = NULL)
100 Imf::RgbaInputFile in(nameFile.c_str());
101 Imath::Box2i win = in.dataWindow();
103 Imath::V2i dim(win.max.x - win.min.x + 1, win.max.y - win.min.y + 1);
107 bool bPixelBufferNULL =
false;
109 if(pixelBuffer == NULL) {
110 pixelBuffer =
new Imf::Rgba[dim.x * dim.y];
111 bPixelBufferNULL =
true;
117 in.setFrameBuffer(pixelBuffer - dx - dy * dim.x, 1, dim.x);
118 in.readPixels(win.min.y, win.max.y);
122 data =
new float[dim.x * dim.y * 3];
129 int tot = width * height * channels;
131 for(
int i = 0; i < tot; i += channels) {
133 data[i ] = pixelBuffer[j].r;
134 data[i + 1] = pixelBuffer[j].g;
135 data[i + 2] = pixelBuffer[j].b;
138 if(bPixelBufferNULL) {
139 delete[] pixelBuffer;
143 }
catch(Iex::BaseExc &e) {
144 std::cerr << e.what() << std::endl;
160 int height,
int channels = 3, Imf::Rgba *pixelBuffer = NULL)
163 win.max.x = width - 1;
164 win.max.y = height - 1;
167 Imf::RgbaOutputFile outC(nameFile.c_str(), win, win, Imf::WRITE_RGBA);
170 int tot = width * height;
171 bool bPixelBufferNULL =
false;
173 if(pixelBuffer == NULL) {
174 pixelBuffer =
new Imf::Rgba[tot];
175 bPixelBufferNULL =
true;
180 for(
int i = 0; i < tot; i++) {
181 pixelBuffer[i].r = data[j];
183 pixelBuffer[i].g = data[j];
185 pixelBuffer[i].b = data[j];
187 pixelBuffer[i].a = 1.0f;
190 outC.setFrameBuffer(pixelBuffer, 1, width);
191 outC.writePixels(height);
193 if(bPixelBufferNULL) {
194 delete[] pixelBuffer;
201 #endif //PIC_ENABLE_OPEN_EXR PIC_INLINE bool WriteEXR(std::string nameFile, float *data, int width, int height, int channels=3)
WriteEXR.
Definition: exr_tiny.hpp:95
PIC_INLINE float * ReadEXR(std::string nameFile, float *data, int &width, int &height, int &channels)
Definition: exr_tiny.hpp:33
#define PIC_INLINE
Definition: base.hpp:33
Definition: bilateral_separation.hpp:25