Commit 6873cc20 authored by Robert Menzel's avatar Robert Menzel

added option to compile EXR loading in

parent 9b28ede5
......@@ -53,6 +53,8 @@ SharedTextureData loadTextureDataFromQT(const std::string &_filename);
SharedTextureData loadTextureDataFromRGBE(const std::string &_filename);
SharedTextureData loadTextureDataFromEXR(const std::string &_filename);
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific save
///////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -25,6 +25,18 @@
#include <QImageWriter>
#endif
// EXR:
#ifndef ACGL_BUILD_WITH_EXR
#define ACGL_BUILD_WITH_EXR
#endif
#ifdef ACGL_BUILD_WITH_EXR
//#include <ImfInputFile.h>
#include <ImfRgbaFile.h>
using namespace Imf;
using namespace Imath;
#endif
using namespace ACGL;
using namespace ACGL::OpenGL;
using namespace ACGL::Utils;
......@@ -45,6 +57,8 @@ SharedTextureData loadTextureData(const std::string &_filename)
return loadTextureDataFromLodepng( _filename );
} else if (fileEnding == "hdr") {
return loadTextureDataFromRGBE( _filename );
} else if (fileEnding == "exr") {
return loadTextureDataFromEXR( _filename );
}
#ifdef ACGL_COMPILE_WITH_QT
else if ( fileEnding == "bmp" || fileEnding == "jpg" || fileEnding == "jpeg"
......@@ -233,6 +247,44 @@ SharedTextureData loadTextureDataFromRGBE(const std::string &_filename)
return data;
}
SharedTextureData loadTextureDataFromEXR(const std::string &_filename)
{
#ifndef ACGL_BUILD_WITH_EXR
error() << "can't load EXR file " << _filename << " ACGL was not build with EXR support" << endl;
return SharedTextureData();
#else
SharedTextureData data = SharedTextureData( new TextureData() );
try {
// see GPU gems 1:
Imf::RgbaInputFile in( _filename.c_str() );
Imath::Box2i window = in.dataWindow();
Imath::V2i dimension( window.max.x - window.min.x +1,
window.max.y - window.min.y +1);
unsigned char *buffer = (unsigned char *) new Imf::Rgba[ dimension.x*dimension.y ];
int dx = window.min.x;
int dy = window.min.y;
in.setFrameBuffer( (Imf::Rgba*)buffer-dx-dy*dimension.x, 1, dimension.x );
in.readPixels( window.min.y, window.max.y );
data->setData( buffer );
data->setHeight( dimension.y );
data->setWidth( dimension.x );
data->setFormat( GL_RGBA );
data->setType( GL_HALF_FLOAT );
} catch(Iex::BaseExc &e) {
error() << "EXR loading failed: " << e.what() << std::endl;
return SharedTextureData();
}
return data;
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific save
///////////////////////////////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment