Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginPFM.cpp view on Meta::CPAN
// ==========================================================
// PFM Loader and Writer
//
// Design and implementation by
// - Hervé Drolon (drolon@infonie.fr)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#include "FreeImage.h"
#include "Utilities.h"
// ==========================================================
// Internal functions
// ==========================================================
/** maximum size of a line in the header */
#define PFM_MAXLINE 256
/** Big endian / Little endian float conversion */
#define REVERSEBYTES(source, dest) \
{ \
char *j = (char *) source; \
char *dj = (char *) dest; \
dj[0] = j[3]; \
dj[1] = j[2]; \
dj[2] = j[1]; \
dj[3] = j[0]; \
}
/**
Get a line from a ASCII io stream
*/
static BOOL
pfm_get_line(FreeImageIO *io, fi_handle handle, char *buffer, int length) {
int i;
memset(buffer, 0, length);
for(i = 0; i < length; i++) {
if(!io->read_proc(&buffer[i], 1, 1, handle))
return FALSE;
if(buffer[i] == 0x0A)
break;
}
return (i < length) ? TRUE : FALSE;
}
/**
Get an integer value from the actual position pointed by handle
*/
static int
pfm_get_int(FreeImageIO *io, fi_handle handle) {
char c = 0;
BOOL bFirstChar;
// skip forward to start of next number
if(!io->read_proc(&c, 1, 1, handle)) {
throw FI_MSG_ERROR_PARSING;
}
while (1) {
// eat comments
if (c == '#') {
// if we're at a comment, read to end of line
bFirstChar = TRUE;
while (1) {
if(!io->read_proc(&c, 1, 1, handle)) {
throw FI_MSG_ERROR_PARSING;
}
if (bFirstChar && c == ' ') {
// loop off 1 sp after #
bFirstChar = FALSE;
} else if (c == '\n') {
break;
}
}
}
if (c >= '0' && c <='9') {
// we've found what we were looking for
break;
}
if(!io->read_proc(&c, 1, 1, handle)) {
throw FI_MSG_ERROR_PARSING;
}
}
// we're at the start of a number, continue until we hit a non-number
int i = 0;
while (1) {
i = (i * 10) + (c - '0');
if(!io->read_proc(&c, 1, 1, handle)) {
throw FI_MSG_ERROR_PARSING;
}
if (c < '0' || c > '9') {
( run in 1.337 second using v1.01-cache-2.11-cpan-119454b85a5 )