Skip to content

Commit b5f68a5

Browse files
authored
Add support for EXR depth-maps stored as equal RGB channels (#5)
1 parent 5f391d6 commit b5f68a5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/HDRImageIO.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,30 @@ bool HDRImage::load(const string & filename)
365365
});
366366
copyPixelsFromArray(*this, data.data(), w, h, 1, false, false);
367367
} else {
368+
for (int y = 0; y < h; ++y)
369+
for (int x = 0; x < w; ++x)
370+
{
371+
const Imf::Rgba &p = pixels[y][x];
372+
if (p.r != p.g || p.g != p.b)
373+
goto ProcessRGB;
374+
}
375+
ProcessIntensity:
376+
// copy intensity image
377+
{
378+
Intensity& data = intensity();
379+
data.resize(w, h);
380+
for (int y = 0; y < h; ++y)
381+
for (int x = 0; x < w; ++x)
382+
{
383+
const Imf::Rgba &p = pixels[y][x];
384+
const float v(p.r);
385+
data(x,y) = v;
386+
}
387+
// convert 1- exr data to 4-channel internal representation
388+
copyPixelsFromArray(*this, data.data(), w, h, 1, false, false);
389+
goto ProcessEnd;
390+
}
391+
ProcessRGB:
368392
// copy pixels over to the Image
369393
parallel_for(0, h, [this, w, &pixels](int y)
370394
{
@@ -374,6 +398,7 @@ bool HDRImage::load(const string & filename)
374398
(*this)(x, y) = Color4(p.r, p.g, p.b, p.a);
375399
}
376400
});
401+
ProcessEnd:;
377402
}
378403

379404
console->debug("Copying EXR image data took: {} seconds.", (timer.lap() / 1000.f));

0 commit comments

Comments
 (0)