Moved the union to inside the functions
This commit is contained in:
parent
2e1ec8e44c
commit
30dedbc3f4
|
|
@ -5384,18 +5384,17 @@ int GetPixelDataSize(int width, int height, int format)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Definition
|
// Module specific Functions Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
union floatUnsignedUnion {
|
|
||||||
float fm;
|
|
||||||
unsigned int ui;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Convert half-float (stored as unsigned short) to float
|
// Convert half-float (stored as unsigned short) to float
|
||||||
// REF: https://stackoverflow.com/questions/1659440/32-bit-to-16-bit-floating-point-conversion/60047308#60047308
|
// REF: https://stackoverflow.com/questions/1659440/32-bit-to-16-bit-floating-point-conversion/60047308#60047308
|
||||||
static float HalfToFloat(unsigned short x)
|
static float HalfToFloat(unsigned short x)
|
||||||
{
|
{
|
||||||
float result = 0.0f;
|
float result = 0.0f;
|
||||||
|
|
||||||
union floatUnsignedUnion uni;
|
union
|
||||||
|
{
|
||||||
|
float fm;
|
||||||
|
unsigned int ui;
|
||||||
|
} uni;
|
||||||
|
|
||||||
const unsigned int e = (x & 0x7C00) >> 10; // Exponent
|
const unsigned int e = (x & 0x7C00) >> 10; // Exponent
|
||||||
const unsigned int m = (x & 0x03FF) << 13; // Mantissa
|
const unsigned int m = (x & 0x03FF) << 13; // Mantissa
|
||||||
|
|
@ -5413,7 +5412,11 @@ static unsigned short FloatToHalf(float x)
|
||||||
{
|
{
|
||||||
unsigned short result = 0;
|
unsigned short result = 0;
|
||||||
|
|
||||||
union floatUnsignedUnion uni;
|
union
|
||||||
|
{
|
||||||
|
float fm;
|
||||||
|
unsigned int ui;
|
||||||
|
} uni;
|
||||||
uni.fm = x;
|
uni.fm = x;
|
||||||
|
|
||||||
const unsigned int b = uni.ui + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa
|
const unsigned int b = uni.ui + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user