19 #ifndef OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
20 #define OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
24 #include <tbb/spin_mutex.h>
29 class TestStreamCompression;
34 namespace compression {
39 static const int BLOSC_MINIMUM_BYTES = 48;
43 static const int BLOSC_PAD_BYTES = 128;
62 const size_t bufferBytes,
const char* uncompressedBuffer,
const size_t uncompressedBytes);
73 const size_t uncompressedBytes,
size_t& compressedBytes,
const bool resize =
true);
89 const size_t bufferBytes,
const char* compressedBuffer);
99 const size_t expectedBytes,
const bool resize =
true);
106 static const int PageSize = 1024 * 1024;
117 #ifdef OPENVDB_USE_DELAYED_LOADING
118 io::MappedFile::Ptr mappedFile;
121 std::streamoff filepos;
122 long compressedBytes;
123 long uncompressedBytes;
127 using Ptr = std::shared_ptr<Page>;
136 long uncompressedBytes()
const;
143 void readHeader(std::istream&);
147 void readBuffers(std::istream&,
bool delayed);
150 bool isOutOfCore()
const;
154 void copy(
const std::unique_ptr<
char[]>& temp,
int pageSize);
157 void decompress(
const std::unique_ptr<
char[]>& temp);
162 std::unique_ptr<Info> mInfo = std::unique_ptr<Info>(
new Info);
163 std::unique_ptr<char[]> mData;
164 tbb::spin_mutex mMutex;
173 using Ptr = std::unique_ptr<PageHandle>;
185 int size()
const {
return mSize; }
189 std::unique_ptr<char[]> read();
195 friend class ::TestStreamCompression;
210 using Ptr = std::shared_ptr<PagedInputStream>;
230 void read(
PageHandle::Ptr& pageHandle, std::streamsize
n,
bool delayed =
true);
234 int mUncompressedBytes = 0;
235 std::istream* mIs =
nullptr;
237 bool mSizeOnly =
false;
247 using Ptr = std::shared_ptr<PagedOutputStream>;
270 void compressAndWrite(
const char* buffer,
size_t size);
275 std::unique_ptr<char[]> mData = std::unique_ptr<char[]>(
new char[PageSize]);
276 std::unique_ptr<char[]> mCompressedData =
nullptr;
277 size_t mCapacity = PageSize;
279 std::ostream* mOs =
nullptr;
280 bool mSizeOnly =
false;
288 #endif // OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
std::unique_ptr< PageHandle > Ptr
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
#define OPENVDB_USE_VERSION_NAMESPACE
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
std::ostream & getOutputStream()
Set and get the output stream.
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
#define OPENVDB_ASSERT(X)
std::shared_ptr< T > SharedPtr
A PageHandle holds a unique ptr to a Page and a specific stream pointer to a point within the decompr...
std::shared_ptr< Page > Ptr
void setInputStream(std::istream &is)
OPENVDB_API void bloscDecompress(char *uncompressedBuffer, const size_t expectedBytes, const size_t bufferBytes, const char *compressedBuffer)
Decompress into the supplied buffer. Will throw if decompression fails or uncompressed buffer has ins...
std::istream & getInputStream()
Ptr copy()
Return a copy of this PageHandle.
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
ImageBuf OIIO_API resize(const ImageBuf &src, string_view filtername="", float filterwidth=0.0f, ROI roi={}, int nthreads=0)
int size() const
Return the size of the buffer.
Stores a variable-size, compressed, delayed-load Page of data that is loaded into memory when accesse...
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
OPENVDB_API bool bloscCanCompress()
Returns true if compression is available.
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
OPENVDB_API size_t bloscUncompressedSize(const char *buffer)
Retrieves the uncompressed size of buffer when uncompressed.
std::shared_ptr< PagedOutputStream > Ptr
std::shared_ptr< PagedInputStream > Ptr
void setOutputStream(std::ostream &os)
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.