def create_ocio_processor(lutfile,
                          interpolation=INTERP_LINEAR,
                          inverse=False,
                          prelutfile=None,
                          postlutfile=None):
    """Create an OpenColorIO processor for lutfile

    Args:
        lutfile (str): path to a LUT

        interpolation (int): can be INTERP_NEAREST, INTERP_LINEAR or
        INTERP_TETRAHEDRAL (only for 3D LUT)

        inverse (bool): get an inverse direction processor

    Kwargs:
        prelutfile (str): path to a pre LUT

        postlutfile (str): path to a post LUT

    Returns:
        PyOpenColorIO.config.Processor.

    """
    if inverse:
        direction = TRANSFORM_DIR_INVERSE
    else:
        direction = TRANSFORM_DIR_FORWARD
    config = Config()
    # In colorspace (LUT)
    colorspace = ColorSpace(name='RawInput')
    mainLut = FileTransform(lutfile,
                            interpolation=interpolation,
                            direction=direction)
    group = GroupTransform()
    # Prelut
    if prelutfile:
        prelut = FileTransform(prelutfile, interpolation=interpolation)
        group.push_back(prelut)
    # Mainlut
    group.push_back(mainLut)
    # Postlut
    if postlutfile:
        postlut = FileTransform(postlutfile, interpolation=interpolation)
        group.push_back(postlut)
    colorspace.setTransform(group, COLORSPACE_DIR_TO_REFERENCE)
    config.addColorSpace(colorspace)
    # Out colorspace
    colorspace = ColorSpace(name='ProcessedOutput')
    config.addColorSpace(colorspace)
    # Create a processor corresponding to the LUT transformation
    return config.getProcessor('RawInput', 'ProcessedOutput')
def create_ocio_processor(lutfile, interpolation=INTERP_LINEAR, inverse=False,
                          prelutfile=None, postlutfile=None):
    """Create an OpenColorIO processor for lutfile

    Args:
        lutfile (str): path to a LUT

        interpolation (int): can be INTERP_NEAREST, INTERP_LINEAR or
        INTERP_TETRAHEDRAL (only for 3D LUT)

        inverse (bool): get an inverse direction processor

    Kwargs:
        prelutfile (str): path to a pre LUT

        postlutfile (str): path to a post LUT

    Returns:
        PyOpenColorIO.config.Processor.

    """
    if inverse:
        direction = TRANSFORM_DIR_INVERSE
    else:
        direction = TRANSFORM_DIR_FORWARD
    config = Config()
    # In colorspace (LUT)
    colorspace = ColorSpace(name='RawInput')
    mainLut = FileTransform(lutfile, interpolation=interpolation,
                            direction=direction)
    group = GroupTransform()
    # Prelut
    if prelutfile:
        prelut = FileTransform(prelutfile, interpolation=interpolation)
        group.push_back(prelut)
    # Mainlut
    group.push_back(mainLut)
    # Postlut
    if postlutfile:
        postlut = FileTransform(postlutfile, interpolation=interpolation)
        group.push_back(postlut)
    colorspace.setTransform(group, COLORSPACE_DIR_TO_REFERENCE)
    config.addColorSpace(colorspace)
    # Out colorspace
    colorspace = ColorSpace(name='ProcessedOutput')
    config.addColorSpace(colorspace)
    # Create a processor corresponding to the LUT transformation
    return config.getProcessor('RawInput', 'ProcessedOutput')
Beispiel #3
0
def create_ocio_processor(lutfiles,
                          interpolation=Constants.INTERP_LINEAR,
                          inverse=False,
                          prelutfile=None,
                          postlutfile=None):
    """Create an OpenColorIO processor for lutfile

    Args:
        lutfiles (str or [str]): path to a LUT or list of LUT paths

        interpolation (int): can be INTERP_NEAREST, INTERP_LINEAR or
        INTERP_TETRAHEDRAL (only for 3D LUT)

        inverse (bool): get an inverse direction processor

    Kwargs:
        prelutfile (str): path to a pre LUT

        postlutfile (str): path to a post LUT

    Returns:
        PyOpenColorIO.config.Processor.

    """
    if inverse:
        direction = Constants.TRANSFORM_DIR_INVERSE
    else:
        direction = Constants.TRANSFORM_DIR_FORWARD
    config = Config()
    # In colorspace (LUT)
    colorspace = ColorSpace(name='RawInput')
    group = GroupTransform()
    # Prelut
    if prelutfile:
        prelut = FileTransform(prelutfile, interpolation=interpolation)
        group.push_back(prelut)
    # Mainlut
    if not isinstance(lutfiles, (list, tuple)):
        lutfiles = [lutfiles]
    for lutfile in lutfiles:
        main_lut = FileTransform(lutfile,
                                 interpolation=interpolation,
                                 direction=direction)
        group.push_back(main_lut)
    # Postlut
    if postlutfile:
        postlut = FileTransform(postlutfile, interpolation=interpolation)
        group.push_back(postlut)
    colorspace.setTransform(group, Constants.COLORSPACE_DIR_TO_REFERENCE)
    config.addColorSpace(colorspace)
    # Out colorspace
    colorspace = ColorSpace(name='ProcessedOutput')
    config.addColorSpace(colorspace)
    # Create a processor corresponding to the LUT transformation
    try:
        return config.getProcessor('RawInput', 'ProcessedOutput')
    except Exception as e:
        # tetrahedral interpolation is only allowed with 3D LUT
        # TODO set interpo mode by LUT
        if "tetrahedral interpolation is not allowed" in str(e):
            return create_ocio_processor(lutfiles,
                                         interpolation=Constants.INTERP_LINEAR,
                                         inverse=inverse,
                                         prelutfile=prelutfile,
                                         postlutfile=postlutfile)
        raise
Beispiel #4
0
def create_ocio_processor(lutfiles, interpolation=INTERP_LINEAR, inverse=False,
                          prelutfile=None, postlutfile=None):
    """Create an OpenColorIO processor for lutfile

    Args:
        lutfiles (str or [str]): path to a LUT or list of LUT paths

        interpolation (int): can be INTERP_NEAREST, INTERP_LINEAR or
        INTERP_TETRAHEDRAL (only for 3D LUT)

        inverse (bool): get an inverse direction processor

    Kwargs:
        prelutfile (str): path to a pre LUT

        postlutfile (str): path to a post LUT

    Returns:
        PyOpenColorIO.config.Processor.

    """
    if inverse:
        direction = TRANSFORM_DIR_INVERSE
    else:
        direction = TRANSFORM_DIR_FORWARD
    config = Config()
    # In colorspace (LUT)
    colorspace = ColorSpace(name='RawInput')
    group = GroupTransform()
    # Prelut
    if prelutfile:
        prelut = FileTransform(prelutfile, interpolation=interpolation)
        group.push_back(prelut)
    # Mainlut
    if not isinstance(lutfiles, (list, tuple)):
        lutfiles = [lutfiles]
    for lutfile in lutfiles:
        main_lut = FileTransform(lutfile, interpolation=interpolation,
                                 direction=direction)
        group.push_back(main_lut)
    # Postlut
    if postlutfile:
        postlut = FileTransform(postlutfile, interpolation=interpolation)
        group.push_back(postlut)
    colorspace.setTransform(group, COLORSPACE_DIR_TO_REFERENCE)
    config.addColorSpace(colorspace)
    # Out colorspace
    colorspace = ColorSpace(name='ProcessedOutput')
    config.addColorSpace(colorspace)
    # Create a processor corresponding to the LUT transformation
    try:
        return config.getProcessor('RawInput', 'ProcessedOutput')
    except Exception, e:
        # tetrahedral interpolation is only allowed with 3D LUT
        # TODO set interpo mode by LUT
        if "tetrahedral interpolation is not allowed" in str(e):
            return create_ocio_processor(lutfiles, interpolation=INTERP_LINEAR,
                                         inverse=inverse,
                                         prelutfile=prelutfile,
                                         postlutfile=postlutfile)
        raise
Beispiel #5
0
def get_displays_list(ocio_config_obj: OCIO.Config) -> Generator[Any, Any, None]:
    """Retrieve the display names from the OCIO configuration object"""
    return (display for display in ocio_config_obj.getDisplays())
Beispiel #6
0
def get_looks_names_list(ocio_config_obj: OCIO.Config) -> Generator[Any, Any, None]:
    """Retrieve the look names from the OCIO configuration object"""
    return (look_name for look_name in ocio_config_obj.getLookNames())
Beispiel #7
0
def get_colorspaces_names_list(
    ocio_config_obj: OCIO.Config,
) -> Generator[Any, Any, None]:
    """Retrieve the colorspace names from the OCIO configuration object"""
    return (colorspace_name for colorspace_name in ocio_config_obj.getColorSpaceNames())