diff options
author | Mikael Sundell <mikaelsundell@Mikaels-MBP.lan> | 2016-02-01 20:07:01 +0100 |
---|---|---|
committer | Mikael Sundell <mikaelsundell@Mikaels-MBP.lan> | 2016-02-01 20:07:01 +0100 |
commit | 08765db00c5bfd0c21c360f7266a670a6031e44a (patch) | |
tree | b1aa34bdd13c545828a89cd2a74ba1325449ec02 | |
parent | 0bba767db1ebfd810e76ab9e21b1af50a4646657 (diff) | |
download | devil-08765db00c5bfd0c21c360f7266a670a6031e44a.tar.gz |
Various fixed for llvm
-rw-r--r-- | DevIL/configure.ac | 4 | ||||
-rw-r--r-- | DevIL/include/IL/il.h | 2 | ||||
-rw-r--r-- | DevIL/src-IL/include/il_endian.h | 295 | ||||
-rw-r--r-- | DevIL/src-IL/include/il_manip.h | 204 | ||||
-rw-r--r-- | DevIL/src-IL/src/il_endian.c | 268 | ||||
-rw-r--r-- | DevIL/src-IL/src/il_manip.c | 206 | ||||
-rw-r--r-- | DevIL/src-ILU/ilur/ilur.c | 2 | ||||
-rw-r--r-- | DevIL/src-ILU/include/ilu_internal.h | 13 | ||||
-rw-r--r-- | DevIL/src-ILU/src/ilu_internal.c | 12 |
9 files changed, 505 insertions, 501 deletions
diff --git a/DevIL/configure.ac b/DevIL/configure.ac index c427aa78..2268246a 100644 --- a/DevIL/configure.ac +++ b/DevIL/configure.ac @@ -150,9 +150,7 @@ AS_IF([test "x$enable_ILU" = "xyes" -o "x$enable_ILUT" = "xyes"], dnl Test for restrict c/c++ keyword DEVIL_CHECK_RESTRICT -dnl checking if the -std=gnu99 flag is required -AS_IF([test "x$restrict_keyword" = "xfound"], - [DEVIL_CHECK_RESTRICT_GNU99]) + dnl must add AC_CACHE_CHECK support where possible diff --git a/DevIL/include/IL/il.h b/DevIL/include/IL/il.h index 540a56eb..21fd6b28 100644 --- a/DevIL/include/IL/il.h +++ b/DevIL/include/IL/il.h @@ -63,7 +63,7 @@ extern "C" { #endif #endif -#ifdef RESTRICT_KEYWORD +#if defined(RESTRICT_KEYWORD) && !defined(__cplusplus) #define RESTRICT restrict #define CONST_RESTRICT const restrict #else diff --git a/DevIL/src-IL/include/il_endian.h b/DevIL/src-IL/include/il_endian.h index 08189484..4b64d8a8 100644 --- a/DevIL/src-IL/include/il_endian.h +++ b/DevIL/src-IL/include/il_endian.h @@ -39,8 +39,10 @@ #define BigDouble(d) #else #undef __BIG_ENDIAN__ +#if !defined(__LITTLE_ENDIAN__) #undef __LITTLE_ENDIAN__ // Not sure if it's defined by any compiler... #define __LITTLE_ENDIAN__ +#endif #define Short(s) #define UShort(s) #define Int(i) @@ -56,6 +58,12 @@ #define BigDouble(d) iSwapDouble(d) #endif +#ifdef IL_ENDIAN_C +#undef NOINLINE +#undef INLINE +#define INLINE +#endif + void iSwapUShort(ILushort *s); void iSwapShort(ILshort *s); void iSwapUInt(ILuint *i); @@ -87,291 +95,6 @@ ILubyte SaveBigInt(ILint i); ILubyte SaveBigFloat(ILfloat f); ILubyte SaveBigDouble(ILdouble d); -#ifdef IL_ENDIAN_C -#undef NOINLINE -#undef INLINE -#define INLINE -#endif - -#ifndef NOINLINE -INLINE void iSwapUShort(ILushort *s) { - #ifdef USE_WIN32_ASM - __asm { - mov ebx, s - mov al, [ebx+1] - mov ah, [ebx ] - mov [ebx], ax - } - #else - #ifdef GCC_X86_ASM - asm("ror $8,%0" - : "=r" (*s) - : "0" (*s)); - #else - *s = ((*s)>>8) | ((*s)<<8); - #endif //GCC_X86_ASM - #endif //USE_WIN32_ASM -} - -INLINE void iSwapShort(ILshort *s) { - iSwapUShort((ILushort*)s); -} - -INLINE void iSwapUInt(ILuint *i) { - #ifdef USE_WIN32_ASM - __asm { - mov ebx, i - mov eax, [ebx] - bswap eax - mov [ebx], eax - } - #else - #ifdef GCC_X86_ASM - asm("bswap %0;" - : "+r" (*i)); - #else - *i = ((*i)>>24) | (((*i)>>8) & 0xff00) | (((*i)<<8) & 0xff0000) | ((*i)<<24); - #endif //GCC_X86_ASM - #endif //USE_WIN32_ASM -} - -INLINE void iSwapInt(ILint *i) { - iSwapUInt((ILuint*)i); -} - -INLINE void iSwapFloat(ILfloat *f) { - iSwapUInt((ILuint*)f); -} - -INLINE void iSwapDouble(ILdouble *d) { - #ifdef GCC_X86_ASM - int *t = (int*)d; - asm("bswap %2 \n" - "bswap %3 \n" - "movl %2,%1 \n" - "movl %3,%0 \n" - : "=g" (t[0]), "=g" (t[1]) - : "r" (t[0]), "r" (t[1])); - #else - ILubyte t,*b = (ILubyte*)d; - #define dswap(x,y) t=b[x];b[x]=b[y];b[y]=b[x]; - dswap(0,7); - dswap(1,6); - dswap(2,5); - dswap(3,4); - #undef dswap - #endif -} - - -INLINE ILushort GetLittleUShort() { - ILushort s; - iread(&s, sizeof(ILushort), 1); -#ifdef __BIG_ENDIAN__ - iSwapUShort(&s); -#endif - return s; -} - -INLINE ILshort GetLittleShort() { - ILshort s; - iread(&s, sizeof(ILshort), 1); -#ifdef __BIG_ENDIAN__ - iSwapShort(&s); -#endif - return s; -} - -INLINE ILuint GetLittleUInt() { - ILuint i; - iread(&i, sizeof(ILuint), 1); -#ifdef __BIG_ENDIAN__ - iSwapUInt(&i); -#endif - return i; -} - -INLINE ILint GetLittleInt() { - ILint i; - iread(&i, sizeof(ILint), 1); -#ifdef __BIG_ENDIAN__ - iSwapInt(&i); -#endif - return i; -} - -INLINE ILfloat GetLittleFloat() { - ILfloat f; - iread(&f, sizeof(ILfloat), 1); -#ifdef __BIG_ENDIAN__ - iSwapFloat(&f); -#endif - return f; -} - -INLINE ILdouble GetLittleDouble() { - ILdouble d; - iread(&d, sizeof(ILdouble), 1); -#ifdef __BIG_ENDIAN__ - iSwapDouble(&d); -#endif - return d; -} - - -INLINE ILushort GetBigUShort() { - ILushort s; - iread(&s, sizeof(ILushort), 1); -#ifdef __LITTLE_ENDIAN__ - iSwapUShort(&s); -#endif - return s; -} - - -INLINE ILshort GetBigShort() { - ILshort s; - iread(&s, sizeof(ILshort), 1); -#ifdef __LITTLE_ENDIAN__ - iSwapShort(&s); -#endif - return s; -} - - -INLINE ILuint GetBigUInt() { - ILuint i; - iread(&i, sizeof(ILuint), 1); -#ifdef __LITTLE_ENDIAN__ - iSwapUInt(&i); -#endif - return i; -} - - -INLINE ILint GetBigInt() { - ILint i; - iread(&i, sizeof(ILint), 1); -#ifdef __LITTLE_ENDIAN__ - iSwapInt(&i); -#endif - return i; -} - - -INLINE ILfloat GetBigFloat() { - ILfloat f; - iread(&f, sizeof(ILfloat), 1); -#ifdef __LITTLE_ENDIAN__ - iSwapFloat(&f); -#endif - return f; -} - - -INLINE ILdouble GetBigDouble() { - ILdouble d; - iread(&d, sizeof(ILdouble), 1); -#ifdef __LITTLE_ENDIAN__ - iSwapDouble(&d); -#endif - return d; -} - -INLINE ILubyte SaveLittleUShort(ILushort s) { -#ifdef __BIG_ENDIAN__ - iSwapUShort(&s); -#endif - return iwrite(&s, sizeof(ILushort), 1); -} - -INLINE ILubyte SaveLittleShort(ILshort s) { -#ifdef __BIG_ENDIAN__ - iSwapShort(&s); -#endif - return iwrite(&s, sizeof(ILshort), 1); -} - - -INLINE ILubyte SaveLittleUInt(ILuint i) { -#ifdef __BIG_ENDIAN__ - iSwapUInt(&i); -#endif - return iwrite(&i, sizeof(ILuint), 1); -} - - -INLINE ILubyte SaveLittleInt(ILint i) { -#ifdef __BIG_ENDIAN__ - iSwapInt(&i); -#endif - return iwrite(&i, sizeof(ILint), 1); -} - -INLINE ILubyte SaveLittleFloat(ILfloat f) { -#ifdef __BIG_ENDIAN__ - iSwapFloat(&f); -#endif - return iwrite(&f, sizeof(ILfloat), 1); -} - - -INLINE ILubyte SaveLittleDouble(ILdouble d) { -#ifdef __BIG_ENDIAN__ - iSwapDouble(&d); -#endif - return iwrite(&d, sizeof(ILdouble), 1); -} - - -INLINE ILubyte SaveBigUShort(ILushort s) { -#ifdef __LITTLE_ENDIAN__ - iSwapUShort(&s); -#endif - return iwrite(&s, sizeof(ILushort), 1); -} - - -INLINE ILubyte SaveBigShort(ILshort s) { -#ifdef __LITTLE_ENDIAN__ - iSwapShort(&s); -#endif - return iwrite(&s, sizeof(ILshort), 1); -} - - -INLINE ILubyte SaveBigUInt(ILuint i) { -#ifdef __LITTLE_ENDIAN__ - iSwapUInt(&i); -#endif - return iwrite(&i, sizeof(ILuint), 1); -} - - -INLINE ILubyte SaveBigInt(ILint i) { -#ifdef __LITTLE_ENDIAN__ - iSwapInt(&i); -#endif - return iwrite(&i, sizeof(ILint), 1); -} - - -INLINE ILubyte SaveBigFloat(ILfloat f) { -#ifdef __LITTLE_ENDIAN__ - iSwapFloat(&f); -#endif - return iwrite(&f, sizeof(ILfloat), 1); -} - - -INLINE ILubyte SaveBigDouble(ILdouble d) { -#ifdef __LITTLE_ENDIAN__ - iSwapDouble(&d); -#endif - return iwrite(&d, sizeof(ILdouble), 1); -} -#endif//NOINLINE - -void EndianSwapData(void *_Image); +void EndianSwapData(void *_Image); #endif//ENDIAN_H diff --git a/DevIL/src-IL/include/il_manip.h b/DevIL/src-IL/include/il_manip.h index d19f4589..42ce8db8 100644 --- a/DevIL/src-IL/include/il_manip.h +++ b/DevIL/src-IL/include/il_manip.h @@ -31,14 +31,9 @@ ILboolean ilMirrorImage(void); //@JASON New routine created 03/28/2001 #pragma warning(push) #pragma warning(disable : 4756) // Disables 'named type definition in parentheses' warning #endif -INLINE ILfloat /*ILAPIENTRY*/ ilFloatToHalfOverflow() { - ILfloat f = 1e10; - ILint j; - for (j = 0; j < 10; j++) - f *= f; // this will overflow before - // the for loop terminates - return f; -} + +ILfloat /*ILAPIENTRY*/ ilFloatToHalfOverflow(); + #if defined(_MSC_VER) #pragma warning(pop) #endif @@ -47,199 +42,8 @@ INLINE ILfloat /*ILAPIENTRY*/ ilFloatToHalfOverflow() { // Float-to-half conversion -- general case, including // zeroes, denormalized numbers and exponent overflows. //----------------------------------------------------- -INLINE ILushort ILAPIENTRY ilFloatToHalf(ILuint i) { - // - // Our floating point number, f, is represented by the bit - // pattern in integer i. Disassemble that bit pattern into - // the sign, s, the exponent, e, and the significand, m. - // Shift s into the position where it will go in in the - // resulting half number. - // Adjust e, accounting for the different exponent bias - // of float and half (127 versus 15). - // - - register int s = (i >> 16) & 0x00008000; - register int e = ((i >> 23) & 0x000000ff) - (127 - 15); - register int m = i & 0x007fffff; - - // - // Now reassemble s, e and m into a half: - // - - if (e <= 0) - { - if (e < -10) - { - // - // E is less than -10. The absolute value of f is - // less than HALF_MIN (f may be a small normalized - // float, a denormalized float or a zero). - // - // We convert f to a half zero. - // - - return 0; - } - - // - // E is between -10 and 0. F is a normalized float, - // whose magnitude is less than HALF_NRM_MIN. - // - // We convert f to a denormalized half. - // - - m = (m | 0x00800000) >> (1 - e); - - // - // Round to nearest, round "0.5" up. - // - // Rounding may cause the significand to overflow and make - // our number normalized. Because of the way a half's bits - // are laid out, we don't have to treat this case separately; - // the code below will handle it correctly. - // - - if (m & 0x00001000) - m += 0x00002000; - - // - // Assemble the half from s, e (zero) and m. - // - - return s | (m >> 13); - } - else if (e == 0xff - (127 - 15)) - { - if (m == 0) - { - // - // F is an infinity; convert f to a half - // infinity with the same sign as f. - // - - return s | 0x7c00; - } - else - { - // - // F is a NAN; we produce a half NAN that preserves - // the sign bit and the 10 leftmost bits of the - // significand of f, with one exception: If the 10 - // leftmost bits are all zero, the NAN would turn - // into an infinity, so we have to set at least one - // bit in the significand. - // - - m >>= 13; - return s | 0x7c00 | m | (m == 0); - } - } - else - { - // - // E is greater than zero. F is a normalized float. - // We try to convert f to a normalized half. - // - - // - // Round to nearest, round "0.5" up - // - - if (m & 0x00001000) - { - m += 0x00002000; - - if (m & 0x00800000) - { - m = 0; // overflow in significand, - e += 1; // adjust exponent - } - } +ILushort ILAPIENTRY ilFloatToHalf(ILuint i); - // - // Handle exponent overflow - // - - if (e > 30) - { - ilFloatToHalfOverflow(); // Cause a hardware floating point overflow; - return s | 0x7c00; // if this returns, the half becomes an - } // infinity with the same sign as f. - - // - // Assemble the half from s, e and m. - // - - return s | (e << 10) | (m >> 13); - } -} - -// Taken from OpenEXR -INLINE ILuint ILAPIENTRY ilHalfToFloat (ILushort y) { - - int s = (y >> 15) & 0x00000001; - int e = (y >> 10) & 0x0000001f; - int m = y & 0x000003ff; - - if (e == 0) - { - if (m == 0) - { - // - // Plus or minus zero - // - - return s << 31; - } - else - { - // - // Denormalized number -- renormalize it - // - - while (!(m & 0x00000400)) - { - m <<= 1; - e -= 1; - } - - e += 1; - m &= ~0x00000400; - } - } - else if (e == 31) - { - if (m == 0) - { - // - // Positive or negative infinity - // - - return (s << 31) | 0x7f800000; - } - else - { - // - // Nan -- preserve sign and significand bits - // - - return (s << 31) | 0x7f800000 | (m << 13); - } - } - - // - // Normalized number - // - - e = e + (127 - 15); - m = m << 13; - - // - // Assemble s, e and m. - // - - return (s << 31) | (e << 23) | m; -} #endif //NOINLINE #ifdef _cplusplus diff --git a/DevIL/src-IL/src/il_endian.c b/DevIL/src-IL/src/il_endian.c index 82860f16..60a42f19 100644 --- a/DevIL/src-IL/src/il_endian.c +++ b/DevIL/src-IL/src/il_endian.c @@ -14,6 +14,274 @@ #include "il_endian.h" +void iSwapUShort(ILushort *s) { + #ifdef USE_WIN32_ASM + __asm { + mov ebx, s + mov al, [ebx+1] + mov ah, [ebx ] + mov [ebx], ax + } + #else + #ifdef GCC_X86_ASM + asm("ror $8,%0" + : "=r" (*s) + : "0" (*s)); + #else + *s = ((*s)>>8) | ((*s)<<8); + #endif //GCC_X86_ASM + #endif //USE_WIN32_ASM +} + +void iSwapShort(ILshort *s) { + iSwapUShort((ILushort*)s); +} + +void iSwapUInt(ILuint *i) { + #ifdef USE_WIN32_ASM + __asm { + mov ebx, i + mov eax, [ebx] + bswap eax + mov [ebx], eax + } + #else + #ifdef GCC_X86_ASM + asm("bswap %0;" + : "+r" (*i)); + #else + *i = ((*i)>>24) | (((*i)>>8) & 0xff00) | (((*i)<<8) & 0xff0000) | ((*i)<<24); + #endif //GCC_X86_ASM + #endif //USE_WIN32_ASM +} + +void iSwapInt(ILint *i) { + iSwapUInt((ILuint*)i); +} + +void iSwapFloat(ILfloat *f) { + iSwapUInt((ILuint*)f); +} + +void iSwapDouble(ILdouble *d) { + #ifdef GCC_X86_ASM + int *t = (int*)d; + asm("bswap %2 \n" + "bswap %3 \n" + "movl %2,%1 \n" + "movl %3,%0 \n" + : "=g" (t[0]), "=g" (t[1]) + : "r" (t[0]), "r" (t[1])); + #else + ILubyte t,*b = (ILubyte*)d; + #define dswap(x,y) t=b[x];b[x]=b[y];b[y]=b[x]; + dswap(0,7); + dswap(1,6); + dswap(2,5); + dswap(3,4); + #undef dswap + #endif +} + + +ILushort GetLittleUShort() { + ILushort s; + iread(&s, sizeof(ILushort), 1); +#ifdef __BIG_ENDIAN__ + iSwapUShort(&s); +#endif + return s; +} + +ILshort GetLittleShort() { + ILshort s; + iread(&s, sizeof(ILshort), 1); +#ifdef __BIG_ENDIAN__ + iSwapShort(&s); +#endif + return s; +} + +ILuint GetLittleUInt() { + ILuint i; + iread(&i, sizeof(ILuint), 1); +#ifdef __BIG_ENDIAN__ + iSwapUInt(&i); +#endif + return i; +} + +ILint GetLittleInt() { + ILint i; + iread(&i, sizeof(ILint), 1); +#ifdef __BIG_ENDIAN__ + iSwapInt(&i); +#endif + return i; +} + +ILfloat GetLittleFloat() { + ILfloat f; + iread(&f, sizeof(ILfloat), 1); +#ifdef __BIG_ENDIAN__ + iSwapFloat(&f); +#endif + return f; +} + +ILdouble GetLittleDouble() { + ILdouble d; + iread(&d, sizeof(ILdouble), 1); +#ifdef __BIG_ENDIAN__ + iSwapDouble(&d); +#endif + return d; +} + +ILushort GetBigUShort() { + ILushort s; + iread(&s, sizeof(ILushort), 1); +#ifdef __LITTLE_ENDIAN__ + iSwapUShort(&s); +#endif + return s; +} + +ILshort GetBigShort() { + ILshort s; + iread(&s, sizeof(ILshort), 1); +#ifdef __LITTLE_ENDIAN__ + iSwapShort(&s); +#endif + return s; +} + +ILuint GetBigUInt() { + ILuint i; + iread(&i, sizeof(ILuint), 1); +#ifdef __LITTLE_ENDIAN__ + iSwapUInt(&i); +#endif + return i; +} + +ILint GetBigInt() { + ILint i; + iread(&i, sizeof(ILint), 1); +#ifdef __LITTLE_ENDIAN__ + iSwapInt(&i); +#endif + return i; +} + +ILfloat GetBigFloat() { + ILfloat f; + iread(&f, sizeof(ILfloat), 1); +#ifdef __LITTLE_ENDIAN__ + iSwapFloat(&f); +#endif + return f; +} + +ILdouble GetBigDouble() { + ILdouble d; + iread(&d, sizeof(ILdouble), 1); +#ifdef __LITTLE_ENDIAN__ + iSwapDouble(&d); +#endif + return d; +} + +ILubyte SaveLittleUShort(ILushort s) { +#ifdef __BIG_ENDIAN__ + iSwapUShort(&s); +#endif + return iwrite(&s, sizeof(ILushort), 1); +} + +ILubyte SaveLittleShort(ILshort s) { +#ifdef __BIG_ENDIAN__ + iSwapShort(&s); +#endif + return iwrite(&s, sizeof(ILshort), 1); +} + +ILubyte SaveLittleUInt(ILuint i) { +#ifdef __BIG_ENDIAN__ + iSwapUInt(&i); +#endif + return iwrite(&i, sizeof(ILuint), 1); +} + +ILubyte SaveLittleInt(ILint i) { +#ifdef __BIG_ENDIAN__ + iSwapInt(&i); +#endif + return iwrite(&i, sizeof(ILint), 1); +} + +ILubyte SaveLittleFloat(ILfloat f) { +#ifdef __BIG_ENDIAN__ + iSwapFloat(&f); +#endif + return iwrite(&f, sizeof(ILfloat), 1); +} + +ILubyte SaveLittleDouble(ILdouble d) { +#ifdef __BIG_ENDIAN__ + iSwapDouble(&d); +#endif + return iwrite(&d, sizeof(ILdouble), 1); +} + + +ILubyte SaveBigUShort(ILushort s) { +#ifdef __LITTLE_ENDIAN__ + iSwapUShort(&s); +#endif + return iwrite(&s, sizeof(ILushort), 1); +} + + +ILubyte SaveBigShort(ILshort s) { +#ifdef __LITTLE_ENDIAN__ + iSwapShort(&s); +#endif + return iwrite(&s, sizeof(ILshort), 1); +} + + +ILubyte SaveBigUInt(ILuint i) { +#ifdef __LITTLE_ENDIAN__ + iSwapUInt(&i); +#endif + return iwrite(&i, sizeof(ILuint), 1); +} + + +ILubyte SaveBigInt(ILint i) { +#ifdef __LITTLE_ENDIAN__ + iSwapInt(&i); +#endif + return iwrite(&i, sizeof(ILint), 1); +} + + +ILubyte SaveBigFloat(ILfloat f) { +#ifdef __LITTLE_ENDIAN__ + iSwapFloat(&f); +#endif + return iwrite(&f, sizeof(ILfloat), 1); +} + + +ILubyte SaveBigDouble(ILdouble d) { +#ifdef __LITTLE_ENDIAN__ + iSwapDouble(&d); +#endif + return iwrite(&d, sizeof(ILdouble), 1); +} + void EndianSwapData(void *_Image) { ILuint i; diff --git a/DevIL/src-IL/src/il_manip.c b/DevIL/src-IL/src/il_manip.c index c94b12c5..edd9c955 100644 --- a/DevIL/src-IL/src/il_manip.c +++ b/DevIL/src-IL/src/il_manip.c @@ -12,6 +12,212 @@ #include "il_internal.h" +ILfloat /*ILAPIENTRY*/ ilFloatToHalfOverflow() { + ILfloat f = 1e10; + ILint j; + for (j = 0; j < 10; j++) + f *= f; // this will overflow before + // the for loop terminates + return f; +} + +//----------------------------------------------------- +// Float-to-half conversion -- general case, including +// zeroes, denormalized numbers and exponent overflows. +//----------------------------------------------------- +ILushort ILAPIENTRY ilFloatToHalf(ILuint i) { + // + // Our floating point number, f, is represented by the bit + // pattern in integer i. Disassemble that bit pattern into + // the sign, s, the exponent, e, and the significand, m. + // Shift s into the position where it will go in in the + // resulting half number. + // Adjust e, accounting for the different exponent bias + // of float and half (127 versus 15). + // + + register int s = (i >> 16) & 0x00008000; + register int e = ((i >> 23) & 0x000000ff) - (127 - 15); + register int m = i & 0x007fffff; + + // + // Now reassemble s, e and m into a half: + // + + if (e <= 0) + { + if (e < -10) + { + // + // E is less than -10. The absolute value of f is + // less than HALF_MIN (f may be a small normalized + // float, a denormalized float or a zero). + // + // We convert f to a half zero. + // + + return 0; + } + + // + // E is between -10 and 0. F is a normalized float, + // whose magnitude is less than HALF_NRM_MIN. + // + // We convert f to a denormalized half. + // + + m = (m | 0x00800000) >> (1 - e); + + // + // Round to nearest, round "0.5" up. + // + // Rounding may cause the significand to overflow and make + // our number normalized. Because of the way a half's bits + // are laid out, we don't have to treat this case separately; + // the code below will handle it correctly. + // + + if (m & 0x00001000) + m += 0x00002000; + + // + // Assemble the half from s, e (zero) and m. + // + + return s | (m >> 13); + } + else if (e == 0xff - (127 - 15)) + { + if (m == 0) + { + // + // F is an infinity; convert f to a half + // infinity with the same sign as f. + // + + return s | 0x7c00; + } + else + { + // + // F is a NAN; we produce a half NAN that preserves + // the sign bit and the 10 leftmost bits of the + // significand of f, with one exception: If the 10 + // leftmost bits are all zero, the NAN would turn + // into an infinity, so we have to set at least one + // bit in the significand. + // + + m >>= 13; + return s | 0x7c00 | m | (m == 0); + } + } + else + { + // + // E is greater than zero. F is a normalized float. + // We try to convert f to a normalized half. + // + + // + // Round to nearest, round "0.5" up + // + + if (m & 0x00001000) + { + m += 0x00002000; + + if (m & 0x00800000) + { + m = 0; // overflow in significand, + e += 1; // adjust exponent + } + } + + // + // Handle exponent overflow + // + + if (e > 30) + { + ilFloatToHalfOverflow(); // Cause a hardware floating point overflow; + return s | 0x7c00; // if this returns, the half becomes an + } // infinity with the same sign as f. + + // + // Assemble the half from s, e and m. + // + + return s | (e << 10) | (m >> 13); + } +} + +// Taken from OpenEXR +INLINE ILuint ILAPIENTRY ilHalfToFloat (ILushort y) { + + int s = (y >> 15) & 0x00000001; + int e = (y >> 10) & 0x0000001f; + int m = y & 0x000003ff; + + if (e == 0) + { + if (m == 0) + { + // + // Plus or minus zero + // + + return s << 31; + } + else + { + // + // Denormalized number -- renormalize it + // + + while (!(m & 0x00000400)) + { + m <<= 1; + e -= 1; + } + + e += 1; + m &= ~0x00000400; + } + } + else if (e == 31) + { + if (m == 0) + { + // + // Positive or negative infinity + // + + return (s << 31) | 0x7f800000; + } + else + { + // + // Nan -- preserve sign and significand bits + // + + return (s << 31) | 0x7f800000 | (m << 13); + } + } + + // + // Normalized number + // + + e = e + (127 - 15); + m = m << 13; + + // + // Assemble s, e and m. + // + + return (s << 31) | (e << 23) | m; +} ILAPI void ILAPIENTRY iFlipBuffer(ILubyte *buff, ILuint depth, ILuint line_size, ILuint line_num) { diff --git a/DevIL/src-ILU/ilur/ilur.c b/DevIL/src-ILU/ilur/ilur.c index 9663e3b4..a366bbe4 100644 --- a/DevIL/src-ILU/ilur/ilur.c +++ b/DevIL/src-ILU/ilur/ilur.c @@ -1,6 +1,6 @@ #include <string.h> #include <stdio.h> -#include <malloc.h> +#include <stdlib.h> #include <IL/il.h> #include <IL/ilu.h> diff --git a/DevIL/src-ILU/include/ilu_internal.h b/DevIL/src-ILU/include/ilu_internal.h index 61980e6e..239da929 100644 --- a/DevIL/src-ILU/include/ilu_internal.h +++ b/DevIL/src-ILU/include/ilu_internal.h @@ -77,18 +77,11 @@ ILfloat ilSin(ILfloat Angle); ILint ilRound(ILfloat Num); #ifndef NOINLINE -INLINE ILfloat ilCos(ILfloat Angle) { - return (ILfloat)(cos(Angle * IL_DEGCONV)); -} - -INLINE ILfloat ilSin(ILfloat Angle) { - return (ILfloat)(sin(Angle * IL_DEGCONV)); -} +ILfloat ilCos(ILfloat Angle); +ILfloat ilSin(ILfloat Angle); -INLINE ILint ilRound(ILfloat Num) { - return (ILint)(Num + 0.5); // this is truncating in away-from-0, not rounding -} +ILint ilRound(ILfloat Num); #endif diff --git a/DevIL/src-ILU/src/ilu_internal.c b/DevIL/src-ILU/src/ilu_internal.c index d1ef2380..20036d7f 100644 --- a/DevIL/src-ILU/src/ilu_internal.c +++ b/DevIL/src-ILU/src/ilu_internal.c @@ -7,3 +7,15 @@ const ILdouble IL_PI = 3.1415926535897932384626; const ILdouble IL_DEGCONV = 0.0174532925199432957692; ILimage *iluCurImage = NULL; +ILfloat ilCos(ILfloat Angle) { + return (ILfloat)(cos(Angle * IL_DEGCONV)); +} + +ILfloat ilSin(ILfloat Angle) { + return (ILfloat)(sin(Angle * IL_DEGCONV)); +} + + +ILint ilRound(ILfloat Num) { + return (ILint)(Num + 0.5); // this is truncating in away-from-0, not rounding +} |