Skip to content

Commit

Permalink
[image] Use separate EStorageDataType to specify not set value
Browse files Browse the repository at this point in the history
  • Loading branch information
p12tic committed Oct 20, 2022
1 parent e5b63c7 commit b313aba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ std::string EStorageDataType_informations()
return EStorageDataType_enumToString(EStorageDataType::Float) + ", " +
EStorageDataType_enumToString(EStorageDataType::Half) + ", " +
EStorageDataType_enumToString(EStorageDataType::HalfFinite) + ", " +
EStorageDataType_enumToString(EStorageDataType::Auto);
EStorageDataType_enumToString(EStorageDataType::Auto) + ", " +
EStorageDataType_enumToString(EStorageDataType::Undefined);
}

EStorageDataType EStorageDataType_stringToEnum(const std::string& dataType)
Expand All @@ -167,6 +168,7 @@ EStorageDataType EStorageDataType_stringToEnum(const std::string& dataType)
if (type == "half") return EStorageDataType::Half;
if (type == "halffinite") return EStorageDataType::HalfFinite;
if (type == "auto") return EStorageDataType::Auto;
if (type == "undefined") return EStorageDataType::Undefined;

throw std::out_of_range("Invalid EStorageDataType: " + dataType);
}
Expand All @@ -179,6 +181,7 @@ std::string EStorageDataType_enumToString(const EStorageDataType dataType)
case EStorageDataType::Half: return "half";
case EStorageDataType::HalfFinite: return "halfFinite";
case EStorageDataType::Auto: return "auto";
case EStorageDataType::Undefined: return "undefined";
}
throw std::out_of_range("Invalid EStorageDataType enum");
}
Expand Down Expand Up @@ -586,7 +589,7 @@ void writeImage(const std::string& path,
// Storage data type may be saved as attributes to formats that support it and then come back
// as metadata to this function. Therefore we store the storage data type to attributes if it
// is set and load it from attributes if it isn't set.
if (options.isStorageDataTypeSet())
if (options.getStorageDataType() != EStorageDataType::Undefined)
{
imageSpec.attribute("AliceVision:storageDataType",
EStorageDataType_enumToString(options.getStorageDataType()));
Expand Down
8 changes: 3 additions & 5 deletions src/aliceVision/image/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ enum class EStorageDataType
Float, //< Use full floating point precision to store
Half, //< Use half (values our of range could become inf or nan)
HalfFinite, //< Use half, but ensures out-of-range pixels are clamps to keep finite pixel values
Auto //< Use half if all pixels can be stored in half without clamp, else use full float
Auto, //< Use half if all pixels can be stored in half without clamp, else use full float
Undefined //< Storage data type is not defined and should be inferred from other sources
};

std::string EStorageDataType_informations();
Expand Down Expand Up @@ -183,7 +184,6 @@ class ImageWriteOptions
EImageColorSpace getFromColorSpace() const { return _fromColorSpace; }
EImageColorSpace getToColorSpace() const { return _toColorSpace; }
EStorageDataType getStorageDataType() const { return _storageDataType; }
bool isStorageDataTypeSet() const { return _storageDataTypeSet; }

ImageWriteOptions& fromColorSpace(EImageColorSpace colorSpace)
{
Expand All @@ -200,15 +200,13 @@ class ImageWriteOptions
ImageWriteOptions& storageDataType(EStorageDataType storageDataType)
{
_storageDataType = storageDataType;
_storageDataTypeSet = true;
return *this;
}

private:
EImageColorSpace _fromColorSpace{EImageColorSpace::LINEAR};
EImageColorSpace _toColorSpace{EImageColorSpace::AUTO};
EStorageDataType _storageDataType{EStorageDataType::HalfFinite};
bool _storageDataTypeSet = false;
EStorageDataType _storageDataType{EStorageDataType::Undefined};
};

/**
Expand Down

0 comments on commit b313aba

Please sign in to comment.