Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[image] Introduce a function to retrieve ALICEVISION_ROOT #1268

Merged
merged 2 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,13 @@ void writeImage(const std::string& path,
}
else if((imageColorSpace != EImageColorSpace::LINEAR) && (imageColorSpace != EImageColorSpace::NO_CONVERSION)) // ACES or ACEScg
{
char const* val = getenv("ALICEVISION_ROOT");
if (val == NULL)
const auto colorConfigPath = getAliceVisionOCIOConfig();
if (colorConfigPath.empty())
{
throw std::runtime_error("ALICEVISION_ROOT is not defined, OCIO config file cannot be accessed.");
}
std::string configOCIOFilePath = std::string(val);
configOCIOFilePath.append("/share/aliceVision/config.ocio");

oiio::ColorConfig colorConfig(configOCIOFilePath);
oiio::ColorConfig colorConfig(colorConfigPath);
oiio::ImageBufAlgo::colorconvert(colorspaceBuf, *outBuf, "Linear",
(imageColorSpace != EImageColorSpace::ACES) ? "aces" : "ACEScg", true, "", "",
&colorConfig);
Expand Down Expand Up @@ -719,5 +717,27 @@ bool tryLoadMask(Image<unsigned char>* mask, const std::vector<std::string>& mas
return false;
}

static std::string aliceVisionRootOverride;

std::string getAliceVisionRoot()
{
if (!aliceVisionRootOverride.empty())
return aliceVisionRootOverride;
const char* value = std::getenv("ALICEVISION_ROOT");
return value ? value : "";
}

std::string getAliceVisionOCIOConfig()
{
if (!getAliceVisionRoot().empty())
return getAliceVisionRoot() + "/share/aliceVision/config.ocio";
return {};
}

void setAliceVisionRootOverride(const std::string& value)
{
aliceVisionRootOverride = value;
}

} // namespace image
} // namespace aliceVision
13 changes: 13 additions & 0 deletions src/aliceVision/image/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,18 @@ struct ColorTypeInfo<RGBAfColor>
bool tryLoadMask(Image<unsigned char>* mask, const std::vector<std::string>& masksFolders,
const IndexT viewId, const std::string & srcImage);

/**
* Returns the value of ALICEVISION_ROOT environmental variable, or empty string if it is not
* defined. The returned value can be overridden by `setAliceVisionRootOverride` if needed, for
* example in tests.
*/
// TODO: use std::optional when the C++ standard version is upgraded to C++17
std::string getAliceVisionRoot();

/// Returns path to OpenColorIO config that is shipped with aliceVision
std::string getAliceVisionOCIOConfig();

void setAliceVisionRootOverride(const std::string& value);

} // namespace image
} // namespace aliceVision
7 changes: 3 additions & 4 deletions src/software/pipeline/main_cameraInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,14 @@ int aliceVision_main(int argc, char **argv)
std::vector<sensorDB::Datasheet> sensorDatabase;
if (sensorDatabasePath.empty())
{
char const* val = getenv("ALICEVISION_ROOT");
if (val == NULL)
const auto root = image::getAliceVisionRoot();
if (root.empty())
{
ALICEVISION_LOG_WARNING("ALICEVISION_ROOT is not defined, default sensor database cannot be accessed.");
}
else
{
sensorDatabasePath = std::string(val);
sensorDatabasePath.append("/share/aliceVision/cameraSensors.db");
sensorDatabasePath = root + "/share/aliceVision/cameraSensors.db";
}
}

Expand Down