1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-23 18:17:46 +00:00
sapphire/deps/datReader/conv.cpp

37 lines
742 B
C++
Raw Normal View History

#include "conv.h"
#include <cstring>
namespace xiv::utils::conv
{
float half2float( const uint16_t i_value )
{
uint32_t t1;
uint32_t t2;
uint32_t t3;
2023-04-23 15:30:18 +02:00
t1 = i_value & 0x7fff; // Non-sign bits
t2 = i_value & 0x8000; // Sign bit
t3 = i_value & 0x7c00; // Exponent
t1 <<= 13; // Align mantissa on MSB
t2 <<= 16; // Shift sign bit into position
2023-04-23 15:30:18 +02:00
t1 += 0x38000000; // Adjust bias
2023-04-23 15:30:18 +02:00
t1 = ( t3 == 0 ? 0 : t1 );// Denormals-as-zero
2023-04-23 15:30:18 +02:00
t1 |= t2; // Re-insert sign bit
2023-04-23 15:30:18 +02:00
float result;
memcpy( &result, &t1, sizeof( float ) );
2023-04-23 15:30:18 +02:00
return result;
}
float ubyte2float( const uint8_t i_value )
{
return i_value / 255.0f;
}
}