Blender V5.3
libocio_config.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <memory>
8
9#include "MEM_guardedalloc.h"
10
11#include "BLI_set.hh"
12#include "BLI_vector.hh"
13
14#include "OCIO_config.hh"
15
16#include "libocio_colorspace.hh"
17#include "libocio_display.hh"
19#include "libocio_look.hh"
20
21#include "../opencolorio.hh"
22
23namespace blender::ocio {
24
25class ColorSpace;
26class Display;
27class View;
28
29class LibOCIOConfig : public Config {
30 OCIO_NAMESPACE::ConstConfigRcPtr ocio_config_;
31
32 /* Storage of for Blender-side representation of OpenColorIO configuration.
33 * Note that the color spaces correspond to color spaces from OpenColorIO configuration: this
34 * array does not contain aliases or roles. If role or alias is to be resolved OpenColorIO is to
35 * be used first to provide color space name which then can be looked up in this array.
36 *
37 * Color spaces are stored through unique pointers so their addresses are stable after
38 * switching configs and reusing color spaces. */
40 Vector<std::unique_ptr<LibOCIOColorSpace>> inactive_color_spaces_;
42 Vector<LibOCIODisplay> displays_;
43
44 /* Color spaces that existed in a previous configuration but no longer exist
45 * in the current config. */
46 Vector<std::unique_ptr<LibOCIOColorSpace>> retained_color_spaces_;
47
48 /* Array with indices into color_spaces_.
49 * color_spaces_[sorted_color_space_index_[i]] provides alphabetically sorted access. */
50 Vector<int> sorted_color_space_index_;
51
52 LibOCIOGPUShaderBinder gpu_shader_binder_{*this};
53
54 public:
55 ~LibOCIOConfig() override;
56
57 static std::unique_ptr<Config> create_from_environment();
58 static std::unique_ptr<Config> create_fallback();
59
60 /* Color space information. */
61 float3 get_default_luma_coefs() const override;
63 const char *get_color_space_from_filepath(const char *filepath) const override;
64
65 /* Color space API. */
66 const ColorSpace *get_color_space(StringRefNull name) const override;
67 int get_num_active_color_spaces() const override;
68 int get_num_all_color_spaces() const override;
69 const ColorSpace *get_color_space_by_index(int index) const override;
70 const ColorSpace *get_sorted_color_space_by_index(int index) const override;
71 const ColorSpace *get_color_space_by_interop_id(StringRefNull interop_id) const override;
72 bool is_role(StringRefNull name) const override;
73 const ColorSpace *get_color_space_for_hdr_image(StringRefNull name) const override;
74
75 /* Working space API. */
76 void set_scene_linear_role(StringRefNull name) override;
77
78 /* Config switching API. */
79 bool switch_to_from_environment(FunctionRef<bool(const Config &)> validate) override;
80 bool switch_to(Config &new_config, FunctionRef<bool(const Config &)> validate) override;
81
82 /* Display API. */
83 const Display *get_default_display() const override;
84 const Display *get_display_by_name(StringRefNull name) const override;
85 int get_num_displays() const override;
86 const Display *get_display_by_index(int index) const override;
87
88 /* Display colorspace API. */
90 StringRefNull view) const override;
91
92 /* Look API. */
93 const Look *get_look_by_name(StringRefNull name) const override;
94 int get_num_looks() const override;
95 const Look *get_look_by_index(int index) const override;
96
97 /* Processor API. */
98 std::shared_ptr<const CPUProcessor> get_display_cpu_processor(
99 const DisplayParameters &display_parameters) const override;
100 std::shared_ptr<const CPUProcessor> get_cpu_processor(
101 StringRefNull from_colorspace, StringRefNull to_colorspace) const override;
102
103 /* Processor API. */
104 const GPUShaderBinder &get_gpu_shader_binder() const override;
105
106 /* Integration with the OpenColorIO specific routines. */
107 const OCIO_NAMESPACE::ConstConfigRcPtr &get_ocio_config() const
108 {
109 return ocio_config_;
110 }
111
113
114 private:
115 struct ColorSpacesRetained;
116
117 explicit LibOCIOConfig(const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config);
118
119 void reinitialize(LibOCIOConfig &new_config);
120
121 /* Initialize BLender-side representation of color spaces, displays, etc. from the current
122 * OpenColorIO configuration. */
123 void initialize_active_color_spaces(Set<StringRef> &primary_interop_ids);
124 void initialize_sorted_color_space_index();
125 void initialize_inactive_color_spaces(Set<StringRef> &primary_interop_ids);
126 void initialize_hdr_color_spaces(Set<StringRef> &primary_interop_ids);
127 void initialize_looks();
128 void initialize_displays();
129
130 /* Move #new_color_spaces into #color_spaces, reusing retained color spaces if possible. */
131 void reuse_color_spaces(Vector<std::unique_ptr<LibOCIOColorSpace>> &new_color_spaces,
132 Vector<std::unique_ptr<LibOCIOColorSpace>> &color_spaces,
133 ColorSpacesRetained &retained);
134
135 bool has_color_space_name(const char *name) const;
136};
137
138} // namespace blender::ocio
Read Blender memory allocation and freeing.
const ColorSpace * get_color_space_for_hdr_image(StringRefNull name) const override
const Display * get_display_by_name(StringRefNull name) const override
int get_num_looks() const override
std::shared_ptr< const CPUProcessor > get_display_cpu_processor(const DisplayParameters &display_parameters) const override
void set_scene_linear_role(StringRefNull name) override
int get_num_all_color_spaces() const override
int get_num_active_color_spaces() const override
float3 get_default_luma_coefs() const override
int get_num_displays() const override
float3x3 get_xyz_to_scene_linear_matrix() const override
std::shared_ptr< const CPUProcessor > get_cpu_processor(StringRefNull from_colorspace, StringRefNull to_colorspace) const override
const char * get_color_space_from_filepath(const char *filepath) const override
const Display * get_display_by_index(int index) const override
bool switch_to(Config &new_config, FunctionRef< bool(const Config &)> validate) override
static std::unique_ptr< Config > create_from_environment()
const Look * get_look_by_index(int index) const override
const ColorSpace * get_display_view_color_space(StringRefNull display, StringRefNull view) const override
static std::unique_ptr< Config > create_fallback()
bool switch_to_from_environment(FunctionRef< bool(const Config &)> validate) override
const ColorSpace * get_sorted_color_space_by_index(int index) const override
const ColorSpace * get_color_space(StringRefNull name) const override
const ColorSpace * get_color_space_by_interop_id(StringRefNull interop_id) const override
const ColorSpace * get_color_space_by_index(int index) const override
const GPUShaderBinder & get_gpu_shader_binder() const override
const Look * get_look_by_name(StringRefNull name) const override
const OCIO_NAMESPACE::ConstConfigRcPtr & get_ocio_config() const
bool is_role(StringRefNull name) const override
const Display * get_default_display() const override
MEM_CXX_CLASS_ALLOC_FUNCS("LibOCIOConfig")
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3