Commit 9b28ede5 authored by Robert Menzel's avatar Robert Menzel

added read-support for RADIANCE / RGBE files

parent f853399f
......@@ -8,6 +8,7 @@ Included third-party software:
* Includes OpenGL loader code created by a modified glLoadGen by Jason McKesson.
* Includes GLM by Christophe Riccio.
* Includes data type definitions from libspnav header originally by John Tsiombikas (see mini_spnav.h for details).
* Includes RGBE/Radiance image import by Bruce Walter (code provided 'as-is').
See LICENSE.TXT for licensing information.
......
......@@ -51,6 +51,8 @@ SharedTextureData loadTextureDataFromLodepng(const std::string &_filename);
SharedTextureData loadTextureDataFromQT(const std::string &_filename);
#endif
SharedTextureData loadTextureDataFromRGBE(const std::string &_filename);
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific save
///////////////////////////////////////////////////////////////////////////////////////////////////
......
#ifndef _H_RGBE
#define _H_RGBE
/* THIS CODE CARRIES NO GUARANTEE OF USABILITY OR FITNESS FOR ANY PURPOSE.
* WHILE THE AUTHORS HAVE TRIED TO ENSURE THE PROGRAM WORKS CORRECTLY,
* IT IS STRICTLY USE AT YOUR OWN RISK. */
/* utility for reading and writing Ward's rgbe image format.
See rgbe.txt file for more details.
*/
#include <stdio.h>
typedef struct {
int valid; /* indicate which fields are valid */
char programtype[16]; /* listed at beginning of file to identify it
* after "#?". defaults to "RGBE" */
float gamma; /* image has already been gamma corrected with
* given gamma. defaults to 1.0 (no correction) */
float exposure; /* a value of 1.0 in an image corresponds to
* <exposure> watts/steradian/m^2.
* defaults to 1.0 */
} rgbe_header_info;
/* flags indicating which fields in an rgbe_header_info are valid */
#define RGBE_VALID_PROGRAMTYPE 0x01
#define RGBE_VALID_GAMMA 0x02
#define RGBE_VALID_EXPOSURE 0x04
/* return codes for rgbe routines */
#define RGBE_RETURN_SUCCESS 0
#define RGBE_RETURN_FAILURE -1
/* read or write headers */
/* you may set rgbe_header_info to null if you want to */
int RGBE_WriteHeader(FILE *fp, int width, int height, rgbe_header_info *info);
int RGBE_ReadHeader(FILE *fp, int *width, int *height, rgbe_header_info *info);
/* read or write pixels */
/* can read or write pixels in chunks of any size including single pixels*/
int RGBE_WritePixels(FILE *fp, float *data, int numpixels);
int RGBE_ReadPixels(FILE *fp, float *data, int numpixels);
/* read or write run length encoded files */
/* must be called to read or write whole scanlines */
int RGBE_WritePixels_RLE(FILE *fp, float *data, int scanline_width,
int num_scanlines);
int RGBE_ReadPixels_RLE(FILE *fp, float *data, int scanline_width,
int num_scanlines);
#endif /* _H_RGBE */
......@@ -16,6 +16,7 @@
#include <fstream>
#include "lodepng/lodepng.h"
#include "rgbe/rgbe.hh"
#ifdef ACGL_COMPILE_WITH_QT
#include <QImage>
......@@ -42,6 +43,8 @@ SharedTextureData loadTextureData(const std::string &_filename)
if (fileEnding == "png") {
return loadTextureDataFromLodepng( _filename );
} else if (fileEnding == "hdr") {
return loadTextureDataFromRGBE( _filename );
}
#ifdef ACGL_COMPILE_WITH_QT
else if ( fileEnding == "bmp" || fileEnding == "jpg" || fileEnding == "jpeg"
......@@ -209,6 +212,27 @@ SharedTextureData loadTextureDataFromQT(const std::string &_filename)
}
#endif
SharedTextureData loadTextureDataFromRGBE(const std::string &_filename)
{
SharedTextureData data = SharedTextureData( new TextureData() );
FILE* f = fopen(_filename.c_str(), "rb");
int texWidth, texHeight;
RGBE_ReadHeader(f, &texWidth, &texHeight, NULL);
GLubyte* tempdata = new GLubyte[ sizeof(GL_FLOAT) * 3 * texWidth * texHeight];
RGBE_ReadPixels_RLE(f, (float*)tempdata, texWidth, texHeight);
fclose(f);
data->setData( tempdata );
data->setHeight( texHeight );
data->setWidth( texWidth );
data->setFormat( GL_RGB );
data->setType( GL_FLOAT );
return data;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific save
///////////////////////////////////////////////////////////////////////////////////////////////////
......
This diff is collapsed.
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