[Liblas-commits] laszip: handling big endian writes and reads

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Dec 15 08:13:37 EST 2010


changeset 70aa87413dcb in /Volumes/Data/www/liblas.org/laszip
details: http://hg.liblas.orglaszip?cmd=changeset;node=70aa87413dcb
summary: handling big endian writes and reads

diffstat:

 src/lasreaditemrawendianswapped.hpp  |  102 +++++++++++++++++++++++++++++++++++
 src/laswriteitemrawendianswapped.hpp |   99 +++++++++++++++++++++++++++++++++
 2 files changed, 201 insertions(+), 0 deletions(-)

diffs (209 lines):

diff -r a2f165041d2a -r 70aa87413dcb src/lasreaditemrawendianswapped.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lasreaditemrawendianswapped.hpp	Wed Dec 15 05:11:54 2010 -0800
@@ -0,0 +1,102 @@
+/******************************************************************************
+ *
+ * Project:  integrating laszip into liblas - http://liblas.org -
+ * Purpose:
+ * Author:   Martin Isenburg
+ *           isenburg at cs.unc.edu
+ *
+ ******************************************************************************
+ * Copyright (c) 2010, Martin Isenburg
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Licence as published
+ * by the Free Software Foundation.
+ *
+ * See the COPYING file for more information.
+ *
+ ****************************************************************************/
+
+/*
+===============================================================================
+
+  FILE:  LASitemreadrawendianswapped.hpp
+  
+  CONTENTS:
+  
+    Implementation of LASitemReadRaw for *all* items that compose a point.
+
+  PROGRAMMERS:
+  
+    martin isenburg at cs.unc.edu
+  
+  COPYRIGHT:
+  
+    copyright (C) 2007-2010  martin isenburg at cs.unc.edu
+    
+    This software is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  
+  CHANGE HISTORY:
+  
+    14 December 2010 -- at Starbucks in Offenbach before watching "Fair Game"
+  
+===============================================================================
+*/
+#ifndef LAS_READ_ITEM_RAW_ENDIAN_SWAPPED_H
+#define LAS_READ_ITEM_RAW_ENDIAN_SWAPPED_H
+
+#include "lasreaditem.hpp"
+
+#include <assert.h>
+
+class LASreadItemRawEndianSwapped_POINT10 : public LASreadItemRaw
+{
+public:
+  LASreadItemRawEndianSwapped_POINT10(){};
+  BOOL read(U8* item)
+  {
+    U8 copy[20];
+    BOOL flag = instream->getBytes(copy, 20);
+    ENDIAN_SWAP_32(&(copy[ 0]), &(item[ 0]));   // x
+    ENDIAN_SWAP_32(&(copy[ 4]), &(item[ 4]));   // y
+    ENDIAN_SWAP_32(&(copy[ 8]), &(item[ 8]));   // z
+    ENDIAN_SWAP_16(&(copy[12]), &(item[12]));   // intensity
+    item[14] = copy[14];                        // bitfield
+    item[15] = copy[15];                        // classification
+    item[16] = copy[16];                        // scan_angle_rank
+    item[17] = copy[17];                        // user_data
+    ENDIAN_SWAP_16(&(copy[18]), &(item[18]));   // point_source_ID
+    return flag;
+  };
+};
+
+class LASreadItemRawEndianSwapped_GPSTIME : public LASreadItemRaw
+{
+public:
+  LASreadItemRawEndianSwapped_GPSTIME(){};
+  BOOL read(U8* item)
+  {
+    U8 copy[8];
+    BOOL flag = instream->getBytes(copy, 8);
+    ENDIAN_SWAP_64(copy, item);
+    return flag;
+  };
+};
+
+class LASreadItemRawEndianSwapped_RGB : public LASreadItemRaw
+{
+public:
+  LASreadItemRawEndianSwapped_RGB(){};
+  BOOL read(U8* item)
+  {
+    U8 copy[6];
+    BOOL flag = instream->getBytes(copy, 6);
+    ENDIAN_SWAP_16(&(copy[0]), &(item[0]));
+    ENDIAN_SWAP_16(&(copy[2]), &(item[2]));
+    ENDIAN_SWAP_16(&(copy[4]), &(item[4]));
+    return flag;
+  };
+};
+
+#endif
diff -r a2f165041d2a -r 70aa87413dcb src/laswriteitemrawendianswapped.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/laswriteitemrawendianswapped.hpp	Wed Dec 15 05:11:54 2010 -0800
@@ -0,0 +1,99 @@
+/******************************************************************************
+ *
+ * Project:  integrating laszip into liblas - http://liblas.org -
+ * Purpose:
+ * Author:   Martin Isenburg
+ *           isenburg at cs.unc.edu
+ *
+ ******************************************************************************
+ * Copyright (c) 2010, Martin Isenburg
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Licence as published
+ * by the Free Software Foundation.
+ *
+ * See the COPYING file for more information.
+ *
+ ****************************************************************************/
+
+/*
+===============================================================================
+
+  FILE:  LASwriteitemrawendianswapped.hpp
+  
+  CONTENTS:
+  
+    Implementation of LASwriteItemRaw for *all* items that compose a point.
+
+  PROGRAMMERS:
+  
+    martin isenburg at cs.unc.edu
+  
+  COPYRIGHT:
+  
+    copyright (C) 2007-2010  martin isenburg at cs.unc.edu
+    
+    This software is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  
+  CHANGE HISTORY:
+  
+    14 December 2010 -- at Starbucks in Offenbach before watching "Fair Game"
+  
+===============================================================================
+*/
+#ifndef LAS_WRITE_ITEM_RAW_WITH_ENDIAN_SWAPPED_H
+#define LAS_WRITE_ITEM_RAW_WITH_ENDIAN_SWAPPED_H
+
+#include "laswriteitem.hpp"
+
+#include <assert.h>
+
+class LASwriteItemRawEndianSwapped_POINT10 : public LASwriteItemRaw
+{
+public:
+  LASwriteItemRawEndianSwapped_POINT10(){};
+  BOOL write(U8* item)
+  {
+    U8 copy[20];
+    ENDIAN_SWAP_32(&(item[ 0]), &(copy[ 0]));   // x
+    ENDIAN_SWAP_32(&(item[ 4]), &(copy[ 4]));   // y
+    ENDIAN_SWAP_32(&(item[ 8]), &(copy[ 8]));   // z
+    ENDIAN_SWAP_16(&(item[12]), &(copy[12]));   // intensity
+    copy[14] = item[14];                        // bitfield
+    copy[15] = item[15];                        // classification
+    copy[16] = item[16];                        // scan_angle_rank
+    copy[17] = item[17];                        // user_data
+    ENDIAN_SWAP_16(&(item[18]), &(copy[18]));   // point_source_ID
+    return outstream->putBytes(copy, 20);
+  };
+};
+
+class LASwriteItemRawEndianSwapped_GPSTIME : public LASwriteItemRaw
+{
+public:
+  LASwriteItemRawEndianSwapped_GPSTIME() {};
+  BOOL write(U8* item)
+  {
+    U8 copy[8];
+    ENDIAN_SWAP_64(item, copy);
+    return outstream->putBytes(copy, 8);
+  };
+};
+
+class LASwriteItemRawEndianSwapped_RGB : public LASwriteItemRaw
+{
+public:
+  LASwriteItemRawEndianSwapped_RGB(){}
+  BOOL write(U8* item)
+  {
+    U8 copy[6];
+    ENDIAN_SWAP_16(&(item[0]), &(copy[0]));
+    ENDIAN_SWAP_16(&(item[2]), &(copy[2]));
+    ENDIAN_SWAP_16(&(item[4]), &(copy[4]));
+    return outstream->putBytes(copy, 6);
+  };
+};
+
+#endif


More information about the Liblas-commits mailing list