Skip to content

Commit

Permalink
Update color space metadata extraction from read image.
Browse files Browse the repository at this point in the history
First, search AliceVision:ColorSpace metadata in oiio read buf.
If non-existent or invalid search oiio:ColorSpace metadata in read buf.
If still non-existent or invalid use filename to guess the color space by using the oiio::readmetadata function and then the OCIO configuration file if any.
  • Loading branch information
demoulinv committed Oct 10, 2022
1 parent c8a0c19 commit 4033e60
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ bool isValidColorSpace(std::string colorSpace)
{
const std::string CSlc = boost::to_lower_copy(colorSpace);

return (CSlc == "auto") || (CSlc == "linear") || (CSlc == "srgb") || (CSlc == "aces") || (CSlc == "acescg") || (CSlc == "no_conversion");
return (CSlc == "auto") || (CSlc == "linear") || (CSlc == "srgb") || (CSlc == "aces2065-1") || (CSlc == "acescg") || (CSlc == "no_conversion");
}

std::ostream& operator<<(std::ostream& os, EImageColorSpace dataType)
Expand Down Expand Up @@ -508,13 +508,17 @@ void readImage(const std::string& path,

if (imageReadOptions.workingColorSpace != EImageColorSpace::NO_CONVERSION)
{
std::string inputColorSpace = inBuf.spec().get_string_attribute("oiio:ColorSpace", "");
if (inputColorSpace.empty())
std::string inputColorSpace = inBuf.spec().get_string_attribute("AliceVision:ColorSpace", "");
if ((inputColorSpace.empty()) || !isValidColorSpace(inputColorSpace))
{
// Try to get color space using filename
inputColorSpace = EImageColorSpace_enumToString(getImageColorSpace(path));
inputColorSpace = inBuf.spec().get_string_attribute("oiio:ColorSpace", "");
if ((inputColorSpace.empty()) || !isValidColorSpace(inputColorSpace))
{
// Try to get color space using filename
inputColorSpace = EImageColorSpace_enumToString(getImageColorSpace(path));
}
}
if (EImageColorSpace_stringToEnum(boost::to_lower_copy(inputColorSpace)) != imageReadOptions.workingColorSpace)
if ((EImageColorSpace_stringToEnum(inputColorSpace) != imageReadOptions.workingColorSpace) && isValidColorSpace(inputColorSpace))
{
std::string outputColorSpace = (imageReadOptions.workingColorSpace == EImageColorSpace::LINEAR) ? "linear" : EImageColorSpace_enumToString(imageReadOptions.workingColorSpace);
oiio::ImageBufAlgo::colorconvert(inBuf, inBuf, inputColorSpace, outputColorSpace, true, "", "", &colorConfigOCIO);
Expand Down

0 comments on commit 4033e60

Please sign in to comment.