Skip to content

Commit

Permalink
Merge pull request #896 from alicevision/dev/storageDataType
Browse files Browse the repository at this point in the history
[software] ImageProcessing: add storageDataType option
  • Loading branch information
fabiencastan authored Sep 20, 2020
2 parents d86b454 + 910edf7 commit 4608a84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ std::string EStorageDataType_enumToString(const EStorageDataType dataType)
{
switch (dataType)
{
case EStorageDataType::Float: return "Float";
case EStorageDataType::Half: return "Half";
case EStorageDataType::HalfFinite: return "HalfFinite";
case EStorageDataType::Auto: return "Auto";
case EStorageDataType::Float: return "float";
case EStorageDataType::Half: return "half";
case EStorageDataType::HalfFinite: return "halfFinite";
case EStorageDataType::Auto: return "auto";
}
throw std::out_of_range("Invalid EStorageDataType enum");
}
Expand Down
20 changes: 16 additions & 4 deletions src/software/utils/main_imageProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,14 @@ void processImage(image::Image<image::RGBAfColor>& image, const ProcessingParams

void saveImage(image::Image<image::RGBAfColor>& image, const std::string& inputPath, const std::string& outputPath,
const std::vector<std::string>& metadataFolders,
const EImageFormat& outputFormat)
const EImageFormat outputFormat, const image::EStorageDataType storageDataType)
{
// Read metadata path
std::string metadataFilePath;

const std::string filename = fs::path(inputPath).filename().string();
const std::string outExtension = boost::to_lower_copy(fs::path(outputPath).extension().string());
const bool isEXR = (outExtension == ".exr");
// If metadataFolders is specified
if(!metadataFolders.empty())
{
Expand Down Expand Up @@ -496,7 +498,13 @@ void saveImage(image::Image<image::RGBAfColor>& image, const std::string& inputP
metadataFilePath = inputPath;
}

const oiio::ParamValueList metadata = image::readImageMetadata(metadataFilePath);
oiio::ParamValueList metadata = image::readImageMetadata(metadataFilePath);

if(isEXR)
{
// Select storage data type
metadata.push_back(oiio::ParamValue("AliceVision:storageDataType", image::EStorageDataType_enumToString(storageDataType)));
}

// Save image
ALICEVISION_LOG_TRACE("Export image: '" << outputPath << "'.");
Expand Down Expand Up @@ -528,6 +536,7 @@ int aliceVision_main(int argc, char * argv[])
std::vector<std::string> metadataFolders;
std::string outputPath;
EImageFormat outputFormat = EImageFormat::RGBA;
image::EStorageDataType storageDataType = image::EStorageDataType::Float;
std::string extension;

ProcessingParams pParams;
Expand Down Expand Up @@ -603,6 +612,9 @@ int aliceVision_main(int argc, char * argv[])

("outputFormat", po::value<EImageFormat>(&outputFormat)->default_value(outputFormat),
"Output image format (rgba, rgb, grayscale)")

("storageDataType", po::value<image::EStorageDataType>(&storageDataType)->default_value(storageDataType),
("Storage data type: " + image::EStorageDataType_informations()).c_str())

("extension", po::value<std::string>(&extension)->default_value(extension),
"Output image extension (like exr, or empty to keep the source file format.")
Expand Down Expand Up @@ -760,7 +772,7 @@ int aliceVision_main(int argc, char * argv[])
processImage(image, pParams);

// Save the image
saveImage(image, viewPath, outputfilePath, metadataFolders, outputFormat);
saveImage(image, viewPath, outputfilePath, metadataFolders, outputFormat, storageDataType);

// Update view for this modification
view.setImagePath(outputfilePath);
Expand Down Expand Up @@ -855,7 +867,7 @@ int aliceVision_main(int argc, char * argv[])
processImage(image, pParams);

// Save the image
saveImage(image, inputFilePath, outputFilePath, metadataFolders, outputFormat);
saveImage(image, inputFilePath, outputFilePath, metadataFolders, outputFormat, storageDataType);
}
}

Expand Down

0 comments on commit 4608a84

Please sign in to comment.