diff --git a/source/common.c b/source/common.c index 4399af1..5b04423 100644 --- a/source/common.c +++ b/source/common.c @@ -569,64 +569,6 @@ static float FloatNoSwap(float f) return f; } -int16_t ReadBigShort(byte *bytes) -{ - int16_t v; - v = bytes[1]; - v |= bytes[0] << 8; - return v; -} - -int32_t ReadBigLong(byte *bytes) -{ - int32_t v; - v = bytes[3]; - v |= bytes[2] << 8; - v |= bytes[1] << 16; - v |= bytes[0] << 24; - return v; -} - -float ReadBigFloat(byte *bytes) -{ - union - { - float f; - uint32_t i; - } data; - data.i = ReadBigLong(bytes); - return data.f; -} - -int16_t ReadLittleShort(byte *bytes) -{ - int16_t v; - v = bytes[0]; - v |= bytes[1] << 8; - return v; -} - -int32_t ReadLittleLong(byte *bytes) -{ - int32_t v; - v = bytes[0]; - v |= bytes[1] << 8; - v |= bytes[2] << 16; - v |= bytes[3] << 24; - return v; -} - -float ReadLittleFloat(byte *bytes) -{ - union - { - float f; - uint32_t i; - } data; - data.i = ReadLittleLong(bytes); - return data.f; -} - /* ============================================================================== diff --git a/source/common.h b/source/common.h index d9486ba..3123c02 100644 --- a/source/common.h +++ b/source/common.h @@ -74,13 +74,63 @@ extern int16_t (*LittleShort)(int16_t l); extern int32_t (*LittleLong)(int32_t l); extern float (*LittleFloat)(float l); -int16_t ReadBigShort(byte *bytes); -int32_t ReadBigLong(byte *bytes); -float ReadBigFloat(byte *bytes); +static inline int16_t ReadBigShort(byte const *bytes) +{ + int16_t v; + v = bytes[1]; + v |= bytes[0] << 8; + return v; +} -int16_t ReadLittleShort(byte *bytes); -int32_t ReadLittleLong(byte *bytes); -float ReadLittleFloat(byte *bytes); +static inline int32_t ReadBigLong(byte const *bytes) +{ + int32_t v; + v = bytes[3]; + v |= bytes[2] << 8; + v |= bytes[1] << 16; + v |= bytes[0] << 24; + return v; +} + +static inline float ReadBigFloat(byte const *bytes) +{ + union + { + float f; + uint32_t i; + } data; + data.i = ReadBigLong(bytes); + return data.f; +} + +static inline int16_t ReadLittleShort(byte const *bytes) +{ + int16_t v; + v = bytes[0]; + v |= bytes[1] << 8; + return v; +} + +static inline int32_t ReadLittleLong(byte const *bytes) +{ + int32_t v; + v = bytes[0]; + v |= bytes[1] << 8; + v |= bytes[2] << 16; + v |= bytes[3] << 24; + return v; +} + +static inline float ReadLittleFloat(byte const *bytes) +{ + union + { + float f; + uint32_t i; + } data; + data.i = ReadLittleLong(bytes); + return data.f; +} //============================================================================