Skip to content

Commit

Permalink
[image io]
Browse files Browse the repository at this point in the history
Add log trace when OCIO config file found.
Update OCIO config file by removing the possibility to call the OCIO V1 method to identify the color space from the file name. Default color space is still sRGB.
When reading image, avoid searching input image color space if no conversion is needed.
  • Loading branch information
demoulinv committed Jun 1, 2022
1 parent cdb989b commit fd7deef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ std::string getColorConfigFilePath()
configOCIOFilePath.append("/share/aliceVision/config.ocio");

if (!fs::exists(configOCIOFilePath))
{
ALICEVISION_THROW_ERROR("OCIO configuration file: '" << configOCIOFilePath << "' does not exist.");
}
else
{
ALICEVISION_LOG_TRACE("OCIO configuration file: '" << configOCIOFilePath << "' found.");
}

return configOCIOFilePath;
}
Expand Down Expand Up @@ -406,14 +412,16 @@ void readImage(const std::string& path,
if(imageReadOptions.workingColorSpace == EImageColorSpace::AUTO)
throw std::runtime_error("You must specify a requested color space for image file '" + path + "'.");

std::string inputColorSpace = EImageColorSpace_enumToString(getImageColorSpace(path));

if ((imageReadOptions.workingColorSpace != EImageColorSpace::NO_CONVERSION) && (EImageColorSpace_stringToEnum(boost::to_lower_copy(inputColorSpace)) != imageReadOptions.workingColorSpace))
if (imageReadOptions.workingColorSpace != EImageColorSpace::NO_CONVERSION)
{
oiio::ColorConfig colorConfig(getColorConfigFilePath());
std::string outputColorSpace = (imageReadOptions.workingColorSpace == EImageColorSpace::SRGB_LINEAR) ? "linear" : EImageColorSpace_enumToString(imageReadOptions.workingColorSpace);
oiio::ImageBufAlgo::colorconvert(inBuf, inBuf, inputColorSpace, outputColorSpace, true, "", "", &colorConfig);
ALICEVISION_LOG_TRACE("Convert image " << path << " from " << inputColorSpace << " to " << outputColorSpace << " colorspace");
std::string inputColorSpace = EImageColorSpace_enumToString(getImageColorSpace(path));
if (EImageColorSpace_stringToEnum(boost::to_lower_copy(inputColorSpace)) != imageReadOptions.workingColorSpace)
{
oiio::ColorConfig colorConfig(getColorConfigFilePath());
std::string outputColorSpace = (imageReadOptions.workingColorSpace == EImageColorSpace::SRGB_LINEAR) ? "linear" : EImageColorSpace_enumToString(imageReadOptions.workingColorSpace);
oiio::ImageBufAlgo::colorconvert(inBuf, inBuf, inputColorSpace, outputColorSpace, true, "", "", &colorConfig);
ALICEVISION_LOG_TRACE("Convert image " << path << " from " << inputColorSpace << " to " << outputColorSpace << " colorspace");
}
}

// convert to grayscale if needed
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/image/io_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int setenv(const char* name, const char* value, int overwrite)
int err = setenv("ALICEVISION_ROOT", std::string(THIS_SOURCE_DIR).c_str(), 1);

// tested extensions
static std::vector<std::string> extensions = {"jpg", "png", "pgm", "ppm", "tiff", "exr"};
static std::vector<std::string> extensions = { "jpg", "png", "pgm", "ppm", "tiff", "exr" };

BOOST_AUTO_TEST_CASE(read_unexisting) {
Image<unsigned char> image;
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/image/share/aliceVision/config.ocio
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ file_rules:
#
# The next rule uses the OCIO v1 method of searching the path for all colorspaces in the config.
#
- !<Rule> {name: ColorSpaceNamePathSearch}
# - !<Rule> {name: ColorSpaceNamePathSearch}
#
# The rules are ordered, highest priority first. OCIO takes the path to a file and applies
# the rules one-by-one until there is a match. The last rule, "Default", always matches.
Expand Down

0 comments on commit fd7deef

Please sign in to comment.