35 #ifndef IE_CORE_BYTEORDER_H
36 #define IE_CORE_BYTEORDER_H
40 #include "boost/static_assert.hpp"
42 #include "OpenEXR/ImfInt64.h"
47 #if defined(__PPC__) || defined(__ppc__) || defined(__POWERPC__) || defined(__powerpc__)
48 #define IE_CORE_BIG_ENDIAN
50 #define IE_CORE_LITTLE_ENDIAN
57 #ifdef IE_CORE_LITTLE_ENDIAN
68 #ifdef IE_CORE_BIG_ENDIAN
80 BOOST_STATIC_ASSERT(
sizeof(T)==0);
84 inline char reverseBytes<char>(
const char &x )
90 inline unsigned char reverseBytes<unsigned char>(
const unsigned char &x )
96 inline int16_t reverseBytes<int16_t>(
const int16_t &x )
98 return ((x & 255) << 8) |
103 inline uint16_t reverseBytes<uint16_t>(
const uint16_t &x )
105 return ((x & 255) << 8) |
110 inline int32_t reverseBytes<int32_t>(
const int32_t &x )
112 return ((x & 255) << 24) |
113 (((x >> 8) & 255 ) << 16 ) |
114 (((x >> 16) & 255 ) << 8 ) |
119 inline uint32_t reverseBytes<uint32_t>(
const uint32_t &x )
121 return ((x & 255) << 24) |
122 (((x >> 8) & 255 ) << 16 ) |
123 (((x >> 16) & 255 ) << 8 ) |
128 inline float reverseBytes<float>(
const float &x )
130 BOOST_STATIC_ASSERT(
sizeof(uint32_t) ==
sizeof(
float) );
141 inline Imf::Int64 reverseBytes<Imf::Int64>(
const Imf::Int64 &x )
143 return ((x & 255) << 56) |
144 (((x >> 8) & 255) << 48) |
145 (((x >> 16) & 255 ) << 40 ) |
146 (((x >> 24) & 255 ) << 32 ) |
147 (((x >> 32) & 255 ) << 24 ) |
148 (((x >> 40) & 255 ) << 16 ) |
149 (((x >> 48) & 255 ) << 8 ) |
154 inline double reverseBytes<double>(
const double &x )
156 BOOST_STATIC_ASSERT(
sizeof(Imf::Int64) ==
sizeof(
double) );
162 xx.i = reverseBytes<Imf::Int64>(xx.i);
200 #endif // IE_CORE_BYTEORDER_H
bool littleEndian()
Definition: ByteOrder.h:55
T asLittleEndian(const T &x)
Definition: ByteOrder.h:170
T asBigEndian(const T &x)
Definition: ByteOrder.h:186
T reverseBytes(const T &x)
Returns a copy of x with reversed byte order.
Definition: ByteOrder.h:77
bool bigEndian()
Definition: ByteOrder.h:66
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43