[Liblas-commits] laszip: updated RGB encoding to be endian neutral

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Dec 23 08:45:59 EST 2010


changeset 7770fdf9c7c2 in /Volumes/Data/www/liblas.org/laszip
details: http://hg.liblas.orglaszip?cmd=changeset;node=7770fdf9c7c2
summary: updated RGB encoding to be endian neutral

diffstat:

 src/arithmeticdecoder.cpp         |    8 +-
 src/arithmeticencoder.cpp         |    8 +-
 src/lasreaditemcompressed_v1.cpp  |   66 +++++++++++++++++++-----
 src/lasreaditemcompressed_v1.hpp  |    2 +
 src/laswriteitemcompressed_v1.cpp |  101 +++++++++++++++++++++++++------------
 src/laswriteitemcompressed_v1.hpp |    2 +
 src/laswritepoint.cpp             |    4 +-
 7 files changed, 133 insertions(+), 58 deletions(-)

diffs (truncated from 430 to 300 lines):

diff -r 4daf73355dc6 -r 7770fdf9c7c2 src/arithmeticdecoder.cpp
--- a/src/arithmeticdecoder.cpp	Wed Dec 22 14:16:19 2010 -0800
+++ b/src/arithmeticdecoder.cpp	Thu Dec 23 05:45:46 2010 -0800
@@ -235,28 +235,28 @@
   return (U16)sym;
 }
 
-U32 ArithmeticDecoder::readInt()
+inline U32 ArithmeticDecoder::readInt()
 {
   U32 lowerInt = readShort();
   U32 upperInt = readShort();
   return upperInt*U16_MAX_PLUS_ONE+lowerInt;
 }
 
-F32 ArithmeticDecoder::readFloat()
+inline F32 ArithmeticDecoder::readFloat()
 {
   U32F32 u32f32;
   u32f32.u32 = readInt();
   return u32f32.f32;
 }
 
-U64 ArithmeticDecoder::readInt64()
+inline U64 ArithmeticDecoder::readInt64()
 {
   U64 lowerInt = readInt();
   U64 upperInt = readInt();
   return upperInt*U32_MAX_PLUS_ONE+lowerInt;
 }
 
-F64 ArithmeticDecoder::readDouble()
+inline F64 ArithmeticDecoder::readDouble()
 {
   U64F64 u64f64;
   u64f64.u64 = readInt64();
diff -r 4daf73355dc6 -r 7770fdf9c7c2 src/arithmeticencoder.cpp
--- a/src/arithmeticencoder.cpp	Wed Dec 22 14:16:19 2010 -0800
+++ b/src/arithmeticencoder.cpp	Thu Dec 23 05:45:46 2010 -0800
@@ -236,26 +236,26 @@
   if (length < AC__MinLength) renorm_enc_interval();        // renormalization
 }
 
-void ArithmeticEncoder::writeInt(U32 sym)
+inline void ArithmeticEncoder::writeInt(U32 sym)
 {
   writeShort((U16)(sym % U16_MAX_PLUS_ONE)); // lower 16 bits
   writeShort((U16)(sym / U16_MAX_PLUS_ONE)); // UPPER 16 bits
 }
 
-void ArithmeticEncoder::writeFloat(F32 sym)
+inline void ArithmeticEncoder::writeFloat(F32 sym)
 {
   U32F32 u32f32;
   u32f32.f32 = sym;
   writeInt(u32f32.u32);
 }
 
-void ArithmeticEncoder::writeInt64(U64 sym)
+inline void ArithmeticEncoder::writeInt64(U64 sym)
 {
   writeInt((U32)(sym % U32_MAX_PLUS_ONE)); // lower 32 bits
   writeInt((U32)(sym / U32_MAX_PLUS_ONE)); // UPPER 32 bits
 }
 
-void ArithmeticEncoder::writeDouble(F64 sym)
+inline void ArithmeticEncoder::writeDouble(F64 sym)
 {
   U64F64 u64f64;
   u64f64.f64 = sym;
diff -r 4daf73355dc6 -r 7770fdf9c7c2 src/lasreaditemcompressed_v1.cpp
--- a/src/lasreaditemcompressed_v1.cpp	Wed Dec 22 14:16:19 2010 -0800
+++ b/src/lasreaditemcompressed_v1.cpp	Thu Dec 23 05:45:46 2010 -0800
@@ -305,7 +305,7 @@
     }
     else if (multi == 2) // the difference is huge
     {
-      last_gpstime.f64 = dec->readDouble();
+      last_gpstime.i64 = dec->readInt64();
     }
   }
   else
@@ -356,7 +356,7 @@
     }
     else if (multi <  LASZIP_GPSTIME_MULTIMAX-1)
     {
-      last_gpstime.f64 = dec->readDouble();
+      last_gpstime.i64 = dec->readInt64();
     }
   }
   *((F64*)item) = last_gpstime.f64;
@@ -405,15 +405,20 @@
 
 inline BOOL LASreadItemCompressed_RGB12_v1::read(U8* item)
 {
-  U32 i, sym = dec->decodeSymbol(m_byte_used);
-  for (i = 0; i < 6; i++)
-  {
-    if (sym & (1 << i))
-    {
-      item[i] = ic_rgb->decompress(last_item[i], i);
-      last_item[i] = item[i];
-    }
-  }
+  U32 sym = dec->decodeSymbol(m_byte_used);
+  if (sym & (1 << 0)) ((U16*)item)[0] = ic_rgb->decompress(((U16*)last_item)[0]&255, 0);
+  else ((U16*)item)[0] = ((U16*)last_item)[0]&255;
+  if (sym & (1 << 1)) ((U16*)item)[0] |= (ic_rgb->decompress(((U16*)last_item)[0]>>8, 1) << 8);
+  else ((U16*)item)[0] |= (((U16*)last_item)[0]&65280);
+  if (sym & (1 << 2)) ((U16*)item)[1] = ic_rgb->decompress(((U16*)last_item)[1]&255, 2);
+  else ((U16*)item)[1] = ((U16*)last_item)[1]&255;
+  if (sym & (1 << 3)) ((U16*)item)[1] |= (ic_rgb->decompress(((U16*)last_item)[1]>>8, 3) << 8);
+  else ((U16*)item)[1] |= (((U16*)last_item)[1]&65280);
+  if (sym & (1 << 4)) ((U16*)item)[2] = ic_rgb->decompress(((U16*)last_item)[2]&255, 4);
+  else ((U16*)item)[2] = ((U16*)last_item)[2]&255;
+  if (sym & (1 << 5)) ((U16*)item)[2] |= (ic_rgb->decompress(((U16*)last_item)[2]>>8, 5) << 8);
+  else ((U16*)item)[2] |= (((U16*)last_item)[2]&65280);
+  memcpy(last_item, item, 6);
   return TRUE;
 }
 
@@ -423,6 +428,16 @@
 ===============================================================================
 */
 
+struct LASwavepacket13
+{
+  U64 offset;
+  U32 packet_size;
+  I32F32 return_point;
+  I32F32 x;
+  I32F32 y;
+  I32F32 z;
+};
+
 LASreadItemCompressed_WAVEPACKET13_v1::LASreadItemCompressed_WAVEPACKET13_v1(EntropyDecoder* dec)
 {
   /* set decoder */
@@ -433,11 +448,12 @@
   m_packet_index = dec->createSymbolModel(256);
   m_small_offset_diff = dec->createBitModel();
   ic_offset_diff = new IntegerCompressor(dec, 32);
+  ic_packet_size = new IntegerCompressor(dec, 32);
   ic_return_point = new IntegerCompressor(dec, 32);
   ic_xyz = new IntegerCompressor(dec, 32, 3);
 
   /* create last item */
-  last_item = new U8[29];
+  last_item = new U8[28];
 }
 
 LASreadItemCompressed_WAVEPACKET13_v1::~LASreadItemCompressed_WAVEPACKET13_v1()
@@ -445,6 +461,7 @@
   dec->destroySymbolModel(m_packet_index);
   dec->destroyBitModel(m_small_offset_diff);
   delete ic_offset_diff;
+  delete ic_packet_size;
   delete ic_return_point;
   delete ic_xyz;
   delete [] last_item;
@@ -453,23 +470,42 @@
 BOOL LASreadItemCompressed_WAVEPACKET13_v1::init(const U8* item)
 {
   /* init state */
+  last_diff_32 = 0;
 
   /* init models and integer compressors */
   dec->initSymbolModel(m_packet_index);
   dec->initBitModel(m_small_offset_diff);
   ic_offset_diff->initDecompressor();
+  ic_packet_size->initDecompressor();
   ic_return_point->initDecompressor();
   ic_xyz->initDecompressor();
 
   /* init last item */
-  memcpy(last_item, item, 29);
+  item++;
+  memcpy(last_item, item, 28);
   return TRUE;
 }
 
 inline BOOL LASreadItemCompressed_WAVEPACKET13_v1::read(U8* item)
 {
-//  dec->decodeSymbol(m_packet_index);
-//  ic_xyz->decompress(last_item[i], i);
+  item[0] = (U8)(dec->decodeSymbol(m_packet_index));
+  item++;
+
+  if (dec->decodeBit(m_small_offset_diff))
+  {
+    last_diff_32 = ic_offset_diff->decompress(last_diff_32);
+    ((LASwavepacket13*)item)->offset = ((LASwavepacket13*)last_item)->offset + last_diff_32;
+  }
+  else
+  {
+    ((LASwavepacket13*)item)->offset = dec->readInt64();
+  }
+  ((LASwavepacket13*)item)->packet_size = ic_packet_size->decompress(((LASwavepacket13*)last_item)->packet_size);
+  ((LASwavepacket13*)item)->return_point.i32 = ic_return_point->decompress(((LASwavepacket13*)last_item)->return_point.i32);
+  ((LASwavepacket13*)item)->x.i32 = ic_xyz->decompress(((LASwavepacket13*)last_item)->x.i32, 0);
+  ((LASwavepacket13*)item)->y.i32 = ic_xyz->decompress(((LASwavepacket13*)last_item)->y.i32, 1);
+  ((LASwavepacket13*)item)->z.i32 = ic_xyz->decompress(((LASwavepacket13*)last_item)->z.i32, 2);
+  memcpy(last_item, item, 28);
   return TRUE;
 }
 
diff -r 4daf73355dc6 -r 7770fdf9c7c2 src/lasreaditemcompressed_v1.hpp
--- a/src/lasreaditemcompressed_v1.hpp	Wed Dec 22 14:16:19 2010 -0800
+++ b/src/lasreaditemcompressed_v1.hpp	Thu Dec 23 05:45:46 2010 -0800
@@ -137,9 +137,11 @@
   EntropyDecoder* dec;
   U8* last_item;
 
+  I32 last_diff_32;
   EntropyModel* m_packet_index;
   EntropyModel* m_small_offset_diff;
   IntegerCompressor* ic_offset_diff;
+  IntegerCompressor* ic_packet_size;
   IntegerCompressor* ic_return_point;
   IntegerCompressor* ic_xyz;
 };
diff -r 4daf73355dc6 -r 7770fdf9c7c2 src/laswriteitemcompressed_v1.cpp
--- a/src/laswriteitemcompressed_v1.cpp	Wed Dec 22 14:16:19 2010 -0800
+++ b/src/laswriteitemcompressed_v1.cpp	Thu Dec 23 05:45:46 2010 -0800
@@ -57,18 +57,18 @@
 
 struct LASpoint10
 {
-  int x;
-  int y;
-  int z;
-  unsigned short intensity;
-  unsigned char return_number : 3;
-  unsigned char number_of_returns_of_given_pulse : 3;
-  unsigned char scan_direction_flag : 1;
-  unsigned char edge_of_flight_line : 1;
-  unsigned char classification;
-  char scan_angle_rank;
-  unsigned char user_data;
-  unsigned short point_source_ID;
+  I32 x;
+  I32 y;
+  I32 z;
+  U16 intensity;
+  U8 return_number : 3;
+  U8 number_of_returns_of_given_pulse : 3;
+  U8 scan_direction_flag : 1;
+  U8 edge_of_flight_line : 1;
+  U8 classification;
+  I8 scan_angle_rank;
+  U8 user_data;
+  U16 point_source_ID;
 };
 
 LASwriteItemCompressed_POINT10_v1::LASwriteItemCompressed_POINT10_v1(EntropyEncoder* enc)
@@ -318,7 +318,7 @@
       else
       {
         enc->encodeSymbol(m_gpstime_0diff, 2); // the difference is huge
-        enc->writeDouble(this_gpstime.f64);
+        enc->writeInt64(this_gpstime.i64);
       }
       last_gpstime.f64 = this_gpstime.f64;
     }
@@ -396,9 +396,9 @@
       }
       else
       {
-        // if difference is so huge ... we simply write the double (for now) 
+        // if difference is so huge ... we simply write the double
         enc->encodeSymbol(m_gpstime_multi, LASZIP_GPSTIME_MULTIMAX-2);
-        enc->writeDouble(this_gpstime.f64);
+        enc->writeInt64(this_gpstime.i64);
       }
       last_gpstime.f64 = this_gpstime.f64;
     }
@@ -448,20 +448,20 @@
 
 inline BOOL LASwriteItemCompressed_RGB12_v1::write(const U8* item)
 {
-  U32 i, sym = 0;
-  for (i = 0; i < 6; i++)
-  {
-    sym |= ((last_item[i] != item[i]) << i);
-  }
+  U32 sym = ((((U16*)last_item)[0]&0x00FF) != (((U16*)item)[0]&0x00FF)) << 0;
+  sym |= ((((U16*)last_item)[0]&0xFF00) != (((U16*)item)[0]&0xFF00)) << 1;
+  sym |= ((((U16*)last_item)[1]&0x00FF) != (((U16*)item)[1]&0x00FF)) << 2;
+  sym |= ((((U16*)last_item)[1]&0xFF00) != (((U16*)item)[1]&0xFF00)) << 3;
+  sym |= ((((U16*)last_item)[2]&0x00FF) != (((U16*)item)[2]&0x00FF)) << 4;
+  sym |= ((((U16*)last_item)[2]&0xFF00) != (((U16*)item)[2]&0xFF00)) << 5;
   enc->encodeSymbol(m_byte_used, sym);
-  for (i = 0; i < 6; i++)
-  {
-    if (last_item[i] != item[i])
-    {
-      ic_rgb->compress(last_item[i], item[i], i);
-      last_item[i] = item[i];
-    }
-  }


More information about the Liblas-commits mailing list