mudbox::half_ Class Reference
#include <image.h>
List of all
members.
Detailed Description
Half precision (16 bit) float class. Supports fast conversion
between float and half precision.
Format is compatible with openEXRs half precision type. 1 sign
bit, 5 exponent bits (bias = 15), 10 fraction bits.
Constructor & Destructor Documentation
mudbox::half_::half_ |
( |
|
) |
[inline] |
|
mudbox::half_::half_ |
( |
float |
f |
) |
[inline] |
|
|
00043 {
00044 unsigned int x = *(unsigned int *)&f;
00045 unsigned int frac = (x >> 13) & 0x03ff;
00046 int exp = (int)((x >> 23) & 0xff) - 127;
00047
00048 m_bits = (x >> 16) & 0x8000;
00049
00050 if (exp > 16) {
00051 exp = 16;
00052 frac = 0x03ff;
00053 } else if (exp <= -15) {
00054 frac = 0;
00055 exp = -15;
00056 }
00057
00058 m_bits |= ((exp + 15) << 10) | frac;
00059 }
|
Member Function Documentation
mudbox::half_::operator
float |
( |
|
) |
const [inline] |
|
|
00065 {
00066 int exp = (m_bits >> 10) & 0x1f;
00067 unsigned int f = (m_bits & 0x8000) << 16;
00068 unsigned int frac = (m_bits & 0x03ff) << 13;
00069
00070 if (exp == 0x1f) {
00071 exp = 0xff - ExponentBiasDelta;
00072 } else if (exp == 0) {
00073 exp = -ExponentBiasDelta;
00074 }
00075
00076 f |= ((exp + ExponentBiasDelta) << 23) | frac;
00077 return *(float *)&f;
00078 }
|
half_&
mudbox::half_::operator= |
( |
float |
f |
) |
[inline] |
|
|
00081 {
00082 *this = half_ (f);
00083 return *this;
00084 }
|
mudbox::half_ mudbox::half_
mudbox::half_ mudbox::half_ mudbox::half_ mudbox::half_
mudbox::half_ mudbox::half_ mudbox::half_ mudbox::half_
mudbox::half_ mudbox::half_
mudbox::half_ mudbox::half_ mudbox::half_ mudbox::half_
mudbox::half_ mudbox::half_ mudbox::half_ mudbox::half_