Skip to content

Commit

Permalink
Incorporate invert into LUT export
Browse files Browse the repository at this point in the history
Signed-off-by: Brendan Bolles <brendan@fnordware.com>
  • Loading branch information
fnordware committed May 17, 2021
1 parent bef4659 commit ff4b2e9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
43 changes: 24 additions & 19 deletions vendor/aftereffects/OpenColorIO_AE_Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<std::string, std::string> 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();
Expand All @@ -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);
Expand All @@ -755,20 +759,21 @@ 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();

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);

Expand All @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion vendor/aftereffects/OpenColorIO_AE_UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions vendor/photoshop/OpenColorIO_PS_Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ff4b2e9

Please sign in to comment.