forked from jmerdich/aeo-light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadframeexr.cpp
70 lines (57 loc) · 1.56 KB
/
readframeexr.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <OpenEXR/ImfRgbaFile.h>
#include <OpenEXR/ImfArray.h>
#include "aeoexception.h"
#include "readframeexr.h"
double *ReadFrameEXR(const char *fn, double *buf=NULL)
{
Imf::RgbaInputFile exr(fn);
Imath::Box2i dw = exr.dataWindow();
int width = dw.max.x - dw.min.x + 1;
int height = dw.max.y - dw.min.y + 1;
// keep this around, since all the frames will be the same size
static Imf::Array2D<Imf::Rgba> pixels;
if(buf == NULL)
{
buf = new double [width*height];
if(buf == NULL)
{
throw AeoException("Out of Memory: EXR buf");
}
}
pixels.resizeErase(height, width);
exr.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
exr.readPixels(dw.min.y, dw.max.y);
int i = 0;
// "convert" from half BGRA to double Y
for(int x=0; x<height; ++x)
for(int y=0; y<width; ++y, ++i)
{
buf[i] = (
double(pixels[x][y].r) +
double(pixels[x][y].g) +
double(pixels[x][y].b) ) / 3.0;
}
return buf;
}
unsigned char *ReadFrameEXR_ImageData(const char *exrfn, unsigned char *buf,
int &width, int &height, bool &endian)
{
Imf::RgbaInputFile exr(exrfn);
Imath::Box2i dw = exr.dataWindow();
width = dw.max.x - dw.min.x + 1;
height = dw.max.y - dw.min.y + 1;
endian = false;
// keep this around, since all the frames will be the same size
static Imf::Array2D<Imf::Rgba> pixels;
if(buf == NULL)
{
buf = new unsigned char [width*height* 4];//8 or 10 bit
if(buf == NULL)
{
throw AeoException("Out of Memory: EXR buf");
}
}
exr.setFrameBuffer((Imf::Rgba *)buf,1,width);
exr.readPixels(dw.min.y, dw.max.y);
return buf;
}