Skip to content

Commit

Permalink
SRGB_LINEAR becomes LINEAR to be more compliant with the OCIO config …
Browse files Browse the repository at this point in the history
…file that defines a matching between the keyword Linear and a color space also defined in the file.

Search of OCIO config file strategy update :
First try with the ALICEVISION_OCIO env variable.
If unsuccessful, second try with the standardized OCIO env variable.
If unsuccessful, third try with ALICEVISION_ROOT env variable to extract the embedded config file.
  • Loading branch information
demoulinv committed Sep 30, 2022
1 parent 6aec0eb commit 4889a6b
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class CommonDataByPair_vldSegment : public CommonDataByPair
image::Image< unsigned char > & maskRight )
{
image::Image< unsigned char > imageL, imageR;
image::readImage( _sLeftImage, imageL, image::EImageColorSpace::SRGB_LINEAR);
image::readImage( _sRightImage, imageR, image::EImageColorSpace::SRGB_LINEAR);
image::readImage( _sLeftImage, imageL, image::EImageColorSpace::LINEAR);
image::readImage( _sRightImage, imageR, image::EImageColorSpace::LINEAR);

image::Image< float > imgA ( imageL.GetMat().cast< float >() );
image::Image< float > imgB(imageR.GetMat().cast< float >());
Expand Down
4 changes: 2 additions & 2 deletions src/aliceVision/depthMap/depthMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void estimateAndRefineDepthMaps(int cudaDeviceIndex, mvsUtils::MultiViewParams&
computeScaleStepSgmParams(mp, sgmParams);

// load images from files into RAM
mvsUtils::ImagesCache<ImageRGBAf> ic(mp, imageIO::EImageColorSpace::SRGB_LINEAR);
mvsUtils::ImagesCache<ImageRGBAf> ic(mp, imageIO::EImageColorSpace::LINEAR);

// load stuff on GPU memory and creates multi-level images and computes gradients
PlaneSweepingCuda cps(cudaDeviceIndex, ic, mp, sgmParams.scale);
Expand Down Expand Up @@ -115,7 +115,7 @@ void computeNormalMaps(int cudaDeviceIndex, mvsUtils::MultiViewParams& mp, const
const float gammaP = 1.0f;
const int wsh = 3;

mvsUtils::ImagesCache<ImageRGBAf> ic(mp, EImageColorSpace::SRGB_LINEAR);
mvsUtils::ImagesCache<ImageRGBAf> ic(mp, EImageColorSpace::LINEAR);
PlaneSweepingCuda cps(cudaDeviceIndex, ic, mp, 1);

NormalMapping* mapping = cps.createNormalMapping();
Expand Down
92 changes: 66 additions & 26 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,62 @@ namespace
{
std::string getDefaultColorConfigFilePath()
{
char const* val = getenv("ALICEVISION_ROOT");
if (val == NULL)
std::string configOCIOFilePath = "";

char const* ALICEVISION_OCIO = getenv("ALICEVISION_OCIO");
if (ALICEVISION_OCIO != NULL)
{
configOCIOFilePath = std::string(ALICEVISION_OCIO);
if (fs::exists(configOCIOFilePath))
{
ALICEVISION_LOG_TRACE("ALICEVISION_OCIO configuration file: '" << configOCIOFilePath << "' found.");
return configOCIOFilePath;
}
else if (configOCIOFilePath == "")
{
ALICEVISION_LOG_TRACE("ALICEVISION_OCIO is empty. Try OCIO...");
}
else
{
ALICEVISION_LOG_TRACE("ALICEVISION_OCIO does not point to an existing file. Try OCIO...");
}
}

char const* OCIO = getenv("OCIO");
if (OCIO != NULL)
{
configOCIOFilePath = std::string(OCIO);
if (fs::exists(configOCIOFilePath))
{
ALICEVISION_LOG_TRACE("OCIO configuration file: '" << configOCIOFilePath << "' found.");
return configOCIOFilePath;
}
else if (configOCIOFilePath == "")
{
ALICEVISION_LOG_TRACE("OCIO is empty. Use embedded config...");
}
else
{
ALICEVISION_LOG_TRACE("OCIO does not point to an existing file. Use embedded config...");
}
}

char const* ALICEVISION_ROOT = getenv("ALICEVISION_ROOT");
if (ALICEVISION_ROOT == NULL)
{
ALICEVISION_THROW_ERROR("ALICEVISION_ROOT is not defined, OCIO config file cannot be accessed.");
ALICEVISION_THROW_ERROR("ALICEVISION_ROOT is not defined, embedded OCIO config file cannot be accessed.");
}
std::string configOCIOFilePath = std::string(val);
configOCIOFilePath = std::string(ALICEVISION_ROOT);
configOCIOFilePath.append("/share/aliceVision/config.ocio");

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

return configOCIOFilePath;
Expand Down Expand Up @@ -78,9 +118,9 @@ void initColorConfigOCIO(const std::string& colorConfigFilePath)
std::string EImageColorSpace_informations()
{
return EImageColorSpace_enumToString(EImageColorSpace::AUTO) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::SRGB_LINEAR) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::LINEAR) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::SRGB) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::ACES) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::ACES2065_1) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::ACEScg) + ", " +
EImageColorSpace_enumToString(EImageColorSpace::NO_CONVERSION);
}
Expand All @@ -91,12 +131,12 @@ EImageColorSpace EImageColorSpace_stringToEnum(const std::string& dataType)

if(type == "auto")
return EImageColorSpace::AUTO;
if((type == "srgb_linear")||(type == "linear"))
return EImageColorSpace::SRGB_LINEAR;
if(type == "linear")
return EImageColorSpace::LINEAR;
if(type == "srgb")
return EImageColorSpace::SRGB;
if(type == "aces")
return EImageColorSpace::ACES;
if(type == "ACES2065-1")
return EImageColorSpace::ACES2065_1;
if(type == "acescg")
return EImageColorSpace::ACEScg;
if(type == "no_conversion")
Expand All @@ -111,12 +151,12 @@ std::string EImageColorSpace_enumToString(const EImageColorSpace dataType)
{
case EImageColorSpace::AUTO:
return "auto";
case EImageColorSpace::SRGB_LINEAR:
return "srgb_linear";
case EImageColorSpace::LINEAR:
return "linear";
case EImageColorSpace::SRGB:
return "srgb";
case EImageColorSpace::ACES:
return "aces";
case EImageColorSpace::ACES2065_1:
return "ACES2065-1";
case EImageColorSpace::ACEScg:
return "acescg";
case EImageColorSpace::NO_CONVERSION:
Expand All @@ -129,7 +169,7 @@ bool isValidColorSpace(std::string colorSpace)
{
const std::string CSlc = boost::to_lower_copy(colorSpace);

return (CSlc == "auto") || (CSlc == "srgb_linear") || (CSlc == "linear") || (CSlc == "srgb") || (CSlc == "aces") || (CSlc == "acescg") || (CSlc == "no_conversion");
return (CSlc == "auto") || (CSlc == "linear") || (CSlc == "srgb") || (CSlc == "aces") || (CSlc == "acescg") || (CSlc == "no_conversion");
}

std::ostream& operator<<(std::ostream& os, EImageColorSpace dataType)
Expand Down Expand Up @@ -183,7 +223,7 @@ EImageColorSpace getImageColorSpace(const std::string imagePath)
{
size_t npos = imagePath.find_last_of(".");
std::string ext = imagePath.substr(npos + 1);
std::string forcedColorSpace = (ext == "exr" || ext == "EXR") ? "sRGB_linear" : "sRGB";
std::string forcedColorSpace = (ext == "exr" || ext == "EXR") ? "linear" : "sRGB";

ALICEVISION_LOG_WARNING("The color space " << colorSpace << " detected for " << imagePath << " is not supported. Force Color space to " << forcedColorSpace << ".");
colorSpace = forcedColorSpace;
Expand Down Expand Up @@ -458,7 +498,7 @@ void readImage(const std::string& path,
inputColorSpace = EImageColorSpace_enumToString(getImageColorSpace(path));
if (EImageColorSpace_stringToEnum(boost::to_lower_copy(inputColorSpace)) != imageReadOptions.workingColorSpace)
{
std::string outputColorSpace = (imageReadOptions.workingColorSpace == EImageColorSpace::SRGB_LINEAR) ? "linear" : EImageColorSpace_enumToString(imageReadOptions.workingColorSpace);
std::string outputColorSpace = (imageReadOptions.workingColorSpace == EImageColorSpace::LINEAR) ? "linear" : EImageColorSpace_enumToString(imageReadOptions.workingColorSpace);
oiio::ImageBufAlgo::colorconvert(inBuf, inBuf, inputColorSpace, outputColorSpace, true, "", "", &colorConfigOCIO);
ALICEVISION_LOG_TRACE("Convert image " << path << " from " << inputColorSpace << " to " << outputColorSpace << " colorspace");
}
Expand Down Expand Up @@ -591,7 +631,7 @@ void writeImage(const std::string& path,
if(isJPG || isPNG)
outputImageColorSpace = EImageColorSpace::SRGB;
else
outputImageColorSpace = EImageColorSpace::SRGB_LINEAR;
outputImageColorSpace = EImageColorSpace::LINEAR;
}

oiio::ImageSpec imageSpec(image.Width(), image.Height(), nchannels, typeDesc);
Expand All @@ -611,16 +651,16 @@ void writeImage(const std::string& path,
const oiio::ImageBuf* outBuf = &imgBuf; // buffer to write

oiio::ImageBuf colorspaceBuf; // buffer for image colorspace modification
if(((outputImageColorSpace == EImageColorSpace::SRGB) && (EImageColorSpace_stringToEnum(currentColorSpace) == EImageColorSpace::SRGB_LINEAR)) ||
((outputImageColorSpace == EImageColorSpace::SRGB_LINEAR) && (EImageColorSpace_stringToEnum(currentColorSpace) == EImageColorSpace::SRGB)))
if(((outputImageColorSpace == EImageColorSpace::SRGB) && (EImageColorSpace_stringToEnum(currentColorSpace) == EImageColorSpace::LINEAR)) ||
((outputImageColorSpace == EImageColorSpace::LINEAR) && (EImageColorSpace_stringToEnum(currentColorSpace) == EImageColorSpace::SRGB)))
{
oiio::ImageBufAlgo::colorconvert(colorspaceBuf, *outBuf, currentColorSpace, EImageColorSpace_enumToString(outputImageColorSpace));
outBuf = &colorspaceBuf;
}
else if((outputImageColorSpace != EImageColorSpace_stringToEnum(currentColorSpace)) && (outputImageColorSpace != EImageColorSpace::NO_CONVERSION))
{
oiio::ImageBufAlgo::colorconvert(colorspaceBuf, *outBuf, currentColorSpace,
(outputImageColorSpace == EImageColorSpace::SRGB_LINEAR) ? "Linear" : EImageColorSpace_enumToString(outputImageColorSpace),
(outputImageColorSpace == EImageColorSpace::LINEAR) ? "Linear" : EImageColorSpace_enumToString(outputImageColorSpace),
true, "", "", &colorConfigOCIO);
outBuf = &colorspaceBuf;
}
Expand Down Expand Up @@ -686,7 +726,7 @@ void writeImageNoFloat(const std::string& path,
if(isJPG || isPNG)
imageColorSpace = EImageColorSpace::SRGB;
else
imageColorSpace = EImageColorSpace::SRGB_LINEAR;
imageColorSpace = EImageColorSpace::LINEAR;
}

oiio::ImageSpec imageSpec(image.Width(), image.Height(), 1, typeDesc);
Expand Down Expand Up @@ -807,12 +847,12 @@ bool tryLoadMask(Image<unsigned char>* mask, const std::vector<std::string>& mas

if (fs::exists(idMaskPath))
{
readImage(idMaskPath.string(), *mask, EImageColorSpace::SRGB_LINEAR);
readImage(idMaskPath.string(), *mask, EImageColorSpace::LINEAR);
return true;
}
else if (fs::exists(nameMaskPath))
{
readImage(nameMaskPath.string(), *mask, EImageColorSpace::SRGB_LINEAR);
readImage(nameMaskPath.string(), *mask, EImageColorSpace::LINEAR);
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/aliceVision/image/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace image {
enum class EImageColorSpace
{
AUTO,
SRGB_LINEAR,
LINEAR,
SRGB,
ACES,
ACES2065_1,
ACEScg,
NO_CONVERSION
};
Expand Down
14 changes: 7 additions & 7 deletions src/aliceVision/mvsData/imageAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ void colorconvert(oiio::ImageBuf& imgBuf, imageIO::EImageColorSpace fromColorSpa
if(fromColorSpace == toColorSpace)
return;

else if(toColorSpace == EImageColorSpace::SRGB_LINEAR)
else if(toColorSpace == EImageColorSpace::LINEAR)
{
if(fromColorSpace == EImageColorSpace::SRGB)
oiio::ImageBufAlgo::colorconvert(imgBuf, imgBuf,
EImageColorSpace_enumToString(EImageColorSpace::SRGB), EImageColorSpace_enumToString(EImageColorSpace::SRGB_LINEAR));
EImageColorSpace_enumToString(EImageColorSpace::SRGB), EImageColorSpace_enumToString(EImageColorSpace::LINEAR));
else if(fromColorSpace == EImageColorSpace::XYZ)
processImage(imgBuf, &XYZtoRGB);
else if(fromColorSpace == EImageColorSpace::LAB)
Expand All @@ -133,29 +133,29 @@ void colorconvert(oiio::ImageBuf& imgBuf, imageIO::EImageColorSpace fromColorSpa
else if(fromColorSpace == EImageColorSpace::LAB)
processImage(imgBuf, &LABtoRGB);
oiio::ImageBufAlgo::colorconvert(imgBuf, imgBuf,
EImageColorSpace_enumToString(EImageColorSpace::SRGB_LINEAR), EImageColorSpace_enumToString(EImageColorSpace::SRGB));
EImageColorSpace_enumToString(EImageColorSpace::LINEAR), EImageColorSpace_enumToString(EImageColorSpace::SRGB));
}
else if(toColorSpace == EImageColorSpace::XYZ)
{
if(fromColorSpace == EImageColorSpace::SRGB_LINEAR)
if(fromColorSpace == EImageColorSpace::LINEAR)
processImage(imgBuf, &RGBtoXYZ);
else if(fromColorSpace == EImageColorSpace::SRGB)
{
oiio::ImageBufAlgo::colorconvert(imgBuf, imgBuf,
EImageColorSpace_enumToString(EImageColorSpace::SRGB), EImageColorSpace_enumToString(EImageColorSpace::SRGB_LINEAR));
EImageColorSpace_enumToString(EImageColorSpace::SRGB), EImageColorSpace_enumToString(EImageColorSpace::LINEAR));
processImage(imgBuf, &RGBtoXYZ);
}
else if(fromColorSpace == EImageColorSpace::LAB)
processImage(imgBuf, &LABtoXYZ);
}
else if(toColorSpace == EImageColorSpace::LAB)
{
if(fromColorSpace == EImageColorSpace::SRGB_LINEAR)
if(fromColorSpace == EImageColorSpace::LINEAR)
processImage(imgBuf, &RGBtoLAB);
else if(fromColorSpace == EImageColorSpace::SRGB)
{
oiio::ImageBufAlgo::colorconvert(imgBuf, imgBuf,
EImageColorSpace_enumToString(EImageColorSpace::SRGB), EImageColorSpace_enumToString(EImageColorSpace::SRGB_LINEAR));
EImageColorSpace_enumToString(EImageColorSpace::SRGB), EImageColorSpace_enumToString(EImageColorSpace::LINEAR));
processImage(imgBuf, &RGBtoLAB);
}
else if(fromColorSpace == EImageColorSpace::XYZ)
Expand Down
6 changes: 3 additions & 3 deletions src/aliceVision/mvsData/imageIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::string EImageColorSpace_enumToString(const EImageColorSpace colorSpace)
switch(colorSpace)
{
case EImageColorSpace::SRGB: return "sRGB"; // WARNING: string should match with OIIO definitions or implemented conversion
case EImageColorSpace::SRGB_LINEAR: return "Linear";
case EImageColorSpace::LINEAR: return "Linear";
case EImageColorSpace::LAB: return "LAB";
case EImageColorSpace::XYZ: return "XYZ";
default: ;
Expand All @@ -52,7 +52,7 @@ std::string EImageColorSpace_enumToString(const EImageColorSpace colorSpace)

EImageColorSpace EImageColorSpace_stringToEnum(const std::string& colorspace)
{
if(colorspace == "Linear") return EImageColorSpace::SRGB_LINEAR;
if(colorspace == "Linear") return EImageColorSpace::LINEAR;
if(colorspace == "sRGB") return EImageColorSpace::SRGB;
if(colorspace == "LAB") return EImageColorSpace::LAB;
if(colorspace == "XYZ") return EImageColorSpace::XYZ;
Expand Down Expand Up @@ -400,7 +400,7 @@ void writeImage(const std::string& path,
if(isJPG || isPNG)
colorspace.to = EImageColorSpace::SRGB;
else
colorspace.to = EImageColorSpace::SRGB_LINEAR;
colorspace.to = EImageColorSpace::LINEAR;
}


Expand Down
4 changes: 2 additions & 2 deletions src/aliceVision/mvsData/imageIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum class EImageFileType
enum class EImageColorSpace
{
AUTO,
SRGB_LINEAR,
LINEAR,
SRGB,
LAB,
XYZ,
Expand All @@ -51,7 +51,7 @@ enum class EImageColorSpace

struct OutputFileColorSpace
{
EImageColorSpace from{EImageColorSpace::SRGB_LINEAR};
EImageColorSpace from{EImageColorSpace::LINEAR};
EImageColorSpace to{EImageColorSpace::AUTO};

OutputFileColorSpace(EImageColorSpace from_, EImageColorSpace to_)
Expand Down
4 changes: 2 additions & 2 deletions src/aliceVision/mvsUtils/fileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void loadImage(const std::string& path, const MultiViewParams& mp, int camId, Im
// if exposure correction, apply it in linear colorspace and then convert colorspace
else
{
imageIO::readImage(path, img, imageIO::EImageColorSpace::SRGB_LINEAR);
imageIO::readImage(path, img, imageIO::EImageColorSpace::LINEAR);
checkImageSize();

oiio::ParamValueList metadata;
Expand All @@ -357,7 +357,7 @@ void loadImage(const std::string& path, const MultiViewParams& mp, int camId, Im
for(int pix = 0; pix < img.size(); ++pix)
img[pix] = img[pix] * exposureCompensation;

imageAlgo::colorconvert(img, imageIO::EImageColorSpace::SRGB_LINEAR, colorspace);
imageAlgo::colorconvert(img, imageIO::EImageColorSpace::LINEAR, colorspace);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ int main(int argc, char **argv)
std::mt19937 randomNumberGenerator;

Image<float> imageLeft;
readImage(filenameLeft, imageLeft, EImageColorSpace::SRGB_LINEAR);
readImage(filenameLeft, imageLeft, EImageColorSpace::LINEAR);
const auto imageLeftSize = std::make_pair(imageLeft.Width(), imageLeft.Height());
Image<float> imageRight;
readImage(filenameRight, imageRight, EImageColorSpace::SRGB_LINEAR);
readImage(filenameRight, imageRight, EImageColorSpace::LINEAR);
const auto imageRightSize = std::make_pair(imageRight.Width(), imageRight.Height());

//--
Expand Down
8 changes: 4 additions & 4 deletions src/samples/texturing/main_evcorrection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int main(int argc, char **argv)
const float evComp = float(cameraExposureMedian / view.getCameraExposureSetting().getExposure());

image::Image<image::RGBfColor> img;
image::readImage(view.getImagePath(), img, image::EImageColorSpace::SRGB_LINEAR);
image::readImage(view.getImagePath(), img, image::EImageColorSpace::LINEAR);

for(int pix = 0; pix < view.getWidth() * view.getHeight(); ++pix)
img(pix) *= evComp;
Expand All @@ -128,7 +128,7 @@ int main(int argc, char **argv)

std::string outputPath = outputFilePath + fs::path(view.getImagePath()).stem().string() + ".EXR";
oiio::ParamValueList metadata = image::getMetadataFromMap(view.getMetadata());
image::writeImage(outputPath, img, image::EImageColorSpace::SRGB_LINEAR, metadata);
image::writeImage(outputPath, img, image::EImageColorSpace::LINEAR, metadata);
}

/*
Expand All @@ -141,7 +141,7 @@ int main(int argc, char **argv)
float ev;
oiio::ParamValueList metadata;
imageIO::readImage(filePath.path().string(), w, h, img.data(), imageIO::EImageColorSpace::SRGB_LINEAR);
imageIO::readImage(filePath.path().string(), w, h, img.data(), imageIO::EImageColorSpace::LINEAR);
img.setSize(w, h);
img.setName(filePath.path().stem().string());
imageIO::readImageMetadata(filePath.path().string(), metadata);
Expand Down Expand Up @@ -185,7 +185,7 @@ int main(int argc, char **argv)
}
std::string outputPath = outputFilePath + imgList[i].getName() + ".EXR";
imageIO::writeImage(outputPath, imgList[i].width(), imgList[i].height(), imgList[i].data(), imageIO::EImageQuality::LOSSLESS, imageIO::EImageColorSpace::SRGB_LINEAR);
imageIO::writeImage(outputPath, imgList[i].width(), imgList[i].height(), imgList[i].data(), imageIO::EImageQuality::LOSSLESS, imageIO::EImageColorSpace::LINEAR);
}
*/
Expand Down
Loading

0 comments on commit 4889a6b

Please sign in to comment.