11 #ifndef __COVISE_BYTESWAP_INCLUDED
12 #define __COVISE_BYTESWAP_INCLUDED
19 inline bool machineIsLittleEndian()
22 return (1 == (
int)*((
char *)&x));
25 inline bool machineIsBigEndian()
28 return (1 != (
int)*((
char *)&x));
31 inline void byteSwap(uint32_t &
value)
33 value = ((value & 0x000000ff) << 24) | ((value & 0x0000ff00) << 8) | ((value & 0x00ff0000) >> 8) | ((value & 0xff000000) >> 24);
36 inline void byteSwap(int32_t &
value)
38 int uval = (uint32_t)value;
39 value = ((uval & 0x000000ff) << 24) | ((uval & 0x0000ff00) << 8) | ((uval & 0x00ff0000) >> 8) | ((uval & 0xff000000) >> 24);
42 inline void byteSwap(uint32_t *
values,
int no)
44 for (
int i = 0; i < no; i++, values++)
45 *values = ((*values & 0x000000ff) << 24) | ((*values & 0x0000ff00) << 8) | ((*values & 0x00ff0000) >> 8) | ((*values & 0xff000000) >> 24);
48 inline void byteSwap(int32_t *values,
int no)
50 byteSwap((uint32_t *)values, no);
53 inline void byteSwap(uint64_t &
value)
56 #if defined(_WIN32) && !defined(__MINGW32__)
57 ((value & 0x00000000000000ff) << 56) | ((value & 0x000000000000ff00) << 40) | ((value & 0x0000000000ff0000) << 24) | ((value & 0x00000000ff000000) << 8) | ((value & 0x000000ff00000000) >> 8) | ((value & 0x0000ff0000000000) >> 24) | ((value & 0x00ff000000000000) >> 40) | ((value & 0xff00000000000000) >> 56);
59 ((value & 0x00000000000000ffll) << 56) | ((value & 0x000000000000ff00ll) << 40) | ((value & 0x0000000000ff0000ll) << 24) | ((value & 0x00000000ff000000ll) << 8) | ((value & 0x000000ff00000000ll) >> 8) | ((value & 0x0000ff0000000000ll) >> 24) | ((value & 0x00ff000000000000ll) >> 40) | ((value & 0xff00000000000000ll) >> 56);
63 inline void byteSwap(int64_t &
value)
66 #if defined(_WIN32) && !defined(__MINGW32__)
67 ((value & 0x00000000000000ff) << 56) | ((value & 0x000000000000ff00) << 40) | ((value & 0x0000000000ff0000) << 24) | ((value & 0x00000000ff000000) << 8) | ((value & 0x000000ff00000000) >> 8) | ((value & 0x0000ff0000000000) >> 24) | ((value & 0x00ff000000000000) >> 40) | ((value & 0xff00000000000000) >> 56);
69 ((value & 0x00000000000000ffll) << 56) | ((value & 0x000000000000ff00ll) << 40) | ((value & 0x0000000000ff0000ll) << 24) | ((value & 0x00000000ff000000ll) << 8) | ((value & 0x000000ff00000000ll) >> 8) | ((value & 0x0000ff0000000000ll) >> 24) | ((value & 0x00ff000000000000ll) >> 40) | ((value & 0xff00000000000000ll) >> 56);
73 inline void byteSwap(uint64_t *values,
int no)
76 for (i = 0; i < no; i++, values++)
79 #if defined(_WIN32) && !defined(__MINGW32__)
80 ((*values & 0x00000000000000ff) << 56) | ((*values & 0x000000000000ff00) << 40) | ((*values & 0x0000000000ff0000) << 24) | ((*values & 0x00000000ff000000) << 8) | ((*values & 0x000000ff00000000) >> 8) | ((*values & 0x0000ff0000000000) >> 24) | ((*values & 0x00ff000000000000) >> 40) | ((*values & 0xff00000000000000) >> 56);
82 ((*values & 0x00000000000000ffll) << 56) | ((*values & 0x000000000000ff00ll) << 40) | ((*values & 0x0000000000ff0000ll) << 24) | ((*values & 0x00000000ff000000ll) << 8) | ((*values & 0x000000ff00000000ll) >> 8) | ((*values & 0x0000ff0000000000ll) >> 24) | ((*values & 0x00ff000000000000ll) >> 40) | ((*values & 0xff00000000000000ll) >> 56);
89 #define double2ll(value) (*(uint64_t *)(&value))
90 inline void byteSwap(
double &
value)
94 #if defined(_WIN32) && !defined(__MINGW32__)
95 ((
double2ll(value) & 0x00000000000000ff) << 56) | ((
double2ll(value) & 0x000000000000ff00) << 40) | ((
double2ll(value) & 0x0000000000ff0000) << 24) | ((
double2ll(value) & 0x00000000ff000000) << 8) | ((
double2ll(value) & 0x000000ff00000000) >> 8) | ((
double2ll(value) & 0x0000ff0000000000) >> 24) | ((
double2ll(value) & 0x00ff000000000000) >> 40) | ((
double2ll(value) & 0xff00000000000000) >> 56);
97 ((
double2ll(value) & 0x00000000000000ffll) << 56) | ((
double2ll(value) & 0x000000000000ff00ll) << 40) | ((
double2ll(value) & 0x0000000000ff0000ll) << 24) | ((
double2ll(value) & 0x00000000ff000000ll) << 8) | ((
double2ll(value) & 0x000000ff00000000ll) >> 8) | ((
double2ll(value) & 0x0000ff0000000000ll) >> 24) | ((
double2ll(value) & 0x00ff000000000000ll) >> 40) | ((
double2ll(value) & 0xff00000000000000ll) >> 56);
101 inline void byteSwap(
double *values,
int no)
103 for (
int i = 0; i < no; i++)
109 #define float2int(value) (*(uint32_t *)(&value))
110 inline void byteSwap(
float &
value)
116 inline void byteSwap(
float *values,
int no)
118 uint32_t *intValues = (uint32_t *)values;
119 for (
int i = 0; i < no; i++, intValues++)
120 *intValues = ((*intValues & 0x000000ff) << 24) | ((*intValues & 0x0000ff00) << 8) | ((*intValues & 0x00ff0000) >> 8) | ((*intValues & 0xff000000) >> 24);
123 inline void byteSwap(uint16_t &
value)
125 value = ((value & 0x00ff) << 8) | ((value & 0xff00) >> 8);
128 inline void byteSwap(uint16_t *values,
int no)
130 for (
int i = 0; i < no; i++, values++)
131 *values = ((*values & 0x00ff) << 8) | ((*values & 0xff00) >> 8);
134 inline void byteSwap(int16_t &
value)
136 uint16_t uval = (uint16_t)value;
137 value = ((uval & 0x00ff) << 8) | ((uval & 0xff00) >> 8);
140 inline void byteSwap(int16_t *values,
int no)
142 byteSwap((uint16_t *)values, no);
#define double2ll(value)
Definition: byteswap.h:89
#define float2int(value)
Definition: byteswap.h:109
GLsizei const GLfloat * value
Definition: khronos-glext.h:6760
GLboolean GLenum GLenum GLvoid * values
Definition: khronos-glext.h:6369
GLint GLint GLint GLint GLint x
Definition: khronos-glext.h:6346