Skip to content

Commit

Permalink
ociodisplay gets an inverse control
Browse files Browse the repository at this point in the history
Fixes 3648
  • Loading branch information
lgritz committed Nov 3, 2022
1 parent f099e19 commit 783b9bf
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 42 deletions.
4 changes: 4 additions & 0 deletions src/doc/oiiotool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4188,6 +4188,10 @@ bottom you will see the list of all color spaces, looks, and displays that
is 0, meaning the color transformation not will be automatically
bracketed by divide-by-alpha / mult-by-alpha operations.

`inverse=` *val* :

If *val* is nonzero, inverts the color transformation.

`:subimages=` *indices-or-names*
Include/exclude subimages (see :ref:`sec-oiiotool-subimage-modifier`).

Expand Down
4 changes: 2 additions & 2 deletions src/doc/pythonbindings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3572,8 +3572,8 @@ Color manipulation
.. py:method:: ImageBuf ImageBufAlgo.ociodisplay (src, display, view, fromspace="", looks="", unpremult=True, context_key="", context_value="", colorconfig="", roi=ROI.All, nthreads=0)
bool ImageBufAlgo.ociodisplay (dst, src, display, view, fromspace="", looks="", unpremult=True, context_key="", context_value="", colorconfig="", roi=ROI.All, nthreads=0)
.. py:method:: ImageBuf ImageBufAlgo.ociodisplay (src, display, view, fromspace="", looks="", unpremult=True, inverse=False, context_key="", context_value="", colorconfig="", roi=ROI.All, nthreads=0)
bool ImageBufAlgo.ociodisplay (dst, src, display, view, fromspace="", looks="", unpremult=True, inverse=False, context_key="", context_value="", colorconfig="", roi=ROI.All, nthreads=0)
Apply an OpenColorIO "display" transform to the pixel values.
Expand Down
16 changes: 14 additions & 2 deletions src/include/OpenImageIO/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class OIIO_API ColorConfig {
/// inverse==true, request the inverse transformation. The
/// context_key and context_value can optionally be used to establish
/// extra key/value pairs in the OCIO context if they are comma-
/// separated lists of ontext keys and values, respectively.
/// separated lists of context keys and values, respectively.
///
/// The handle is actually a shared_ptr, so when you're done with a
/// ColorProcess, just discard it. ColorProcessor(s) remain valid even
Expand Down Expand Up @@ -245,14 +245,26 @@ class OIIO_API ColorConfig {
ColorProcessorHandle
createDisplayTransform(string_view display, string_view view,
string_view inputColorSpace, string_view looks = "",
string_view context_key = "",
bool inverse = false, string_view context_key = "",
string_view context_value = "") const;
ColorProcessorHandle
createDisplayTransform(ustring display, ustring view,
ustring inputColorSpace, ustring looks = ustring(),
bool inverse = false,
ustring context_key = ustring(),
ustring context_value = ustring()) const;

// OIIO_DEPRECATED("prefer the kind that takes an `inverse` parameter (2.5)")
ColorProcessorHandle
createDisplayTransform(string_view display, string_view view,
string_view inputColorSpace, string_view looks,
string_view context_key,
string_view context_value = "") const;
// OIIO_DEPRECATED("prefer the kind that takes an `inverse` parameter (2.5)")
ColorProcessorHandle createDisplayTransform(
ustring display, ustring view, ustring inputColorSpace, ustring looks,
ustring context_key, ustring context_value = ustring()) const;

/// Construct a processor to perform color transforms determined by an
/// OpenColorIO FileTransform. It is possible that this will return an
/// empty handle if the FileTransform doesn't exist or is not allowed.
Expand Down
23 changes: 21 additions & 2 deletions src/include/OpenImageIO/imagebufalgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1980,19 +1980,38 @@ bool OIIO_API ociolook (ImageBuf &dst, const ImageBuf &src, string_view looks,
ImageBuf OIIO_API ociodisplay (const ImageBuf &src,
string_view display, string_view view,
string_view fromspace="", string_view looks="",
bool unpremult=true,
bool unpremult=true, bool inverse=false,
string_view context_key="", string_view context_value="",
ColorConfig *colorconfig=nullptr,
ROI roi={}, int nthreads=0);
/// Write to an existing image `dst` (allocating if it is uninitialized).
bool OIIO_API ociodisplay (ImageBuf &dst, const ImageBuf &src,
string_view display, string_view view,
string_view fromspace="", string_view looks="",
bool unpremult=true,
bool unpremult=true, bool inverse=false,
string_view context_key="", string_view context_value="",
ColorConfig *colorconfig=nullptr,
ROI roi={}, int nthreads=0);

#ifndef OIIO_DOXYGEN
// OIIO_DEPRECATED("prefer the kind that takes an `inverse` parameter (2.5)")
ImageBuf OIIO_API ociodisplay (const ImageBuf &src,
string_view display, string_view view,
string_view fromspace, string_view looks,
bool unpremult,
string_view context_key, string_view context_value="",
ColorConfig *colorconfig=nullptr,
ROI roi={}, int nthreads=0);
// OIIO_DEPRECATED("prefer the kind that takes an `inverse` parameter (2.5)")
bool OIIO_API ociodisplay (ImageBuf &dst, const ImageBuf &src,
string_view display, string_view view,
string_view fromspace, string_view looks,
bool unpremult,
string_view context_key, string_view context_value="",
ColorConfig *colorconfig=nullptr,
ROI roi={}, int nthreads=0);
#endif


/// Return the pixels of `src` within the ROI, applying an OpenColorIO
/// "file" transform. In-place operations (`dst` == `src`) are supported.
Expand Down
76 changes: 66 additions & 10 deletions src/libOpenImageIO/color_ocio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,20 +1250,22 @@ ColorConfig::createLookTransform(ustring looks, ustring inputColorSpace,
ColorProcessorHandle
ColorConfig::createDisplayTransform(string_view display, string_view view,
string_view inputColorSpace,
string_view looks, string_view context_key,
string_view looks, bool inverse,
string_view context_key,
string_view context_value) const
{
return createDisplayTransform(ustring(display), ustring(view),
ustring(inputColorSpace), ustring(looks),
ustring(context_key), ustring(context_value));
inverse, ustring(context_key),
ustring(context_value));
}



ColorProcessorHandle
ColorConfig::createDisplayTransform(ustring display, ustring view,
ustring inputColorSpace, ustring looks,
ustring context_key,
bool inverse, ustring context_key,
ustring context_value) const
{
if (display.empty())
Expand All @@ -1273,7 +1275,8 @@ ColorConfig::createDisplayTransform(ustring display, ustring view,
// First, look up the requested processor in the cache. If it already
// exists, just return it.
ColorProcCacheKey prockey(inputColorSpace, ustring() /*outputColorSpace*/,
context_key, context_value, looks, display, view);
context_key, context_value, looks, display, view,
ustring() /*file*/, inverse);
ColorProcessorHandle handle = getImpl()->findproc(prockey);
if (handle)
return handle;
Expand All @@ -1300,6 +1303,8 @@ ColorConfig::createDisplayTransform(ustring display, ustring view,
transform->setLooksOverrideEnabled(false);
}
# endif
OCIO::TransformDirection dir = inverse ? OCIO::TRANSFORM_DIR_INVERSE
: OCIO::TRANSFORM_DIR_FORWARD;
transform->setDisplay(display.c_str());
transform->setView(view.c_str());
auto context = config->getCurrentContext();
Expand All @@ -1315,8 +1320,7 @@ ColorConfig::createDisplayTransform(ustring display, ustring view,
OCIO::ConstProcessorRcPtr p;
try {
// Get the processor corresponding to this transform.
p = getImpl()->config_->getProcessor(context, transform,
OCIO::TRANSFORM_DIR_FORWARD);
p = getImpl()->config_->getProcessor(context, transform, dir);
getImpl()->clear_error();
handle = ColorProcessorHandle(new ColorProcessor_OCIO(p));
} catch (OCIO::Exception& e) {
Expand All @@ -1333,6 +1337,30 @@ ColorConfig::createDisplayTransform(ustring display, ustring view,



ColorProcessorHandle
ColorConfig::createDisplayTransform(string_view display, string_view view,
string_view inputColorSpace,
string_view looks, string_view context_key,
string_view context_value) const
{
return createDisplayTransform(ustring(display), ustring(view),
ustring(inputColorSpace), ustring(looks),
false, ustring(context_key),
ustring(context_value));
}

ColorProcessorHandle
ColorConfig::createDisplayTransform(ustring display, ustring view,
ustring inputColorSpace, ustring looks,
ustring context_key,
ustring context_value) const
{
return createDisplayTransform(display, view, inputColorSpace, looks, false,
context_key, context_value);
}



ColorProcessorHandle
ColorConfig::createFileTransform(string_view name, bool inverse) const
{
Expand Down Expand Up @@ -1848,7 +1876,7 @@ bool
ImageBufAlgo::ociodisplay(ImageBuf& dst, const ImageBuf& src,
string_view display, string_view view,
string_view from, string_view looks, bool unpremult,
string_view key, string_view value,
bool inverse, string_view key, string_view value,
ColorConfig* colorconfig, ROI roi, int nthreads)
{
pvt::LoggedTimer logtime("IBA::ociodisplay");
Expand Down Expand Up @@ -1889,19 +1917,47 @@ ImageBufAlgo::ociodisplay(ImageBuf& dst, const ImageBuf& src,
ImageBuf
ImageBufAlgo::ociodisplay(const ImageBuf& src, string_view display,
string_view view, string_view from, string_view looks,
bool unpremult, string_view key, string_view value,
ColorConfig* colorconfig, ROI roi, int nthreads)
bool unpremult, bool inverse, string_view key,
string_view value, ColorConfig* colorconfig, ROI roi,
int nthreads)
{
ImageBuf result;
bool ok = ociodisplay(result, src, display, view, from, looks, unpremult,
key, value, colorconfig, roi, nthreads);
unpremult, key, value, colorconfig, roi, nthreads);
if (!ok && !result.has_error())
result.errorfmt("ImageBufAlgo::ociodisplay() error");
return result;
}



// DEPRECATED(2.5)
bool
ImageBufAlgo::ociodisplay(ImageBuf& dst, const ImageBuf& src,
string_view display, string_view view,
string_view from, string_view looks, bool unpremult,
string_view key, string_view value,
ColorConfig* colorconfig, ROI roi, int nthreads)
{
return ociodisplay(dst, src, display, view, from, looks, unpremult, false,
key, value, colorconfig, roi, nthreads);
}



// DEPRECATED(2.5)
ImageBuf
ImageBufAlgo::ociodisplay(const ImageBuf& src, string_view display,
string_view view, string_view from, string_view looks,
bool unpremult, string_view key, string_view value,
ColorConfig* colorconfig, ROI roi, int nthreads)
{
return ociodisplay(src, display, view, from, looks, unpremult, false, key,
value, colorconfig, roi, nthreads);
}



bool
ImageBufAlgo::ociofiletransform(ImageBuf& dst, const ImageBuf& src,
string_view name, bool unpremult, bool inverse,
Expand Down
7 changes: 4 additions & 3 deletions src/oiiotool/oiiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2777,12 +2777,13 @@ OIIOTOOL_OP(ociodisplay, 1, [](OiiotoolOp& op, span<ImageBuf*> img) {
std::string contextvalue = op.options()["value"];
std::string looks = op.options()["looks"];
bool unpremult = op.options().get_int("unpremult");
bool inverse = op.options().get_int("inverse");
if (fromspace == "current" || fromspace == "")
fromspace = img[1]->spec().get_string_attribute("oiio:Colorspace",
"Linear");
return ImageBufAlgo::ociodisplay(*img[0], *img[1], displayname, viewname,
fromspace, looks, unpremult, contextkey,
contextvalue, &ot.colorconfig);
fromspace, looks, unpremult, inverse,
contextkey, contextvalue, &ot.colorconfig);
});


Expand Down Expand Up @@ -6801,7 +6802,7 @@ Oiiotool::getargs(int argc, char* argv[])
.help("Apply the named OCIO look (options: from=, to=, inverse=, key=, value=, unpremult=)")
.action(action_ociolook);
ap.arg("--ociodisplay %s:DISPLAY %s:VIEW")
.help("Apply the named OCIO display and view (options: from=, looks=, key=, value=, unpremult=)")
.help("Apply the named OCIO display and view (options: from=, looks=, key=, value=, unpremult=, inverse=)")
.action(action_ociodisplay);
ap.arg("--ociofiletransform %s:FILENAME")
.help("Apply the named OCIO filetransform (options: inverse=, unpremult=)")
Expand Down
Loading

0 comments on commit 783b9bf

Please sign in to comment.