OpenColorIO: Full display pipeline Python example broken

The example at https://opencolorio.org/developers/usage_examples.html#displaying-an-image-using-the-cpu-full-display-pipeline is broken in a bunch of ways; mainly just wrong method names being used in step 1 and 2

import PyOpenColorIO as OCIO

# Step 1: Get the config
config = OCIO.GetCurrentConfig()

# Step 2: Lookup the display ColorSpace
device = config.getDefaultDisplayDeviceName()
transformName = config.getDefaultDisplayTransformName(device)
displayColorSpace = config.getDisplayColorSpaceName(device, transformName)

# Step 3: Create a DisplayTransform, and set the input and display ColorSpaces
# (This example assumes the input is scene linear. Adapt as needed.)

transform = OCIO.DisplayTransform()
transform.setInputColorSpaceName(OCIO.Constants.ROLE_SCENE_LINEAR)
transform.setDisplayColorSpaceName(displayColorSpace)

# Step 4: Add custom transforms for a 'canonical' Display Pipeline

# Add an fstop exposure control (in SCENE_LINEAR)
gain = 2**exposure
slope3f = (gain, gain, gain)

cc = OCIO.CDLTransform()
cc.setSlope(slope3f)

transform.setLinearCC(cc)

# Add a Channel view 'swizzle'

channelHot = (1, 1, 1, 1) # show rgb
# channelHot = (1, 0, 0, 0) # show red
# channelHot = (0, 0, 0, 1) # show alpha
# channelHot = (1, 1, 1, 0) # show luma

lumacoef = config.getDefaultLumaCoefs()

m44, offset = OCIO.MatrixTransform.View(channelHot, lumacoef)

swizzle = OCIO.MatrixTransform()
swizzle.setValue(m44, offset)
transform.setChannelView(swizzle)

# And then process the image normally.
processor = config.getProcessor(transform)

print processor.applyRGB(imageData)

I believe this is the current way of doing things (at least as of OCIO 1.x):

import PyOpenColorIO as OCIO

# Step 1: Get the config
cfg = OCIO.Config.CreateFromEnv()

# Step 2: Get the default display and view (see also cfg.getActiveDisplays/Views)
display = cfg.getDefaultDisplay()
view = cfg.getDefaultView(display)

# Step 3: Create a DisplayTransform, and set the input and display ColorSpaces
# (This example assumes the input is scene linear. Adapt as needed.)

transform = OCIO.DisplayTransform()
transform.setInputColorSpaceName(OCIO.Constants.ROLE_SCENE_LINEAR)
transform.setDisplay(display)
transform.setView(view)

# Step 4: Add custom transforms for a 'canonical' Display Pipeline

# Add an fstop exposure control (in SCENE_LINEAR)
exposure = 0 # Example data: zero exposure adjustment
gain = 2**exposure
slope3f = (gain, gain, gain)

cc = OCIO.CDLTransform()
cc.setSlope(slope3f)

transform.setLinearCC(cc)

# Add a Channel view 'swizzle'

channelHot = (1, 1, 1, 1) # show rgb
# channelHot = (1, 0, 0, 0) # show red
# channelHot = (0, 0, 0, 1) # show alpha
# channelHot = (1, 1, 1, 0) # show luma

lumacoef = cfg.getDefaultLumaCoefs()

m44, offset = OCIO.MatrixTransform.View(channelHot, lumacoef)

swizzle = OCIO.MatrixTransform()
swizzle.setValue(m44, offset)
transform.setChannelView(swizzle)

# And then process the image normally.
processor = cfg.getProcessor(transform)

imageData = [0,0,0, 1,0,0] # Example data: A black and a red pixel
print processor.applyRGB(imageData)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (15 by maintainers)

Most upvoted comments

@thirdknife You could now update the example as #929 is now merged.

  1. Yes.

  2. The command /usr/bin/python2.7 "/workspaces/CIO/tests/python/OpenColorIOTestSuite.py" "/workspaces/CIO/build" "True" takes care of everything needed to run the unit tests. Check the content of the file OpenColorIOTestSuite.py from line 6 to line 26.

Bottom line, running unit tests does not require any installation. The idea is to guarantee the use of the locally compiled library.