From ff4b2e904f27e72fa36829acd5fd553b9a21a6b7 Mon Sep 17 00:00:00 2001 From: Brendan Bolles Date: Mon, 17 May 2021 03:23:40 -0700 Subject: [PATCH] Incorporate invert into LUT export Signed-off-by: Brendan Bolles --- .../aftereffects/OpenColorIO_AE_Context.cpp | 43 +++++++++++-------- vendor/aftereffects/OpenColorIO_AE_UI.cpp | 7 ++- vendor/photoshop/OpenColorIO_PS_Context.cpp | 4 +- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/vendor/aftereffects/OpenColorIO_AE_Context.cpp b/vendor/aftereffects/OpenColorIO_AE_Context.cpp index 4becbd335..4b3c2bf5e 100644 --- a/vendor/aftereffects/OpenColorIO_AE_Context.cpp +++ b/vendor/aftereffects/OpenColorIO_AE_Context.cpp @@ -699,22 +699,22 @@ void OpenColorIO_AE_Context::setupLUT(OCIO_Invert invert, OCIO_Interp interpolat bool OpenColorIO_AE_Context::ExportLUT(const std::string &path, const std::string &display_icc_path) { - std::string the_extension = path.substr( path.find_last_of('.') + 1 ); + const std::string the_extension = path.substr( path.find_last_of('.') + 1 ); try{ if(the_extension == "icc") { - int cubesize = 32; - int whitepointtemp = 6505; - std::string copyright = ""; + const int cubesize = 32; + const int whitepointtemp = 6505; + const std::string copyright = ""; // create a description tag from the filename - size_t filename_start = path.find_last_of(delimiter) + 1; - size_t filename_end = path.find_last_of('.') - 1; + const size_t filename_start = path.find_last_of(delimiter) + 1; + const size_t filename_end = path.find_last_of('.') - 1; - std::string description = path.substr(path.find_last_of(delimiter) + 1, - 1 + filename_end - filename_start); + const std::string description = path.substr(path.find_last_of(delimiter) + 1, + 1 + filename_end - filename_start); SaveICCProfileToFile(path, _cpu_processor, cubesize, whitepointtemp, display_icc_path, description, copyright, false); @@ -723,18 +723,22 @@ bool OpenColorIO_AE_Context::ExportLUT(const std::string &path, const std::strin { // this code lovingly pulled from ociobakelut - // need an extension->format map (yes, just did this one call up) - std::map extensions; + std::string format; for(int i=0; i < OCIO::Baker::getNumFormats(); ++i) { const char *extension = OCIO::Baker::getFormatExtensionByIndex(i); - const char *format = OCIO::Baker::getFormatNameByIndex(i); + const char *formatName = OCIO::Baker::getFormatNameByIndex(i); - extensions[ extension ] = format; + if(the_extension == extension) + { + format = formatName; + break; + } } - std::string format = extensions[ the_extension ]; + if(format.empty()) + return false; OCIO::BakerRcPtr baker = OCIO::Baker::Create(); @@ -744,8 +748,8 @@ bool OpenColorIO_AE_Context::ExportLUT(const std::string &path, const std::strin if(_action == OCIO_ACTION_CONVERT) { baker->setConfig(_config); - baker->setInputSpace(_input.c_str()); - baker->setTargetSpace(_output.c_str()); + baker->setInputSpace(_invert ? _output.c_str() : _input.c_str()); + baker->setTargetSpace(_invert ? _input.c_str() : _output.c_str()); std::ofstream f(path.c_str()); baker->bake(f); @@ -755,13 +759,13 @@ bool OpenColorIO_AE_Context::ExportLUT(const std::string &path, const std::strin OCIO::ConfigRcPtr editableConfig = _config->createEditableCopy(); OCIO::ColorSpaceRcPtr inputColorSpace = OCIO::ColorSpace::Create(); - std::string inputspace = "RawInput"; + const std::string inputspace = "RawInput"; inputColorSpace->setName(inputspace.c_str()); editableConfig->addColorSpace(inputColorSpace); OCIO::ColorSpaceRcPtr outputColorSpace = OCIO::ColorSpace::Create(); - std::string outputspace = "ProcessedOutput"; + const std::string outputspace = "ProcessedOutput"; outputColorSpace->setName(outputspace.c_str()); OCIO::DisplayViewTransformRcPtr transform = OCIO::DisplayViewTransform::Create(); @@ -769,6 +773,7 @@ bool OpenColorIO_AE_Context::ExportLUT(const std::string &path, const std::strin transform->setSrc(_input.c_str()); transform->setDisplay(_display.c_str()); transform->setView(_view.c_str()); + transform->setDirection(_invert ? OCIO::TRANSFORM_DIR_INVERSE : OCIO::TRANSFORM_DIR_FORWARD); outputColorSpace->setTransform(transform, OCIO::COLORSPACE_DIR_FROM_REFERENCE); @@ -787,13 +792,13 @@ bool OpenColorIO_AE_Context::ExportLUT(const std::string &path, const std::strin OCIO::ConfigRcPtr editableConfig = OCIO::Config::Create(); OCIO::ColorSpaceRcPtr inputColorSpace = OCIO::ColorSpace::Create(); - std::string inputspace = "RawInput"; + const std::string inputspace = "RawInput"; inputColorSpace->setName(inputspace.c_str()); editableConfig->addColorSpace(inputColorSpace); OCIO::ColorSpaceRcPtr outputColorSpace = OCIO::ColorSpace::Create(); - std::string outputspace = "ProcessedOutput"; + const std::string outputspace = "ProcessedOutput"; outputColorSpace->setName(outputspace.c_str()); OCIO::FileTransformRcPtr transform = OCIO::FileTransform::Create(); diff --git a/vendor/aftereffects/OpenColorIO_AE_UI.cpp b/vendor/aftereffects/OpenColorIO_AE_UI.cpp index 1245920e8..125564eae 100644 --- a/vendor/aftereffects/OpenColorIO_AE_UI.cpp +++ b/vendor/aftereffects/OpenColorIO_AE_UI.cpp @@ -985,7 +985,12 @@ static void DoClickExport( } if(do_export) - seq_data->context->ExportLUT(the_path, monitor_icc_path); + { + const bool exported = seq_data->context->ExportLUT(the_path, monitor_icc_path); + + if(!exported) + throw OCIO::Exception("Failed to Export LUT"); + } } } diff --git a/vendor/photoshop/OpenColorIO_PS_Context.cpp b/vendor/photoshop/OpenColorIO_PS_Context.cpp index e684975ff..f4dbc3de3 100644 --- a/vendor/photoshop/OpenColorIO_PS_Context.cpp +++ b/vendor/photoshop/OpenColorIO_PS_Context.cpp @@ -204,13 +204,13 @@ OpenColorIO_PS_Context::getLUTBaker(OCIO::Interpolation interpolation, bool inve OCIO::ConfigRcPtr editableConfig = OCIO::Config::Create(); OCIO::ColorSpaceRcPtr inputColorSpace = OCIO::ColorSpace::Create(); - std::string inputspace = "RawInput"; + const std::string inputspace = "RawInput"; inputColorSpace->setName(inputspace.c_str()); editableConfig->addColorSpace(inputColorSpace); OCIO::ColorSpaceRcPtr outputColorSpace = OCIO::ColorSpace::Create(); - std::string outputspace = "ProcessedOutput"; + const std::string outputspace = "ProcessedOutput"; outputColorSpace->setName(outputspace.c_str()); OCIO::FileTransformRcPtr transform = OCIO::FileTransform::Create();