2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
23
#include "NuxCore/NuxCore.h"
25
#include "NuxCore/NuxCore.h"
26
#include "BitmapFormats.h"
29
#ifdef NUX_OPENEXR_SUPPORT
31
//#include "OpenEXR/ctlToLut.h"
32
//#include "OpenEXR/fileNameForFrame.h"
33
//#include "OpenEXR/FileReadingThread.h"
34
//#include "OpenEXR/osDependent.h"
35
//#include "OpenEXR/ImageBuffers.h"
36
//#include "OpenEXR/Timer.h"
37
#include "OpenEXR/ImfThreading.h"
38
#include "OpenEXR/ImfInputFile.h"
39
#include "OpenEXR/ImfChannelList.h"
40
#include "OpenEXR/ImfStandardAttributes.h"
41
#include "OpenEXR/ImfRgbaYca.h"
42
#include "OpenEXR/ImfArray.h"
43
#include "OpenEXR/ImfRgbaFile.h"
44
#include "OpenEXR/ImfChannelList.h"
45
#include "OpenEXR/half.h"
46
#include "OpenEXR/imathbox.h"
47
#include "OpenEXR/ImfFrameBuffer.h"
58
NBitmapData *Load_OpenEXR (const TCHAR *fileName)
60
Imf::Array2D<float> rPixels;
61
Imf::Array2D<float> gPixels;
62
Imf::Array2D<float> bPixels;
64
Imf::InputFile in (fileName);
66
Imf::Header header = in.header();
67
const Imath::Box2i &dw = in.header().dataWindow();
69
int width = dw.max.x - dw.min.x + 1;
70
int height = dw.max.y - dw.min.y + 1;
72
const Imf::ChannelList &ch = in.header().channels();
75
rPixels.resizeErase (height, width);
76
gPixels.resizeErase (height, width);
77
bPixels.resizeErase (height, width);
79
float *FloatArray = 0;
80
NBitmapData *BitmapData = 0;
82
if (ch.findChannel ("Y") || ch.findChannel ("RY") || ch.findChannel ("BY") )
86
else if (ch.findChannel ("R") && ch.findChannel ("G") && ch.findChannel ("B") && ch.findChannel ("A") )
91
// The pixel buffers for the tree image channels (RGB)
92
// are padded with a fourth dummy channel (A) and interleaved
93
// (RGBARGBARGBA...). All three buffers have the same width
94
// and height as the frame.
97
BitmapData = (NBitmapData *) new NTextureData (
102
BYTE *Dest = BitmapData->GetSurface (0).GetPtrRawData(); //new float[4*width*height];
104
Imf::FrameBuffer frameBuffer;
106
frameBuffer.insert ("R", // name
107
Imf::Slice (Imf::FLOAT, // type
108
(char *) (&Dest[0] - // base
111
sizeof (float) * 4, // xStride
112
sizeof (float) * 4 * width, // yStride
113
1, 1, // x/y sampling
116
frameBuffer.insert ("G", // name
117
Imf::Slice (Imf::FLOAT, // type
118
(char *) (&Dest[4] - // base
121
sizeof (float) * 4, // xStride
122
sizeof (float) * 4 * width, // yStride
123
1, 1, // x/y sampling
126
frameBuffer.insert ("B", // name
127
Imf::Slice (Imf::FLOAT, // type
128
(char *) (&Dest[8] - // base
131
sizeof (float) * 4, // xStride
132
sizeof (float) * 4 * width, // yStride
133
1, 1, // x/y sampling
136
frameBuffer.insert ("A", // name
137
Imf::Slice (Imf::FLOAT, // type
138
(char *) (&Dest[12] - // base
141
sizeof (float) * 4, // xStride
142
sizeof (float) * 4 * width, // yStride
143
1, 1, // x/y sampling
146
in.setFrameBuffer (frameBuffer);
147
in.readPixels (dw.min.y, dw.max.y);
150
else if (ch.findChannel ("R") && ch.findChannel ("G") && ch.findChannel ("B") )
155
// The pixel buffers for the tree image channels (RGB)
156
// are padded with a fourth dummy channel (A) and interleaved
157
// (RGBRGBRGB...). All three buffers have the same width
158
// and height as the frame.
161
BitmapData = (NBitmapData *) new NTextureData (
166
BYTE *Dest = BitmapData->GetSurface (0).GetPtrRawData(); //new float[4*width*height];
168
Imf::FrameBuffer frameBuffer;
170
frameBuffer.insert ("R", // name
171
Imf::Slice (Imf::FLOAT, // type
172
(char *) (&Dest[0] - // base
175
sizeof (float) * 3, // xStride
176
sizeof (float) * 3 * width, // yStride
177
1, 1, // x/y sampling
180
frameBuffer.insert ("G", // name
181
Imf::Slice (Imf::FLOAT, // type
182
(char *) (&Dest[4] - // base
185
sizeof (float) * 3, // xStride
186
sizeof (float) * 3 * width, // yStride
187
1, 1, // x/y sampling
190
frameBuffer.insert ("B", // name
191
Imf::Slice (Imf::FLOAT, // type
192
(char *) (&Dest[8] - // base
195
sizeof (float) * 3, // xStride
196
sizeof (float) * 3 * width, // yStride
197
1, 1, // x/y sampling
200
in.setFrameBuffer (frameBuffer);
201
in.readPixels (dw.min.y, dw.max.y);
210
#endif // NUX_OPENEXR_SUPPORT