Fix #144681: Add support for inactive color spaces
So far only active color spaces were queries from the OpenColorIO, which made sense from the list of spaces displayed in the menus. However, some logic requires knowing more details about color spaces used by displays, for example to check if it is data, or whether color space matches the display one. This change makes it so our OpenColorIO integration handles inactive color spaces by storing them in a separate array. Config::get_color_space will now work for both active and inactive color spaces. Pull Request: https://projects.blender.org/blender/blender/pulls/144780
This commit is contained in:
committed by
Sergey Sharybin
parent
075c2eca06
commit
660f6ae0ec
@@ -78,14 +78,15 @@ LibOCIOConfig::LibOCIOConfig(const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config
|
||||
OCIO_NAMESPACE::SetCurrentConfig(ocio_config);
|
||||
ocio_config_ = OCIO_NAMESPACE::GetCurrentConfig();
|
||||
|
||||
initialize_color_spaces();
|
||||
initialize_active_color_spaces();
|
||||
initialize_inactive_color_spaces();
|
||||
initialize_looks();
|
||||
initialize_displays();
|
||||
}
|
||||
|
||||
LibOCIOConfig::~LibOCIOConfig() {}
|
||||
|
||||
void LibOCIOConfig::initialize_color_spaces()
|
||||
void LibOCIOConfig::initialize_active_color_spaces()
|
||||
{
|
||||
OCIO_NAMESPACE::ColorSpaceSetRcPtr ocio_color_spaces;
|
||||
|
||||
@@ -125,6 +126,34 @@ void LibOCIOConfig::initialize_color_spaces()
|
||||
});
|
||||
}
|
||||
|
||||
void LibOCIOConfig::initialize_inactive_color_spaces()
|
||||
{
|
||||
const int num_inactive_color_spaces = ocio_config_->getNumColorSpaces(
|
||||
OCIO_NAMESPACE::SEARCH_REFERENCE_SPACE_ALL, OCIO_NAMESPACE::COLORSPACE_INACTIVE);
|
||||
if (num_inactive_color_spaces < 0) {
|
||||
report_error(fmt::format(
|
||||
"Invalid OpenColorIO configuration: invalid number of inactive color spaces {}",
|
||||
num_inactive_color_spaces));
|
||||
return;
|
||||
}
|
||||
|
||||
for (const int i : IndexRange(num_inactive_color_spaces)) {
|
||||
const char *colorspace_name = ocio_config_->getColorSpaceNameByIndex(
|
||||
OCIO_NAMESPACE::SEARCH_REFERENCE_SPACE_ALL, OCIO_NAMESPACE::COLORSPACE_INACTIVE, i);
|
||||
|
||||
OCIO_NAMESPACE::ConstColorSpaceRcPtr ocio_color_space;
|
||||
try {
|
||||
ocio_color_space = ocio_config_->getColorSpace(colorspace_name);
|
||||
}
|
||||
catch (OCIO_NAMESPACE::Exception &exception) {
|
||||
report_exception(exception);
|
||||
continue;
|
||||
}
|
||||
|
||||
inactive_color_spaces_.append_as(i, ocio_config_, ocio_color_space);
|
||||
}
|
||||
}
|
||||
|
||||
void LibOCIOConfig::initialize_looks()
|
||||
{
|
||||
const int num_looks = ocio_config_->getNumLooks();
|
||||
@@ -269,10 +298,18 @@ const ColorSpace *LibOCIOConfig::get_color_space(const StringRefNull name) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* TODO(sergey): Is there faster way to lookup Blender-side color space?
|
||||
* It does not seem that pointer in ConstColorSpaceRcPtr is unique enough to use for
|
||||
* comparison. */
|
||||
for (const LibOCIOColorSpace &color_space : color_spaces_) {
|
||||
/* TODO(sergey): Is there faster way to lookup Blender-side color space?
|
||||
* It does not seem that pointer in ConstColorSpaceRcPtr is unique enough to use for
|
||||
* comparison. */
|
||||
if (color_space.name() == ocio_color_space->getName()) {
|
||||
return &color_space;
|
||||
}
|
||||
}
|
||||
|
||||
/* Also lookup in the inactive color space, as the requested space might be coming from the
|
||||
* display and marked as inactive to prevent it from showing up in the application menu. */
|
||||
for (const LibOCIOColorSpace &color_space : inactive_color_spaces_) {
|
||||
if (color_space.name() == ocio_color_space->getName()) {
|
||||
return &color_space;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ class LibOCIOConfig : public Config {
|
||||
* array does not contain aliases or roles. If role or alias is to be resolved OpenColorIO is to
|
||||
* be used first to provide color space name which then can be looked up in this array. */
|
||||
Vector<LibOCIOColorSpace> color_spaces_;
|
||||
Vector<LibOCIOColorSpace> inactive_color_spaces_;
|
||||
Vector<LibOCIOLook> looks_;
|
||||
Vector<LibOCIODisplay> displays_;
|
||||
|
||||
@@ -96,7 +97,8 @@ class LibOCIOConfig : public Config {
|
||||
|
||||
/* Initialize BLender-side representation of color spaces, displays, etc. from the current
|
||||
* OpenColorIO configuration. */
|
||||
void initialize_color_spaces();
|
||||
void initialize_active_color_spaces();
|
||||
void initialize_inactive_color_spaces();
|
||||
void initialize_looks();
|
||||
void initialize_displays();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user