Skip to content

Commit

Permalink
Add NamedTransform option to ocioconvert tool. (#1988)
Browse files Browse the repository at this point in the history
Signed-off-by: pylee <[email protected]>
Co-authored-by: Doug Walker <[email protected]>
  • Loading branch information
pennelee and doug-walker committed Aug 9, 2024
1 parent 87ccf32 commit 77133f5
Showing 1 changed file with 109 additions and 30 deletions.
139 changes: 109 additions & 30 deletions src/apps/ocioconvert/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,40 @@ int main(int argc, const char **argv)
std::vector<std::string> intAttrs;
std::vector<std::string> stringAttrs;

bool usegpu = false;
bool usegpuLegacy = false;
bool outputgpuInfo = false;
bool verbose = false;
bool help = false;
bool useLut = false;
bool useDisplayView = false;
bool useInvertView = false;
bool usegpu = false;
bool usegpuLegacy = false;
bool outputgpuInfo = false;
bool verbose = false;
bool help = false;
bool useLut = false;
bool useDisplayView = false;
bool useInvertView = false;
bool useNamedTransform = false;
bool useInvNamedTransform = false;

ap.options("ocioconvert -- apply colorspace transform to an image \n\n"
"usage: ocioconvert [options] inputimage inputcolorspace outputimage outputcolorspace\n"
" or: ocioconvert [options] --lut lutfile inputimage outputimage\n"
" or: ocioconvert [options] --view inputimage inputcolorspace outputimage displayname viewname\n"
" or: ocioconvert [options] --invertview inputimage displayname viewname outputimage outputcolorspace\n\n",
" or: ocioconvert [options] --invertview inputimage displayname viewname outputimage outputcolorspace\n"
" or: ocioconvert [options] --namedtransform transformname inputimage outputimage\n"
" or: ocioconvert [options] --invnamedtransform transformname inputimage outputimage\n\n",
"%*", parse_end_args, "",
"<SEPARATOR>", "Options:",
"--lut", &useLut, "Convert using a LUT rather than a config file",
"--view", &useDisplayView, "Convert to a (display,view) pair rather than to "
"an output color space",
"--invertview", &useInvertView, "Convert from a (display,view) pair rather than "
"from a color space",
"--gpu", &usegpu, "Use GPU color processing instead of CPU (CPU is the default)",
"--gpulegacy", &usegpuLegacy, "Use the legacy (i.e. baked) GPU color processing "
"instead of the CPU one (--gpu is ignored)",
"--gpuinfo", &outputgpuInfo, "Output the OCIO shader program",
"--h", &help, "Display the help and exit",
"--help", &help, "Display the help and exit",
"-v" , &verbose, "Display general information",
"--lut", &useLut, "Convert using a LUT rather than a config file",
"--view", &useDisplayView, "Convert to a (display,view) pair rather than to "
"an output color space",
"--invertview", &useInvertView, "Convert from a (display,view) pair rather than "
"from a color space",
"--namedtransform", &useNamedTransform, "Convert using a named transform in the forward direction",
"--invnamedtransform", &useInvNamedTransform, "Convert using a named transform in the inverse direction",
"--gpu", &usegpu, "Use GPU color processing instead of CPU (CPU is the default)",
"--gpulegacy", &usegpuLegacy, "Use the legacy (i.e. baked) GPU color processing "
"instead of the CPU one (--gpu is ignored)",
"--gpuinfo", &outputgpuInfo, "Output the OCIO shader program",
"--h", &help, "Display the help and exit",
"--help", &help, "Display the help and exit",
"-v" , &verbose, "Display general information",
"<SEPARATOR>", "\nOpenImageIO or OpenEXR options:",
"--float-attribute %L", &floatAttrs, "\"name=float\" pair defining OIIO float attribute "
"for outputimage",
Expand Down Expand Up @@ -109,15 +115,16 @@ int main(int argc, const char **argv)
}
#endif // OCIO_GPU_ENABLED

const char * inputimage = nullptr;
const char * inputcolorspace = nullptr;
const char * outputimage = nullptr;
const char * outputcolorspace = nullptr;
const char * lutFile = nullptr;
const char * display = nullptr;
const char * view = nullptr;

if (!useLut && !useDisplayView && !useInvertView)
const char * inputimage = nullptr;
const char * inputcolorspace = nullptr;
const char * outputimage = nullptr;
const char * outputcolorspace = nullptr;
const char * lutFile = nullptr;
const char * display = nullptr;
const char * view = nullptr;
const char * namedtransform = nullptr;

if (!useLut && !useDisplayView && !useInvertView && !useNamedTransform && !useInvNamedTransform)
{
if (args.size() != 4)
{
Expand Down Expand Up @@ -186,6 +193,50 @@ int main(int argc, const char **argv)
outputimage = args[3].c_str();
outputcolorspace = args[4].c_str();
}
else if (useNamedTransform)
{
if (useLut || useDisplayView || useInvertView || useInvNamedTransform)
{
std::cerr << "ERROR: Option namedtransform can't be used with lut, view, invertview, \
or invnamedtransform at the same time." << std::endl;
ap.usage();
exit(1);
}

if (args.size() != 3)
{
std::cerr << "ERROR: Expecting 3 arguments for --namedtransform option, found "
<< args.size() << "." << std::endl;
ap.usage();
exit(1);
}

namedtransform = args[0].c_str();
inputimage = args[1].c_str();
outputimage = args[2].c_str();
}
else if (useInvNamedTransform)
{
if (useLut || useDisplayView || useInvertView || useNamedTransform)
{
std::cerr << "ERROR: Option invnamedtransform can't be used with lut, view, invertview, \
or namedtransform at the same time." << std::endl;
ap.usage();
exit(1);
}

if (args.size() != 3)
{
std::cerr << "ERROR: Expecting 3 arguments for --invnamedtransform option, found "
<< args.size() << "." << std::endl;
ap.usage();
exit(1);
}

namedtransform = args[0].c_str();
inputimage = args[1].c_str();
outputimage = args[2].c_str();
}

if (verbose)
{
Expand Down Expand Up @@ -343,6 +394,34 @@ int main(int argc, const char **argv)
t->setView(view);
processor = config->getProcessor(t, OCIO::TRANSFORM_DIR_INVERSE);
}
else if (useNamedTransform)
{
auto nt = config->getNamedTransform(namedtransform);

if (nt)
{
processor = config->getProcessor(nt, OCIO::TRANSFORM_DIR_FORWARD);
}
else
{
std::cout << "ERROR: Could not get NamedTransform " << namedtransform << std::endl;
exit(1);
}
}
else if (useInvNamedTransform)
{
auto nt = config->getNamedTransform(namedtransform);

if (nt)
{
processor = config->getProcessor(nt, OCIO::TRANSFORM_DIR_INVERSE);
}
else
{
std::cout << "ERROR: Could not get NamedTransform " << namedtransform << std::endl;
exit(1);
}
}
else
{
processor = config->getProcessor(inputcolorspace, outputcolorspace);
Expand Down

0 comments on commit 77133f5

Please sign in to comment.