Commit 2a45824c authored by Edward Vigmond's avatar Edward Vigmond
Browse files

added support for IGB files using IEEE half float storage

parent e49a1d00
......@@ -224,7 +224,7 @@ const char *Header_Type[] =
"", "byte", "char", "short", "long", "float", "double", "complex",
"double_complex", "rgba", "structure", "pointer", "list","int","uint",
"ushort",
"vec3f","vec3d","vec4f","vec4d"
"vec3f","vec3d","vec4f","vec4d","hfloat"
};
......@@ -238,15 +238,16 @@ unsigned short Data_Size[] =
{
0, sizeof(Byte), sizeof(char), sizeof(short), sizeof(long), sizeof(float),
sizeof(double), 0, 0, 0, 0, sizeof(void *), 0, sizeof(int), sizeof(UInt),
sizeof(unsigned short),
3*sizeof(float), 3*sizeof(double), 4*sizeof(float), 4*sizeof(double)
sizeof(unsigned short),
3*sizeof(float), 3*sizeof(double), 4*sizeof(float), 4*sizeof(double),
sizeof(short_float)
};
/** the number of components for each data type */
int Num_Components[] =
{
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 3, 3, 4, 4
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 3, 3, 4, 4, 1
};
......@@ -1314,9 +1315,9 @@ void IGBheader::systeme( const char* s )
void IGBheader::type( char *datatype )
{
int tn=IGB_MIN_TYPE;
while ( tn<IGB_MAX_TYPE && strcmp(Header_Type[tn],datatype) )
while ( tn<=IGB_MAX_TYPE && strcmp(Header_Type[tn],datatype) )
tn++;
if ( tn<IGB_MAX_TYPE )
if ( tn<=IGB_MAX_TYPE )
v_type = tn;
else {
cerr << "illegal data type specified for IGB header" << endl;
......
......@@ -10,6 +10,7 @@
#include <cctype>
#include<assert.h>
#include<float.h>
#include "short_float.h"
#define NALLOC 100
......@@ -41,8 +42,9 @@
#define IGB_VEC3_d 17 /* -- 3 X double ----------------------------- */
#define IGB_VEC4_f 18 /* -- 4 X float ------------------------------ */
#define IGB_VEC4_d 19 /* -- 4 X double ----------------------------- */
#define IGB_MIN_TYPE 1
#define IGB_MAX_TYPE 19
#define IGB_HFLOAT 20 /* -- half float ----------------------------- */
#define IGB_MIN_TYPE 1
#define IGB_MAX_TYPE 20
#define Byte hByte
......@@ -99,7 +101,7 @@ struct S_Complex
{
Float real, imag;
};
struct D_Complex
struct D_Complex
{
Double real, imag;
};
......@@ -129,6 +131,8 @@ typedef union rgba {
#define RGBA_BLEU 1
#define RGBA_ALPHA 0
#define HFLT_MIN -65504
#define HFLT_MAX 65504
/* -------------- Definition du type des variables globales de header.c - */
......@@ -456,6 +460,9 @@ T IGBheader::convert_buffer_datum( void *buf, int a )
case IGB_USHORT:
datum = ((unsigned short *)buf)[a];
break;
case IGB_HFLOAT:
datum = floatFromShort(((short_float *)buf)[a]);
break;
default:
memset(&datum,0,sizeof(datum));
}
......@@ -463,8 +470,8 @@ T IGBheader::convert_buffer_datum( void *buf, int a )
}
#define CONVERT_TYPE(T,m,M) { if(datum<m)datum=m;else if(datum>M)datum=M; \
T a0 = (T)datum; *((T*)buf)=a0;};
#define CONVERT_TYPE(D,m,M,B) { if(datum<m)datum=m;else if(datum>M)datum=M; \
D a0 = (D)datum; *((D*)(B))=a0;};
/** convert the data to the binary representation
*
* \param h IGB header
......@@ -478,39 +485,44 @@ IGBheader::to_bin( void *buf, T d )
double datum=to_raw(d);
switch ( type() ) {
case IGB_BYTE:
CONVERT_TYPE( unsigned char, 0, UCHAR_MAX )
CONVERT_TYPE( unsigned char, 0, UCHAR_MAX, buf )
break;
case IGB_CHAR:
CONVERT_TYPE( char, CHAR_MIN, CHAR_MAX )
CONVERT_TYPE( char, CHAR_MIN, CHAR_MAX, buf )
break;
case IGB_SHORT:
CONVERT_TYPE( short, SHRT_MIN, SHRT_MAX )
CONVERT_TYPE( short, SHRT_MIN, SHRT_MAX, buf )
break;
case IGB_LONG:
CONVERT_TYPE( long, LONG_MIN, LONG_MAX )
CONVERT_TYPE( long, LONG_MIN, LONG_MAX, buf )
break;
case IGB_FLOAT:
CONVERT_TYPE( float, FLT_MIN, FLT_MAX )
CONVERT_TYPE( float, FLT_MIN, FLT_MAX, buf )
break;
case IGB_VEC3_f:
case IGB_VEC4_f:
assert(0);
break;
case IGB_DOUBLE:
CONVERT_TYPE( double, DBL_MIN, DBL_MAX )
CONVERT_TYPE( double, DBL_MIN, DBL_MAX, buf )
break;
case IGB_VEC3_d:
case IGB_VEC4_d:
assert(0);
break;
case IGB_INT:
CONVERT_TYPE( int, INT_MIN, INT_MAX )
CONVERT_TYPE( int, INT_MIN, INT_MAX, buf )
break;
case IGB_UINT:
CONVERT_TYPE( unsigned int, 0, UINT_MAX )
CONVERT_TYPE( unsigned int, 0, UINT_MAX, buf )
break;
case IGB_USHORT:
CONVERT_TYPE( unsigned short, 0, USHRT_MAX )
CONVERT_TYPE( unsigned short, 0, USHRT_MAX, buf )
break;
case IGB_HFLOAT:
float fdatum;
CONVERT_TYPE( float, HFLT_MIN, HFLT_MAX, &fdatum )
*((short_float*)buf) = shortFromFloat(fdatum);
break;
default:
assert(0);
......
......@@ -26,7 +26,7 @@ COMMON_LIBS = $(FLTK_LIBS) -lpng -lpthread -lm -lz $(LIB_HDF5)
LIBS = -L$(HDF5API_ROOT)/lib $(FLTK_LD_FLAGS) $(COMMON_LIBS)
#LDFLAGS = -fopenmp
CXXFLAGS = -I$(HDF5API_ROOT)/src $(FLTK_INC) $(COMMON_INC)
CXXFLAGS = -std=c++11 -I$(HDF5API_ROOT)/src $(FLTK_INC) $(COMMON_INC)
CPPFLAGS = $(CFLAGS) -g
ifdef ENABLE_LOGGING
......
This diff is collapsed.
//// HEADER GUARD ///////////////////////////
// If automatically generated, keep above
// comment as first line in file.
#ifndef __SHORT_FLOAT_H__
#define __SHORT_FLOAT_H__
//// HEADER GUARD ///////////////////////////
/*
ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf
Fast Half Float Conversions
Jeroen van der Zijp
November 2008
(Revised September 2010)
Use the dumpTables code to generate the corresponding C file.
*/
#include <cstdint>
extern const uint16_t basetable[512];
extern const uint16_t shifttable[512];
extern const uint32_t mantissatable[2048];
extern const uint16_t offsettable[64];
extern const uint32_t exponenttable[64];
typedef uint16_t short_float;
static inline short_float shortFromFloat(const float external_ff) {
union {
float as_float;
uint32_t as_uint32;
} c;
c.as_float = external_ff;
return basetable[(c.as_uint32>>23)&0x1ff]+((c.as_uint32&0x007fffff)>>shifttable[(c.as_uint32>>23)&0x1ff]);
}
static inline float floatFromShort(const short_float h) {
union {
float as_float;
uint32_t as_uint32;
} c;
c.as_uint32 = mantissatable[offsettable[h>>10]+(h&0x3ff)]+exponenttable[h>>10];
return c.as_float;
}
#define SHORT_FLOAT_MACHINE_EPS 0.0009765625
//// HEADER GUARD ///////////////////////////
#endif
//// HEADER GUARD ///////////////////////////
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