[Liblas-commits] laszip: more efficient big endian handling
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Jan 7 12:46:04 EST 2011
details: http://hg.liblas.orglaszip/rev/7ff2569cc64a
changeset: 124:7ff2569cc64a
user: isenburg
date: Fri Jan 07 09:45:52 2011 -0800
description:
more efficient big endian handling
diffstat:
src/mydefs.hpp | 29 ++++++++++++++++++++---------
1 files changed, 20 insertions(+), 9 deletions(-)
diffs (74 lines):
diff -r 7ae269f43dde -r 7ff2569cc64a src/mydefs.hpp
--- a/src/mydefs.hpp Fri Jan 07 09:42:34 2011 -0800
+++ b/src/mydefs.hpp Fri Jan 07 09:45:52 2011 -0800
@@ -27,7 +27,7 @@
typedef unsigned short U16;
typedef unsigned char U8;
-#if defined(WIN32) // 64 byte integer under Windows
+#if defined(_WIN32) // 64 byte integer under Windows
typedef unsigned __int64 U64;
typedef __int64 I64;
#else // 64 byte integer elsewhere ...
@@ -38,7 +38,11 @@
typedef float F32;
typedef double F64;
+#if defined(_WIN32)
+typedef int BOOL;
+#else
typedef bool BOOL;
+#endif
typedef union U32F32 { U32 u32; F32 f32; } U32F32;
typedef union U64F64 { U64 u64; F64 f64; } U64F64;
@@ -84,12 +88,19 @@
inline BOOL IS_LITTLE_ENDIAN()
{
- U32 i = 1;
- if (*((U8*)&i) == 1)
- return TRUE;
- else
- return FALSE;
+ const U32 i = 1;
+ return (*((U8*)&i) == 1);
}
+
+#define ENDIANSWAP16(n) \
+ ( ((((U16) n) << 8) & 0xFF00) | \
+ ((((U16) n) >> 8) & 0x00FF) )
+
+#define ENDIANSWAP32(n) \
+ ( ((((U32) n) << 24) & 0xFF000000) | \
+ ((((U32) n) << 8) & 0x00FF0000) | \
+ ((((U32) n) >> 8) & 0x0000FF00) | \
+ ((((U32) n) >> 24) & 0x000000FF) )
inline void ENDIAN_SWAP_16(U8* field)
{
@@ -126,13 +137,13 @@
field[4] = help;
}
-inline void ENDIAN_SWAP_16(U8* from, U8* to)
+inline void ENDIAN_SWAP_16(const U8* from, U8* to)
{
to[0] = from[1];
to[1] = from[0];
}
-inline void ENDIAN_SWAP_32(U8* from, U8* to)
+inline void ENDIAN_SWAP_32(const U8* from, U8* to)
{
to[0] = from[3];
to[1] = from[2];
@@ -140,7 +151,7 @@
to[3] = from[0];
}
-inline void ENDIAN_SWAP_64(U8* from, U8* to)
+inline void ENDIAN_SWAP_64(const U8* from, U8* to)
{
to[0] = from[7];
to[1] = from[6];
More information about the Liblas-commits
mailing list