35 #define __has_builtin(x) 0
54#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_COMP_VER >= 1310
56#elif (OGRE_COMPILER == OGRE_COMPILER_CLANG && __has_builtin(__builtin_bswap16)) || (OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 480)
59 return ((
arg << 8) & 0xFF00) | ((
arg >> 8) & 0x00FF);
66#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_COMP_VER >= 1310
68#elif (OGRE_COMPILER == OGRE_COMPILER_CLANG && __has_builtin(__builtin_bswap32)) || (OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 430)
71 return ((
arg & 0x000000FF) << 24) | ((
arg & 0x0000FF00) << 8) | ((
arg >> 8) & 0x0000FF00) | ((
arg >> 24) & 0x000000FF);
78#if OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_COMP_VER >= 1310
80#elif (OGRE_COMPILER == OGRE_COMPILER_CLANG && __has_builtin(__builtin_bswap64)) || (OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_COMP_VER >= 430)
99 for(
char *
p0 = (
char*)pData, *
p1 =
p0 + size - 1;
p0 <
p1; ++
p0, --
p1)
113 for(
char *
p0 = (
char*)pData +
c * size, *
p1 =
p0 + size - 1;
p0 <
p1; ++
p0, --
p1)
126 unsigned int result = 0;
154 return (
n & (
n-1)) == 0;
165 unsigned int result = 0;
166 while ((
mask & 1) == 0) {
178 template<
typename SrcT,
typename DestT>
217 else if(value == (
static_cast<unsigned int>(1)<<
n)-1)
219 else value = value*(1<<
p)/((1<<
n)-1);
230 if(value <= 0.0f)
return 0;
231 else if (value >= 1.0f)
return (1<<
bits)-1;
232 else return (
unsigned int)(value * (1<<
bits));
240 return (
float)value/(
float)((1<<
bits)-1);
246 static inline void intWrite(
void *
dest,
const int n,
const unsigned int value)
256#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
274 static inline unsigned int intRead(
const void *src,
int n) {
277 return ((
const uint8*)src)[0];
279 return ((
const uint16*)src)[0];
281#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
291 return ((
const uint32*)src)[0];
309 register int s = (
i >> 16) & 0x00008000;
310 register int e = ((
i >> 23) & 0x000000ff) - (127 - 15);
311 register int m =
i & 0x007fffff;
319 m = (m | 0x00800000) >> (1 -
e);
321 return static_cast<uint16>(
s | (m >> 13));
323 else if (
e == 0xff - (127 - 15))
327 return static_cast<uint16>(
s | 0x7c00);
332 return static_cast<uint16>(
s | 0x7c00 | m | (m == 0));
339 return static_cast<uint16>(
s | 0x7c00);
342 return static_cast<uint16>(
s | (
e << 10) | (m >> 13));
361 register int s = (y >> 15) & 0x00000001;
362 register int e = (y >> 10) & 0x0000001f;
363 register int m = y & 0x000003ff;
373 while (!(m & 0x00000400))
387 return (
s << 31) | 0x7f800000;
391 return (
s << 31) | 0x7f800000 | (m << 13);
398 return (
s << 31) | (
e << 23) | m;
Class for manipulating bit patterns.
static void bswapBuffer(void *pData, size_t size)
Reverses byte order of buffer.
static float fixedToFloat(unsigned value, unsigned int bits)
Fixed point to float.
static FORCEINLINE unsigned int getBitShift(T mask)
Returns the number of bits a pattern must be shifted right by to remove right-hand zeros.
static DestT convertBitPattern(SrcT srcValue, SrcT srcBitMask, DestT destBitMask)
Takes a value with a given src bit mask, and produces another value with a desired bit mask.
static uint32 halfToFloatI(uint16 y)
Converts a half in uint16 format to a float in uint32 format.
static FORCEINLINE uint16 bswap16(uint16 arg)
Returns value with reversed bytes order.
static FORCEINLINE uint64 bswap64(uint64 arg)
Returns value with reversed bytes order.
static uint16 floatToHalf(float i)
Convert a float32 to a float16 (NV_half_float) Courtesy of OpenEXR.
static FORCEINLINE unsigned int mostSignificantBitSet(unsigned int value)
Returns the most significant bit set in a value.
static unsigned int fixedToFixed(uint32 value, unsigned int n, unsigned int p)
Convert N bit colour channel value to P bits.
static FORCEINLINE uint32 bswap32(uint32 arg)
Returns value with reversed bytes order.
static float halfToFloat(uint16 y)
Convert a float16 (NV_half_float) to a float32 Courtesy of OpenEXR.
static FORCEINLINE bool isPO2(T n)
Determines whether the number is power-of-two or not.
static unsigned int intRead(const void *src, int n)
Read a n*8 bits integer value to memory in native endian.
static void bswapChunks(void *pData, size_t size, size_t count)
Reverses byte order of chunks in buffer, where 'size' is size of one chunk.
static unsigned int floatToFixed(const float value, const unsigned int bits)
Convert floating point colour channel value between 0.0 and 1.0 (otherwise clamped) to integer of a c...
static uint16 floatToHalfI(uint32 i)
Converts float in uint32 format to a a half in uint16 format.
static FORCEINLINE uint32 firstPO2From(uint32 n)
Returns the closest power-of-two number greater or equal to value.
static void intWrite(void *dest, const int n, const unsigned int value)
Write a n*8 bits integer value to memory in native endian.
Reference-counted shared pointer, used for objects where implicit destruction is required.