8686 /* 2*/ NO_MASK_AND_ONE_INACTIVE_VAL, // all inactive vals have the same non-background val
8787 /* 3*/ MASK_AND_NO_INACTIVE_VALS, // mask selects between -background and +background
8888 /* 4*/ MASK_AND_ONE_INACTIVE_VAL, // mask selects between backgd and one other inactive val
89- /* 5*/ MASK_AND_TWO_INACTIVE_VALS // mask selects between two non-background inactive vals
89+ /* 5*/ MASK_AND_TWO_INACTIVE_VALS, // mask selects between two non-background inactive vals
90+ /* 6*/ NO_MASK_AND_ALL_VALS // > 2 inactive vals, so no mask compression at all
9091};
9192
9293
@@ -282,7 +283,7 @@ readCompressedValues(std::istream& is, ValueT* destBuf, Index destCount,
282283 zipped = compression & COMPRESS_ZIP,
283284 maskCompressed = compression & COMPRESS_ACTIVE_MASK;
284285
285- int8_t metadata = NO_MASK_OR_INACTIVE_VALS ;
286+ int8_t metadata = NO_MASK_AND_ALL_VALS ;
286287 if (getFormatVersion (is) >= OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
287288 // Read the flag that specifies what, if any, additional metadata
288289 // (selection mask and/or inactive value(s)) is saved.
@@ -297,9 +298,9 @@ readCompressedValues(std::istream& is, ValueT* destBuf, Index destCount,
297298 ValueT inactiveVal0 =
298299 ((metadata == NO_MASK_OR_INACTIVE_VALS) ? background : math::negative (background));
299300
300- if (metadata != NO_MASK_OR_INACTIVE_VALS &&
301- metadata != NO_MASK_AND_MINUS_BG &&
302- metadata != MASK_AND_NO_INACTIVE_VALS )
301+ if (metadata == NO_MASK_AND_ONE_INACTIVE_VAL ||
302+ metadata == MASK_AND_ONE_INACTIVE_VAL ||
303+ metadata == MASK_AND_TWO_INACTIVE_VALS )
303304 {
304305 // Read one of at most two distinct inactive values.
305306 is.read (reinterpret_cast <char *>(&inactiveVal0), sizeof (ValueT));
@@ -310,9 +311,9 @@ readCompressedValues(std::istream& is, ValueT* destBuf, Index destCount,
310311 }
311312
312313 MaskT selectionMask;
313- if (metadata != NO_MASK_OR_INACTIVE_VALS &&
314- metadata != NO_MASK_AND_MINUS_BG &&
315- metadata != NO_MASK_AND_ONE_INACTIVE_VAL )
314+ if (metadata == MASK_AND_NO_INACTIVE_VALS ||
315+ metadata == MASK_AND_ONE_INACTIVE_VAL ||
316+ metadata == MASK_AND_TWO_INACTIVE_VALS )
316317 {
317318 // For use in mask compression (only), read the bitmask that selects
318319 // between two distinct inactive values.
@@ -323,7 +324,9 @@ readCompressedValues(std::istream& is, ValueT* destBuf, Index destCount,
323324 boost::scoped_array<ValueT> scopedTempBuf;
324325
325326 Index tempCount = destCount;
326- if (maskCompressed && getFormatVersion (is) >= OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
327+ if (maskCompressed && metadata != NO_MASK_AND_ALL_VALS
328+ && getFormatVersion (is) >= OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION)
329+ {
327330 tempCount = valueMask.countOn ();
328331 if (tempCount != destCount) {
329332 // If this node has inactive voxels, allocate a temporary buffer
@@ -395,7 +398,7 @@ writeCompressedValues(std::ostream& os, ValueT* srcBuf, Index srcCount,
395398 ValueT* tempBuf = srcBuf;
396399 boost::scoped_array<ValueT> scopedTempBuf;
397400
398- int8_t metadata = NO_MASK_OR_INACTIVE_VALS ;
401+ int8_t metadata = NO_MASK_AND_ALL_VALS ;
399402
400403 if (!maskCompress) {
401404 os.write (reinterpret_cast <const char *>(&metadata), /* bytes=*/ 1 );
@@ -478,13 +481,15 @@ writeCompressedValues(std::ostream& os, ValueT* srcBuf, Index srcCount,
478481 metadata = MASK_AND_ONE_INACTIVE_VAL;
479482 }
480483 }
484+ } else if (numUniqueInactiveVals > 2 ) {
485+ metadata = NO_MASK_AND_ALL_VALS;
481486 }
482487
483488 os.write (reinterpret_cast <const char *>(&metadata), /* bytes=*/ 1 );
484489
485- if (metadata != NO_MASK_OR_INACTIVE_VALS &&
486- metadata != NO_MASK_AND_MINUS_BG &&
487- metadata != MASK_AND_NO_INACTIVE_VALS )
490+ if (metadata == NO_MASK_AND_ONE_INACTIVE_VAL ||
491+ metadata == MASK_AND_ONE_INACTIVE_VAL ||
492+ metadata == MASK_AND_TWO_INACTIVE_VALS )
488493 {
489494 if (!toHalf) {
490495 // Write one of at most two distinct inactive values.
@@ -505,7 +510,7 @@ writeCompressedValues(std::ostream& os, ValueT* srcBuf, Index srcCount,
505510 }
506511 }
507512
508- if (metadata == NO_MASK_OR_INACTIVE_VALS && numUniqueInactiveVals > 2 ) {
513+ if (metadata == NO_MASK_AND_ALL_VALS ) {
509514 // If there are more than two unique inactive values, the entire input buffer
510515 // needs to be saved (both active and inactive values).
511516 // / @todo Save the selection mask as long as most of the inactive values
0 commit comments