Point Cloud Library (PCL)  1.7.1
opennurbs_zlib.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_ZLIB_INC_)
18 #define OPENNURBS_ZLIB_INC_
19 
20 // If you are using opennurbs as a statically linked library, then
21 // you may make calls to the same zlib that opennurbs uses. This
22 // zlib is compiled with z_ symbol projectection. All the necessary
23 // header files are included by opennurbs.h.
24 //
25 // If you are using opennurbs as a DLL or writing a Rhino plug-in
26 // and you want to use the same zlib that opennurbs uses, then
27 // compile opennurbs_zlib_memory.cpp into your application
28 // and statically link with the zlib library. All the necessary
29 // header files are included by opennurbs.h.
30 
31 
32 #if !defined(Z_PREFIX)
33 /* decorates zlib functions with a "z_" prefix to prevent symbol collision. */
34 #define Z_PREFIX
35 #endif
36 
37 #if !defined(MY_ZCALLOC)
38 /* have zlib use oncalloc() and onfree() for memory managment*/
39 #define MY_ZCALLOC
40 #endif
41 
42 #include "zlib.h"
43 
44 ON_BEGIN_EXTERNC
45 voidpf zcalloc (voidpf, unsigned, unsigned);
46 void zcfree (voidpf, voidpf);
47 ON_END_EXTERNC
48 
49 class ON_CLASS ON_CompressedBuffer
50 {
51 public:
55  ON_CompressedBuffer& operator=(const ON_CompressedBuffer& src);
56 
57  /*
58  Description:
59  Compress inbuffer.
60  Parameters:
61  sizeof__inbuffer - [in]
62  Number of bytes in inbuffer.
63  inbuffer - [in]
64  Uncompressed information.
65  sizeof_element - [out]
66  This parameter only matters if the buffer will be compressed,
67  and decompressed on CPUs with different endianness. If this
68  is the case, then the types in the buffer need to have the
69  same size (2,4, or 8).
70  Returns:
71  True if inbuffer is successfully compressed.
72  */
73  bool Compress(
74  size_t sizeof__inbuffer, // sizeof uncompressed input data
75  const void* inbuffer, // uncompressed input data
76  int sizeof_element
77  );
78 
79  /*
80  Returns:
81  Number of bytes in the uncompressed information.
82  */
83  size_t SizeOfUncompressedBuffer() const;
84 
85  /*
86  Description:
87  Uncompress the contents of this ON_CompressedBuffer.
88  Parameters:
89  outbuffer - [in/out]
90  This buffer must have at least SizeOfUncompressedBuffer() bytes.
91  If the function returns true, then the uncopressed information
92  is stored in this buffer.
93  bFailedCRC - [out]
94  If not null, then this boolean is set to true if the CRC
95  of the uncompressed information has changed.
96  Returns:
97  True if uncompressed information is returned in outbuffer.
98  */
99  bool Uncompress( // read and uncompress
100  void* outbuffer, // uncompressed output data returned here
101  int* bFailedCRC
102  ) const;
103 
104  /*
105  Description:
106  Destroy the current informtion in the ON_CompressedBuffer
107  so the class can be reused.
108  */
109  void Destroy();
110 
111  bool Write( ON_BinaryArchive& binary_archive ) const;
112  bool Read( ON_BinaryArchive& binary_archive );
113 
114  /////////////////////////////////////////////////
115  //
116  // Implementation
117  //
118  bool CompressionInit( struct ON_CompressedBufferHelper* ) const;
119  bool CompressionEnd( struct ON_CompressedBufferHelper* ) const;
120  size_t DeflateHelper( // returns number of bytes written
121  struct ON_CompressedBufferHelper*,
122  size_t sizeof___inbuffer, // sizeof uncompressed input data ( > 0 )
123  const void* in___buffer // uncompressed input data ( != NULL )
124  );
125  bool InflateHelper(
126  struct ON_CompressedBufferHelper*,
127  size_t sizeof___outbuffer, // sizeof uncompressed data
128  void* out___buffer // buffer for uncompressed data
129  ) const;
130  bool WriteChar(
131  size_t count,
132  const void* buffer
133  );
134 
137  ON__UINT32 m_crc_uncompressed;
138  ON__UINT32 m_crc_compressed;
139  int m_method; // 0 = copied, 1 = compressed
143 };
144 
145 #endif