From daeef50aa6ae7116b5b2d681498023ea4a46abe1 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 23 Jun 2018 17:01:19 -0700 Subject: [PATCH] blending modes added (#54) --- effects/effects.h | 2 ++ effects/transformeffect.cpp | 34 ++++++++++++++++++++++++++++++++++ olive.pro.user | 2 +- ui/viewerwidget.cpp | 4 +++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/effects/effects.h b/effects/effects.h index bde898949..58683dc1f 100644 --- a/effects/effects.h +++ b/effects/effects.h @@ -6,6 +6,7 @@ #include class QSpinBox; class QCheckBox; +class QComboBox; class LabelSlider; enum VideoEffects { @@ -43,6 +44,7 @@ public: LabelSlider* anchor_x_box; LabelSlider* anchor_y_box; LabelSlider* opacity; + QComboBox* blend_mode_box; public slots: void toggle_uniform_scale(bool enabled); private: diff --git a/effects/transformeffect.cpp b/effects/transformeffect.cpp index bb411f289..db6b51fd0 100644 --- a/effects/transformeffect.cpp +++ b/effects/transformeffect.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "ui/collapsiblewidget.h" #include "project/clip.h" @@ -14,6 +15,10 @@ #include "io/media.h" #include "ui/labelslider.h" +#define BLEND_MODE_NORMAL 0 +#define BLEND_MODE_SCREEN 1 +#define BLEND_MODE_MULTIPLY 2 + TransformEffect::TransformEffect(Clip* c) : Effect(c) { setup_effect(EFFECT_TYPE_VIDEO, VIDEO_TRANSFORM_EFFECT); @@ -56,6 +61,13 @@ TransformEffect::TransformEffect(Clip* c) : Effect(c) { opacity->set_maximum_value(100); ui_layout->addWidget(opacity, 5, 1); + ui_layout->addWidget(new QLabel("Blend Mode:"), 6, 0); + blend_mode_box = new QComboBox(); + blend_mode_box->addItem("Normal", BLEND_MODE_NORMAL); + blend_mode_box->addItem("Screen", BLEND_MODE_SCREEN); + blend_mode_box->addItem("Multiply", BLEND_MODE_MULTIPLY); + ui_layout->addWidget(blend_mode_box, 6, 1); + ui->setLayout(ui_layout); container->setContents(ui); @@ -72,6 +84,7 @@ TransformEffect::TransformEffect(Clip* c) : Effect(c) { anchor_x_box->set_default_value(default_anchor_x); anchor_y_box->set_default_value(default_anchor_y); opacity->set_default_value(100); + blend_mode_box->setCurrentIndex(0); connect(position_x, SIGNAL(valueChanged()), this, SLOT(field_changed())); connect(position_y, SIGNAL(valueChanged()), this, SLOT(field_changed())); @@ -83,6 +96,7 @@ TransformEffect::TransformEffect(Clip* c) : Effect(c) { connect(opacity, SIGNAL(valueChanged()), this, SLOT(field_changed())); connect(uniform_scale_box, SIGNAL(toggled(bool)), this, SLOT(toggle_uniform_scale(bool))); connect(uniform_scale_box, SIGNAL(toggled(bool)), this, SLOT(field_changed())); + connect(blend_mode_box, SIGNAL(currentIndexChanged(int)), this, SLOT(field_changed())); } Effect* TransformEffect::copy(Clip* c) { @@ -96,6 +110,7 @@ Effect* TransformEffect::copy(Clip* c) { t->anchor_x_box->set_value(anchor_x_box->value()); t->anchor_y_box->set_value(anchor_y_box->value()); t->opacity->set_value(opacity->value()); + t->blend_mode_box->setCurrentIndex(blend_mode_box->currentIndex()); return t; } @@ -129,6 +144,9 @@ void TransformEffect::load(QXmlStreamReader *stream) { } else if (stream->isStartElement() && stream->name() == "opacity") { stream->readNext(); opacity->set_value(stream->text().toFloat()); + } else if (stream->isStartElement() && stream->name() == "blendmode") { + stream->readNext(); + blend_mode_box->setCurrentIndex(stream->text().toInt()); } } } @@ -143,6 +161,7 @@ void TransformEffect::save(QXmlStreamWriter *stream) { stream->writeTextElement("anchorx", QString::number(anchor_x_box->value())); stream->writeTextElement("anchory", QString::number(anchor_y_box->value())); stream->writeTextElement("opacity", QString::number(opacity->value())); + stream->writeTextElement("blendmode", QString::number(blend_mode_box->currentIndex())); } void TransformEffect::toggle_uniform_scale(bool enabled) { @@ -165,6 +184,21 @@ void TransformEffect::process_gl(int* anchor_x, int* anchor_y) { float sy = (uniform_scale_box->isChecked()) ? sx : scale_y->value()*0.01; glScalef(sx, sy, 1); + // blend mode + switch (blend_mode_box->currentData().toInt()) { + case BLEND_MODE_NORMAL: + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + break; + case BLEND_MODE_SCREEN: + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); + break; + case BLEND_MODE_MULTIPLY: + glBlendFunc(GL_DST_COLOR, GL_ZERO); + break; + default: + qDebug() << "[ERROR] Invalid blend mode. This is a bug - please contact developers"; + } + // opacity glColor4f(1.0, 1.0, 1.0, opacity->value()*0.01); } diff --git a/olive.pro.user b/olive.pro.user index aeaf887a2..a2502092b 100644 --- a/olive.pro.user +++ b/olive.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index 14903dc8a..2a7b4c000 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -41,7 +41,7 @@ void ViewerWidget::initializeGL() { glMatrixMode(GL_PROJECTION); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } //void ViewerWidget::resizeGL(int w, int h) @@ -58,6 +58,8 @@ void ViewerWidget::paintGL() glClear(GL_COLOR_BUFFER_BIT); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + long playhead = panel_timeline->playhead; handle_media(sequence, playhead, multithreaded);