List available color spaces

Color spaces available in texture nodes depend on the OpenColorIO configuration of the user. Is there a clean way to list them? So far I’ve been using this terrible hack:

def listAvailableColorSpaces(image):
    # Warning: hack ahead
    try:
        image.colorspace_settings.name = ''
    except TypeError as e:
        s = str(e)
    return eval(s[s.find('('):])

bl_rna should be of help here:

type(img).bl_rna.properties['colorspace_settings'].fixed_type.properties['name'].enum_items

gives:

0 <bpy_struct, EnumPropertyItem("Filmic Log")>
1 <bpy_struct, EnumPropertyItem("Linear")>
2 <bpy_struct, EnumPropertyItem("Linear ACES")>
3 <bpy_struct, EnumPropertyItem("Non-Color")>
4 <bpy_struct, EnumPropertyItem("Raw")>
5 <bpy_struct, EnumPropertyItem("sRGB")>
6 <bpy_struct, EnumPropertyItem("XYZ")>
1 Like

Great, thanks, I must admit I’m not used to dive into the raw bl_rna attribute!