Skip to content

Commit

Permalink
[image] Introduce a function to retrieve ALICEVISION_ROOT
Browse files Browse the repository at this point in the history
This allows to override the returned value if needed, e.g. in tests.
  • Loading branch information
p12tic committed Oct 7, 2022
1 parent d3ad668 commit e81b73e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
23 changes: 18 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& root = getAliceVisionRoot();
if (root.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(root + "/share/aliceVision/config.ocio");
oiio::ImageBufAlgo::colorconvert(colorspaceBuf, *outBuf, "Linear",
(imageColorSpace != EImageColorSpace::ACES) ? "aces" : "ACEScg", true, "", "",
&colorConfig);
Expand Down Expand Up @@ -719,5 +717,20 @@ 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 : "";
}

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

} // namespace image
} // namespace aliceVision
10 changes: 10 additions & 0 deletions src/aliceVision/image/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,15 @@ 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();

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

0 comments on commit e81b73e

Please sign in to comment.