@@ -46,22 +46,25 @@ namespace compression {
46
46
#ifdef OPENVDB_USE_BLOSC
47
47
48
48
49
- bool bloscCanCompress ()
49
+ bool
50
+ bloscCanCompress ()
50
51
{
51
52
return true ;
52
53
}
53
54
54
55
55
- size_t bloscUncompressedSize (const char * buffer)
56
+ size_t
57
+ bloscUncompressedSize (const char * buffer)
56
58
{
57
59
size_t bytes, _1, _2;
58
60
blosc_cbuffer_sizes (buffer, &bytes, &_1, &_2);
59
61
return bytes;
60
62
}
61
63
62
64
63
- void bloscCompress ( char * compressedBuffer, size_t & compressedBytes, const size_t bufferBytes,
64
- const char * uncompressedBuffer, const size_t uncompressedBytes)
65
+ void
66
+ bloscCompress (char * compressedBuffer, size_t & compressedBytes, const size_t bufferBytes,
67
+ const char * uncompressedBuffer, const size_t uncompressedBytes)
65
68
{
66
69
if (bufferBytes > BLOSC_MAX_BUFFERSIZE) {
67
70
OPENVDB_LOG_DEBUG (" Blosc compress failed due to exceeding maximum buffer size." );
@@ -84,7 +87,8 @@ void bloscCompress( char* compressedBuffer, size_t& compressedBytes, const size_
84
87
}
85
88
86
89
if (uncompressedBytes < BLOSC_PAD_BYTES && bufferBytes < BLOSC_PAD_BYTES + BLOSC_MAX_OVERHEAD) {
87
- OPENVDB_LOG_DEBUG (" Blosc compress failed due to insufficient space in compressed buffer for padding." );
90
+ OPENVDB_LOG_DEBUG (
91
+ " Blosc compress failed due to insufficient space in compressed buffer for padding." );
88
92
compressedBytes = 0 ;
89
93
compressedBuffer = nullptr ;
90
94
return ;
@@ -120,7 +124,8 @@ void bloscCompress( char* compressedBuffer, size_t& compressedBytes, const size_
120
124
121
125
if (_compressedBytes <= 0 ) {
122
126
std::ostringstream ostr;
123
- ostr << " Blosc failed to compress " << uncompressedBytes << " byte" << (uncompressedBytes == 1 ? " " : " s" );
127
+ ostr << " Blosc failed to compress " << uncompressedBytes << " byte"
128
+ << (uncompressedBytes == 1 ? " " : " s" );
124
129
if (_compressedBytes < 0 ) ostr << " (internal error " << _compressedBytes << " )" ;
125
130
OPENVDB_LOG_DEBUG (ostr.str ());
126
131
compressedBytes = 0 ;
@@ -140,13 +145,17 @@ void bloscCompress( char* compressedBuffer, size_t& compressedBytes, const size_
140
145
}
141
146
142
147
143
- std::unique_ptr<char []> bloscCompress (const char * buffer, const size_t uncompressedBytes, size_t & compressedBytes, const bool resize)
148
+ std::unique_ptr<char []>
149
+ bloscCompress (const char * buffer, const size_t uncompressedBytes, size_t & compressedBytes,
150
+ const bool resize)
144
151
{
145
- size_t tempBytes = uncompressedBytes + BLOSC_MAX_OVERHEAD ;
152
+ size_t tempBytes = uncompressedBytes;
146
153
// increase temporary buffer for padding if necessary
147
154
if (tempBytes >= BLOSC_MINIMUM_BYTES && tempBytes < BLOSC_PAD_BYTES) {
148
- tempBytes += BLOSC_PAD_BYTES + BLOSC_MAX_OVERHEAD ;
155
+ tempBytes += BLOSC_PAD_BYTES;
149
156
}
157
+ // increase by Blosc max overhead
158
+ tempBytes += BLOSC_MAX_OVERHEAD;
150
159
const bool outOfRange = tempBytes > BLOSC_MAX_BUFFERSIZE;
151
160
std::unique_ptr<char []> outBuffer (outOfRange ? new char [1 ] : new char [tempBytes]);
152
161
@@ -169,23 +178,28 @@ std::unique_ptr<char[]> bloscCompress(const char* buffer, const size_t uncompres
169
178
}
170
179
171
180
172
- size_t bloscCompressedSize ( const char * buffer, const size_t uncompressedBytes)
181
+ size_t
182
+ bloscCompressedSize ( const char * buffer, const size_t uncompressedBytes)
173
183
{
174
184
size_t compressedBytes;
175
185
bloscCompress (buffer, uncompressedBytes, compressedBytes, /* resize=*/ false );
176
186
return compressedBytes;
177
187
}
178
188
179
189
180
- void bloscDecompress (char * uncompressedBuffer, const size_t expectedBytes, const size_t bufferBytes, const char * compressedBuffer)
190
+ void
191
+ bloscDecompress (char * uncompressedBuffer, const size_t expectedBytes,
192
+ const size_t bufferBytes, const char * compressedBuffer)
181
193
{
182
194
size_t uncompressedBytes = bloscUncompressedSize (compressedBuffer);
183
195
184
196
if (bufferBytes > BLOSC_MAX_BUFFERSIZE) {
185
- OPENVDB_THROW (RuntimeError, " Blosc decompress failed due to exceeding maximum buffer size." );
197
+ OPENVDB_THROW (RuntimeError,
198
+ " Blosc decompress failed due to exceeding maximum buffer size." );
186
199
}
187
200
if (bufferBytes < uncompressedBytes + BLOSC_MAX_OVERHEAD) {
188
- OPENVDB_THROW (RuntimeError, " Blosc decompress failed due to insufficient space in uncompressed buffer." );
201
+ OPENVDB_THROW (RuntimeError,
202
+ " Blosc decompress failed due to insufficient space in uncompressed buffer." );
189
203
}
190
204
191
205
uncompressedBytes = blosc_decompress_ctx ( /* src=*/ compressedBuffer,
@@ -208,7 +222,8 @@ void bloscDecompress(char* uncompressedBuffer, const size_t expectedBytes, const
208
222
}
209
223
210
224
211
- std::unique_ptr<char []> bloscDecompress (const char * buffer, const size_t expectedBytes, const bool resize)
225
+ std::unique_ptr<char []>
226
+ bloscDecompress (const char * buffer, const size_t expectedBytes, const bool resize)
212
227
{
213
228
size_t uncompressedBytes = bloscUncompressedSize (buffer);
214
229
size_t tempBytes = uncompressedBytes + BLOSC_MAX_OVERHEAD;
@@ -234,49 +249,55 @@ std::unique_ptr<char[]> bloscDecompress(const char* buffer, const size_t expecte
234
249
#else
235
250
236
251
237
- bool bloscCanCompress ()
252
+ bool
253
+ bloscCanCompress ()
238
254
{
239
255
OPENVDB_LOG_DEBUG (" Can't compress array data without the blosc library." );
240
256
return false ;
241
257
}
242
258
243
259
244
- size_t bloscUncompressedSize (const char *)
260
+ size_t
261
+ bloscUncompressedSize (const char *)
245
262
{
246
263
OPENVDB_THROW (RuntimeError, " Can't extract compressed data without the blosc library." );
247
264
}
248
265
249
266
250
- void bloscCompress ( char *, size_t & compressedBytes, const size_t ,
251
- const char *, const size_t )
267
+ void
268
+ bloscCompress ( char *, size_t & compressedBytes, const size_t , const char *, const size_t )
252
269
{
253
270
OPENVDB_LOG_DEBUG (" Can't compress array data without the blosc library." );
254
271
compressedBytes = 0 ;
255
272
}
256
273
257
274
258
- std::unique_ptr<char []> bloscCompress (const char *, const size_t , size_t & compressedBytes, const bool )
275
+ std::unique_ptr<char []>
276
+ bloscCompress (const char *, const size_t , size_t & compressedBytes, const bool )
259
277
{
260
278
OPENVDB_LOG_DEBUG (" Can't compress array data without the blosc library." );
261
279
compressedBytes = 0 ;
262
280
return nullptr ;
263
281
}
264
282
265
283
266
- size_t bloscCompressedSize (const char *, const size_t )
284
+ size_t
285
+ bloscCompressedSize (const char *, const size_t )
267
286
{
268
287
OPENVDB_LOG_DEBUG (" Can't compress array data without the blosc library." );
269
288
return 0 ;
270
289
}
271
290
272
291
273
- void bloscDecompress (char *, const size_t , const size_t , const char *)
292
+ void
293
+ bloscDecompress (char *, const size_t , const size_t , const char *)
274
294
{
275
295
OPENVDB_THROW (RuntimeError, " Can't extract compressed data without the blosc library." );
276
296
}
277
297
278
298
279
- std::unique_ptr<char []> bloscDecompress (const char *, const size_t , const bool )
299
+ std::unique_ptr<char []>
300
+ bloscDecompress (const char *, const size_t , const bool )
280
301
{
281
302
OPENVDB_THROW (RuntimeError, " Can't extract compressed data without the blosc library." );
282
303
}
@@ -288,28 +309,32 @@ std::unique_ptr<char[]> bloscDecompress(const char*, const size_t, const bool)
288
309
// //////////////////////////////////////
289
310
290
311
291
- void Page::load () const
312
+ void
313
+ Page::load () const
292
314
{
293
315
this ->doLoad ();
294
316
}
295
317
296
318
297
- long Page::uncompressedBytes () const
319
+ long
320
+ Page::uncompressedBytes () const
298
321
{
299
322
assert (mInfo );
300
323
return mInfo ->uncompressedBytes ;
301
324
}
302
325
303
326
304
- const char * Page::buffer (const int index) const
327
+ const char *
328
+ Page::buffer (const int index) const
305
329
{
306
330
if (this ->isOutOfCore ()) this ->load ();
307
331
308
332
return mData .get () + index ;
309
333
}
310
334
311
335
312
- void Page::readHeader (std::istream& is)
336
+ void
337
+ Page::readHeader (std::istream& is)
313
338
{
314
339
assert (mInfo );
315
340
@@ -330,7 +355,8 @@ void Page::readHeader(std::istream& is)
330
355
}
331
356
332
357
333
- void Page::readBuffers (std::istream&is, bool delayed)
358
+ void
359
+ Page::readBuffers (std::istream&is, bool delayed)
334
360
{
335
361
assert (mInfo );
336
362
@@ -345,7 +371,8 @@ void Page::readBuffers(std::istream&is, bool delayed)
345
371
std::streamoff filepos = is.tellg ();
346
372
347
373
// seek over the page
348
- is.seekg ((isCompressed ? mInfo ->compressedBytes : -mInfo ->compressedBytes ), std::ios_base::cur);
374
+ is.seekg ((isCompressed ? mInfo ->compressedBytes : -mInfo ->compressedBytes ),
375
+ std::ios_base::cur);
349
376
350
377
mInfo ->mappedFile = mappedFile;
351
378
mInfo ->meta = meta;
@@ -354,7 +381,8 @@ void Page::readBuffers(std::istream&is, bool delayed)
354
381
assert (mInfo ->mappedFile );
355
382
}
356
383
else {
357
- std::unique_ptr<char []> buffer (new char [(isCompressed ? mInfo ->compressedBytes : -mInfo ->compressedBytes )]);
384
+ std::unique_ptr<char []> buffer (new char [
385
+ (isCompressed ? mInfo ->compressedBytes : -mInfo ->compressedBytes )]);
358
386
is.read (buffer.get (), (isCompressed ? mInfo ->compressedBytes : -mInfo ->compressedBytes ));
359
387
360
388
if (mInfo ->compressedBytes > 0 ) {
@@ -367,20 +395,23 @@ void Page::readBuffers(std::istream&is, bool delayed)
367
395
}
368
396
369
397
370
- bool Page::isOutOfCore () const
398
+ bool
399
+ Page::isOutOfCore () const
371
400
{
372
401
return bool (mInfo );
373
402
}
374
403
375
404
376
- void Page::copy (const std::unique_ptr<char []>& temp, int pageSize)
405
+ void
406
+ Page::copy (const std::unique_ptr<char []>& temp, int pageSize)
377
407
{
378
408
mData .reset (new char [pageSize]);
379
409
std::memcpy (mData .get (), temp.get (), pageSize);
380
410
}
381
411
382
412
383
- void Page::decompress (const std::unique_ptr<char []>& temp)
413
+ void
414
+ Page::decompress (const std::unique_ptr<char []>& temp)
384
415
{
385
416
size_t uncompressedBytes = bloscUncompressedSize (temp.get ());
386
417
size_t tempBytes = uncompressedBytes;
@@ -393,7 +424,8 @@ void Page::decompress(const std::unique_ptr<char[]>& temp)
393
424
}
394
425
395
426
396
- void Page::doLoad () const
427
+ void
428
+ Page::doLoad () const
397
429
{
398
430
if (!this ->isOutOfCore ()) return ;
399
431
@@ -442,14 +474,16 @@ PageHandle::PageHandle( const Page::Ptr& page, const int index, const int size)
442
474
}
443
475
444
476
445
- Page& PageHandle::page ()
477
+ Page&
478
+ PageHandle::page ()
446
479
{
447
480
assert (mPage );
448
481
return *mPage ;
449
482
}
450
483
451
484
452
- std::unique_ptr<char []> PageHandle::read ()
485
+ std::unique_ptr<char []>
486
+ PageHandle::read ()
453
487
{
454
488
assert (mIndex >= 0 );
455
489
assert (mSize > 0 );
@@ -468,7 +502,8 @@ PagedInputStream::PagedInputStream(std::istream& is)
468
502
}
469
503
470
504
471
- PageHandle::Ptr PagedInputStream::createHandle (std::streamsize n)
505
+ PageHandle::Ptr
506
+ PagedInputStream::createHandle (std::streamsize n)
472
507
{
473
508
assert (mByteIndex <= mUncompressedBytes );
474
509
@@ -488,7 +523,8 @@ PageHandle::Ptr PagedInputStream::createHandle(std::streamsize n)
488
523
}
489
524
490
525
491
- void PagedInputStream::read (PageHandle::Ptr & pageHandle, std::streamsize n, bool delayed)
526
+ void
527
+ PagedInputStream::read (PageHandle::Ptr & pageHandle, std::streamsize n, bool delayed)
492
528
{
493
529
assert (mByteIndex <= mUncompressedBytes );
494
530
@@ -524,7 +560,8 @@ PagedOutputStream::PagedOutputStream(std::ostream& os)
524
560
}
525
561
526
562
527
- PagedOutputStream& PagedOutputStream::write (const char * str, std::streamsize n)
563
+ PagedOutputStream&
564
+ PagedOutputStream::write (const char * str, std::streamsize n)
528
565
{
529
566
if (n > PageSize) {
530
567
this ->flush ();
@@ -546,14 +583,16 @@ PagedOutputStream& PagedOutputStream::write(const char* str, std::streamsize n)
546
583
}
547
584
548
585
549
- void PagedOutputStream::flush ()
586
+ void
587
+ PagedOutputStream::flush ()
550
588
{
551
589
this ->compressAndWrite (mData .get (), mBytes );
552
590
mBytes = 0 ;
553
591
}
554
592
555
593
556
- void PagedOutputStream::compressAndWrite (const char * buffer, size_t size)
594
+ void
595
+ PagedOutputStream::compressAndWrite (const char * buffer, size_t size)
557
596
{
558
597
if (size == 0 ) return ;
559
598
@@ -598,7 +637,8 @@ void PagedOutputStream::compressAndWrite(const char* buffer, size_t size)
598
637
}
599
638
600
639
601
- void PagedOutputStream::resize (size_t size)
640
+ void
641
+ PagedOutputStream::resize (size_t size)
602
642
{
603
643
// grow the capacity if not sufficient space
604
644
size_t requiredSize = size;
0 commit comments