11 #ifndef UT_BLOSCCOMPRESSIONFILTER_H_
12 #define UT_BLOSCCOMPRESSIONFILTER_H_
36 int myCompressionLevel;
44 size_t myInputBufferUsage;
47 int64 currentLocation;
63 bool doShuffle =
true,
int compressionLevel = 9);
77 template<
typename Sink>
78 std::streamsize
write(Sink& dest,
const char* sourceBuffer,
79 std::streamsize sourceBufferSize);
81 template<
typename Sink>
82 void close(Sink& dest);
86 size_t typeSize,
size_t blockSize,
bool doShuffle,
int compressionLevel) :
87 myTypeSize(typeSize), myBlockSize(blockSize), myCompressionLevel(
88 compressionLevel), myDoShuffle(doShuffle), myInputBuffer(NULL), myOutputBuffer(
89 NULL), myInputBufferUsage(0), currentLocation(0),
index()
95 delete[] myInputBuffer;
96 delete[] myOutputBuffer;
106 return currentLocation;
113 myDoShuffle ? 1 : 0, myTypeSize, myInputBufferUsage, myInputBuffer,
116 myInputBufferUsage = 0;
119 if (compressedSize == -1)
121 std::cerr <<
"Problem compressing, blosc returned: " << compressedSize
125 return compressedSize;
128 template<
typename Sink>
130 const char* sourceBuffer, std::streamsize sourceBufferSize)
135 if (!myInputBuffer) {
137 myInputBuffer =
new char[myBlockSize];
142 std::streamsize totalRead = sourceBufferSize;
144 while (sourceBufferSize > 0)
148 std::streamsize ammountToCopy =
std::min(sourceBufferSize,
149 (std::streamsize) ((myBlockSize - myInputBufferUsage)));
150 memcpy(myInputBuffer + myInputBufferUsage, sourceBuffer, ammountToCopy);
151 myInputBufferUsage += ammountToCopy;
153 sourceBufferSize -= ammountToCopy;
154 sourceBuffer += ammountToCopy;
156 if (myInputBufferUsage == myBlockSize)
161 if (compressedSize == -1)
166 bios::write<Sink>(dest, myOutputBuffer, compressedSize);
169 currentLocation += compressedSize;
172 index.append(currentLocation);
179 template<
typename Sink>
183 if (myInputBufferUsage > 0)
186 std::streamsize uncompressedSize = myInputBufferUsage;
192 bios::write<Sink>(dest, myOutputBuffer, compressedSize);
196 currentLocation += compressedSize;
199 index.setBlockSize(myBlockSize, uncompressedSize);
211 index.setBlockSize(myBlockSize, myBlockSize);
exint getCurrentLocation()
Retrieves the current location in the file.
virtual ~UT_BloscCompressionFilter()
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
DLL_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)
std::streamsize write(Sink &dest, const char *sourceBuffer, std::streamsize sourceBufferSize)
#define BLOSC_MAX_OVERHEAD
std::streamsize doCompression()
UT_CompressedBlockIndex getIndex()
Retrieves the list of locations in the file where the blocks are.
UT_BloscCompressionFilter(size_t typeSize, size_t blockSize, bool doShuffle=true, int compressionLevel=9)