Skip to content

Commit 92487c6

Browse files
authored
Merge pull request #182 from kenmcgaugh/ocio_additions
OCIO view hotkeys, working_space, and file-path remapping
2 parents e4e48f6 + 58d0915 commit 92487c6

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

src/plugin/colour_pipeline/ocio/src/ocio_engine.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
#include "ocio_engine.hpp"
33

4+
#include "xstudio/utility/helpers.hpp"
45
#include "xstudio/utility/string_helpers.hpp"
56
#include "xstudio/ui/opengl/shader_program_base.hpp"
67
#include "xstudio/thumbnail/thumbnail.hpp"
@@ -328,7 +329,8 @@ OCIO::ConstConfigRcPtr
328329
OCIOEngine::get_ocio_config(const utility::JsonStore &src_colour_mgmt_metadata) const {
329330

330331
const std::string config_name =
331-
src_colour_mgmt_metadata.get_or("ocio_config", default_config_);
332+
utility::forward_remap_file_path(
333+
src_colour_mgmt_metadata.get_or("ocio_config", default_config_));
332334
const std::string displays =
333335
src_colour_mgmt_metadata.get_or("active_displays", std::string(""));
334336
const std::string views = src_colour_mgmt_metadata.get_or("active_views", std::string(""));
@@ -378,17 +380,27 @@ OCIOEngine::get_ocio_config(const utility::JsonStore &src_colour_mgmt_metadata)
378380
econfig->setActiveDisplays(displays.c_str());
379381
if (!views.empty())
380382
econfig->setActiveViews(views.c_str());
383+
384+
econfig->clearSearchPaths();
385+
for (int i = 0; i < config->getNumSearchPaths(); ++i) {
386+
auto path = std::string(config->getSearchPath(i));
387+
auto newpath = utility::forward_remap_file_path(path);
388+
econfig->addSearchPath(newpath.c_str());
389+
}
390+
381391
config = econfig;
382392
ocio_config_cache_[concat] = config;
383393

384394
return config;
385395
}
386396

387-
const char *
397+
std::string
388398
OCIOEngine::working_space(const utility::JsonStore &src_colour_mgmt_metadata) const {
389399
auto config = get_ocio_config(src_colour_mgmt_metadata);
390400
if (not config) {
391401
return "";
402+
} else if (src_colour_mgmt_metadata.contains("working_space")) {
403+
return src_colour_mgmt_metadata["working_space"].get<std::string>();
392404
} else if (config->hasRole(OCIO::ROLE_SCENE_LINEAR)) {
393405
return OCIO::ROLE_SCENE_LINEAR;
394406
} else {
@@ -545,7 +557,7 @@ OCIO::TransformRcPtr OCIOEngine::display_transform(
545557
}
546558

547559
OCIO::DisplayViewTransformRcPtr dt = OCIO::DisplayViewTransform::Create();
548-
dt->setSrc(working_space(src_colour_mgmt_metadata));
560+
dt->setSrc(working_space(src_colour_mgmt_metadata).c_str());
549561
dt->setDisplay(_display.c_str());
550562
dt->setView(_view.c_str());
551563
dt->setDirection(OCIO::TRANSFORM_DIR_FORWARD);

src/plugin/colour_pipeline/ocio/src/ocio_engine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class OCIOEngine {
115115

116116
private:
117117
// OCIO logic
118-
const char *working_space(const utility::JsonStore &src_colour_mgmt_metadata) const;
118+
std::string working_space(const utility::JsonStore &src_colour_mgmt_metadata) const;
119119

120120
// OCIO Transform helpers
121121
OCIO::TransformRcPtr source_transform(

src/plugin/colour_pipeline/ocio/src/ocio_plugin.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ caf::message_handler OCIOColourPipeline::message_handler_extensions() {
5858
{
5959

6060
[=](global_ocio_controls_atom atom,
61-
const std::string &oico_config) -> utility::JsonStore {
61+
const std::string &ocio_config) -> utility::JsonStore {
6262
utility::JsonStore res;
6363

64-
if (oico_config == current_config_name_) {
64+
if (ocio_config == current_config_name_) {
6565
res["source_colour_space"] = source_colour_space_->value();
6666
res["display"] = display_->value();
6767
res["view"] = view_->value();
@@ -288,6 +288,18 @@ void OCIOColourPipeline::register_hotkeys() {
288288
channel_hotkeys_[hotkey_id] = hotkey_props.channel_name;
289289
}
290290

291+
for (int i = 1; i <= 9; ++i) {
292+
auto suffix = std::string(fmt::format(" #{}", i));
293+
auto hotkey_id = register_hotkey(
294+
int('0')+i,
295+
ui::MetaModifier,
296+
std::string("Change OCIO View Transform")+suffix,
297+
"Changes OCIO view transform",
298+
false,
299+
"Viewer");
300+
view_hotkeys_[hotkey_id] = i;
301+
}
302+
291303
reset_hotkey_ = register_hotkey(
292304
int('R'),
293305
ui::ControlModifier,
@@ -352,6 +364,18 @@ void OCIOColourPipeline::hotkey_pressed(
352364
} else if (hotkey_uuid == saturation_hotkey_) {
353365
saturation_->set_role_data(module::Attribute::Activated, true);
354366
grab_mouse_focus();
367+
} else {
368+
auto v = view_hotkeys_.find(hotkey_uuid);
369+
if (v != view_hotkeys_.end()) {
370+
const auto &views = display_views_[display_->value()];
371+
int idx = v->second-1;
372+
if (idx >= 0 and idx < views.size()) {
373+
const auto &new_view = views[idx];
374+
if (new_view != view_->value()) {
375+
view_->set_value(new_view);
376+
}
377+
}
378+
}
355379
}
356380
}
357381

src/plugin/colour_pipeline/ocio/src/ocio_plugin.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class OCIOColourPipeline : public ColourPipeline {
148148
UiText ui_text_;
149149

150150
std::map<utility::Uuid, std::string> channel_hotkeys_;
151+
std::map<utility::Uuid, int> view_hotkeys_;
151152
utility::Uuid exposure_hotkey_;
152153
utility::Uuid gamma_hotkey_;
153154
utility::Uuid saturation_hotkey_;

src/plugin/colour_pipeline/ocio/src/ui_text.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct UiText {
5555
"Luminance"},
5656
{int('C'),
5757
xstudio::ui::NoModifier,
58-
"Rever to RGB Mode",
58+
"Revert to RGB Mode",
5959
"Returns to regular RGB colour view mode",
6060
"RGB"}};
6161

0 commit comments

Comments
 (0)