11 #ifndef UT_BLOSCCOMPRESSIONFILTER_H_
12 #define UT_BLOSCCOMPRESSIONFILTER_H_
38 int myCompressionLevel;
46 size_t myInputBufferUsage;
49 int64 myCurrentLocation;
65 bool doShuffle =
true,
int compressionLevel = 9);
87 template<
typename Sink>
88 std::streamsize
write(Sink& dest,
const char* sourceBuffer,
89 std::streamsize sourceBufferSize);
91 template<
typename Sink>
92 void close(Sink& dest);
100 : myTypeSize(typeSize)
101 , myBlockSize(blockSize)
102 , myCompressionLevel(compressionLevel)
103 , myDoShuffle(doShuffle)
104 , myInputBuffer(nullptr)
105 , myOutputBuffer(nullptr)
106 , myInputBufferUsage(0)
107 , myCurrentLocation(0)
117 : myTypeSize(copy.myTypeSize)
118 , myBlockSize(copy.myBlockSize)
119 , myCompressionLevel(copy.myCompressionLevel)
120 , myDoShuffle(copy.myDoShuffle)
121 , myInputBuffer(nullptr)
122 , myOutputBuffer(nullptr)
123 , myInputBufferUsage(0)
124 , myCurrentLocation(0)
134 myTypeSize = copy.myTypeSize;
135 myBlockSize = copy.myBlockSize;
136 myCompressionLevel = copy.myCompressionLevel;
137 myDoShuffle = copy.myDoShuffle;
139 myInputBuffer =
nullptr;
140 myOutputBuffer =
nullptr;
141 myInputBufferUsage = 0;
142 myCurrentLocation = 0;
157 return myCurrentLocation;
160 inline std::streamsize
165 myCompressionLevel, myDoShuffle ? 1 : 0, myTypeSize,
166 myInputBufferUsage, myInputBuffer.get(), myOutputBuffer.get(),
169 myInputBufferUsage = 0;
172 if (compressedSize == -1)
174 std::cerr <<
"Problem compressing, blosc returned: " << compressedSize
178 return compressedSize;
181 template <
typename Sink>
182 inline std::streamsize
185 const char* sourceBuffer,
186 std::streamsize sourceBufferSize)
191 if (!myInputBuffer) {
193 myInputBuffer = UTmakeUnique<char[]>(myBlockSize);
198 std::streamsize totalRead = sourceBufferSize;
200 while (sourceBufferSize > 0)
204 std::streamsize ammountToCopy =
std::min(sourceBufferSize,
205 (std::streamsize) ((myBlockSize - myInputBufferUsage)));
206 memcpy(myInputBuffer.get() + myInputBufferUsage, sourceBuffer,
208 myInputBufferUsage += ammountToCopy;
210 sourceBufferSize -= ammountToCopy;
211 sourceBuffer += ammountToCopy;
213 if (myInputBufferUsage == myBlockSize)
218 if (compressedSize == -1)
223 bios::write<Sink>(dest, myOutputBuffer.get(), compressedSize);
226 myCurrentLocation += compressedSize;
229 myBlockIndex.
append(myCurrentLocation);
236 template<
typename Sink>
241 if (myInputBufferUsage > 0)
244 std::streamsize uncompressedSize = myInputBufferUsage;
250 bios::write<Sink>(dest, myOutputBuffer.get(), compressedSize);
254 myCurrentLocation += compressedSize;
257 myBlockIndex.
setBlockSize(myBlockSize, uncompressedSize);
void setBlockSize(exint blockSize, exint lastBlockSize)
void removeLast()
Removes the last entry.
UT_BloscCompressionFilter & operator=(const UT_BloscCompressionFilter ©)
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
BLOSC_EXPORT int blosc_compress_ctx(int clevel, int doshuffle, size_t typesize, size_t nbytes, const void *src, void *dest, size_t destsize, const char *compressor, size_t blocksize, int numinternalthreads)
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
std::streamsize write(Sink &dest, const char *sourceBuffer, std::streamsize sourceBufferSize)
~UT_BloscCompressionFilter()=default
void append(BlockLocationType entry)
Adds entry to the end of the index.
#define BLOSC_MAX_OVERHEAD
UT_CompressedBlockIndex getIndex() const
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_14 uint8_t blockSize(VULKAN_HPP_NAMESPACE::Format format)
std::streamsize doCompression()
exint getCurrentLocation() const
Retrieves the current location in the file.
UT_BloscCompressionFilter(size_t typeSize, size_t blockSize, bool doShuffle=true, int compressionLevel=9)