19 #ifndef OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
20 #define OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
23 #include <tbb/spin_mutex.h>
28 class TestStreamCompression;
33 namespace compression {
38 static const int BLOSC_MINIMUM_BYTES = 48;
42 static const int BLOSC_PAD_BYTES = 128;
61 const size_t bufferBytes,
const char* uncompressedBuffer,
const size_t uncompressedBytes);
72 const size_t uncompressedBytes,
size_t& compressedBytes,
const bool resize =
true);
88 const size_t bufferBytes,
const char* compressedBuffer);
98 const size_t expectedBytes,
const bool resize =
true);
105 static const int PageSize = 1024 * 1024;
116 #ifdef OPENVDB_USE_DELAYED_LOADING
117 io::MappedFile::Ptr mappedFile;
120 std::streamoff filepos;
121 long compressedBytes;
122 long uncompressedBytes;
126 using Ptr = std::shared_ptr<Page>;
135 long uncompressedBytes()
const;
142 void readHeader(std::istream&);
146 void readBuffers(std::istream&,
bool delayed);
149 bool isOutOfCore()
const;
153 void copy(
const std::unique_ptr<
char[]>& temp,
int pageSize);
156 void decompress(
const std::unique_ptr<
char[]>& temp);
161 std::unique_ptr<Info> mInfo = std::unique_ptr<Info>(
new Info);
162 std::unique_ptr<char[]> mData;
163 tbb::spin_mutex mMutex;
172 using Ptr = std::unique_ptr<PageHandle>;
184 int size()
const {
return mSize; }
188 std::unique_ptr<char[]> read();
194 friend class ::TestStreamCompression;
209 using Ptr = std::shared_ptr<PagedInputStream>;
229 void read(
PageHandle::Ptr& pageHandle, std::streamsize
n,
bool delayed =
true);
233 int mUncompressedBytes = 0;
234 std::istream* mIs =
nullptr;
236 bool mSizeOnly =
false;
246 using Ptr = std::shared_ptr<PagedOutputStream>;
269 void compressAndWrite(
const char* buffer,
size_t size);
274 std::unique_ptr<char[]> mData = std::unique_ptr<char[]>(
new char[PageSize]);
275 std::unique_ptr<char[]> mCompressedData =
nullptr;
276 size_t mCapacity = PageSize;
278 std::ostream* mOs =
nullptr;
279 bool mSizeOnly =
false;
287 #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.
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.