colormanagement: moved from passing DVL strings everywhere to a consolidated ColorTransform struct

This commit is contained in:
itsmattkc
2020-04-23 01:17:58 +10:00
parent a422f6e369
commit 6c1e90665f
21 changed files with 295 additions and 435 deletions
+5 -5
View File
@@ -27,14 +27,13 @@ OLIVE_NAMESPACE_ENTER
ColorButton::ColorButton(ColorManager* color_manager, QWidget *parent) :
QPushButton(parent),
color_manager_(color_manager),
color_(1.0f, 1.0f, 1.0f),
color_processor_(nullptr)
{
setAutoFillBackground(true);
connect(this, &ColorButton::clicked, this, &ColorButton::ShowColorDialog);
UpdateColor();
SetColor(Color(1.0f, 1.0f, 1.0f));
}
const ManagedColor &ColorButton::GetColor() const
@@ -46,6 +45,9 @@ void ColorButton::SetColor(const ManagedColor &c)
{
color_ = c;
color_.set_color_input(color_manager_->GetCompliantColorSpace(color_.color_input()));
color_.set_color_output(color_manager_->GetCompliantColorSpace(color_.color_output()));
UpdateColor();
}
@@ -66,9 +68,7 @@ void ColorButton::UpdateColor()
{
color_processor_ = ColorProcessor::Create(color_manager_,
color_.color_input(),
color_.color_display(),
color_.color_view(),
color_.color_look());
color_.color_output());
QColor managed = color_processor_->ConvertColor(color_).toQColor();
+13 -52
View File
@@ -131,68 +131,29 @@ QString ColorSpaceChooser::input() const
}
}
QString ColorSpaceChooser::display() const
ColorTransform ColorSpaceChooser::output() const
{
if (display_combobox_) {
return display_combobox_->currentText();
} else {
return QString();
}
}
QString ColorSpaceChooser::view() const
{
if (view_combobox_) {
return view_combobox_->currentText();
} else {
return QString();
}
}
QString ColorSpaceChooser::look() const
{
if (look_combobox_) {
return look_combobox_->currentData().toString();
} else {
return QString();
}
return ColorTransform(display_combobox_->currentText(),
view_combobox_->currentText(),
look_combobox_->currentIndex() == 0 ? QString() : look_combobox_->currentText());
}
void ColorSpaceChooser::set_input(const QString &s)
{
if (s.isEmpty()) {
input_combobox_->setCurrentText(color_manager_->GetDefaultInputColorSpace());
} else {
input_combobox_->setCurrentText(s);
}
input_combobox_->setCurrentText(color_manager_->GetCompliantColorSpace(s));
}
void ColorSpaceChooser::set_display(const QString &s)
void ColorSpaceChooser::set_output(const ColorTransform &out)
{
if (s.isEmpty()) {
display_combobox_->setCurrentText(color_manager_->GetDefaultDisplay());
} else {
display_combobox_->setCurrentText(s);
}
ColorTransform compliant = color_manager_->GetCompliantColorSpace(out);
UpdateViews(display_combobox_->currentText());
}
display_combobox_->setCurrentText(compliant.display());
view_combobox_->setCurrentText(compliant.view());
void ColorSpaceChooser::set_view(const QString &s)
{
if (s.isEmpty()) {
view_combobox_->setCurrentText(color_manager_->GetDefaultView(display_combobox_->currentText()));
} else {
view_combobox_->setCurrentText(s);
}
}
void ColorSpaceChooser::set_look(const QString &s)
{
if (s.isEmpty()) {
if (compliant.look().isEmpty()) {
look_combobox_->setCurrentIndex(0);
} else {
look_combobox_->setCurrentText(s);
look_combobox_->setCurrentText(compliant.look());
}
}
@@ -224,11 +185,11 @@ void ColorSpaceChooser::ComboBoxChanged()
}
if (display_combobox_) {
emit DisplayColorSpaceChanged(display(), view(), look());
emit OutputColorSpaceChanged(output());
}
if (input_combobox_ && display_combobox_) {
emit ColorSpaceChanged(input(), display(), view(), look());
emit ColorSpaceChanged(input(), output());
}
}
+4 -8
View File
@@ -35,21 +35,17 @@ public:
ColorSpaceChooser(ColorManager* color_manager, bool enable_input_field = true, bool enable_display_fields = true, QWidget* parent = nullptr);
QString input() const;
QString display() const;
QString view() const;
QString look() const;
ColorTransform output() const;
void set_input(const QString& s);
void set_display(const QString& s);
void set_view(const QString& s);
void set_look(const QString& s);
void set_output(const ColorTransform& out);
signals:
void InputColorSpaceChanged(const QString& input);
void ColorSpaceChanged(const QString& input, const QString& display, const QString& view, const QString& look);
void OutputColorSpaceChanged(const ColorTransform& out);
void DisplayColorSpaceChanged(const QString& display, const QString& view, const QString& look);
void ColorSpaceChanged(const QString& input, const ColorTransform& out);
private slots:
void UpdateViews(const QString &display);
@@ -361,9 +361,9 @@ void NodeParamViewWidgetBridge::WidgetCallback()
input_->blockSignals(true);
input_->set_property(QStringLiteral("col_input"), c.color_input());
input_->set_property(QStringLiteral("col_display"), c.color_display());
input_->set_property(QStringLiteral("col_view"), c.color_view());
input_->set_property(QStringLiteral("col_look"), c.color_look());
input_->set_property(QStringLiteral("col_display"), c.color_output().display());
input_->set_property(QStringLiteral("col_view"), c.color_output().view());
input_->set_property(QStringLiteral("col_look"), c.color_output().look());
input_->blockSignals(false);
Core::instance()->undo_stack()->pushIfHasChildren(command);
@@ -471,9 +471,12 @@ void NodeParamViewWidgetBridge::UpdateWidgetValues()
ManagedColor mc = input_->get_value_at_time(node_time).value<Color>();
mc.set_color_input(input_->get_property(QStringLiteral("col_input")).toString());
mc.set_color_display(input_->get_property(QStringLiteral("col_display")).toString());
mc.set_color_view(input_->get_property(QStringLiteral("col_view")).toString());
mc.set_color_look(input_->get_property(QStringLiteral("col_look")).toString());
QString d = input_->get_property(QStringLiteral("col_display")).toString();
QString v = input_->get_property(QStringLiteral("col_view")).toString();
QString l = input_->get_property(QStringLiteral("col_look")).toString();
mc.set_color_output(ColorTransform(d, v, l));
static_cast<ColorButton*>(widgets_.first())->SetColor(mc);
break;
+37 -45
View File
@@ -421,6 +421,11 @@ void ViewerWidget::UpdateMinimumScale()
}
}
void ViewerWidget::SetColorTransform(const ColorTransform &transform, ViewerGLWidget *sender)
{
sender->SetColorTransform(transform);
}
void ViewerWidget::UpdateStack()
{
if (!GetConnectedNode() || GetConnectedNode()->texture_input()->IsConnected()) {
@@ -536,6 +541,10 @@ void ViewerWidget::ShowContextMenu(const QPoint &pos)
// Color options
if (context_menu_widget_->color_manager() && color_menu_enabled_) {
const ColorTransform& transform = context_menu_widget_->GetColorTransform();
qDebug() << "CMW transform" << transform.display() << transform.view() << transform.look();
{
QStringList displays = context_menu_widget_->color_manager()->ListAvailableDisplays();
@@ -546,13 +555,13 @@ void ViewerWidget::ShowContextMenu(const QPoint &pos)
foreach (const QString& d, displays) {
QAction* action = ocio_display_menu->addAction(d);
action->setCheckable(true);
action->setChecked(context_menu_widget_->ocio_display() == d);
action->setChecked(transform.display() == d);
action->setData(d);
}
}
{
QStringList views = context_menu_widget_->color_manager()->ListAvailableViews(context_menu_widget_->ocio_display());
QStringList views = context_menu_widget_->color_manager()->ListAvailableViews(transform.display());
Menu* ocio_view_menu = new Menu(tr("View"), &menu);
menu.addMenu(ocio_view_menu);
@@ -561,7 +570,7 @@ void ViewerWidget::ShowContextMenu(const QPoint &pos)
foreach (const QString& v, views) {
QAction* action = ocio_view_menu->addAction(v);
action->setCheckable(true);
action->setChecked(context_menu_widget_->ocio_view() == v);
action->setChecked(transform.view() == v);
action->setData(v);
}
}
@@ -575,11 +584,11 @@ void ViewerWidget::ShowContextMenu(const QPoint &pos)
connect(ocio_look_menu, &QMenu::triggered, this, &ViewerWidget::ContextMenuOCIOLook);
QAction* no_look_action = ocio_look_menu->addAction(tr("(None)"));
no_look_action->setCheckable(true);
no_look_action->setChecked(context_menu_widget_->ocio_look().isEmpty());
no_look_action->setChecked(transform.look().isEmpty());
foreach (const QString& l, looks) {
QAction* action = ocio_look_menu->addAction(l);
action->setCheckable(true);
action->setChecked(context_menu_widget_->ocio_look() == l);
action->setChecked(transform.look() == l);
action->setData(l);
}
}
@@ -751,44 +760,9 @@ void ViewerWidget::ShuttleRight()
PlayInternal(current_speed, false);
}
void ViewerWidget::SetOCIOParameters(const QString &display, const QString &view, const QString &look)
void ViewerWidget::SetColorTransform(const ColorTransform &transform)
{
SetOCIOParameters(display, view, look, main_gl_widget());
}
void ViewerWidget::SetOCIOParameters(const QString &display, const QString &view, const QString &look, ViewerGLWidget* sender)
{
sender->SetOCIOParameters(display, view, look);
}
void ViewerWidget::SetOCIODisplay(const QString &display)
{
SetOCIODisplay(display, main_gl_widget());
}
void ViewerWidget::SetOCIODisplay(const QString &display, ViewerGLWidget* sender)
{
sender->SetOCIODisplay(display);
}
void ViewerWidget::SetOCIOView(const QString &view)
{
SetOCIOView(view, main_gl_widget());
}
void ViewerWidget::SetOCIOLook(const QString &look)
{
SetOCIOLook(look, main_gl_widget());
}
void ViewerWidget::SetOCIOView(const QString &view, ViewerGLWidget* sender)
{
sender->SetOCIOView(view);
}
void ViewerWidget::SetOCIOLook(const QString &look, ViewerGLWidget* sender)
{
sender->SetOCIOLook(look);
SetColorTransform(transform, main_gl_widget());
}
void ViewerWidget::SetSignalCursorColorEnabled(bool e)
@@ -909,17 +883,35 @@ void ViewerWidget::LengthChangedSlot(const rational &length)
void ViewerWidget::ContextMenuOCIODisplay(QAction* action)
{
SetOCIODisplay(action->data().toString(), context_menu_widget_);
const ColorTransform& old_transform = context_menu_widget_->GetColorTransform();
ColorTransform new_transform = context_menu_widget_->color_manager()->GetCompliantColorSpace(ColorTransform(action->data().toString(),
old_transform.view(),
old_transform.look()));
SetColorTransform(new_transform, context_menu_widget_);
}
void ViewerWidget::ContextMenuOCIOView(QAction *action)
{
SetOCIOView(action->data().toString(), context_menu_widget_);
const ColorTransform& old_transform = context_menu_widget_->GetColorTransform();
ColorTransform new_transform = context_menu_widget_->color_manager()->GetCompliantColorSpace(ColorTransform(old_transform.display(),
action->data().toString(),
old_transform.look()));
SetColorTransform(new_transform, context_menu_widget_);
}
void ViewerWidget::ContextMenuOCIOLook(QAction *action)
{
SetOCIOLook(action->data().toString(), context_menu_widget_);
const ColorTransform& old_transform = context_menu_widget_->GetColorTransform();
ColorTransform new_transform = context_menu_widget_->color_manager()->GetCompliantColorSpace(ColorTransform(old_transform.display(),
old_transform.view(),
action->data().toString()));
SetColorTransform(new_transform, context_menu_widget_);
}
void ViewerWidget::SetDividerFromMenu(QAction *action)
+2 -26
View File
@@ -98,28 +98,7 @@ public slots:
void ShuttleRight();
void SetOCIOParameters(const QString& display, const QString& view, const QString& look);
/**
* @brief Externally set the OCIO display to use
*
* This value must be a valid display in the current OCIO configuration.
*/
void SetOCIODisplay(const QString& display);
/**
* @brief Externally set the OCIO view to use
*
* This value must be a valid display in the current OCIO configuration.
*/
void SetOCIOView(const QString& view);
/**
* @brief Externally set the OCIO look to use (use empty string if none)
*
* This value must be a valid display in the current OCIO configuration.
*/
void SetOCIOLook(const QString& look);
void SetColorTransform(const ColorTransform& transform);
/**
* @brief Wrapper for ViewerGLWidget::SetSignalCursorColorEnabled()
@@ -197,10 +176,7 @@ private:
void UpdateMinimumScale();
void SetOCIOParameters(const QString& display, const QString& view, const QString& look, ViewerGLWidget* sender);
void SetOCIODisplay(const QString& display, ViewerGLWidget* sender);
void SetOCIOView(const QString& view, ViewerGLWidget* sender);
void SetOCIOLook(const QString& look, ViewerGLWidget* sender);
void SetColorTransform(const ColorTransform& transform, ViewerGLWidget* sender);
QStackedWidget* stack_;
+20 -85
View File
@@ -63,16 +63,16 @@ void ViewerGLWidget::ConnectColorManager(ColorManager *color_manager)
}
if (color_manager_ != nullptr) {
disconnect(color_manager_, &ColorManager::ConfigChanged, this, &ViewerGLWidget::RefreshColorPipeline);
disconnect(color_manager_, &ColorManager::ConfigChanged, this, &ViewerGLWidget::ColorConfigChanged);
}
color_manager_ = color_manager;
if (color_manager_ != nullptr) {
connect(color_manager_, &ColorManager::ConfigChanged, this, &ViewerGLWidget::RefreshColorPipeline);
connect(color_manager_, &ColorManager::ConfigChanged, this, &ViewerGLWidget::ColorConfigChanged);
}
RefreshColorPipeline();
ColorConfigChanged();
}
void ViewerGLWidget::DisconnectColorManager()
@@ -185,55 +185,11 @@ void ViewerGLWidget::SetEmitDrewManagedTextureEnabled(bool e)
}
}
void ViewerGLWidget::SetOCIODisplay(const QString &display)
{
ocio_display_ = display;
// Determine if the selected view is available in this display
if (color_manager_
&& !color_manager_->ListAvailableViews(ocio_display_).contains(ocio_view_)) {
// If not, set to the default view for this display
ocio_view_ = color_manager_->GetDefaultView(ocio_display_);
}
SetupColorProcessor();
update();
}
void ViewerGLWidget::SetOCIOView(const QString &view)
{
ocio_view_ = view;
SetupColorProcessor();
update();
}
void ViewerGLWidget::SetOCIOLook(const QString &look)
{
ocio_look_ = look;
SetupColorProcessor();
update();
}
ColorManager *ViewerGLWidget::color_manager() const
{
return color_manager_;
}
const QString &ViewerGLWidget::ocio_display() const
{
return ocio_display_;
}
const QString &ViewerGLWidget::ocio_view() const
{
return ocio_view_;
}
const QString &ViewerGLWidget::ocio_look() const
{
return ocio_look_;
}
void ViewerGLWidget::ConnectSibling(ViewerGLWidget *sibling)
{
connect(this, &ViewerGLWidget::LoadedBuffer, sibling, &ViewerGLWidget::SetImageFromLoadBuffer, Qt::QueuedConnection);
@@ -252,6 +208,18 @@ void ViewerGLWidget::SetSafeMargins(const ViewerSafeMarginInfo &safe_margin)
update();
}
const ColorTransform &ViewerGLWidget::GetColorTransform() const
{
return color_transform_;
}
void ViewerGLWidget::SetColorTransform(const ColorTransform &transform)
{
color_transform_ = transform;
SetupColorProcessor();
update();
}
void ViewerGLWidget::mousePressEvent(QMouseEvent *event)
{
QOpenGLWidget::mousePressEvent(event);
@@ -284,15 +252,6 @@ void ViewerGLWidget::mouseMoveEvent(QMouseEvent *event)
}
}
void ViewerGLWidget::SetOCIOParameters(const QString &display, const QString &view, const QString &look)
{
ocio_display_ = display;
ocio_view_ = view;
ocio_look_ = look;
SetupColorProcessor();
update();
}
void ViewerGLWidget::initializeGL()
{
SetupColorProcessor();
@@ -416,30 +375,14 @@ void ViewerGLWidget::paintGL()
}
}
void ViewerGLWidget::RefreshColorPipeline()
void ViewerGLWidget::ColorConfigChanged()
{
if (!color_manager_) {
color_service_ = nullptr;
return;
}
QStringList displays = color_manager_->ListAvailableDisplays();
if (!displays.contains(ocio_display_)) {
ocio_display_ = color_manager_->GetDefaultDisplay();
}
QStringList views = color_manager_->ListAvailableViews(ocio_display_);
if (!views.contains(ocio_view_)) {
ocio_view_ = color_manager_->GetDefaultView(ocio_display_);
}
QStringList looks = color_manager_->ListAvailableLooks();
if (!looks.contains(ocio_look_)) {
ocio_look_.clear();
}
SetupColorProcessor();
update();
SetColorTransform(color_manager_->GetCompliantColorSpace(color_transform_, true));
}
#ifdef Q_OS_LINUX
@@ -467,17 +410,9 @@ void ViewerGLWidget::SetupColorProcessor()
try {
if (ocio_view_.isEmpty()) {
color_service_ = OpenGLColorProcessor::Create(color_manager_,
color_manager_->GetReferenceColorSpace(),
ocio_display_);
} else {
color_service_ = OpenGLColorProcessor::Create(color_manager_,
color_manager_->GetReferenceColorSpace(),
ocio_display_,
ocio_view_,
ocio_look_);
}
color_service_ = OpenGLColorProcessor::Create(color_manager_,
color_manager_->GetReferenceColorSpace(),
color_transform_);
makeCurrent();
color_service_->Enable(context(), true);
+7 -46
View File
@@ -80,10 +80,6 @@ public:
ColorManager* color_manager() const;
const QString& ocio_display() const;
const QString& ocio_view() const;
const QString& ocio_look() const;
const QMatrix4x4& GetMatrix();
void ConnectSibling(ViewerGLWidget* sibling);
@@ -91,38 +87,13 @@ public:
const ViewerSafeMarginInfo& GetSafeMargin() const;
void SetSafeMargins(const ViewerSafeMarginInfo& safe_margin);
const ColorTransform& GetColorTransform() const;
public slots:
/**
* @brief Set the texture to draw and draw it
*
* Use this function to update the viewer.
*
* @param tex
* @brief Replaces the color transform with a new one
*/
//void SetTexture(OpenGLTexturePtr tex);
void SetOCIOParameters(const QString& display, const QString& view, const QString& look);
/**
* @brief Externally set the OCIO display to use
*
* This value must be a valid display in the current OCIO configuration.
*/
void SetOCIODisplay(const QString& display);
/**
* @brief Externally set the OCIO view to use
*
* This value must be a valid display in the current OCIO configuration.
*/
void SetOCIOView(const QString& view);
/**
* @brief Externally set the OCIO look to use (use empty string if none)
*
* This value must be a valid display in the current OCIO configuration.
*/
void SetOCIOLook(const QString& look);
void SetColorTransform(const ColorTransform& transform);
/**
* @brief Set the transformation matrix to draw with
@@ -231,19 +202,9 @@ private:
void ClearOCIOLutTexture();
/**
* @brief Internal variable to set color space to
* @brief Internal color transform storage
*/
QString ocio_display_;
/**
* @brief Internal variable to set color space to
*/
QString ocio_view_;
/**
* @brief Internal variable to set color space to
*/
QString ocio_look_;
ColorTransform color_transform_;
/**
* @brief Internal reference to the OpenGL texture to draw. Set in SetTexture() and used in paintGL().
@@ -308,7 +269,7 @@ private slots:
/**
* @brief Sets all color settings to the defaults pertaining to this configuration
*/
void RefreshColorPipeline();
void ColorConfigChanged();
#ifdef Q_OS_LINUX
/**