33 #define MAXSHORT 0x7fff
99 file = fopen(filePath.c_str(),
"rb");
103 LOGE(
"Could not open file %s", filePath.c_str());
112 string readHeader = header;
116 LOGE(
"File header has not been recognized.\n");
122 char currentChar = 0;
123 char previousChar = 0;
125 while ((previousChar !=
'\n' || currentChar !=
'\n') && currentChar != EOF)
127 previousChar = currentChar;
128 currentChar = fgetc(file);
134 fscanf(file,
"-Y %d ", &imageHeight);
135 fscanf(file,
"+X %d ", &imageWidth);
137 if (imageWidth < minLineLength || imageWidth >
maxLineLength)
139 LOGE(
"Cannot decode image with width lower than %d or higher than %d",
minLineLength, maxLineLength);
153 catch (std::bad_alloc& ba)
155 LOGE(
"Exception caught: %s", ba.what());
159 for (
int y = 0;
y < imageHeight; ++
y)
163 LOGE(
"One of the scan lines has not been encoded correctly.\n");
171 for (
int x = 0;
x < imageWidth; ++
x)
173 int rgbPixelMove = (
y * imageWidth +
x) * 3;
185 int exponent = pixel.
e - 128;
194 float floatValue =
static_cast<float> (
value) /
MAXCHAR;
195 float multiplier = pow(2.0
f, exponent);
197 return floatValue * multiplier;
203 char startLineChar1 = fgetc(file);
204 char startLineChar2 = fgetc(file);
205 char startLineChar3 = fgetc(file);
209 LOGE(
"Error occured while encoding HDR data. Unknown line beginnings.");
221 while (pixelIndex < lineLength)
224 unsigned char rleCode = fgetc(file);
232 unsigned char value = fgetc(file);
249 unsigned char value = fgetc(file);
262 if (rgbePixel == NULL)
264 LOGE(
"Cannot write encoded component to a NULL pointer.\n");
269 switch (componentIndicator)
288 LOGE(
"Invalid value of componentIndicator was passed.\n");
static float convertSingleComponent(unsigned char value, int exponent)
virtual ~HDRImage(void)
Destructor.
static bool decodeLine(FILE *file, int lineLength, RGBEPixel *scanLine)
int width
The width of the HDR image.
const int rgbComponentsCount
void loadFromFile(const std::string &filePath)
Load a HDRImage from a file.
GLint GLsizei GLsizei height
const int rgbeComponentsCount
HDRImage(void)
Default constructor.
float * rgbData
The HDR image data.
GLint GLint GLint GLint GLint x
Class to load an manage HDR images.
HDRImage & operator=(const HDRImage &another)
Overloading assignment operater to do deep copy of the HDRImage data.
static void writeDecodedComponent(int componentIndicator, unsigned char value, RGBEPixel *pixel)
const int radianceHeaderLength
static const string radianceHeader
static void convertRGBEPixel(const RGBEPixel &pixel, float *rgbData)
int height
The height of the HDR image.