colormanagement: moved from passing DVL strings everywhere to a consolidated ColorTransform struct
This commit is contained in:
@@ -71,31 +71,20 @@ void OpenGLColorProcessor::ClearTexture()
|
||||
}
|
||||
}
|
||||
|
||||
OpenGLColorProcessor::OpenGLColorProcessor(ColorManager* config, const QString &source_space, const QString &dest_space) :
|
||||
OpenGLColorProcessor::OpenGLColorProcessor(ColorManager* config, const QString &source_space, const ColorTransform &dest_space) :
|
||||
ColorProcessor(config, source_space, dest_space),
|
||||
ocio_lut_(0)
|
||||
{
|
||||
}
|
||||
|
||||
OpenGLColorProcessor::OpenGLColorProcessor(ColorManager* config, const QString &source_space, QString display, QString view, const QString &look, Direction dir) :
|
||||
ColorProcessor(config, source_space, display, view, look, dir),
|
||||
ocio_lut_(0)
|
||||
{
|
||||
}
|
||||
|
||||
OpenGLColorProcessor::~OpenGLColorProcessor()
|
||||
{
|
||||
ClearTexture();
|
||||
}
|
||||
|
||||
OpenGLColorProcessorPtr OpenGLColorProcessor::Create(ColorManager *config, const QString &source_space, const QString &dest_space)
|
||||
OpenGLColorProcessorPtr OpenGLColorProcessor::Create(ColorManager *config, const QString &source_space, const ColorTransform &dest_space)
|
||||
{
|
||||
return std::make_shared<OpenGLColorProcessor>(config, source_space, dest_space);
|
||||
}
|
||||
|
||||
OpenGLColorProcessorPtr OpenGLColorProcessor::Create(ColorManager *config, const QString &source_space, const QString &display, const QString &view, const QString &look, Direction dir)
|
||||
{
|
||||
return std::make_shared<OpenGLColorProcessor>(config, source_space, display, view, look, dir);
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -33,25 +33,15 @@ class OpenGLColorProcessor : public QObject, public ColorProcessor
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OpenGLColorProcessor(ColorManager *config, const QString &source_space, const QString &dest_space);
|
||||
|
||||
OpenGLColorProcessor(ColorManager *config,
|
||||
const QString& source_space,
|
||||
QString display,
|
||||
QString view,
|
||||
const QString& look,
|
||||
Direction dir);
|
||||
const QString& input,
|
||||
const ColorTransform& dest);
|
||||
|
||||
~OpenGLColorProcessor();
|
||||
|
||||
static OpenGLColorProcessorPtr Create(ColorManager* config, const QString& source_space, const QString& dest_space);
|
||||
virtual ~OpenGLColorProcessor() override;
|
||||
|
||||
static OpenGLColorProcessorPtr Create(ColorManager* config,
|
||||
const QString& source_space,
|
||||
const QString& display,
|
||||
const QString& view,
|
||||
const QString& look,
|
||||
Direction dir = kNormal);
|
||||
const QString& input,
|
||||
const ColorTransform& dest);
|
||||
|
||||
void Enable(QOpenGLContext* context, bool alpha_is_associated);
|
||||
bool IsEnabled() const;
|
||||
|
||||
@@ -218,6 +218,53 @@ void ColorManager::SetReferenceColorSpace(const QString &s)
|
||||
emit ConfigChanged();
|
||||
}
|
||||
|
||||
QString ColorManager::GetCompliantColorSpace(const QString &s)
|
||||
{
|
||||
if (ListAvailableInputColorspaces().contains(s)) {
|
||||
return s;
|
||||
} else {
|
||||
return GetDefaultInputColorSpace();
|
||||
}
|
||||
}
|
||||
|
||||
ColorTransform ColorManager::GetCompliantColorSpace(const ColorTransform &transform, bool force_display)
|
||||
{
|
||||
if (transform.is_display() || force_display) {
|
||||
// Get display information
|
||||
QString display = transform.display();
|
||||
QString view = transform.view();
|
||||
QString look = transform.look();
|
||||
|
||||
// Check if display still exists in config
|
||||
if (!ListAvailableDisplays().contains(display)) {
|
||||
display = GetDefaultDisplay();
|
||||
}
|
||||
|
||||
// Check if view still exists in display
|
||||
if (!ListAvailableViews(display).contains(view)) {
|
||||
view = GetDefaultView(display);
|
||||
}
|
||||
|
||||
// Check if looks still exists
|
||||
if (!ListAvailableLooks().contains(look)) {
|
||||
look.clear();
|
||||
}
|
||||
|
||||
return ColorTransform(display, view, look);
|
||||
|
||||
} else {
|
||||
|
||||
QString output = transform.output();
|
||||
|
||||
if (!ListAvailableInputColorspaces().contains(output)) {
|
||||
output = GetDefaultInputColorSpace();
|
||||
}
|
||||
|
||||
return ColorTransform(output);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ColorManager::ListAvailableInputColorspaces(OCIO::ConstConfigRcPtr config)
|
||||
{
|
||||
QStringList spaces;
|
||||
|
||||
@@ -72,6 +72,10 @@ public:
|
||||
|
||||
void SetReferenceColorSpace(const QString& s);
|
||||
|
||||
QString GetCompliantColorSpace(const QString& s);
|
||||
|
||||
ColorTransform GetCompliantColorSpace(const ColorTransform& transform, bool force_display = false);
|
||||
|
||||
static QStringList ListAvailableInputColorspaces(OCIO::ConstConfigRcPtr config);
|
||||
|
||||
enum OCIOMethod {
|
||||
|
||||
@@ -25,45 +25,33 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
ColorProcessor::ColorProcessor(ColorManager *config, const QString& source_space, const QString& dest_space)
|
||||
ColorProcessor::ColorProcessor(ColorManager *config, const QString &input, const ColorTransform &transform)
|
||||
{
|
||||
processor_ = config->GetConfig()->getProcessor(source_space.toUtf8(),
|
||||
dest_space.toUtf8());
|
||||
}
|
||||
const QString& output = (transform.output().isEmpty()) ? config->GetDefaultDisplay() : transform.output();
|
||||
|
||||
if (transform.is_display()) {
|
||||
|
||||
const QString& view = (transform.view().isEmpty()) ? config->GetDefaultView(output) : transform.view();
|
||||
|
||||
OCIO::DisplayTransformRcPtr display_transform = OCIO::DisplayTransform::Create();
|
||||
|
||||
display_transform->setInputColorSpaceName(input.toUtf8());
|
||||
display_transform->setDisplay(output.toUtf8());
|
||||
display_transform->setView(view.toUtf8());
|
||||
|
||||
if (!transform.look().isEmpty()) {
|
||||
display_transform->setLooksOverride(transform.look().toUtf8());
|
||||
display_transform->setLooksOverrideEnabled(true);
|
||||
}
|
||||
|
||||
processor_ = config->GetConfig()->getProcessor(display_transform);
|
||||
|
||||
} else {
|
||||
|
||||
processor_ = config->GetConfig()->getProcessor(input.toUtf8(),
|
||||
output.toUtf8());
|
||||
|
||||
ColorProcessor::ColorProcessor(ColorManager *config,
|
||||
QString source_space,
|
||||
QString display,
|
||||
QString view,
|
||||
const QString& look,
|
||||
Direction direction)
|
||||
{
|
||||
if (source_space.isEmpty()) {
|
||||
source_space = config->GetDefaultInputColorSpace();
|
||||
}
|
||||
|
||||
if (display.isEmpty()) {
|
||||
display = config->GetDefaultDisplay();
|
||||
}
|
||||
|
||||
if (view.isEmpty()) {
|
||||
view = config->GetDefaultView(display);
|
||||
}
|
||||
|
||||
// Get current display stats
|
||||
OCIO::DisplayTransformRcPtr transform = OCIO::DisplayTransform::Create();
|
||||
transform->setInputColorSpaceName(source_space.toUtf8());
|
||||
transform->setDisplay(display.toUtf8());
|
||||
transform->setView(view.toUtf8());
|
||||
|
||||
if (!look.isEmpty()) {
|
||||
transform->setLooksOverride(look.toUtf8());
|
||||
transform->setLooksOverrideEnabled(true);
|
||||
}
|
||||
|
||||
OCIO::TransformDirection dir = (direction == kInverse) ? OCIO::TRANSFORM_DIR_INVERSE : OCIO::TRANSFORM_DIR_FORWARD;
|
||||
|
||||
processor_ = config->GetConfig()->getProcessor(transform, dir);
|
||||
}
|
||||
|
||||
void ColorProcessor::ConvertFrame(Frame *f)
|
||||
@@ -85,14 +73,9 @@ Color ColorProcessor::ConvertColor(Color in)
|
||||
return in;
|
||||
}
|
||||
|
||||
ColorProcessorPtr ColorProcessor::Create(ColorManager *config, const QString& source_space, const QString& dest_space)
|
||||
ColorProcessorPtr ColorProcessor::Create(ColorManager *config, const QString& input, const ColorTransform &transform)
|
||||
{
|
||||
return std::make_shared<ColorProcessor>(config, source_space, dest_space);
|
||||
}
|
||||
|
||||
ColorProcessorPtr ColorProcessor::Create(ColorManager *config, const QString &source_space, const QString &display, const QString &view, const QString &look, Direction direction)
|
||||
{
|
||||
return std::make_shared<ColorProcessor>(config, source_space, display, view, look, direction);
|
||||
return std::make_shared<ColorProcessor>(config, input, transform);
|
||||
}
|
||||
|
||||
OCIO::ConstProcessorRcPtr ColorProcessor::GetProcessor()
|
||||
|
||||
@@ -21,11 +21,9 @@
|
||||
#ifndef COLORPROCESSOR_H
|
||||
#define COLORPROCESSOR_H
|
||||
|
||||
#include <OpenColorIO/OpenColorIO.h>
|
||||
namespace OCIO = OCIO_NAMESPACE::v1;
|
||||
|
||||
#include "codec/frame.h"
|
||||
#include "render/color.h"
|
||||
#include "render/colortransform.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
@@ -42,25 +40,11 @@ public:
|
||||
kInverse
|
||||
};
|
||||
|
||||
ColorProcessor(ColorManager* config, const QString &source_space, const QString &dest_space);
|
||||
|
||||
ColorProcessor(ColorManager* config,
|
||||
QString source_space,
|
||||
QString display,
|
||||
QString view,
|
||||
const QString& look,
|
||||
Direction direction);
|
||||
ColorProcessor(ColorManager* config, const QString& input, const ColorTransform& dest_space);
|
||||
|
||||
DISABLE_COPY_MOVE(ColorProcessor)
|
||||
|
||||
static ColorProcessorPtr Create(ColorManager* config, const QString& source_space, const QString& dest_space);
|
||||
|
||||
static ColorProcessorPtr Create(ColorManager* config,
|
||||
const QString& source_space,
|
||||
const QString& display,
|
||||
const QString& view,
|
||||
const QString& look,
|
||||
Direction direction = kNormal);
|
||||
static ColorProcessorPtr Create(ColorManager* config, const QString& input, const ColorTransform& dest_space);
|
||||
|
||||
OCIO::ConstProcessorRcPtr GetProcessor();
|
||||
|
||||
@@ -74,6 +58,8 @@ private:
|
||||
|
||||
};
|
||||
|
||||
using ColorProcessorChain = QList<ColorProcessorPtr>;
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
#endif // COLORPROCESSOR_H
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2019 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef COLORTRANSFORM_H
|
||||
#define COLORTRANSFORM_H
|
||||
|
||||
#include <OpenColorIO/OpenColorIO.h>
|
||||
namespace OCIO = OCIO_NAMESPACE::v1;
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
class ColorTransform
|
||||
{
|
||||
public:
|
||||
ColorTransform()
|
||||
{
|
||||
is_display_ = false;
|
||||
}
|
||||
|
||||
ColorTransform(const QString& output)
|
||||
{
|
||||
is_display_ = false;
|
||||
output_ = output;
|
||||
}
|
||||
|
||||
ColorTransform(const QString& display, const QString& view, const QString& look)
|
||||
{
|
||||
is_display_ = true;
|
||||
output_ = display;
|
||||
view_ = view;
|
||||
look_ = look;
|
||||
}
|
||||
|
||||
bool is_display() const {
|
||||
return is_display_;
|
||||
}
|
||||
|
||||
const QString& display() const {
|
||||
return output_;
|
||||
}
|
||||
|
||||
const QString& output() const {
|
||||
return output_;
|
||||
}
|
||||
|
||||
const QString& view() const {
|
||||
return view_;
|
||||
}
|
||||
|
||||
const QString& look() const {
|
||||
return look_;
|
||||
}
|
||||
|
||||
private:
|
||||
QString output_;
|
||||
|
||||
bool is_display_;
|
||||
QString view_;
|
||||
QString look_;
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
#endif // COLORTRANSFORM_H
|
||||
@@ -51,34 +51,14 @@ void ManagedColor::set_color_input(const QString &color_input)
|
||||
color_input_ = color_input;
|
||||
}
|
||||
|
||||
const QString &ManagedColor::color_display() const
|
||||
const ColorTransform &ManagedColor::color_output() const
|
||||
{
|
||||
return color_display_;
|
||||
return color_transform_;
|
||||
}
|
||||
|
||||
void ManagedColor::set_color_display(const QString &color_display)
|
||||
void ManagedColor::set_color_output(const ColorTransform &color_output)
|
||||
{
|
||||
color_display_ = color_display;
|
||||
}
|
||||
|
||||
const QString &ManagedColor::color_view() const
|
||||
{
|
||||
return color_view_;
|
||||
}
|
||||
|
||||
void ManagedColor::set_color_view(const QString &color_view)
|
||||
{
|
||||
color_view_ = color_view;
|
||||
}
|
||||
|
||||
const QString &ManagedColor::color_look() const
|
||||
{
|
||||
return color_look_;
|
||||
}
|
||||
|
||||
void ManagedColor::set_color_look(const QString &color_look)
|
||||
{
|
||||
color_look_ = color_look;
|
||||
color_transform_ = color_output;
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#define MANAGEDCOLOR_H
|
||||
|
||||
#include "color.h"
|
||||
#include "colortransform.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
@@ -36,23 +37,13 @@ public:
|
||||
const QString& color_input() const;
|
||||
void set_color_input(const QString &color_input);
|
||||
|
||||
const QString& color_display() const;
|
||||
void set_color_display(const QString &color_display);
|
||||
|
||||
const QString& color_view() const;
|
||||
void set_color_view(const QString &color_view);
|
||||
|
||||
const QString& color_look() const;
|
||||
void set_color_look(const QString &color_look);
|
||||
const ColorTransform& color_output() const;
|
||||
void set_color_output(const ColorTransform &color_output);
|
||||
|
||||
private:
|
||||
QString color_input_;
|
||||
|
||||
QString color_display_;
|
||||
|
||||
QString color_view_;
|
||||
|
||||
QString color_look_;
|
||||
ColorTransform color_transform_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user