Add support for EXR files
This commit is contained in:
parent
88c811fca5
commit
18c452a2a6
@ -13,7 +13,9 @@ ELSE (WIN32)
|
||||
|
||||
FIND_PATH(OPENEXR_INCLUDE_PATH ImfRgbaFile.h
|
||||
/usr/include
|
||||
/usr/local/include)
|
||||
/usr/local/include
|
||||
/usr/include/OpenEXR
|
||||
/usr/local/include/OpenEXR)
|
||||
|
||||
FIND_LIBRARY(OPENEXR_HALF_LIBRARY
|
||||
NAMES Half
|
||||
@ -41,10 +43,10 @@ ELSE (WIN32)
|
||||
|
||||
ENDIF (WIN32)
|
||||
|
||||
IF (OPENEXR_INCLUDE_DIR AND OPENEXR_IMATH_LIBRARY AND OPENEXR_ILMIMF_LIBRARY AND OPENEXR_IEX_LIBRARY AND OPENEXR_HALF_LIBRARY)
|
||||
IF (OPENEXR_INCLUDE_PATH AND OPENEXR_IMATH_LIBRARY AND OPENEXR_ILMIMF_LIBRARY AND OPENEXR_IEX_LIBRARY AND OPENEXR_HALF_LIBRARY)
|
||||
SET(OPENEXR_FOUND TRUE)
|
||||
SET(OPENEXR_LIBRARIES ${OPENEXR_IMATH_LIBRARY} ${OPENEXR_ILMIMF_LIBRARY} ${OPENEXR_IEX_LIBRARY} ${OPENEXR_HALF_LIBRARY} CACHE STRING "The libraries needed to use OpenEXR")
|
||||
ENDIF (OPENEXR_INCLUDE_DIR AND OPENEXR_IMATH_LIBRARY AND OPENEXR_ILMIMF_LIBRARY AND OPENEXR_IEX_LIBRARY AND OPENEXR_HALF_LIBRARY)
|
||||
ENDIF (OPENEXR_INCLUDE_PATH AND OPENEXR_IMATH_LIBRARY AND OPENEXR_ILMIMF_LIBRARY AND OPENEXR_IEX_LIBRARY AND OPENEXR_HALF_LIBRARY)
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
OPENEXR_INCLUDE_DIR
|
||||
|
@ -1019,26 +1019,31 @@ FloatImage * nv::ImageIO::loadFloatEXR(const char * fileName, Stream & s)
|
||||
int width = box.max.x - box.min.y + 1;
|
||||
int height = box.max.x - box.min.y + 1;
|
||||
|
||||
Array2D<Rgba> pixels;
|
||||
pixels.resizeErase (height, width);
|
||||
const Imf::ChannelList & channels = inputFile.header().channels();
|
||||
|
||||
inputFile.setFrameBuffer (&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
|
||||
inputFile.readPixels (box.min.y, box.max.y);
|
||||
// Count channels.
|
||||
uint channelCount= 0;
|
||||
for (ChannelList::ConstIterator it = channels.begin(); it != channels.end(); ++it)
|
||||
{
|
||||
channelCount++;
|
||||
}
|
||||
|
||||
// Allocate FloatImage.
|
||||
AutoPtr<FloatImage> fimage(new FloatImage());
|
||||
fimage->allocate(spp, width, height);
|
||||
fimage->allocate(channelCount, width, height);
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
// Describe image's layout with a framebuffer.
|
||||
FrameBuffer frameBuffer;
|
||||
uint i = 0;
|
||||
for (ChannelList::ConstIterator it = channels.begin(); it != channels.end(); ++it, ++i)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
fimage->setPixel(imagePixel.r, x, y, 0);
|
||||
fimage->setPixel(imagePixel.g, x, y, 1);
|
||||
fimage->setPixel(imagePixel.b, x, y, 2);
|
||||
fimage->setPixel(imagePixel.a, x, y, 3);
|
||||
}
|
||||
frameBuffer.insert(it.name(), Slice(FLOAT, fimage->channel(i), sizeof(float), sizeof(float) * width));
|
||||
}
|
||||
|
||||
// Read it.
|
||||
inputFile.setFrameBuffer (frameBuffer);
|
||||
inputFile.readPixels (box.min.y, box.max.y);
|
||||
|
||||
return fimage.release();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user