[Liblas-commits] laszip: fixed wrong number of end bytes bug

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Apr 25 19:26:19 EDT 2011


details:   http://hg.liblas.orglaszip/rev/6e46a9b4d84a
changeset: 213:6e46a9b4d84a
user:      isenburg
date:      Mon Apr 25 16:20:14 2011 -0700
description:
fixed wrong number of end bytes bug
Subject: laszip: updated i/o model to support seeking

details:   http://hg.liblas.orglaszip/rev/fc048a9e1db4
changeset: 214:fc048a9e1db4
user:      isenburg
date:      Mon Apr 25 16:21:18 2011 -0700
description:
updated i/o model to support seeking
Subject: laszip: implementation of new laszip interface

details:   http://hg.liblas.orglaszip/rev/de53322e8b30
changeset: 215:de53322e8b30
user:      isenburg
date:      Mon Apr 25 16:26:15 2011 -0700
description:
implementation of new laszip interface
Subject: laszip: point reader and writer with chunking

details:   http://hg.liblas.orglaszip/rev/6ff6f75e809d
changeset: 216:6ff6f75e809d
user:      isenburg
date:      Mon Apr 25 16:27:48 2011 -0700
description:
point reader and writer with chunking
Subject: laszip: the file i usually forget to commit

details:   http://hg.liblas.orglaszip/rev/8b9ecc00ba69
changeset: 217:8b9ecc00ba69
user:      isenburg
date:      Mon Apr 25 16:28:13 2011 -0700
description:
the file i usually forget to commit

diffstat:

 src/arithmeticencoder.cpp     |   10 +-
 src/bytestreamin.hpp          |   16 +-
 src/bytestreamin_file.hpp     |   30 +-
 src/bytestreamin_istream.hpp  |  531 +++++++++++++++++++++--------------------
 src/bytestreamout.hpp         |    8 +-
 src/bytestreamout_file.hpp    |   28 +-
 src/bytestreamout_ostream.hpp |  501 +++++++++++++++++++--------------------
 src/lasreadpoint.cpp          |  183 +++++++++++++-
 src/lasreadpoint.hpp          |   15 +-
 src/lasunzipper.cpp           |   62 +++-
 src/laswritepoint.cpp         |  166 ++++++++++--
 src/laswritepoint.hpp         |   12 +-
 src/laszip.cpp                |   52 +++-
 src/laszipper.cpp             |   67 ++---
 src/mydefs.hpp                |   15 +-
 15 files changed, 1027 insertions(+), 669 deletions(-)

diffs (truncated from 2297 to 300 lines):

diff -r 2a9b8b99bf2d -r 8b9ecc00ba69 src/arithmeticencoder.cpp
--- a/src/arithmeticencoder.cpp	Mon Apr 25 16:18:10 2011 -0700
+++ b/src/arithmeticencoder.cpp	Mon Apr 25 16:28:13 2011 -0700
@@ -72,6 +72,10 @@
 #include <string.h>
 #include <assert.h>
 
+#include <stdio.h>
+
+FILE* file = 0;
+
 #include "arithmeticmodel.hpp"
 
 ArithmeticEncoder::ArithmeticEncoder()
@@ -101,6 +105,7 @@
 void ArithmeticEncoder::done()
 {
   U32 init_base = base;                 // done encoding: set final data bytes
+  BOOL another_byte = TRUE;
 
   if (length > 2 * AC__MinLength) {
     base  += AC__MinLength;                                     // base offset
@@ -109,6 +114,7 @@
   else {
     base  += AC__MinLength >> 1;                                // base offset
     length = AC__MinLength >> 9;            // set new length for 2 more bytes
+    another_byte = FALSE;
   }
 
   if (init_base > base) propagate_carry();                 // overflow = carry
@@ -122,10 +128,10 @@
   U32 buffer_size = outbyte - outbuffer;
   if (buffer_size) outstream->putBytes(outbuffer, buffer_size);
 
-  // write three zero bytes to be sure the decoder does not read past the array
+  // write two or three zero bytes to be in sync with the decoder's byte reads
   outstream->putByte(0);
   outstream->putByte(0);
-  outstream->putByte(0);
+  if (another_byte) outstream->putByte(0);
 
   outstream = 0;
 }
diff -r 2a9b8b99bf2d -r 8b9ecc00ba69 src/bytestreamin.hpp
--- a/src/bytestreamin.hpp	Mon Apr 25 16:18:10 2011 -0700
+++ b/src/bytestreamin.hpp	Mon Apr 25 16:28:13 2011 -0700
@@ -27,8 +27,8 @@
   
 ===============================================================================
 */
-#ifndef BYTE_STREAM_IN_H
-#define BYTE_STREAM_IN_H
+#ifndef BYTE_STREAM_IN_HPP
+#define BYTE_STREAM_IN_HPP
 
 class ByteStreamIn
 {
@@ -36,7 +36,7 @@
 /* read a single byte                                        */
   virtual unsigned int getByte() = 0;
 /* read an array of bytes                                    */
-  virtual bool getBytes(unsigned char* bytes, unsigned int num_bytes) = 0;
+  virtual bool getBytes(unsigned char* bytes, const unsigned int num_bytes) = 0;
 /* read 16 bit low-endian field                              */
   virtual bool get16bitsLE(unsigned char* bytes) = 0;
 /* read 32 bit low-endian field                              */
@@ -51,10 +51,16 @@
   virtual bool get64bitsBE(unsigned char* bytes) = 0;
 /* is the stream seekable (e.g. stdin is not)                */
   virtual bool isSeekable() const = 0;
+/* get current position of stream                            */
+  virtual long position() const = 0;
+/* seek to this position in the stream                       */
+  virtual bool seek(const long position) = 0;
+/* seek to the end of the file                               */
+  virtual bool seekEnd(const long distance=0) = 0;
+/* reset byte counter                                        */
+  virtual void resetCount() = 0;
 /* returns how many bytes were read since last reset         */
   virtual unsigned int byteCount() const = 0;
-/* reset byte counter                                        */
-  virtual void resetCount() = 0;
 /* destructor                                                */
   virtual ~ByteStreamIn() {};
 };
diff -r 2a9b8b99bf2d -r 8b9ecc00ba69 src/bytestreamin_file.hpp
--- a/src/bytestreamin_file.hpp	Mon Apr 25 16:18:10 2011 -0700
+++ b/src/bytestreamin_file.hpp	Mon Apr 25 16:28:13 2011 -0700
@@ -41,15 +41,15 @@
 /* read a single byte                                        */
   unsigned int getByte();
 /* read an array of bytes                                    */
-  bool getBytes(unsigned char* bytes, unsigned int num_bytes);
+  bool getBytes(unsigned char* bytes, const unsigned int num_bytes);
 /* is the stream seekable (e.g. standard in is not)          */
   bool isSeekable() const;
-/* save position in the stream for (forward) seeking later   */
-  bool saveSeekPosition();
-/* seek by offset from saved position (or start of file)     */
-  bool seek(long offset);
+/* get current position of stream                            */
+  long position() const;
+/* seek to this position in the stream                       */
+  bool seek(const long position);
 /* seek to the end of the file                               */
-  bool seekEnd();
+  bool seekEnd(const long distance=0);
 /* returns how many bytes were read since last reset         */
   unsigned int byteCount() const;
 /* reset byte counter                                        */
@@ -60,7 +60,6 @@
   FILE* file;
 private:
   long start;
-  long seek_position;
 };
 
 class ByteStreamInFileLE : public ByteStreamInFile
@@ -107,7 +106,6 @@
 {
   this->file = file;
   start = ftell(file);
-  seek_position = ftell(file);
 }
 
 inline unsigned int ByteStreamInFile::getByte()
@@ -121,7 +119,7 @@
   return (unsigned int)byte;
 }
 
-inline bool ByteStreamInFile::getBytes(unsigned char* bytes, unsigned int num_bytes)
+inline bool ByteStreamInFile::getBytes(unsigned char* bytes, const unsigned int num_bytes)
 {
   return (fread(bytes, 1, num_bytes, file) == num_bytes);
 }
@@ -131,15 +129,19 @@
   return (file != stdin);
 }
 
-inline bool ByteStreamInFile::saveSeekPosition()
+inline long ByteStreamInFile::position() const
 {
-  seek_position = ftell(file);
-  return (seek_position != -1L);
+  return ftell(file);
 }
 
-inline bool ByteStreamInFile::seek(long offset)
+inline bool ByteStreamInFile::seek(const long position)
 {
-  return !fseek(file, seek_position+offset, SEEK_SET);
+  return !(fseek(file, position, SEEK_SET));
+}
+
+inline bool ByteStreamInFile::seekEnd(const long distance)
+{
+  return !(fseek(file, -distance, SEEK_END));
 }
 
 inline unsigned int ByteStreamInFile::byteCount() const
diff -r 2a9b8b99bf2d -r 8b9ecc00ba69 src/bytestreamin_istream.hpp
--- a/src/bytestreamin_istream.hpp	Mon Apr 25 16:18:10 2011 -0700
+++ b/src/bytestreamin_istream.hpp	Mon Apr 25 16:28:13 2011 -0700
@@ -5,271 +5,286 @@
   
   CONTENTS:
       
-  PROGRAMMERS:
-  
-    martin.isenburg at gmail.com
-  
-  COPYRIGHT:
-
-    (c) 2010-2011, Martin Isenburg, LASSO - tools to catch reality
-
-    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.
-
-    This software is distributed WITHOUT ANY WARRANTY and without even the
-    implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-  
-  CHANGE HISTORY:
-  
-    10 January 2011 -- licensing change for LGPL release and liblas integration
-    12 December 2010 -- created from ByteStreamOutFile after Howard got pushy (-;
+  PROGRAMMERS:
+  
+    martin.isenburg at gmail.com
+  
+  COPYRIGHT:
+
+    (c) 2010-2011, Martin Isenburg, LASSO - tools to catch reality
+
+    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.
+
+    This software is distributed WITHOUT ANY WARRANTY and without even the
+    implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  
+  CHANGE HISTORY:
+  
+    10 January 2011 -- licensing change for LGPL release and liblas integration
+    12 December 2010 -- created from ByteStreamOutFile after Howard got pushy (-;
   
 ===============================================================================
 */
 #ifndef BYTE_STREAM_IN_ISTREAM_H
 #define BYTE_STREAM_IN_ISTREAM_H
-
-#include "bytestreamin.hpp"
-
-#ifdef LZ_WIN32_VC6
-#include <fstream.h>
-#else
-#include <istream>
-#include <fstream>
-using namespace std;
-#endif
+
+#include "bytestreamin.hpp"
+
+#ifdef LZ_WIN32_VC6
+#include <fstream.h>
+#else
+#include <istream>
+#include <fstream>
+using namespace std;
+#endif
 
 class ByteStreamInIstream : public ByteStreamIn
 {
-public:
-  ByteStreamInIstream(istream& stream);
-/* read a single byte                                        */
+public:
+  ByteStreamInIstream(istream& stream);
+/* read a single byte                                        */
   unsigned int getByte();
-/* read an array of bytes                                    */
-  bool getBytes(unsigned char* bytes, unsigned int num_bytes);
-/* is the stream seekable (e.g. standard in is not)          */
-  bool isSeekable() const;
-/* returns how many bytes were read since last reset         */
-  unsigned int byteCount() const;
-/* reset byte counter                                        */
-  void resetCount();
-/* destructor                                                */
-  ~ByteStreamInIstream(){};
-protected:
-  istream& stream;
-private:
-#ifdef LZ_WIN32_VC6
-  long start;
-#else
-  ios::off_type start;
+/* read an array of bytes                                    */
+  bool getBytes(unsigned char* bytes, const unsigned int num_bytes);
+/* is the stream seekable (e.g. standard in is not)          */
+  bool isSeekable() const;
+/* get current position of stream                            */
+  long position() const;
+/* seek to this position in the stream                       */
+  bool seek(const long position);
+/* seek to the end of the file                               */
+  bool seekEnd(const long distance=0);
+/* returns how many bytes were read since last reset         */
+  unsigned int byteCount() const;
+/* reset byte counter                                        */
+  void resetCount();
+/* destructor                                                */
+  ~ByteStreamInIstream(){};
+protected:
+  istream& stream;
+private:
+#ifdef LZ_WIN32_VC6
+  long start;
+#else
+  ios::off_type start;
+#endif
+};
+
+class ByteStreamInIstreamLE : public ByteStreamInIstream
+{
+public:
+  ByteStreamInIstreamLE(istream& stream);
+/* read 16 bit low-endian field                              */
+  bool get16bitsLE(unsigned char* bytes);
+/* read 32 bit low-endian field                              */
+  bool get32bitsLE(unsigned char* bytes);
+/* read 64 bit low-endian field                              */
+  bool get64bitsLE(unsigned char* bytes);
+/* read 16 bit big-endian field                              */
+  bool get16bitsBE(unsigned char* bytes);
+/* read 32 bit big-endian field                              */
+  bool get32bitsBE(unsigned char* bytes);
+/* read 64 bit big-endian field                              */
+  bool get64bitsBE(unsigned char* bytes);
+private:


More information about the Liblas-commits mailing list