histogram: implemented color management

This commit is contained in:
itsmattkc
2020-04-21 01:59:06 +10:00
parent bdb13e88f5
commit 0ced48d4df
11 changed files with 68 additions and 11 deletions
+5
View File
@@ -94,6 +94,11 @@ void ScopePanel::SetBuffer(Frame *frame)
histogram_->SetBuffer(frame);
}
void ScopePanel::SetColorProcessor(ColorProcessorPtr processor)
{
histogram_->SetColorProcessor(processor);
}
void ScopePanel::Retranslate()
{
SetTitle(tr("Scope"));
+2
View File
@@ -54,6 +54,8 @@ public slots:
void SetBuffer(Frame* frame);
void SetColorProcessor(ColorProcessorPtr processor);
protected:
virtual void Retranslate() override;
+1
View File
@@ -107,6 +107,7 @@ void ViewerPanelBase::CreateScopePanel(ScopePanel::Type type)
// Connect viewer widget texture drawing to scope panel
connect(vw, &ViewerWidget::DrewManagedTexture, p, &ScopePanel::DrewManagedTexture);
connect(vw, &ViewerWidget::LoadedBuffer, p, &ScopePanel::SetBuffer);
connect(vw, &ViewerWidget::ColorProcessorChanged, p, &ScopePanel::SetColorProcessor);
if (!scope_panel_count_) {
vw->SetEmitDrewManagedTextureEnabled(true);
+6 -1
View File
@@ -66,7 +66,7 @@ ColorProcessor::ColorProcessor(ColorManager *config,
processor_ = config->GetConfig()->getProcessor(transform, dir);
}
void ColorProcessor::ConvertFrame(FramePtr f)
void ColorProcessor::ConvertFrame(Frame *f)
{
OCIO::PackedImageDesc img(reinterpret_cast<float*>(f->data()), f->width(), f->height(), PixelFormat::ChannelCount(f->format()));
@@ -94,4 +94,9 @@ OCIO::ConstProcessorRcPtr ColorProcessor::GetProcessor()
return processor_;
}
void ColorProcessor::ConvertFrame(FramePtr f)
{
ConvertFrame(f.get());
}
OLIVE_NAMESPACE_EXIT
+1
View File
@@ -65,6 +65,7 @@ public:
OCIO::ConstProcessorRcPtr GetProcessor();
void ConvertFrame(FramePtr f);
void ConvertFrame(Frame* f);
Color ConvertColor(Color in);
+28 -7
View File
@@ -30,7 +30,8 @@ OLIVE_NAMESPACE_ENTER
HistogramScope::HistogramScope(QWidget* parent) :
QOpenGLWidget(parent),
buffer_(nullptr)
buffer_(nullptr),
processor_(nullptr)
{
connect(&worker_, &HistogramScopeWorker::Finished, this, &HistogramScope::FinishedProcessing, Qt::QueuedConnection);
worker_.start(QThread::IdlePriority);
@@ -45,12 +46,18 @@ HistogramScope::~HistogramScope()
void HistogramScope::SetBuffer(Frame* frame)
{
// We'll be multithreading this, so we make a copy to prevent collisions
buffer_ = frame;
StartUpdate();
}
void HistogramScope::SetColorProcessor(ColorProcessorPtr processor)
{
processor_ = processor;
StartUpdate();
}
void HistogramScope::FinishedProcessing(QVector<double> red, QVector<double> green, QVector<double> blue)
{
red_val_ = red;
@@ -89,14 +96,20 @@ void HistogramScope::resizeEvent(QResizeEvent *e)
{
QOpenGLWidget::resizeEvent(e);
if (buffer_){
StartUpdate();
}
StartUpdate();
}
void HistogramScope::StartUpdate()
{
worker_.QueueNext(*buffer_, width());
if (buffer_) {
worker_.QueueNext(*buffer_, processor_, width());
} else {
// Update with nothing
red_val_.clear();
green_val_.clear();
blue_val_.clear();
update();
}
}
HistogramScopeWorker::HistogramScopeWorker() :
@@ -120,10 +133,13 @@ void HistogramScopeWorker::run()
// Copy values
Frame f = next_;
int w = next_width_;
ColorProcessorPtr processor = next_processor_;
next_.destroy();
next_lock_.unlock();
// Color manage frame
QVector<int> data(w * kRGBChannels, 0);
int max_w = w-1;
@@ -132,6 +148,10 @@ void HistogramScopeWorker::run()
for (int y=0;y<f.height();y++) {
Color c = f.get_pixel(x, y);
if (processor) {
c = processor->ConvertColor(c);
}
data[qFloor(clamp(c.red(), 0.0f, 1.0f) * max_w)]++;
data[qFloor(clamp(c.green(), 0.0f, 1.0f) * max_w) + w]++;
data[qFloor(clamp(c.blue(), 0.0f, 1.0f) * max_w) + w * 2]++;
@@ -165,12 +185,13 @@ void HistogramScopeWorker::run()
}
}
void HistogramScopeWorker::QueueNext(const Frame &f, int width)
void HistogramScopeWorker::QueueNext(const Frame &f, ColorProcessorPtr processor, int width)
{
next_lock_.lock();
next_ = f;
next_width_ = width;
next_processor_ = processor;
next_wait_.wakeOne();
+11 -3
View File
@@ -27,6 +27,7 @@
#include <QWaitCondition>
#include "codec/frame.h"
#include "render/colorprocessor.h"
OLIVE_NAMESPACE_ENTER
@@ -36,13 +37,15 @@ class HistogramScopeWorker : public QThread
public:
HistogramScopeWorker();
virtual void run() override;
// Thread-safe
void QueueNext(const Frame& f, ColorProcessorPtr processor, int width);
// Thread-safe
void QueueNext(const Frame& f, int width);
void Cancel();
protected:
virtual void run() override;
signals:
void Finished(QVector<double> red, QVector<double> green, QVector<double> blue);
@@ -53,6 +56,7 @@ private:
QWaitCondition next_wait_;
Frame next_;
int next_width_;
ColorProcessorPtr next_processor_;
};
@@ -67,6 +71,8 @@ public:
public slots:
void SetBuffer(Frame* frame);
void SetColorProcessor(ColorProcessorPtr processor);
protected:
// virtual void paintEvent(QPaintEvent* e) override;
virtual void paintGL() override;
@@ -78,6 +84,8 @@ private:
Frame* buffer_;
ColorProcessorPtr processor_;
QVector<double> red_val_;
QVector<double> green_val_;
+1
View File
@@ -68,6 +68,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
connect(main_widget, &ViewerGLWidget::LoadedBuffer, this, &ViewerWidget::LoadedBuffer);
connect(main_widget, &ViewerGLWidget::LoadedTexture, this, &ViewerWidget::LoadedTexture);
connect(main_widget, &ViewerGLWidget::DrewManagedTexture, this, &ViewerWidget::DrewManagedTexture);
connect(main_widget, &ViewerGLWidget::ColorProcessorChanged, this, &ViewerWidget::ColorProcessorChanged);
connect(sizer_, &ViewerSizer::RequestMatrix, main_widget, &ViewerGLWidget::SetMatrix);
sizer_->SetWidget(main_widget);
gl_widgets_.append(main_widget);
+5
View File
@@ -159,6 +159,11 @@ signals:
*/
void RequestScopePanel(ScopePanel::Type type);
/**
* @brief Wrapper for ViewerGLWidget::ColorProcessorChanged()
*/
void ColorProcessorChanged(ColorProcessorPtr processor);
protected:
virtual void TimebaseChangedEvent(const rational &) override;
virtual void TimeChangedEvent(const int64_t &) override;
+3
View File
@@ -489,6 +489,9 @@ void ViewerGLWidget::SetupColorProcessor()
} else {
color_service_ = nullptr;
}
qDebug() << "Emitting" << std::static_pointer_cast<ColorProcessor>(color_service_).get();
emit ColorProcessorChanged(std::static_pointer_cast<ColorProcessor>(color_service_));
}
void ViewerGLWidget::ContextCleanup()
+5
View File
@@ -189,6 +189,11 @@ signals:
*/
void DrewManagedTexture(OpenGLTexture* texture);
/**
* @brief Emitted when the color processor changes
*/
void ColorProcessorChanged(ColorProcessorPtr processor);
protected:
/**
* @brief Override the mouse press event simply to emit the DragStarted() signal