[Liblas-commits] laszip: more efficient big endian handling
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Jan 7 12:42:49 EST 2011
details: http://hg.liblas.orglaszip/rev/7ae269f43dde
changeset: 123:7ae269f43dde
user: isenburg
date: Fri Jan 07 09:42:34 2011 -0800
description:
more efficient big endian handling
diffstat:
src/lasreaditemraw.hpp | 121 +++++++++++++++++++++++++++--------------
src/lasreadpoint.cpp | 22 +++++-
src/laswriteitemraw.hpp | 140 +++++++++++++++++++++++++++++------------------
src/laswritepoint.cpp | 20 +++++-
4 files changed, 199 insertions(+), 104 deletions(-)
diffs (truncated from 410 to 300 lines):
diff -r c544849de62f -r 7ae269f43dde src/lasreaditemraw.hpp
--- a/src/lasreaditemraw.hpp Fri Jan 07 09:24:25 2011 -0600
+++ b/src/lasreaditemraw.hpp Fri Jan 07 09:42:34 2011 -0800
@@ -50,76 +50,113 @@
#include <assert.h>
-class LASreadItemRaw_POINT10 : public LASreadItemRaw
-{
-public:
- LASreadItemRaw_POINT10(){};
- inline BOOL read(U8* item)
- {
- if (!instream->getBytes(item, 20)) return FALSE; // POINT10
- return TRUE;
- }
-};
-
-/*
-class LASreadItemRaw_POINT10 : public LASreadItemRaw
+class LASreadItemRaw_POINT10_LE : public LASreadItemRaw
+{
+public:
+ LASreadItemRaw_POINT10_LE(){};
+ inline BOOL read(U8* item)
+ {
+ return instream->getBytes(item, 20);
+ }
+};
+
+class LASreadItemRaw_POINT10_BE : public LASreadItemRaw
{
public:
- LASreadItemRaw_POINT10(){};
+ LASreadItemRaw_POINT10_BE(){};
inline BOOL read(U8* item)
{
- if (!instream->get32bitsLE(&(item[ 0]))) return FALSE; // x
- if (!instream->get32bitsLE(&(item[ 4]))) return FALSE; // y
- if (!instream->get32bitsLE(&(item[ 8]))) return FALSE; // z
- if (!instream->get16bitsLE(&(item[12]))) return FALSE; // intensity
- if (!instream->getBytes(&(item[14]), 4)) return FALSE; // bitfield
- // classification
- // scan_angle_rank
- // user_data
- if (!instream->get16bitsLE(&(item[18]))) return FALSE; // point_source_ID
+ if (!instream->getBytes(swapped, 20)) return FALSE;
+ ENDIAN_SWAP_32(&swapped[ 0], &item[ 0]); // x
+ ENDIAN_SWAP_32(&swapped[ 4], &item[ 4]); // y
+ ENDIAN_SWAP_32(&swapped[ 8], &item[ 8]); // z
+ ENDIAN_SWAP_16(&swapped[12], &item[12]); // intensity
+ *((U32*)&item[14]) = *((U32*)&swapped[14]); // bitfield, classification, scan_angle_rank, user_data
+ ENDIAN_SWAP_16(&swapped[18], &item[18]); // point_source_ID
return TRUE;
};
+private:
+ U8 swapped[20];
};
-*/
-
-class LASreadItemRaw_GPSTIME11 : public LASreadItemRaw
+
+class LASreadItemRaw_GPSTIME11_LE : public LASreadItemRaw
{
public:
- LASreadItemRaw_GPSTIME11(){};
+ LASreadItemRaw_GPSTIME11_LE(){};
inline BOOL read(U8* item)
{
- return instream->get64bitsLE(item); // GPSTIME
+ return instream->getBytes(item, 8);
};
};
-class LASreadItemRaw_RGB12 : public LASreadItemRaw
+class LASreadItemRaw_GPSTIME11_BE : public LASreadItemRaw
{
public:
- LASreadItemRaw_RGB12(){};
+ LASreadItemRaw_GPSTIME11_BE(){};
inline BOOL read(U8* item)
{
- if (!instream->get16bitsLE(&(item[0]))) return FALSE; // R
- if (!instream->get16bitsLE(&(item[2]))) return FALSE; // G
- if (!instream->get16bitsLE(&(item[4]))) return FALSE; // B
+ if (!instream->getBytes(swapped, 8)) return FALSE;
+ ENDIAN_SWAP_64(swapped, item);
return TRUE;
};
+private:
+ U8 swapped[8];
+};
+
+class LASreadItemRaw_RGB12_LE : public LASreadItemRaw
+{
+public:
+ LASreadItemRaw_RGB12_LE(){};
+ inline BOOL read(U8* item)
+ {
+ return instream->getBytes(item, 6);
+ };
};
-class LASreadItemRaw_WAVEPACKET13 : public LASreadItemRaw
+class LASreadItemRaw_RGB12_BE : public LASreadItemRaw
{
public:
- LASreadItemRaw_WAVEPACKET13(){}
+ LASreadItemRaw_RGB12_BE(){};
inline BOOL read(U8* item)
{
- if (!instream->getBytes(&(item[0]),1)) return FALSE; // wavepacket descriptor index
- if (!instream->get64bitsLE(&(item[ 1]))) return FALSE; // byte offset to waveform data
- if (!instream->get32bitsLE(&(item[ 9]))) return FALSE; // waveform packet size in bytes
- if (!instream->get32bitsLE(&(item[13]))) return FALSE; // return point waveform location
- if (!instream->get32bitsLE(&(item[17]))) return FALSE; // X(t)
- if (!instream->get32bitsLE(&(item[21]))) return FALSE; // Y(t)
- if (!instream->get32bitsLE(&(item[25]))) return FALSE; // Z(t)
+ if (!instream->getBytes(swapped, 6)) return FALSE;
+ ENDIAN_SWAP_32(&swapped[ 0], &item[ 0]); // R
+ ENDIAN_SWAP_32(&swapped[ 2], &item[ 2]); // G
+ ENDIAN_SWAP_32(&swapped[ 4], &item[ 4]); // B
return TRUE;
};
+private:
+ U8 swapped[6];
+};
+
+class LASreadItemRaw_WAVEPACKET13_LE : public LASreadItemRaw
+{
+public:
+ LASreadItemRaw_WAVEPACKET13_LE(){}
+ inline BOOL read(U8* item)
+ {
+ return instream->getBytes(item, 29);
+ };
+};
+
+class LASreadItemRaw_WAVEPACKET13_BE : public LASreadItemRaw
+{
+public:
+ LASreadItemRaw_WAVEPACKET13_BE(){}
+ inline BOOL read(U8* item)
+ {
+ if (!instream->getBytes(swapped, 29)) return FALSE;
+ item[0] = swapped[0]; // wavepacket descriptor index
+ ENDIAN_SWAP_64(&swapped[ 1], &item[ 1]); // byte offset to waveform data
+ ENDIAN_SWAP_32(&swapped[ 9], &item[ 9]); // waveform packet size in bytes
+ ENDIAN_SWAP_32(&swapped[13], &item[13]); // return point waveform location
+ ENDIAN_SWAP_32(&swapped[17], &item[17]); // X(t)
+ ENDIAN_SWAP_32(&swapped[21], &item[21]); // Y(t)
+ ENDIAN_SWAP_32(&swapped[25], &item[25]); // Z(t)
+ return TRUE;
+ };
+private:
+ U8 swapped[29];
};
class LASreadItemRaw_BYTE : public LASreadItemRaw
diff -r c544849de62f -r 7ae269f43dde src/lasreadpoint.cpp
--- a/src/lasreadpoint.cpp Fri Jan 07 09:24:25 2011 -0600
+++ b/src/lasreadpoint.cpp Fri Jan 07 09:42:34 2011 -0800
@@ -101,16 +101,28 @@
switch (items[i].type)
{
case LASitem::POINT10:
- readers_raw[i] = new LASreadItemRaw_POINT10();
+ if (IS_LITTLE_ENDIAN())
+ readers_raw[i] = new LASreadItemRaw_POINT10_LE();
+ else
+ readers_raw[i] = new LASreadItemRaw_POINT10_BE();
break;
case LASitem::GPSTIME11:
- readers_raw[i] = new LASreadItemRaw_GPSTIME11();
- break;
+ if (IS_LITTLE_ENDIAN())
+ readers_raw[i] = new LASreadItemRaw_GPSTIME11_LE();
+ else
+ readers_raw[i] = new LASreadItemRaw_GPSTIME11_BE();
+ break;
case LASitem::RGB12:
- readers_raw[i] = new LASreadItemRaw_RGB12();
+ if (IS_LITTLE_ENDIAN())
+ readers_raw[i] = new LASreadItemRaw_RGB12_LE();
+ else
+ readers_raw[i] = new LASreadItemRaw_RGB12_BE();
break;
case LASitem::WAVEPACKET13:
- readers_raw[i] = new LASreadItemRaw_WAVEPACKET13();
+ if (IS_LITTLE_ENDIAN())
+ readers_raw[i] = new LASreadItemRaw_WAVEPACKET13_LE();
+ else
+ readers_raw[i] = new LASreadItemRaw_WAVEPACKET13_BE();
break;
case LASitem::BYTE:
readers_raw[i] = new LASreadItemRaw_BYTE(items[i].size);
diff -r c544849de62f -r 7ae269f43dde src/laswriteitemraw.hpp
--- a/src/laswriteitemraw.hpp Fri Jan 07 09:24:25 2011 -0600
+++ b/src/laswriteitemraw.hpp Fri Jan 07 09:42:34 2011 -0800
@@ -39,6 +39,7 @@
CHANGE HISTORY:
+ 7 January 2011 -- introduced swap buffers to reduce number of fwrite calls
12 December 2010 -- refactored after watching two movies with silke
===============================================================================
@@ -49,77 +50,110 @@
#include "laswriteitem.hpp"
#include <assert.h>
-
-class LASwriteItemRaw_POINT10 : public LASwriteItemRaw
-{
-public:
- LASwriteItemRaw_POINT10(){};
- inline BOOL write(const U8* item)
- {
- if (!outstream->putBytes(item, 20)) return FALSE; // POINT10
- return TRUE;
- };
-};
-
-/*
-class LASwriteItemRaw_POINT10 : public LASwriteItemRaw
-{
+
+class LASwriteItemRaw_POINT10_LE : public LASwriteItemRaw
+{
public:
- LASwriteItemRaw_POINT10(){};
+ LASwriteItemRaw_POINT10_LE(){};
inline BOOL write(const U8* item)
{
- if (!outstream->put32bitsLE(&(item[ 0]))) return FALSE; // x
- if (!outstream->put32bitsLE(&(item[ 4]))) return FALSE; // y
- if (!outstream->put32bitsLE(&(item[ 8]))) return FALSE; // z
- if (!outstream->put16bitsLE(&(item[12]))) return FALSE; // intensity
- if (!outstream->putBytes(&(item[14]), 4)) return FALSE; // bitfield
- // classification
- // scan_angle_rank
- // user_data
- if (!outstream->put16bitsLE(&(item[18]))) return FALSE; // point_source_ID
- return TRUE;
- };
-};
-*/
-
-class LASwriteItemRaw_GPSTIME11 : public LASwriteItemRaw
-{
-public:
- LASwriteItemRaw_GPSTIME11() {};
- inline BOOL write(const U8* item)
- {
- return outstream->put64bitsLE(item); // GPSTIME
+ return outstream->putBytes(item, 20);
};
};
-class LASwriteItemRaw_RGB12 : public LASwriteItemRaw
+class LASwriteItemRaw_POINT10_BE : public LASwriteItemRaw
{
public:
- LASwriteItemRaw_RGB12(){}
+ LASwriteItemRaw_POINT10_BE(){};
inline BOOL write(const U8* item)
{
- if (!outstream->put16bitsLE(&(item[0]))) return FALSE; // R
- if (!outstream->put16bitsLE(&(item[2]))) return FALSE; // G
- if (!outstream->put16bitsLE(&(item[4]))) return FALSE; // B
- return TRUE;
+ ENDIAN_SWAP_32(&item[ 0], &swapped[ 0]); // x
+ ENDIAN_SWAP_32(&item[ 4], &swapped[ 4]); // y
+ ENDIAN_SWAP_32(&item[ 8], &swapped[ 8]); // z
+ ENDIAN_SWAP_16(&item[12], &swapped[12]); // intensity
+ *((U32*)&swapped[14]) = *((U32*)&item[14]); // bitfield, classification, scan_angle_rank, user_data
+ ENDIAN_SWAP_16(&item[18], &swapped[18]); // point_source_ID
+ return outstream->putBytes(swapped, 20);
+ };
+private:
+ U8 swapped[20];
+};
+
+class LASwriteItemRaw_GPSTIME11_LE : public LASwriteItemRaw
+{
+public:
+ LASwriteItemRaw_GPSTIME11_LE() {};
+ inline BOOL write(const U8* item)
+ {
+ return outstream->putBytes(item, 8);
};
};
-class LASwriteItemRaw_WAVEPACKET13 : public LASwriteItemRaw
+class LASwriteItemRaw_GPSTIME11_BE : public LASwriteItemRaw
{
public:
- LASwriteItemRaw_WAVEPACKET13(){}
+ LASwriteItemRaw_GPSTIME11_BE() {};
inline BOOL write(const U8* item)
More information about the Liblas-commits
mailing list