[Liblas-commits] laszip: 2 new changesets

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Dec 14 21:22:23 EST 2010


changeset 8df920c36a44 in /Volumes/Data/www/liblas.org/laszip
details: http://hg.liblas.orglaszip?cmd=changeset;node=8df920c36a44
summary: it was not using streams but FILE* ... try again. i get a bug.

changeset a2f165041d2a in /Volumes/Data/www/liblas.org/laszip
details: http://hg.liblas.orglaszip?cmd=changeset;node=a2f165041d2a
summary: handling of raw point writing on big endian platforms

diffstat:

 src/lasreadpoint.cpp    |  16 +++++++++--
 src/laswritepoint.cpp   |  16 +++++++++--
 src/mydefs.hpp          |  70 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/laszippertest.cpp |  18 +++++++-----
 4 files changed, 106 insertions(+), 14 deletions(-)

diffs (220 lines):

diff -r 487fafda44f2 -r a2f165041d2a src/lasreadpoint.cpp
--- a/src/lasreadpoint.cpp	Tue Dec 14 10:35:09 2010 -0600
+++ b/src/lasreadpoint.cpp	Tue Dec 14 18:21:57 2010 -0800
@@ -48,6 +48,7 @@
 
 #include "arithmeticdecoder.hpp"
 #include "lasreaditemraw.hpp"
+#include "lasreaditemrawendianswapped.hpp"
 #include "lasreaditemcompressed_v1.hpp"
 
 #include <string.h>
@@ -151,13 +152,22 @@
     switch (items[i].type)
     {
     case LASitem::POINT10:
-      readers_raw[i] = new LASreadItemRaw_POINT10();
+      if (IS_LITTLE_ENDIAN())
+        readers_raw[i] = new LASreadItemRaw_POINT10();
+      else
+        readers_raw[i] = new LASreadItemRawEndianSwapped_POINT10();
       break;
     case LASitem::GPSTIME:
-      readers_raw[i] = new LASreadItemRaw_GPSTIME();
+      if (IS_LITTLE_ENDIAN())
+        readers_raw[i] = new LASreadItemRaw_GPSTIME();
+      else
+        readers_raw[i] = new LASreadItemRawEndianSwapped_GPSTIME();
       break;
     case LASitem::RGB:
-      readers_raw[i] = new LASreadItemRaw_RGB();
+      if (IS_LITTLE_ENDIAN())
+        readers_raw[i] = new LASreadItemRaw_RGB();
+      else
+        readers_raw[i] = new LASreadItemRawEndianSwapped_RGB();
       break;
     case LASitem::BYTE:
       readers_raw[i] = new LASreadItemRaw_BYTE(items[i].size);
diff -r 487fafda44f2 -r a2f165041d2a src/laswritepoint.cpp
--- a/src/laswritepoint.cpp	Tue Dec 14 10:35:09 2010 -0600
+++ b/src/laswritepoint.cpp	Tue Dec 14 18:21:57 2010 -0800
@@ -48,6 +48,7 @@
 
 #include "arithmeticencoder.hpp"
 #include "laswriteitemraw.hpp"
+#include "laswriteitemrawendianswapped.hpp"
 #include "laswriteitemcompressed_v1.hpp"
 
 #include <string.h>
@@ -115,13 +116,22 @@
     switch (items[i].type)
     {
     case LASitem::POINT10:
-      writers_raw[i] = new LASwriteItemRaw_POINT10();
+      if (IS_LITTLE_ENDIAN())
+        writers_raw[i] = new LASwriteItemRaw_POINT10();
+      else
+        writers_raw[i] = new LASwriteItemRawEndianSwapped_POINT10();
       break;
     case LASitem::GPSTIME:
-      writers_raw[i] = new LASwriteItemRaw_GPSTIME();
+      if (IS_LITTLE_ENDIAN())
+        writers_raw[i] = new LASwriteItemRaw_GPSTIME();
+      else
+        writers_raw[i] = new LASwriteItemRawEndianSwapped_GPSTIME();
       break;
     case LASitem::RGB:
-      writers_raw[i] = new LASwriteItemRaw_RGB();
+      if (IS_LITTLE_ENDIAN())
+        writers_raw[i] = new LASwriteItemRaw_RGB();
+      else
+        writers_raw[i] = new LASwriteItemRawEndianSwapped_RGB();
       break;
     case LASitem::BYTE:
       writers_raw[i] = new LASwriteItemRaw_BYTE(items[i].size);
diff -r 487fafda44f2 -r a2f165041d2a src/mydefs.hpp
--- a/src/mydefs.hpp	Tue Dec 14 10:35:09 2010 -0600
+++ b/src/mydefs.hpp	Tue Dec 14 18:21:57 2010 -0800
@@ -81,5 +81,75 @@
 #ifndef NULL
 #define NULL    0
 #endif
+
+inline BOOL IS_LITTLE_ENDIAN()
+{
+  U32 i = 1;
+  if (*((U8*)&i) == 1)
+    return TRUE;
+  else
+    return FALSE;
+}
 
+inline void ENDIAN_SWAP_16(U8* field)
+{
+  U8 help = field[0];
+  field[0] = field[1];
+  field[1] = help;
+}
+
+inline void ENDIAN_SWAP_32(U8* field)
+{
+  U8 help;
+  help = field[0];
+  field[0] = field[3];
+  field[3] = help;
+  help = field[1];
+  field[1] = field[2];
+  field[2] = help;
+}
+
+inline void ENDIAN_SWAP_64(U8* field)
+{
+  U8 help;
+  help = field[0];
+  field[0] = field[7];
+  field[7] = help;
+  help = field[1];
+  field[1] = field[6];
+  field[6] = help;
+  help = field[2];
+  field[2] = field[5];
+  field[5] = help;
+  help = field[3];
+  field[3] = field[4];
+  field[4] = help;
+}
+
+inline void ENDIAN_SWAP_16(U8* from, U8* to)
+{
+  to[0] = from[1];
+  to[1] = from[0];
+}
+
+inline void ENDIAN_SWAP_32(U8* from, U8* to)
+{
+  to[0] = from[3];
+  to[1] = from[2];
+  to[2] = from[1];
+  to[3] = from[0];
+}
+
+inline void ENDIAN_SWAP_64(U8* from, U8* to)
+{
+  to[0] = from[7];
+  to[1] = from[6];
+  to[2] = from[5];
+  to[3] = from[4];
+  to[4] = from[3];
+  to[5] = from[2];
+  to[6] = from[1];
+  to[7] = from[0];
+}
+
 #endif
diff -r 487fafda44f2 -r a2f165041d2a tools/laszippertest.cpp
--- a/tools/laszippertest.cpp	Tue Dec 14 10:35:09 2010 -0600
+++ b/tools/laszippertest.cpp	Tue Dec 14 18:21:57 2010 -0800
@@ -64,7 +64,7 @@
 {
   unsigned char c;
   unsigned int i, j;
-  unsigned int num_points = 10000000;
+  unsigned int num_points = 100000;
   unsigned int num_errors = 0;
   std::filebuf ofb1;
   std::filebuf ofb2;
@@ -80,7 +80,7 @@
   FILE* ifile2 = 0;
   
   bool range = false;
-  bool use_iostream = false;
+  bool use_iostream = true;
 
   // describe the point structure
 
@@ -123,7 +123,7 @@
   if (use_iostream)
   {
     ofb1.open("test1.lax", std::ios::out);
-    std::ostream* ostream1 = new std::ostream(&ofb1);
+    ostream1 = new std::ostream(&ofb1);
     if (!laszipper1->open(ostream1, num_items, items, LASZIP_COMPRESSION_NONE))
     {
       fprintf(stderr, "ERROR: could not open laszipper1\n");
@@ -131,7 +131,7 @@
     }
 
     ofb2.open("test2.lax", std::ios::out);
-    std::ostream* ostream2 = new std::ostream(&ofb2);
+    ostream2 = new std::ostream(&ofb2);
     if (!laszipper2->open(ostream2, num_items, items, LASZIP_COMPRESSION_ARITHMETIC))
     {
       fprintf(stderr, "ERROR: could not open laszipper2\n");
@@ -177,10 +177,12 @@
 
   if (use_iostream)
   {
+    ostream1.flush();
+    ostream2.flush();
+    delete ostream1;
+    delete ostream2;
     ofb1.close();
     ofb2.close();
-    delete ostream1;
-    delete ostream2;
   }
   else
   {
@@ -269,10 +271,10 @@
 
   if (use_iostream)
   {
+    delete istream1;
+    delete istream2;
     ifb1.close();
     ifb2.close();
-    delete istream1;
-    delete istream2;
   }
   else
   {


More information about the Liblas-commits mailing list