started frontend for effect keyframes
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#include "inverteffect.h"
|
||||
|
||||
#include "ui/labelslider.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QXmlStreamAttributes>
|
||||
|
||||
InvertEffect::InvertEffect(Clip* c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_INVERT_EFFECT), vert_shader(QOpenGLShader::Vertex), frag_shader(QOpenGLShader::Fragment) {
|
||||
enable_opengl = true;
|
||||
|
||||
EffectRow* amount_row = add_row("Amount:");
|
||||
amount_val = amount_row->add_field(EFFECT_FIELD_DOUBLE);
|
||||
amount_val->set_double_minimum_value(0);
|
||||
amount_val->set_double_maximum_value(100);
|
||||
|
||||
// set defaults
|
||||
amount_val->set_double_default_value(100);
|
||||
|
||||
connect(amount_val, SIGNAL(changed()), this, SLOT(compile()));
|
||||
|
||||
compile();
|
||||
}
|
||||
|
||||
void InvertEffect::compile() {
|
||||
double value = amount_val->get_double_value()*0.01;
|
||||
vert_shader.compileSourceCode("varying vec2 vTexCoord; void main() { vTexCoord = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }");
|
||||
frag_shader.compileSourceCode("uniform sampler2D myTexture; varying vec2 vTexCoord; void main(void) { vec4 textureColor = texture2D(myTexture, vTexCoord); gl_FragColor = vec4(textureColor.r+((1.0-textureColor.r-textureColor.r)*" + QString::number(value) + "), textureColor.g+((1.0-textureColor.g-textureColor.g)*" + QString::number(value) + "), textureColor.b+((1.0-textureColor.b-textureColor.b)*" + QString::number(value) + "), 1); }");
|
||||
field_changed();
|
||||
}
|
||||
|
||||
Effect* InvertEffect::copy(Clip* c) {
|
||||
InvertEffect* i = new InvertEffect(c);
|
||||
i->amount_val->set_double_value(amount_val->get_double_value());
|
||||
return i;
|
||||
}
|
||||
|
||||
void InvertEffect::process_gl(QOpenGLShaderProgram& shader_prog, int* anchor_x, int* anchor_y) {
|
||||
shader_prog.addShader(&vert_shader);
|
||||
shader_prog.addShader(&frag_shader);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef INVERTEFFECT_H
|
||||
#define INVERTEFFECT_H
|
||||
|
||||
#include "../effect.h"
|
||||
|
||||
//#include <QOpenGLShader>
|
||||
|
||||
class InvertEffect : public Effect {
|
||||
Q_OBJECT
|
||||
public:
|
||||
InvertEffect(Clip* c);
|
||||
void process_gl(QOpenGLShaderProgram& shader_prog, int *anchor_x, int *anchor_y);
|
||||
Effect* copy(Clip *c);
|
||||
|
||||
EffectField* amount_val;
|
||||
private slots:
|
||||
void compile();
|
||||
private:
|
||||
QOpenGLShader vert_shader;
|
||||
QOpenGLShader frag_shader;
|
||||
};
|
||||
|
||||
#endif // INVERTEFFECT_H
|
||||
@@ -0,0 +1,116 @@
|
||||
#include "shakeeffect.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QtMath>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QDebug>
|
||||
|
||||
#include "ui/labelslider.h"
|
||||
#include "ui/collapsiblewidget.h"
|
||||
#include "project/clip.h"
|
||||
#include "project/sequence.h"
|
||||
#include "panels/timeline.h"
|
||||
|
||||
ShakeEffect::ShakeEffect(Clip *c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_SHAKE_EFFECT), inside(false) {
|
||||
enable_opengl = true;
|
||||
|
||||
EffectRow* intensity_row = add_row("Intensity:");
|
||||
intensity_val = intensity_row->add_field(EFFECT_FIELD_DOUBLE);
|
||||
intensity_val->set_double_minimum_value(0);
|
||||
|
||||
EffectRow* rotation_row = add_row("Rotation:");
|
||||
rotation_val = rotation_row->add_field(EFFECT_FIELD_DOUBLE);
|
||||
rotation_val->set_double_minimum_value(0);
|
||||
|
||||
EffectRow* frequency_row = add_row("Frequency:");
|
||||
frequency_val = frequency_row->add_field(EFFECT_FIELD_DOUBLE);
|
||||
frequency_val->set_double_minimum_value(0);
|
||||
|
||||
// set defaults
|
||||
intensity_val->set_double_default_value(50);
|
||||
rotation_val->set_double_default_value(0);
|
||||
frequency_val->set_double_default_value(10);
|
||||
|
||||
refresh();
|
||||
|
||||
connect(intensity_val, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(rotation_val, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(frequency_val, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
}
|
||||
|
||||
void ShakeEffect::refresh() {
|
||||
if (parent_clip->sequence != NULL) {
|
||||
shake_limit = qRound(parent_clip->sequence->frame_rate / frequency_val->get_double_value());
|
||||
shake_progress = shake_limit;
|
||||
next_x = 0;
|
||||
next_y = 0;
|
||||
next_rot = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Effect* ShakeEffect::copy(Clip* c) {
|
||||
ShakeEffect* e = new ShakeEffect(c);
|
||||
e->intensity_val->set_double_value(intensity_val->get_double_value());
|
||||
e->rotation_val->set_double_value(rotation_val->get_double_value());
|
||||
e->frequency_val->set_double_value(frequency_val->get_double_value());
|
||||
return e;
|
||||
}
|
||||
|
||||
void ShakeEffect::process_gl(QOpenGLShaderProgram&, int*, int*) {
|
||||
if (shake_progress > shake_limit) {
|
||||
double ival = intensity_val->get_double_value();
|
||||
if ((int)ival > 0) {
|
||||
prev_x = next_x;
|
||||
prev_y = next_y;
|
||||
next_x = (qrand() % (int) (ival * 2)) - ival;
|
||||
next_y = (qrand() % (int) (ival * 2)) - ival;
|
||||
|
||||
// find perpendicular slope that passes through (mid_x, mid_y)
|
||||
int mid_x = (prev_x + next_x) / 2;
|
||||
int mid_y = (prev_y + next_y) / 2;
|
||||
int slope_num = (next_y-prev_y);
|
||||
if (slope_num > 0) {
|
||||
int slope_den = (next_x-prev_x);
|
||||
int add = (next_x-prev_x)/4;
|
||||
if (inside) add = -add;
|
||||
inside = !inside;
|
||||
perp_x = mid_x + add;
|
||||
perp_y = (-(slope_den / slope_num)) * perp_x + mid_y;
|
||||
} else {
|
||||
perp_x = mid_x;
|
||||
perp_y = mid_y;
|
||||
}
|
||||
} else {
|
||||
prev_x = 0;
|
||||
prev_y = 0;
|
||||
next_x = 0;
|
||||
next_y = 0;
|
||||
offset_x = 0;
|
||||
offset_y = 0;
|
||||
}
|
||||
double rot_val = rotation_val->get_double_value();
|
||||
if ((int)rot_val > 0) {
|
||||
prev_rot = next_rot;
|
||||
next_rot = (qrand() % (int) (rot_val * 2)) - rot_val;
|
||||
} else {
|
||||
prev_rot = 0;
|
||||
next_rot = 0;
|
||||
offset_rot = 0;
|
||||
}
|
||||
shake_progress = 0;
|
||||
}
|
||||
|
||||
t = (double) shake_progress / (double) shake_limit;
|
||||
|
||||
double oneminust = 1 - t;
|
||||
|
||||
offset_x = (qPow(oneminust, 2)*prev_x) + (2*oneminust*t*perp_x) + (qPow(t, 2) * next_x);
|
||||
offset_y = (qPow(oneminust, 2)*prev_y) + (2*oneminust*t*perp_y) + (qPow(t, 2) * next_y);
|
||||
|
||||
offset_rot = lerp(prev_rot, next_rot, t);
|
||||
|
||||
glTranslatef(offset_x, offset_y, 0);
|
||||
glRotatef(offset_rot, 0, 0, 1);
|
||||
shake_progress++;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef SHAKEEFFECT_H
|
||||
#define SHAKEEFFECT_H
|
||||
|
||||
#include "../effect.h"
|
||||
|
||||
class ShakeEffect : public Effect {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ShakeEffect(Clip* c);
|
||||
void process_gl(QOpenGLShaderProgram& shader_prog, int* anchor_x, int* anchor_y);
|
||||
Effect* copy(Clip *c);
|
||||
|
||||
EffectField* intensity_val;
|
||||
EffectField* rotation_val;
|
||||
EffectField* frequency_val;
|
||||
public slots:
|
||||
void refresh();
|
||||
private:
|
||||
int shake_progress;
|
||||
int shake_limit;
|
||||
int next_x;
|
||||
int next_y;
|
||||
int next_rot;
|
||||
int offset_x;
|
||||
int offset_y;
|
||||
int offset_rot;
|
||||
int prev_x;
|
||||
int prev_y;
|
||||
int prev_rot;
|
||||
int perp_x;
|
||||
int perp_y;
|
||||
double t;
|
||||
bool inside;
|
||||
};
|
||||
|
||||
#endif // SHAKEEFFECT_H
|
||||
@@ -0,0 +1,133 @@
|
||||
#include "solideffect.h"
|
||||
|
||||
#include <QOpenGLTexture>
|
||||
#include <QPainter>
|
||||
#include <QtMath>
|
||||
#include <QVariant>
|
||||
|
||||
#include "project/clip.h"
|
||||
#include "project/sequence.h"
|
||||
|
||||
#define SOLID_TYPE_COLOR 0
|
||||
#define SOLID_TYPE_BARS 1
|
||||
|
||||
#define SMPTE_BARS 7
|
||||
#define SMPTE_STRIP_COUNT 3
|
||||
#define SMPTE_LOWER_BARS 4
|
||||
|
||||
SolidEffect::SolidEffect(Clip* c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_SOLID_EFFECT) {
|
||||
enable_image = true;
|
||||
|
||||
solid_type = add_row("Type:")->add_field(EFFECT_FIELD_COMBO);
|
||||
solid_type->add_combo_item("Solid Color", SOLID_TYPE_COLOR);
|
||||
solid_type->add_combo_item("SMPTE Bars", SOLID_TYPE_BARS);
|
||||
|
||||
solid_color_field = add_row("Color:")->add_field(EFFECT_FIELD_COLOR);
|
||||
solid_color_field->set_color_value(Qt::red);
|
||||
|
||||
opacity_field = add_row("Opacity:")->add_field(EFFECT_FIELD_DOUBLE);
|
||||
opacity_field->set_double_minimum_value(0);
|
||||
opacity_field->set_double_maximum_value(100);
|
||||
opacity_field->set_double_default_value(100);
|
||||
|
||||
connect(solid_type, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(solid_type, SIGNAL(changed()), this, SLOT(enable_color()));
|
||||
connect(solid_color_field, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(opacity_field, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
}
|
||||
|
||||
void SolidEffect::enable_color() {
|
||||
solid_color_field->set_enabled(solid_type->get_combo_data() == SOLID_TYPE_COLOR);
|
||||
}
|
||||
|
||||
void SolidEffect::process_image(QImage& img) {
|
||||
QPainter p(&img);
|
||||
int width = img.width();
|
||||
int height = img.height();
|
||||
|
||||
switch (solid_type->get_combo_data().toInt()) {
|
||||
case SOLID_TYPE_COLOR:
|
||||
{
|
||||
QColor brush = solid_color_field->get_color_value();
|
||||
p.fillRect(0, 0, width, height, QColor(brush.red(), brush.green(), brush.blue(), opacity_field->get_double_value()*2.55));
|
||||
}
|
||||
break;
|
||||
case SOLID_TYPE_BARS:
|
||||
// draw smpte bars
|
||||
int bar_width = qCeil((double) parent_clip->sequence->width / 7.0);
|
||||
int first_bar_height = qCeil((double) parent_clip->sequence->height / 3.0 * 2.0);
|
||||
int second_bar_height = qCeil((double) parent_clip->sequence->height / 12.5);
|
||||
int third_bar_y = first_bar_height + second_bar_height;
|
||||
int third_bar_height = parent_clip->sequence->height - third_bar_y;
|
||||
int third_bar_width = 0;
|
||||
int bar_x, strip_width;
|
||||
QColor first_color, second_color, third_color;
|
||||
for (int i=0;i<SMPTE_BARS;i++) {
|
||||
bar_x = bar_width*i;
|
||||
switch (i) {
|
||||
case 0:
|
||||
first_color = QColor(192, 192, 192);
|
||||
second_color = QColor(0, 0, 192);
|
||||
break;
|
||||
case 1:
|
||||
first_color = QColor(192, 192, 0);
|
||||
second_color = QColor(19, 19, 19);
|
||||
break;
|
||||
case 2:
|
||||
first_color = QColor(0, 192, 192);
|
||||
second_color = QColor(192, 0, 192);
|
||||
break;
|
||||
case 3:
|
||||
first_color = QColor(0, 192, 0);
|
||||
second_color = QColor(19, 19, 19);
|
||||
break;
|
||||
case 4:
|
||||
first_color = QColor(192, 0, 192);
|
||||
second_color = QColor(0, 192, 192);
|
||||
break;
|
||||
case 5:
|
||||
third_bar_width = bar_x / SMPTE_LOWER_BARS;
|
||||
|
||||
first_color = QColor(192, 0, 0);
|
||||
second_color = QColor(19, 19, 19);
|
||||
|
||||
strip_width = qCeil(bar_width/SMPTE_STRIP_COUNT);
|
||||
for (int j=0;j<SMPTE_STRIP_COUNT;j++) {
|
||||
switch (j) {
|
||||
case 0:
|
||||
third_color = QColor(29, 29, 29);
|
||||
p.fillRect(QRect(bar_x, third_bar_y, bar_width, third_bar_height), third_color);
|
||||
break;
|
||||
case 1:
|
||||
third_color = QColor(19, 19, 19);
|
||||
p.fillRect(QRect(bar_x + strip_width, third_bar_y, strip_width, third_bar_height), third_color);
|
||||
break;
|
||||
case 2:
|
||||
third_color = QColor(9, 9, 9);
|
||||
p.fillRect(QRect(bar_x, third_bar_y, strip_width, third_bar_height), third_color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
first_color = QColor(0, 0, 192);
|
||||
second_color = QColor(192, 192, 192);
|
||||
p.fillRect(QRect(bar_x, third_bar_y, bar_width, third_bar_height), QColor(19, 19, 19));
|
||||
break;
|
||||
}
|
||||
p.fillRect(QRect(bar_x, 0, bar_width, first_bar_height), first_color);
|
||||
p.fillRect(QRect(bar_x, first_bar_height, bar_width, second_bar_height), second_color);
|
||||
}
|
||||
for (int i=0;i<SMPTE_LOWER_BARS;i++) {
|
||||
bar_x = third_bar_width*i;
|
||||
switch (i) {
|
||||
case 0: third_color = QColor(0, 33, 76); break;
|
||||
case 1: third_color = QColor(255, 255, 255); break;
|
||||
case 2: third_color = QColor(50, 0, 106); break;
|
||||
case 3: third_color = QColor(19, 19, 19); break;
|
||||
}
|
||||
p.fillRect(QRect(bar_x, third_bar_y, third_bar_width, third_bar_height), third_color);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef SOLIDEFFECT_H
|
||||
#define SOLIDEFFECT_H
|
||||
|
||||
#include "../effect.h"
|
||||
|
||||
class SolidEffect : public Effect {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SolidEffect(Clip* c);
|
||||
EffectField* solid_type;
|
||||
EffectField* solid_color_field;
|
||||
EffectField* opacity_field;
|
||||
void process_image(QImage &img);
|
||||
private slots:
|
||||
void enable_color();
|
||||
};
|
||||
|
||||
#endif // SOLIDEFFECT_H
|
||||
@@ -0,0 +1,370 @@
|
||||
#include "texteffect.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QOpenGLTexture>
|
||||
#include <QTextEdit>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
#include <QColorDialog>
|
||||
#include <QFontDatabase>
|
||||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
|
||||
#include "ui/labelslider.h"
|
||||
#include "ui/collapsiblewidget.h"
|
||||
#include "project/clip.h"
|
||||
#include "project/sequence.h"
|
||||
#include "ui/comboboxex.h"
|
||||
#include "ui/colorbutton.h"
|
||||
#include "ui/fontcombobox.h"
|
||||
|
||||
TextEffect::TextEffect(Clip *c) :
|
||||
Effect(c, EFFECT_TYPE_VIDEO, VIDEO_TEXT_EFFECT)
|
||||
{
|
||||
enable_image = true;
|
||||
|
||||
text_val = add_row("Text:")->add_field(EFFECT_FIELD_STRING, 2);
|
||||
|
||||
set_font_combobox = add_row("Font:")->add_field(EFFECT_FIELD_FONT, 2);
|
||||
|
||||
size_val = add_row("Size:")->add_field(EFFECT_FIELD_DOUBLE, 2);
|
||||
size_val->set_double_minimum_value(0);
|
||||
|
||||
set_color_button = add_row("Color:")->add_field(EFFECT_FIELD_COLOR, 2);
|
||||
|
||||
EffectRow* alignment_row = add_row("Alignment:");
|
||||
halign_field = alignment_row->add_field(EFFECT_FIELD_COMBO);
|
||||
halign_field->add_combo_item("Left", Qt::AlignLeft);
|
||||
halign_field->add_combo_item("Center", Qt::AlignHCenter);
|
||||
halign_field->add_combo_item("Right", Qt::AlignRight);
|
||||
halign_field->add_combo_item("Justify", Qt::AlignJustify);
|
||||
valign_field = alignment_row->add_field(EFFECT_FIELD_COMBO);
|
||||
valign_field->add_combo_item("Top", Qt::AlignTop);
|
||||
valign_field->add_combo_item("Center", Qt::AlignVCenter);
|
||||
valign_field->add_combo_item("Bottom", Qt::AlignBottom);
|
||||
|
||||
word_wrap_field = add_row("Word Wrap:")->add_field(EFFECT_FIELD_BOOL, 2);
|
||||
|
||||
outline_bool = add_row("Outline:")->add_field(EFFECT_FIELD_BOOL, 2);
|
||||
outline_color = add_row("Outline Color:")->add_field(EFFECT_FIELD_COLOR, 2);
|
||||
outline_width = add_row("Outline Width:")->add_field(EFFECT_FIELD_DOUBLE, 2);
|
||||
outline_width->set_double_minimum_value(0);
|
||||
|
||||
shadow_bool = add_row("Shadow:")->add_field(EFFECT_FIELD_BOOL, 2);
|
||||
shadow_color = add_row("Shadow Color:")->add_field(EFFECT_FIELD_COLOR, 2);
|
||||
shadow_distance = add_row("Shadow Distance:")->add_field(EFFECT_FIELD_DOUBLE, 2);
|
||||
shadow_distance->set_double_minimum_value(0);
|
||||
shadow_softness = add_row("Shadow Softness:")->add_field(EFFECT_FIELD_DOUBLE, 2);
|
||||
shadow_softness->set_double_minimum_value(0);
|
||||
shadow_opacity = add_row("Shadow Opacity:")->add_field(EFFECT_FIELD_DOUBLE, 2);
|
||||
shadow_opacity->set_double_minimum_value(0);
|
||||
shadow_opacity->set_double_maximum_value(100);
|
||||
|
||||
size_val->set_double_default_value(48);
|
||||
text_val->set_string_value("Sample Text");
|
||||
halign_field->set_combo_index(1);
|
||||
valign_field->set_combo_index(1);
|
||||
word_wrap_field->set_bool_value(true);
|
||||
outline_color->set_color_value(Qt::black);
|
||||
shadow_color->set_color_value(Qt::black);
|
||||
shadow_opacity->set_double_default_value(100);
|
||||
shadow_softness->set_double_default_value(5);
|
||||
shadow_distance->set_double_default_value(5);
|
||||
shadow_opacity->set_double_default_value(80);
|
||||
outline_width->set_double_default_value(2);
|
||||
|
||||
outline_enable(false);
|
||||
shadow_enable(false);
|
||||
|
||||
connect(text_val, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(size_val, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(set_color_button, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(set_font_combobox, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(halign_field, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(valign_field, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(word_wrap_field, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(outline_bool, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(outline_color, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(outline_width, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(shadow_bool, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(shadow_color, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(shadow_distance, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(shadow_softness, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(shadow_opacity, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
|
||||
connect(shadow_bool, SIGNAL(toggled(bool)), this, SLOT(shadow_enable(bool)));
|
||||
connect(outline_bool, SIGNAL(toggled(bool)), this, SLOT(outline_enable(bool)));
|
||||
}
|
||||
|
||||
void TextEffect::shadow_enable(bool e) {
|
||||
shadow_color->set_enabled(e);
|
||||
shadow_distance->set_enabled(e);
|
||||
shadow_softness->set_enabled(e);
|
||||
shadow_opacity->set_enabled(e);
|
||||
}
|
||||
|
||||
void TextEffect::outline_enable(bool e) {
|
||||
outline_color->set_enabled(e);
|
||||
outline_width->set_enabled(e);
|
||||
}
|
||||
|
||||
QImage blurred(const QImage& image, const QRect& rect, int radius, bool alphaOnly = false)
|
||||
{
|
||||
int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
|
||||
int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];
|
||||
|
||||
QImage result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
int r1 = rect.top();
|
||||
int r2 = rect.bottom();
|
||||
int c1 = rect.left();
|
||||
int c2 = rect.right();
|
||||
|
||||
int bpl = result.bytesPerLine();
|
||||
int rgba[4];
|
||||
unsigned char* p;
|
||||
|
||||
int i1 = 0;
|
||||
int i2 = 3;
|
||||
|
||||
if (alphaOnly)
|
||||
i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);
|
||||
|
||||
for (int col = c1; col <= c2; col++) {
|
||||
p = result.scanLine(r1) + col * 4;
|
||||
for (int i = i1; i <= i2; i++)
|
||||
rgba[i] = p[i] << 4;
|
||||
|
||||
p += bpl;
|
||||
for (int j = r1; j < r2; j++, p += bpl)
|
||||
for (int i = i1; i <= i2; i++)
|
||||
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
|
||||
}
|
||||
|
||||
for (int row = r1; row <= r2; row++) {
|
||||
p = result.scanLine(row) + c1 * 4;
|
||||
for (int i = i1; i <= i2; i++)
|
||||
rgba[i] = p[i] << 4;
|
||||
|
||||
p += 4;
|
||||
for (int j = c1; j < c2; j++, p += 4)
|
||||
for (int i = i1; i <= i2; i++)
|
||||
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
|
||||
}
|
||||
|
||||
for (int col = c1; col <= c2; col++) {
|
||||
p = result.scanLine(r2) + col * 4;
|
||||
for (int i = i1; i <= i2; i++)
|
||||
rgba[i] = p[i] << 4;
|
||||
|
||||
p -= bpl;
|
||||
for (int j = r1; j < r2; j++, p -= bpl)
|
||||
for (int i = i1; i <= i2; i++)
|
||||
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
|
||||
}
|
||||
|
||||
for (int row = r1; row <= r2; row++) {
|
||||
p = result.scanLine(row) + c2 * 4;
|
||||
for (int i = i1; i <= i2; i++)
|
||||
rgba[i] = p[i] << 4;
|
||||
|
||||
p -= 4;
|
||||
for (int j = c1; j < c2; j++, p -= 4)
|
||||
for (int i = i1; i <= i2; i++)
|
||||
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void blurred2(QImage& result, const QRect& rect, int radius, bool alphaOnly = false) {
|
||||
int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
|
||||
int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];
|
||||
|
||||
int r1 = rect.top();
|
||||
int r2 = rect.bottom();
|
||||
int c1 = rect.left();
|
||||
int c2 = rect.right();
|
||||
|
||||
int bpl = result.bytesPerLine();
|
||||
int rgba[4];
|
||||
unsigned char* p;
|
||||
|
||||
int i1 = 0;
|
||||
int i2 = 3;
|
||||
|
||||
if (alphaOnly)
|
||||
i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);
|
||||
|
||||
for (int col = c1; col <= c2; col++) {
|
||||
p = result.scanLine(r1) + col * 4;
|
||||
for (int i = i1; i <= i2; i++)
|
||||
rgba[i] = p[i] << 4;
|
||||
|
||||
p += bpl;
|
||||
for (int j = r1; j < r2; j++, p += bpl)
|
||||
for (int i = i1; i <= i2; i++)
|
||||
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
|
||||
}
|
||||
|
||||
for (int row = r1; row <= r2; row++) {
|
||||
p = result.scanLine(row) + c1 * 4;
|
||||
for (int i = i1; i <= i2; i++)
|
||||
rgba[i] = p[i] << 4;
|
||||
|
||||
p += 4;
|
||||
for (int j = c1; j < c2; j++, p += 4)
|
||||
for (int i = i1; i <= i2; i++)
|
||||
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
|
||||
}
|
||||
|
||||
for (int col = c1; col <= c2; col++) {
|
||||
p = result.scanLine(r2) + col * 4;
|
||||
for (int i = i1; i <= i2; i++)
|
||||
rgba[i] = p[i] << 4;
|
||||
|
||||
p -= bpl;
|
||||
for (int j = r1; j < r2; j++, p -= bpl)
|
||||
for (int i = i1; i <= i2; i++)
|
||||
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
|
||||
}
|
||||
|
||||
for (int row = r1; row <= r2; row++) {
|
||||
p = result.scanLine(row) + c2 * 4;
|
||||
for (int i = i1; i <= i2; i++)
|
||||
rgba[i] = p[i] << 4;
|
||||
|
||||
p -= 4;
|
||||
for (int j = c1; j < c2; j++, p -= 4)
|
||||
for (int i = i1; i <= i2; i++)
|
||||
p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
|
||||
}
|
||||
}
|
||||
|
||||
void TextEffect::process_image(QImage& img) {
|
||||
QPainter p(&img);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
int width = img.width();
|
||||
int height = img.height();
|
||||
|
||||
// set font
|
||||
font.setStyleHint(QFont::Helvetica, QFont::PreferAntialias);
|
||||
font.setFamily(set_font_combobox->get_font_name());
|
||||
font.setPointSize(size_val->get_double_value());
|
||||
p.setFont(font);
|
||||
QFontMetrics fm(font);
|
||||
|
||||
QStringList lines = text_val->get_string_value().split('\n');
|
||||
|
||||
// word wrap function
|
||||
if (word_wrap_field->get_bool_value()) {
|
||||
for (int i=0;i<lines.size();i++) {
|
||||
const QString& s = lines.at(i);
|
||||
if (fm.width(s) > width) {
|
||||
int last_space_index = 0;
|
||||
for (int j=0;j<s.length();j++) {
|
||||
if (s.at(j) == ' ') {
|
||||
if (fm.width(s.left(j)) > width) {
|
||||
break;
|
||||
} else {
|
||||
last_space_index = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (last_space_index > 0) {
|
||||
lines.insert(i+1, s.mid(last_space_index + 1));
|
||||
lines[i] = s.left(last_space_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QPainterPath path;
|
||||
|
||||
int text_height = fm.height()*lines.size();
|
||||
|
||||
for (int i=0;i<lines.size();i++) {
|
||||
int text_x, text_y;
|
||||
|
||||
switch (halign_field->get_combo_data().toInt()) {
|
||||
case Qt::AlignLeft: text_x = 0; break;
|
||||
case Qt::AlignHCenter: text_x = (width/2) - (fm.width(lines.at(i))/2); break;
|
||||
case Qt::AlignRight: text_x = width - fm.width(lines.at(i)); break;
|
||||
case Qt::AlignJustify:
|
||||
// add spaces until the string is too big
|
||||
text_x = 0;
|
||||
while (fm.width(lines.at(i) < width)) {
|
||||
bool space = false;
|
||||
QString spaced(lines.at(i));
|
||||
for (int i=0;i<spaced.length();i++) {
|
||||
if (spaced.at(i) == ' ') {
|
||||
// insert a space
|
||||
spaced.insert(i, ' ');
|
||||
space = true;
|
||||
|
||||
// scan to next non-space
|
||||
while (i < spaced.length() && spaced.at(i) == ' ') i++;
|
||||
}
|
||||
}
|
||||
if (fm.width(spaced) > width || !space) {
|
||||
break;
|
||||
} else {
|
||||
lines[i] = spaced;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (valign_field->get_combo_data().toInt()) {
|
||||
case Qt::AlignTop: text_y = (fm.height()*i)+fm.ascent(); break;
|
||||
case Qt::AlignVCenter: text_y = ((height/2) - (text_height/2) - fm.descent()) + (fm.height()*(i+1)); break;
|
||||
case Qt::AlignBottom: text_y = (height - text_height - fm.descent()) + (fm.height()*(i+1)); break;
|
||||
}
|
||||
|
||||
path.addText(text_x, text_y, font, lines.at(i));
|
||||
}
|
||||
|
||||
p.setPen(Qt::NoPen);
|
||||
|
||||
// draw shadow
|
||||
if (shadow_bool->get_bool_value()) {
|
||||
QImage shadow(width, height, QImage::Format_ARGB32_Premultiplied);
|
||||
shadow.fill(Qt::transparent);
|
||||
QPainter spaint(&shadow);
|
||||
|
||||
int shadow_offset = shadow_distance->get_double_value();
|
||||
QColor col = shadow_color->get_color_value();
|
||||
col.setAlphaF(shadow_opacity->get_double_value()*0.01);
|
||||
spaint.setBrush(col);
|
||||
spaint.drawPath(path);
|
||||
|
||||
blurred2(shadow, shadow.rect(), shadow_softness->get_double_value(), false);
|
||||
p.drawImage(shadow_offset, shadow_offset, shadow);
|
||||
|
||||
spaint.end();
|
||||
}
|
||||
|
||||
// draw outline
|
||||
int outline_width_val = outline_width->get_double_value();
|
||||
if (outline_bool->get_bool_value() && outline_width_val > 0) {
|
||||
QPen outline(outline_color->get_color_value());
|
||||
outline.setWidth(outline_width_val);
|
||||
p.setPen(outline);
|
||||
}
|
||||
|
||||
// draw "master" text
|
||||
p.setBrush(set_color_button->get_color_value());
|
||||
p.drawPath(path);
|
||||
}
|
||||
|
||||
Effect* TextEffect::copy(Clip* c) {
|
||||
TextEffect* e = new TextEffect(c);
|
||||
e->text_val->set_string_value(text_val->get_string_value());
|
||||
e->size_val->set_double_value(size_val->get_double_value());
|
||||
e->set_color_button->set_color_value(set_color_button->get_color_value());
|
||||
e->set_font_combobox->set_font_name(set_font_combobox->get_font_name());
|
||||
e->halign_field->set_combo_index(halign_field->get_combo_index());
|
||||
e->valign_field->set_combo_index(valign_field->get_combo_index());
|
||||
return e;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef TEXTEFFECT_H
|
||||
#define TEXTEFFECT_H
|
||||
|
||||
#include "../effect.h"
|
||||
|
||||
#include <QFont>
|
||||
|
||||
class TextEffect : public Effect {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TextEffect(Clip* c);
|
||||
void process_image(QImage& img);
|
||||
Effect* copy(Clip* c);
|
||||
|
||||
EffectField* text_val;
|
||||
EffectField* size_val;
|
||||
EffectField* set_color_button;
|
||||
EffectField* set_font_combobox;
|
||||
EffectField* halign_field;
|
||||
EffectField* valign_field;
|
||||
EffectField* word_wrap_field;
|
||||
|
||||
EffectField* outline_bool;
|
||||
EffectField* outline_width;
|
||||
EffectField* outline_color;
|
||||
|
||||
EffectField* shadow_bool;
|
||||
EffectField* shadow_distance;
|
||||
EffectField* shadow_color;
|
||||
EffectField* shadow_softness;
|
||||
EffectField* shadow_opacity;
|
||||
private slots:
|
||||
void outline_enable(bool);
|
||||
void shadow_enable(bool);
|
||||
private:
|
||||
QFont font;
|
||||
};
|
||||
|
||||
#endif // TEXTEFFECT_H
|
||||
@@ -0,0 +1,177 @@
|
||||
#include "transformeffect.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
#include <QSpinBox>
|
||||
#include <QCheckBox>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QComboBox>
|
||||
|
||||
#include "ui/collapsiblewidget.h"
|
||||
#include "project/clip.h"
|
||||
#include "project/sequence.h"
|
||||
#include "io/media.h"
|
||||
#include "ui/labelslider.h"
|
||||
#include "ui/comboboxex.h"
|
||||
#include "panels/project.h"
|
||||
|
||||
#define BLEND_MODE_NORMAL 0
|
||||
#define BLEND_MODE_SCREEN 1
|
||||
#define BLEND_MODE_MULTIPLY 2
|
||||
#define BLEND_MODE_OVERLAY 3
|
||||
|
||||
TransformEffect::TransformEffect(Clip* c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_TRANSFORM_EFFECT) {
|
||||
enable_opengl = true;
|
||||
|
||||
EffectRow* position_row = add_row("Position:");
|
||||
position_x = position_row->add_field(EFFECT_FIELD_DOUBLE); // position X
|
||||
position_y = position_row->add_field(EFFECT_FIELD_DOUBLE); // position Y
|
||||
|
||||
EffectRow* scale_row = add_row("Scale:");
|
||||
scale_x = scale_row->add_field(EFFECT_FIELD_DOUBLE); // scale X (and Y is uniform scale is selected)
|
||||
scale_x->set_double_minimum_value(0);
|
||||
scale_x->set_double_maximum_value(3000);
|
||||
scale_y = scale_row->add_field(EFFECT_FIELD_DOUBLE); // scale Y (disabled if uniform scale is selected)
|
||||
scale_y->set_double_minimum_value(0);
|
||||
scale_y->set_double_maximum_value(3000);
|
||||
|
||||
EffectRow* uniform_scale_row = add_row("Uniform Scale:");
|
||||
uniform_scale_field = uniform_scale_row->add_field(EFFECT_FIELD_BOOL); // uniform scale option
|
||||
|
||||
EffectRow* rotation_row = add_row("Rotation:");
|
||||
rotation = rotation_row->add_field(EFFECT_FIELD_DOUBLE);
|
||||
|
||||
EffectRow* anchor_point_row = add_row("Anchor Point:");
|
||||
anchor_x_box = anchor_point_row->add_field(EFFECT_FIELD_DOUBLE); // anchor point X
|
||||
anchor_y_box = anchor_point_row->add_field(EFFECT_FIELD_DOUBLE); // anchor point Y
|
||||
|
||||
EffectRow* opacity_row = add_row("Opacity:");
|
||||
opacity = opacity_row->add_field(EFFECT_FIELD_DOUBLE); // opacity
|
||||
opacity->set_double_minimum_value(0);
|
||||
opacity->set_double_maximum_value(100);
|
||||
|
||||
EffectRow* blend_mode_row = add_row("Blend Mode:");
|
||||
blend_mode_box = blend_mode_row->add_field(EFFECT_FIELD_COMBO); // blend mode
|
||||
blend_mode_box->add_combo_item("Normal", BLEND_MODE_NORMAL);
|
||||
blend_mode_box->add_combo_item("Overlay", BLEND_MODE_OVERLAY);
|
||||
blend_mode_box->add_combo_item("Screen", BLEND_MODE_SCREEN);
|
||||
blend_mode_box->add_combo_item("Multiply", BLEND_MODE_MULTIPLY);
|
||||
|
||||
// set defaults
|
||||
scale_y->set_enabled(false);
|
||||
uniform_scale_field->set_bool_value(true);
|
||||
blend_mode_box->set_combo_index(0);
|
||||
refresh();
|
||||
|
||||
connect(position_x, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(position_y, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(scale_x, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(scale_y, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(uniform_scale_field, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(rotation, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(anchor_x_box, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(anchor_y_box, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(opacity, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(blend_mode_box, SIGNAL(changed()), this, SLOT(field_changed()));
|
||||
connect(uniform_scale_field, SIGNAL(toggled(bool)), this, SLOT(toggle_uniform_scale(bool)));
|
||||
}
|
||||
|
||||
Effect* TransformEffect::copy(Clip* c) {
|
||||
TransformEffect* t = new TransformEffect(c);
|
||||
t->position_x->set_double_value(position_x->get_double_value());
|
||||
t->position_y->set_double_value(position_y->get_double_value());
|
||||
t->scale_x->set_double_value(scale_x->get_double_value());
|
||||
t->scale_y->set_double_value(scale_y->get_double_value());
|
||||
t->uniform_scale_field->set_bool_value(uniform_scale_field->get_bool_value());
|
||||
t->rotation->set_double_value(rotation->get_double_value());
|
||||
t->anchor_x_box->set_double_value(anchor_x_box->get_double_value());
|
||||
t->anchor_y_box->set_double_value(anchor_y_box->get_double_value());
|
||||
t->opacity->set_double_value(opacity->get_double_value());
|
||||
t->blend_mode_box->set_combo_index(blend_mode_box->get_combo_index());
|
||||
return t;
|
||||
}
|
||||
|
||||
void TransformEffect::refresh() {
|
||||
if (parent_clip->sequence != NULL) {
|
||||
double default_pos_x = parent_clip->sequence->width/2;
|
||||
double default_pos_y = parent_clip->sequence->height/2;
|
||||
|
||||
position_x->set_double_default_value(default_pos_x);
|
||||
position_y->set_double_default_value(default_pos_y);
|
||||
scale_x->set_double_default_value(100);
|
||||
scale_y->set_double_default_value(100);
|
||||
|
||||
default_anchor_x = default_pos_x;
|
||||
default_anchor_y = default_pos_y;
|
||||
if (parent_clip->media != NULL) {
|
||||
switch (parent_clip->media_type) {
|
||||
case MEDIA_TYPE_FOOTAGE:
|
||||
{
|
||||
MediaStream* ms = static_cast<Media*>(parent_clip->media)->get_stream_from_file_index(parent_clip->media_stream);
|
||||
if (ms != NULL) {
|
||||
default_anchor_x = ms->video_width/2;
|
||||
default_anchor_y = ms->video_height/2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MEDIA_TYPE_SEQUENCE:
|
||||
{
|
||||
Sequence* s = static_cast<Sequence*>(parent_clip->media);
|
||||
default_anchor_x = s->width/2;
|
||||
default_anchor_y = s->height/2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
anchor_x_box->set_double_default_value(default_anchor_x);
|
||||
anchor_y_box->set_double_default_value(default_anchor_y);
|
||||
opacity->set_double_default_value(100);
|
||||
}
|
||||
}
|
||||
|
||||
void TransformEffect::toggle_uniform_scale(bool enabled) {
|
||||
scale_y->set_enabled(!enabled);
|
||||
}
|
||||
|
||||
void TransformEffect::process_gl(QOpenGLShaderProgram&, int* anchor_x, int* anchor_y) {
|
||||
// position
|
||||
glTranslatef(position_x->get_double_value()-(parent_clip->sequence->width/2), position_y->get_double_value()-(parent_clip->sequence->height/2), 0);
|
||||
|
||||
// anchor point
|
||||
*anchor_x += (anchor_x_box->get_double_value()-default_anchor_x);
|
||||
*anchor_y += (anchor_y_box->get_double_value()-default_anchor_y);
|
||||
|
||||
// rotation
|
||||
glRotatef(rotation->get_double_value(), 0, 0, 1);
|
||||
|
||||
// scale
|
||||
float sx = scale_x->get_double_value()*0.01;
|
||||
float sy = (uniform_scale_field->get_bool_value()) ? sx : scale_y->get_double_value()*0.01;
|
||||
glScalef(sx, sy, 1);
|
||||
|
||||
// blend mode
|
||||
switch (blend_mode_box->get_combo_data().toInt()) {
|
||||
case BLEND_MODE_NORMAL:
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
break;
|
||||
case BLEND_MODE_OVERLAY:
|
||||
glBlendFunc(GL_DST_COLOR, GL_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
|
||||
float color[4];
|
||||
glGetFloatv(GL_CURRENT_COLOR, color);
|
||||
glColor4f(1.0, 1.0, 1.0, color[3]*(opacity->get_double_value()*0.01));
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef TRANSFORMEFFECT_H
|
||||
#define TRANSFORMEFFECT_H
|
||||
|
||||
#include "../effect.h"
|
||||
|
||||
class TransformEffect : public Effect {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TransformEffect(Clip* c);
|
||||
void refresh();
|
||||
void process_gl(QOpenGLShaderProgram& shader_prog, int* anchor_x, int* anchor_y);
|
||||
Effect* copy(Clip *c);
|
||||
|
||||
EffectField* position_x;
|
||||
EffectField* position_y;
|
||||
EffectField* scale_x;
|
||||
EffectField* scale_y;
|
||||
EffectField* uniform_scale_field;
|
||||
EffectField* rotation;
|
||||
EffectField* anchor_x_box;
|
||||
EffectField* anchor_y_box;
|
||||
EffectField* opacity;
|
||||
EffectField* blend_mode_box;
|
||||
public slots:
|
||||
void toggle_uniform_scale(bool enabled);
|
||||
private:
|
||||
int default_anchor_x;
|
||||
int default_anchor_y;
|
||||
};
|
||||
|
||||
#endif // TRANSFORMEFFECT_H
|
||||
Reference in New Issue
Block a user