Skip to content

Commit d9f326f

Browse files
authored
ociodisplay gets an inverse control (#3650)
Fixes #3648
1 parent 1278f60 commit d9f326f

File tree

7 files changed

+225
-43
lines changed

7 files changed

+225
-43
lines changed

src/doc/oiiotool.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,6 +4188,10 @@ bottom you will see the list of all color spaces, looks, and displays that
41884188
is 0, meaning the color transformation not will be automatically
41894189
bracketed by divide-by-alpha / mult-by-alpha operations.
41904190

4191+
`inverse=` *val* :
4192+
4193+
If *val* is nonzero, inverts the color transformation.
4194+
41914195
`:subimages=` *indices-or-names*
41924196
Include/exclude subimages (see :ref:`sec-oiiotool-subimage-modifier`).
41934197

src/doc/pythonbindings.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,8 +3572,8 @@ Color manipulation
35723572
35733573
35743574
3575-
.. py:method:: ImageBuf ImageBufAlgo.ociodisplay (src, display, view, fromspace="", looks="", unpremult=True, context_key="", context_value="", colorconfig="", roi=ROI.All, nthreads=0)
3576-
bool ImageBufAlgo.ociodisplay (dst, src, display, view, fromspace="", looks="", unpremult=True, context_key="", context_value="", colorconfig="", roi=ROI.All, nthreads=0)
3575+
.. py:method:: ImageBuf ImageBufAlgo.ociodisplay (src, display, view, fromspace="", looks="", unpremult=True, inverse=False, context_key="", context_value="", colorconfig="", roi=ROI.All, nthreads=0)
3576+
bool ImageBufAlgo.ociodisplay (dst, src, display, view, fromspace="", looks="", unpremult=True, inverse=False, context_key="", context_value="", colorconfig="", roi=ROI.All, nthreads=0)
35773577
35783578
Apply an OpenColorIO "display" transform to the pixel values.
35793579

src/include/OpenImageIO/color.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class OIIO_API ColorConfig {
161161
/// inverse==true, request the inverse transformation. The
162162
/// context_key and context_value can optionally be used to establish
163163
/// extra key/value pairs in the OCIO context if they are comma-
164-
/// separated lists of ontext keys and values, respectively.
164+
/// separated lists of context keys and values, respectively.
165165
///
166166
/// The handle is actually a shared_ptr, so when you're done with a
167167
/// ColorProcess, just discard it. ColorProcessor(s) remain valid even
@@ -245,14 +245,26 @@ class OIIO_API ColorConfig {
245245
ColorProcessorHandle
246246
createDisplayTransform(string_view display, string_view view,
247247
string_view inputColorSpace, string_view looks = "",
248-
string_view context_key = "",
248+
bool inverse = false, string_view context_key = "",
249249
string_view context_value = "") const;
250250
ColorProcessorHandle
251251
createDisplayTransform(ustring display, ustring view,
252252
ustring inputColorSpace, ustring looks = ustring(),
253+
bool inverse = false,
253254
ustring context_key = ustring(),
254255
ustring context_value = ustring()) const;
255256

257+
// OIIO_DEPRECATED("prefer the kind that takes an `inverse` parameter (2.5)")
258+
ColorProcessorHandle
259+
createDisplayTransform(string_view display, string_view view,
260+
string_view inputColorSpace, string_view looks,
261+
string_view context_key,
262+
string_view context_value = "") const;
263+
// OIIO_DEPRECATED("prefer the kind that takes an `inverse` parameter (2.5)")
264+
ColorProcessorHandle createDisplayTransform(
265+
ustring display, ustring view, ustring inputColorSpace, ustring looks,
266+
ustring context_key, ustring context_value = ustring()) const;
267+
256268
/// Construct a processor to perform color transforms determined by an
257269
/// OpenColorIO FileTransform. It is possible that this will return an
258270
/// empty handle if the FileTransform doesn't exist or is not allowed.

src/include/OpenImageIO/imagebufalgo.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,19 +1980,38 @@ bool OIIO_API ociolook (ImageBuf &dst, const ImageBuf &src, string_view looks,
19801980
ImageBuf OIIO_API ociodisplay (const ImageBuf &src,
19811981
string_view display, string_view view,
19821982
string_view fromspace="", string_view looks="",
1983-
bool unpremult=true,
1983+
bool unpremult=true, bool inverse=false,
19841984
string_view context_key="", string_view context_value="",
19851985
ColorConfig *colorconfig=nullptr,
19861986
ROI roi={}, int nthreads=0);
19871987
/// Write to an existing image `dst` (allocating if it is uninitialized).
19881988
bool OIIO_API ociodisplay (ImageBuf &dst, const ImageBuf &src,
19891989
string_view display, string_view view,
19901990
string_view fromspace="", string_view looks="",
1991-
bool unpremult=true,
1991+
bool unpremult=true, bool inverse=false,
19921992
string_view context_key="", string_view context_value="",
19931993
ColorConfig *colorconfig=nullptr,
19941994
ROI roi={}, int nthreads=0);
19951995

1996+
#ifndef OIIO_DOXYGEN
1997+
// OIIO_DEPRECATED("prefer the kind that takes an `inverse` parameter (2.5)")
1998+
ImageBuf OIIO_API ociodisplay (const ImageBuf &src,
1999+
string_view display, string_view view,
2000+
string_view fromspace, string_view looks,
2001+
bool unpremult,
2002+
string_view context_key, string_view context_value="",
2003+
ColorConfig *colorconfig=nullptr,
2004+
ROI roi={}, int nthreads=0);
2005+
// OIIO_DEPRECATED("prefer the kind that takes an `inverse` parameter (2.5)")
2006+
bool OIIO_API ociodisplay (ImageBuf &dst, const ImageBuf &src,
2007+
string_view display, string_view view,
2008+
string_view fromspace, string_view looks,
2009+
bool unpremult,
2010+
string_view context_key, string_view context_value="",
2011+
ColorConfig *colorconfig=nullptr,
2012+
ROI roi={}, int nthreads=0);
2013+
#endif
2014+
19962015

19972016
/// Return the pixels of `src` within the ROI, applying an OpenColorIO
19982017
/// "file" transform. In-place operations (`dst` == `src`) are supported.

src/libOpenImageIO/color_ocio.cpp

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,20 +1252,22 @@ ColorConfig::createLookTransform(ustring looks, ustring inputColorSpace,
12521252
ColorProcessorHandle
12531253
ColorConfig::createDisplayTransform(string_view display, string_view view,
12541254
string_view inputColorSpace,
1255-
string_view looks, string_view context_key,
1255+
string_view looks, bool inverse,
1256+
string_view context_key,
12561257
string_view context_value) const
12571258
{
12581259
return createDisplayTransform(ustring(display), ustring(view),
12591260
ustring(inputColorSpace), ustring(looks),
1260-
ustring(context_key), ustring(context_value));
1261+
inverse, ustring(context_key),
1262+
ustring(context_value));
12611263
}
12621264

12631265

12641266

12651267
ColorProcessorHandle
12661268
ColorConfig::createDisplayTransform(ustring display, ustring view,
12671269
ustring inputColorSpace, ustring looks,
1268-
ustring context_key,
1270+
bool inverse, ustring context_key,
12691271
ustring context_value) const
12701272
{
12711273
if (display.empty())
@@ -1275,7 +1277,8 @@ ColorConfig::createDisplayTransform(ustring display, ustring view,
12751277
// First, look up the requested processor in the cache. If it already
12761278
// exists, just return it.
12771279
ColorProcCacheKey prockey(inputColorSpace, ustring() /*outputColorSpace*/,
1278-
context_key, context_value, looks, display, view);
1280+
context_key, context_value, looks, display, view,
1281+
ustring() /*file*/, inverse);
12791282
ColorProcessorHandle handle = getImpl()->findproc(prockey);
12801283
if (handle)
12811284
return handle;
@@ -1302,6 +1305,8 @@ ColorConfig::createDisplayTransform(ustring display, ustring view,
13021305
transform->setLooksOverrideEnabled(false);
13031306
}
13041307
# endif
1308+
OCIO::TransformDirection dir = inverse ? OCIO::TRANSFORM_DIR_INVERSE
1309+
: OCIO::TRANSFORM_DIR_FORWARD;
13051310
transform->setDisplay(display.c_str());
13061311
transform->setView(view.c_str());
13071312
auto context = config->getCurrentContext();
@@ -1317,8 +1322,7 @@ ColorConfig::createDisplayTransform(ustring display, ustring view,
13171322
OCIO::ConstProcessorRcPtr p;
13181323
try {
13191324
// Get the processor corresponding to this transform.
1320-
p = getImpl()->config_->getProcessor(context, transform,
1321-
OCIO::TRANSFORM_DIR_FORWARD);
1325+
p = getImpl()->config_->getProcessor(context, transform, dir);
13221326
getImpl()->clear_error();
13231327
handle = ColorProcessorHandle(new ColorProcessor_OCIO(p));
13241328
} catch (OCIO::Exception& e) {
@@ -1335,6 +1339,30 @@ ColorConfig::createDisplayTransform(ustring display, ustring view,
13351339

13361340

13371341

1342+
ColorProcessorHandle
1343+
ColorConfig::createDisplayTransform(string_view display, string_view view,
1344+
string_view inputColorSpace,
1345+
string_view looks, string_view context_key,
1346+
string_view context_value) const
1347+
{
1348+
return createDisplayTransform(ustring(display), ustring(view),
1349+
ustring(inputColorSpace), ustring(looks),
1350+
false, ustring(context_key),
1351+
ustring(context_value));
1352+
}
1353+
1354+
ColorProcessorHandle
1355+
ColorConfig::createDisplayTransform(ustring display, ustring view,
1356+
ustring inputColorSpace, ustring looks,
1357+
ustring context_key,
1358+
ustring context_value) const
1359+
{
1360+
return createDisplayTransform(display, view, inputColorSpace, looks, false,
1361+
context_key, context_value);
1362+
}
1363+
1364+
1365+
13381366
ColorProcessorHandle
13391367
ColorConfig::createFileTransform(string_view name, bool inverse) const
13401368
{
@@ -1850,7 +1878,7 @@ bool
18501878
ImageBufAlgo::ociodisplay(ImageBuf& dst, const ImageBuf& src,
18511879
string_view display, string_view view,
18521880
string_view from, string_view looks, bool unpremult,
1853-
string_view key, string_view value,
1881+
bool inverse, string_view key, string_view value,
18541882
ColorConfig* colorconfig, ROI roi, int nthreads)
18551883
{
18561884
pvt::LoggedTimer logtime("IBA::ociodisplay");
@@ -1871,7 +1899,8 @@ ImageBufAlgo::ociodisplay(ImageBuf& dst, const ImageBuf& src,
18711899
return false;
18721900
}
18731901
processor = colorconfig->createDisplayTransform(display, view, from,
1874-
looks, key, value);
1902+
looks, inverse, key,
1903+
value);
18751904
if (!processor) {
18761905
if (colorconfig->error())
18771906
dst.errorfmt("{}", colorconfig->geterror());
@@ -1891,19 +1920,47 @@ ImageBufAlgo::ociodisplay(ImageBuf& dst, const ImageBuf& src,
18911920
ImageBuf
18921921
ImageBufAlgo::ociodisplay(const ImageBuf& src, string_view display,
18931922
string_view view, string_view from, string_view looks,
1894-
bool unpremult, string_view key, string_view value,
1895-
ColorConfig* colorconfig, ROI roi, int nthreads)
1923+
bool unpremult, bool inverse, string_view key,
1924+
string_view value, ColorConfig* colorconfig, ROI roi,
1925+
int nthreads)
18961926
{
18971927
ImageBuf result;
18981928
bool ok = ociodisplay(result, src, display, view, from, looks, unpremult,
1899-
key, value, colorconfig, roi, nthreads);
1929+
inverse, key, value, colorconfig, roi, nthreads);
19001930
if (!ok && !result.has_error())
19011931
result.errorfmt("ImageBufAlgo::ociodisplay() error");
19021932
return result;
19031933
}
19041934

19051935

19061936

1937+
// DEPRECATED(2.5)
1938+
bool
1939+
ImageBufAlgo::ociodisplay(ImageBuf& dst, const ImageBuf& src,
1940+
string_view display, string_view view,
1941+
string_view from, string_view looks, bool unpremult,
1942+
string_view key, string_view value,
1943+
ColorConfig* colorconfig, ROI roi, int nthreads)
1944+
{
1945+
return ociodisplay(dst, src, display, view, from, looks, unpremult, false,
1946+
key, value, colorconfig, roi, nthreads);
1947+
}
1948+
1949+
1950+
1951+
// DEPRECATED(2.5)
1952+
ImageBuf
1953+
ImageBufAlgo::ociodisplay(const ImageBuf& src, string_view display,
1954+
string_view view, string_view from, string_view looks,
1955+
bool unpremult, string_view key, string_view value,
1956+
ColorConfig* colorconfig, ROI roi, int nthreads)
1957+
{
1958+
return ociodisplay(src, display, view, from, looks, unpremult, false, key,
1959+
value, colorconfig, roi, nthreads);
1960+
}
1961+
1962+
1963+
19071964
bool
19081965
ImageBufAlgo::ociofiletransform(ImageBuf& dst, const ImageBuf& src,
19091966
string_view name, bool unpremult, bool inverse,

src/oiiotool/oiiotool.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,12 +2778,13 @@ OIIOTOOL_OP(ociodisplay, 1, [](OiiotoolOp& op, span<ImageBuf*> img) {
27782778
std::string contextvalue = op.options()["value"];
27792779
std::string looks = op.options()["looks"];
27802780
bool unpremult = op.options().get_int("unpremult");
2781+
bool inverse = op.options().get_int("inverse");
27812782
if (fromspace == "current" || fromspace == "")
27822783
fromspace = img[1]->spec().get_string_attribute("oiio:Colorspace",
27832784
"Linear");
27842785
return ImageBufAlgo::ociodisplay(*img[0], *img[1], displayname, viewname,
2785-
fromspace, looks, unpremult, contextkey,
2786-
contextvalue, &ot.colorconfig);
2786+
fromspace, looks, unpremult, inverse,
2787+
contextkey, contextvalue, &ot.colorconfig);
27872788
});
27882789

27892790

@@ -6807,7 +6808,7 @@ Oiiotool::getargs(int argc, char* argv[])
68076808
.help("Apply the named OCIO look (options: from=, to=, inverse=, key=, value=, unpremult=)")
68086809
.action(action_ociolook);
68096810
ap.arg("--ociodisplay %s:DISPLAY %s:VIEW")
6810-
.help("Apply the named OCIO display and view (options: from=, looks=, key=, value=, unpremult=)")
6811+
.help("Apply the named OCIO display and view (options: from=, looks=, key=, value=, unpremult=, inverse=)")
68116812
.action(action_ociodisplay);
68126813
ap.arg("--ociofiletransform %s:FILENAME")
68136814
.help("Apply the named OCIO filetransform (options: inverse=, unpremult=)")

0 commit comments

Comments
 (0)