in src/open_vp_cal/core/ocio_utils.py [0:0]
def bake_3d_lut(
input_color_space: str, ocio_display_colour_space: str, ocio_view_transform: str, config_path: str,
output_lut_path: str, cube_size: int = 64, lut_format: str = "resolve_cube") -> str:
"""
Bake a 3D LUT from an OpenColorIO configuration.
Args:
input_color_space (str): The input colour space.
ocio_display_colour_space (str): The OCIO display colour space.
ocio_view_transform (str): The OCIO view transform.
config_path (str): Path to the OCIO configuration file.
output_lut_path (str): Path to save the baked 3D LUT.
cube_size (int): Cube size for the 3D LUT. Default is 33.
lut_format (str): Format for the 3D LUT. Default is "cub".
"""
# Load the OCIO configuration
config = ocio.Config.CreateFromFile(config_path)
# Validate the colour spaces
if not any(cs.getName() == input_color_space for cs in config.getColorSpaces()):
raise ValueError(f"Input color space '{input_color_space}' does not exist in the provided OCIO config.")
if not any(cs == ocio_display_colour_space for cs in config.getDisplaysAll()):
raise ValueError(
f"Display Colour Space '{ocio_display_colour_space}' does not exist in the provided OCIO config.")
if not any(cs == ocio_view_transform for cs in config.getViews(ocio_display_colour_space)):
raise ValueError(
f"View Transform '{ocio_view_transform}' does not exist in the provided OCIO config.")
# Create the Baker and set its properties
baker = ocio.Baker()
baker.setConfig(config)
baker.setFormat(lut_format)
baker.setInputSpace(input_color_space)
baker.setDisplayView(ocio_display_colour_space, ocio_view_transform)
baker.setCubeSize(cube_size)
# Bake the LUT
baker.bake(output_lut_path)
return output_lut_path