Example #1
0
def get_camera_colorspaces(family=""):
    colorspaces = []
    # get Camera Log colorspaces from Builtins
    for name, description in ocio.BuiltinTransformRegistry().getBuiltins():
        if name.endswith("to_ACES2065-1"):
            colorspaces.append(
                ocio.ColorSpace(
                    name=description.split("Convert ")[-1].split(" to ")[0],
                    family=family,
                    encoding="log",
                    toReference=ocio.BuiltinTransform(name),
                ))
    return colorspaces
Example #2
0
    def test_multi_reference(self):
        # Registry is a singleton. Make sure multiple Python
        # instances can be held.
        instances = []
        for i in range(10):
            instances.append(OCIO.BuiltinTransformRegistry())

        # Other instances should still function after deleting one. The
        # underlying C++ object is not deleted.
        instance_0 = instances.pop(0)
        self.assertEqual(len(instances), 9)
        del instance_0

        # Variable is no longer defined
        with self.assertRaises(NameError):
            len(instance_0)

        # Test underlying C++ reference validity by accessing registry
        # data for each instance.
        for instance in instances:
            self.assertGreaterEqual(len(instance), 1)
            self.assertEqual(len(instance), len(self.REGISTRY))
def generate_config_aces(
        config_name=None,
        validate=True,
        describe=ColorspaceDescriptionStyle.SHORT_UNION,
        config_mapping_file_path=ACES_CONFIG_REFERENCE_MAPPING_FILE_PATH,
        analytical=True,
        additional_data=False):
    """
    Generates the *aces-dev* reference implementation *OpenColorIO* Config
    using the *Mapping* method.

    The Config generation is constrained by a *CSV* file exported from the
    *Reference Config - Mapping* sheet from a
    `Google Sheets file <https://docs.google.com/spreadsheets/d/\
    1SXPt-USy3HlV2G2qAvh9zit6ZCINDOlfKT07yXJdWLg>`__. The *Google Sheets* file
    was originally authored using the output of the *aces-dev* conversion graph
    to support the discussions of the *OpenColorIO* *Working Group* on the
    design of the  *aces-dev* reference implementation *OpenColorIO* Config.
    The resulting mapping is the outcome of those discussions and leverages the
    new *OpenColorIO 2* display architecture while factoring many transforms.

    Parameters
    ----------
    config_name : unicode, optional
        *OpenColorIO* config file name, if given the config will be written to
        disk.
    validate : bool, optional
        Whether to validate the config.
    describe : int, optional
        Any value from the
        :class:`opencolorio_config_aces.ColorspaceDescriptionStyle` enum.
    config_mapping_file_path : unicode, optional
        Path to the *CSV* mapping file used by the *Mapping* method.
    analytical : bool, optional
        Whether to generate *OpenColorIO* transform families that analytically
        match the given *ACES* *CTL* transform, i.e. true to the *aces-dev*
        reference but not necessarily user friendly.
    additional_data : bool, optional
        Whether to return additional data.

    Returns
    -------
    Config or tuple
        *OpenColorIO* config or tuple of *OpenColorIO* config,
        :class:`opencolorio_config_aces.ConfigData` class instance and dict of
        *OpenColorIO* colorspaces and
        :class:`opencolorio_config_aces.config.reference.CTLTransform` class
        instances.
    """

    import PyOpenColorIO as ocio

    ctl_transforms = unclassify_ctl_transforms(
        classify_aces_ctl_transforms(discover_aces_ctl_transforms()))

    builtin_transforms = [
        builtin for builtin in ocio.BuiltinTransformRegistry()
    ]

    config_mapping = defaultdict(list)
    with open(config_mapping_file_path) as csv_file:
        dict_reader = csv.DictReader(csv_file,
                                     delimiter=',',
                                     fieldnames=[
                                         'ordering',
                                         'aces_transform_id',
                                         'builtin_transform_style',
                                         'linked_display_colorspace_style',
                                         'interface',
                                         'encoding',
                                         'categories',
                                     ])

        # Skipping the first header line.
        next(dict_reader)

        for transform_data in dict_reader:
            # Checking whether the "BuiltinTransform" style exists.
            style = transform_data['builtin_transform_style']
            if style:
                assert (style in builtin_transforms), (
                    f'"{style}" "BuiltinTransform" style does not '
                    f'exist!')

            # Checking whether the linked "DisplayColorspace"
            # "BuiltinTransform" style exists.
            style = transform_data['linked_display_colorspace_style']
            if style:
                assert (style in builtin_transforms), (
                    f'"{style}" "BuiltinTransform" style does not '
                    f'exist!')

            # Finding the "CTLTransform" class instance that matches given
            # "ACEStransformID", if it does not exist, there is a critical
            # mismatch in the mapping with *aces-dev*.
            aces_transform_id = transform_data['aces_transform_id']
            filtered_ctl_transforms = [
                ctl_transform for ctl_transform in ctl_transforms
                if ctl_transform.aces_transform_id.aces_transform_id ==
                aces_transform_id
            ]

            ctl_transform = next(iter(filtered_ctl_transforms), None)

            assert ctl_transform is not None, (
                f'"aces-dev" has no transform with "{aces_transform_id}" '
                f'ACEStransformID, please cross-check the '
                f'"{config_mapping_file_path}" config mapping file and '
                f'the "aces-dev" "CTL" transforms!')

            transform_data['ctl_transform'] = ctl_transform

            config_mapping[transform_data['builtin_transform_style']].append(
                transform_data)

    colorspaces = []
    looks = []
    displays, display_names = [], []
    view_transforms, view_transform_names = [], []
    shared_views = []

    aces_family_prefix = 'CSC' if analytical else 'ACES'

    scene_reference_colorspace = colorspace_factory(
        f'{aces_family_prefix} - {ACES_CONFIG_REFERENCE_COLORSPACE}',
        'ACES',
        description=(
            'The "Academy Color Encoding System" reference colorspace.'),
        encoding='scene-linear')

    display_reference_colorspace = colorspace_factory(
        'CIE-XYZ-D65',
        description='The "CIE XYZ (D65)" display connection colorspace.',
        reference_space=ocio.REFERENCE_SPACE_DISPLAY)

    raw_colorspace = colorspace_factory(
        'Utility - Raw',
        'Utility',
        description='The utility "Raw" colorspace.',
        is_data=True)

    colorspaces += [
        scene_reference_colorspace,
        display_reference_colorspace,
        raw_colorspace,
    ]

    for style, transforms_data in config_mapping.items():
        if transforms_data[0]['interface'] == 'ViewTransform':
            view_transform = style_to_view_transform(style, [
                transform_data['ctl_transform']
                for transform_data in transforms_data
            ], describe)
            view_transforms.append(view_transform)
            view_transform_name = view_transform.getName()
            view_transform_names.append(view_transform_name)

            for transform_data in transforms_data:
                display_style = transform_data[
                    'linked_display_colorspace_style']

                display = style_to_display_colorspace(
                    display_style,
                    encoding=transform_data.get('encoding'),
                    categories=transform_data.get('categories'))
                display_name = display.getName()

                if display_name not in display_names:
                    displays.append(display)
                    display_names.append(display_name)

                shared_views.append({
                    'display': display_name,
                    'view': view_transform_name,
                    'view_transform': view_transform_name,
                })
        else:
            for transform_data in transforms_data:
                ctl_transform = transform_data['ctl_transform']

                if transform_data['interface'] == 'Look':
                    look = ctl_transform_to_look(
                        ctl_transform,
                        describe,
                        analytical=analytical,
                        forward_transform=create_builtin_transform(style),
                        process_space=scene_reference_colorspace.getName(),
                    )

                    looks.append(look)
                else:
                    colorspace = ctl_transform_to_colorspace(
                        ctl_transform,
                        describe,
                        analytical=analytical,
                        to_reference=create_builtin_transform(style),
                        encoding=transform_data.get('encoding'),
                        categories=transform_data.get('categories'))

                    colorspaces.append(colorspace)

    untonemapped_view_transform = view_transform_factory(
        'Un-tone-mapped',
        from_reference=ocio.BuiltinTransform(
            'UTILITY - ACES-AP0_to_CIE-XYZ-D65_BFD'),
    )
    untonemapped_view_transform_name = untonemapped_view_transform.getName()
    for display in display_names:
        shared_views.append({
            'display': display,
            'view': untonemapped_view_transform_name,
            'view_transform': untonemapped_view_transform_name,
        })

    data = ConfigData(
        description=(
            f'The "Academy Color Encoding System" (ACES) "Reference Config".'
            f'\n\n'
            f'This "OpenColorIO" config is a strict and quasi-analytical '
            f'implementation of "aces-dev" and is designed as a reference for '
            f'software developers. It is not a replacement for the previous '
            f'"ACES" configs nor the "ACES Studio Config".'
            f'\n\n'
            f'Generated with "OpenColorIO-Config-ACES" {git_describe()} '
            f'on the {datetime.now().strftime("%Y/%m/%d at %H:%M")}.'),
        roles={
            ocio.ROLE_COLOR_TIMING: f'{aces_family_prefix} - ACEScct',
            ocio.ROLE_COMPOSITING_LOG: f'{aces_family_prefix} - ACEScct',
            ocio.ROLE_DATA: 'Utility - Raw',
            ocio.ROLE_DEFAULT: scene_reference_colorspace.getName(),
            ocio.ROLE_INTERCHANGE_DISPLAY:
            display_reference_colorspace.getName(),
            ocio.ROLE_INTERCHANGE_SCENE: scene_reference_colorspace.getName(),
            ocio.ROLE_REFERENCE: scene_reference_colorspace.getName(),
            ocio.ROLE_RENDERING: f'{aces_family_prefix} - ACEScg',
            ocio.ROLE_SCENE_LINEAR: f'{aces_family_prefix} - ACEScg',
        },
        colorspaces=colorspaces + displays,
        looks=looks,
        view_transforms=view_transforms + [untonemapped_view_transform],
        shared_views=shared_views,
        views=shared_views + [{
            'display': display,
            'view': 'Raw',
            'colorspace': 'Utility - Raw'
        } for display in display_names],
        active_displays=display_names,
        active_views=view_transform_names + ['Raw'],
        file_rules=[{
            'name': 'Default',
            'colorspace': scene_reference_colorspace.getName()
        }],
        inactive_colorspaces=['CIE-XYZ-D65'],
        default_view_transform=untonemapped_view_transform.getName(),
        profile_version=2)

    config = generate_config(data, config_name, validate)

    if additional_data:
        return config, data
    else:
        return config
Example #4
0
 def setUpClass(cls):
     cls.REGISTRY = OCIO.BuiltinTransformRegistry()