Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ociodisplay gets an inverse control #3650

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
79 changes: 68 additions & 11 deletions src/libOpenImageIO/color_ocio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,20 +1252,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 @@ -1275,7 +1277,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 @@ -1302,6 +1305,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 @@ -1317,8 +1322,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 @@ -1335,6 +1339,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 @@ -1850,7 +1878,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)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know how to select the line 1872, but don't you want to pass inverse there too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think you're right

pvt::LoggedTimer logtime("IBA::ociodisplay");
Expand All @@ -1871,7 +1899,8 @@ ImageBufAlgo::ociodisplay(ImageBuf& dst, const ImageBuf& src,
return false;
}
processor = colorconfig->createDisplayTransform(display, view, from,
looks, key, value);
looks, inverse, key,
value);
if (!processor) {
if (colorconfig->error())
dst.errorfmt("{}", colorconfig->geterror());
Expand All @@ -1891,19 +1920,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);
inverse, 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 @@ -2778,12 +2778,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 @@ -6807,7 +6808,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