OpenColorIO (OCIO)

2.5.1 · active · verified Thu Apr 16

OpenColorIO (OCIO) is an Academy Software Foundation (ASWF) project providing a comprehensive color management solution for motion picture production, visual effects, and computer animation. It offers a consistent user experience, is compatible with the Academy Color Encoding Specification (ACES), and is LUT-format agnostic. The current version is 2.5.1, and the project targets annual releases around September, aligning with the VFX Reference Platform schedule.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to perform a basic color space transformation on an RGB value. It requires an OpenColorIO configuration file (e.g., an ACES config) to be accessible, typically via the `OCIO` environment variable. The example shows how to load the current configuration, create a processor between two color spaces, and apply the transformation using the CPU processor.

import os
import PyOpenColorIO as OCIO

def apply_color_transform(rgb_value, source_space, destination_space, ocio_config_path):
    # Ensure the OCIO environment variable is set for config loading
    if 'OCIO' not in os.environ or os.environ['OCIO'] != ocio_config_path:
        os.environ['OCIO'] = ocio_config_path
    
    try:
        config = OCIO.GetCurrentConfig()
        processor = config.getProcessor(source_space, destination_space)
        cpu_processor = processor.getDefaultCPUProcessor()
        
        # Apply the transform to an RGB tuple/list
        transformed_rgb = cpu_processor.applyRGB(rgb_value)
        return transformed_rgb
    except OCIO.Exception as e:
        print(f"OpenColorIO Error: {e}")
        return None

# Example Usage (requires an OCIO config file to be set up)
# You can download reference configs from https://github.com/AcademySoftwareFoundation/OpenColorIO-Config-ACES
# For example, use 'aces_1.2/config.ocio'

# NOTE: Replace with the actual path to your OCIO config file
ocio_config_file = os.environ.get('OCIO_TEST_CONFIG', './config.ocio') # Placeholder for CI/testing

if not os.path.exists(ocio_config_file):
    print(f"Warning: OCIO config file not found at '{ocio_config_file}'. Skipping quickstart example. "
          "Please set the OCIO_TEST_CONFIG environment variable or provide a valid path.")
else:
    print(f"Using OCIO config: {ocio_config_file}")
    input_rgb = [0.5, 0.1, 0.9] # Example color in source_space
    src_cs = 'sRGB'
    dst_cs = 'ACES - ACEScg'
    
    # Note: The exact color space names depend on the loaded OCIO config.
    # Common ones are 'sRGB', 'ACES - ACEScg', 'Utility - Linear - sRGB', etc.
    
    transformed_color = apply_color_transform(
        input_rgb, src_cs, dst_cs, ocio_config_file
    )

    if transformed_color:
        print(f"Original RGB ({src_cs}): {input_rgb}")
        print(f"Transformed RGB ({dst_cs}): {transformed_color}")

view raw JSON →