Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4a7088e8 authored by Dušan Hanuš's avatar Dušan Hanuš Committed by Jean-Baptiste Mardelle

Fix lift to handle negative values (requires latest MLT version)

parent 04541ba0
......@@ -21,7 +21,55 @@
#include "colorwheel.h"
#include <qmath.h>
ColorWheel::ColorWheel(const QString &id, const QString &name, const QColor &color, QWidget *parent)
NegQColor NegQColor::fromHsvF(qreal h, qreal s, qreal l, qreal a)
{
NegQColor color;
color.qcolor = QColor::fromHsvF(h,s,l<0?-l:l,a);
color.sign_r = l<0?-1:1;
color.sign_g = l<0?-1:1;
color.sign_b = l<0?-1:1;
return color;
}
NegQColor NegQColor::fromRgbF(qreal r, qreal g, qreal b, qreal a)
{
NegQColor color;
color.qcolor = QColor::fromRgbF(r<0?-r:r,g<0?-g:g,b<0?-b:b,a);
color.sign_r = r<0?-1:1;
color.sign_g = g<0?-1:1;
color.sign_b = b<0?-1:1;
return color;
}
qreal NegQColor::redF() {
return qcolor.redF()*sign_r;
}
qreal NegQColor::greenF() {
return qcolor.greenF()*sign_g;
}
qreal NegQColor::blueF() {
return qcolor.blueF()*sign_b;
}
qreal NegQColor::valueF() {
return qcolor.valueF()*sign_g;
}
int NegQColor::hue() {
return qcolor.hue();
}
qreal NegQColor::hueF() {
return qcolor.hueF();
}
qreal NegQColor::saturationF() {
return qcolor.saturationF();
}
ColorWheel::ColorWheel(const QString &id, const QString &name, const NegQColor &color, QWidget *parent)
: QWidget(parent)
, m_id(id)
, m_isMouseDown(false)
......@@ -41,12 +89,18 @@ ColorWheel::ColorWheel(const QString &id, const QString &name, const QColor &col
setCursor(Qt::CrossCursor);
}
QColor ColorWheel::color()
void ColorWheel::setFactorDefaultZero(qreal factor, qreal defvalue, qreal zero) {
m_sizeFactor = factor;
m_defaultValue = defvalue;
m_zeroShift = zero;
}
NegQColor ColorWheel::color()
{
return m_color;
}
void ColorWheel::setColor(const QColor &color)
void ColorWheel::setColor(const NegQColor &color)
{
m_color = color;
}
......@@ -56,10 +110,10 @@ int ColorWheel::wheelSize() const
return qMin(width() - m_sliderWidth, height() - m_unitSize);
}
QColor ColorWheel::colorForPoint(const QPoint &point)
NegQColor ColorWheel::colorForPoint(const QPoint &point)
{
if (! m_image.valid(point)) {
return QColor();
return NegQColor();
}
if (m_isInWheel) {
qreal w = wheelSize();
......@@ -74,19 +128,24 @@ QColor ColorWheel::colorForPoint(const QPoint &point)
theta += 2.0 * M_PI;
}
qreal hue = (theta * 180.0 / M_PI) / 360.0;
return QColor::fromHsvF(hue, rad, m_color.valueF());
return NegQColor::fromHsvF(hue, rad, m_color.valueF());
}
if (m_isInSquare) {
qreal value = 1.0 - qreal(point.y() - m_margin) / (wheelSize() - m_margin * 2);
return QColor::fromHsvF(m_color.hueF(), m_color.saturationF(), value);
if (m_zeroShift!=0) {
value=value-m_zeroShift;
}
return NegQColor::fromHsvF(m_color.hueF(), m_color.saturationF(), value);
}
return QColor();
return NegQColor();
}
QSize ColorWheel::sizeHint() const
{
return QSize(width(), height());
}
QSize ColorWheel::minimumSizeHint() const
{
return QSize(100, 100);
......@@ -107,7 +166,7 @@ void ColorWheel::mousePressEvent(QMouseEvent *event)
qreal g = m_color.greenF();
qreal max = qMax(r, b);
max = qMax(max, g);
changeColor(QColor::fromRgbF(max, max, max));
changeColor(NegQColor::fromRgbF(max, max, max));
}
} else if (m_sliderRegion.contains(m_lastPoint)) {
m_isInWheel = false;
......@@ -115,14 +174,8 @@ void ColorWheel::mousePressEvent(QMouseEvent *event)
if (event->button() != Qt::MidButton) {
changeColor(colorForPoint(m_lastPoint));
} else {
QColor c;
if (m_id == QLatin1String("lift")) {
c = QColor::fromRgbF(0, 0, 0);
} else if (m_id == QLatin1String("gamma")) {
c = QColor::fromRgbF(0.5, 0.5, 0.5);
} else {
c = QColor::fromRgbF(0.25, 0.25, 0.25);
}
NegQColor c;
c = NegQColor::fromRgbF(m_defaultValue/m_sizeFactor, m_defaultValue/m_sizeFactor, m_defaultValue/m_sizeFactor);
changeColor(c);
}
}
......@@ -136,10 +189,10 @@ void ColorWheel::mouseMoveEvent(QMouseEvent *event)
return;
}
if (m_wheelRegion.contains(m_lastPoint) && m_isInWheel) {
const QColor color = colorForPoint(m_lastPoint);
const NegQColor color = colorForPoint(m_lastPoint);
changeColor(color);
} else if (m_sliderRegion.contains(m_lastPoint) && m_isInSquare) {
const QColor color = colorForPoint(m_lastPoint);
const NegQColor color = colorForPoint(m_lastPoint);
changeColor(color);
}
}
......@@ -164,14 +217,7 @@ void ColorWheel::resizeEvent(QResizeEvent *event)
QString ColorWheel::getParamValues()
{
if (m_id == QLatin1String("gamma")) {
return QString::number(m_color.redF() * 2, 'g', 2) + QLatin1Char(',') + QString::number(m_color.greenF() * 2, 'g', 2) + QLatin1Char(',') + QString::number(m_color.blueF() * 2, 'g', 2);
} else if (m_id == QLatin1String("gain")) {
return QString::number(m_color.redF() * 4, 'g', 2) + QLatin1Char(',') + QString::number(m_color.greenF() * 4, 'g', 2) + QLatin1Char(',') + QString::number(m_color.blueF() * 4, 'g', 2);
}
// default (lift)
return QString::number(m_color.redF(), 'g', 2) + QLatin1Char(',') + QString::number(m_color.greenF(), 'g', 2) + QLatin1Char(',') + QString::number(m_color.blueF(), 'g', 2);
return QString::number(m_color.redF() * m_sizeFactor, 'g', 2) + QLatin1Char(',') + QString::number(m_color.greenF() * m_sizeFactor, 'g', 2) + QLatin1Char(',') + QString::number(m_color.blueF() * m_sizeFactor, 'g', 2);
}
void ColorWheel::paintEvent(QPaintEvent *event)
......@@ -262,6 +308,10 @@ void ColorWheel::drawWheelDot(QPainter &painter)
void ColorWheel::drawSliderBar(QPainter &painter)
{
qreal value = 1.0 - m_color.valueF();
if (m_id == QLatin1String("lift")) {
value -= m_zeroShift;
}
int ws = wheelSize();
qreal scale = qreal(ws + m_sliderWidth) / maximumWidth();
int w = m_sliderWidth * scale;
......@@ -275,7 +325,7 @@ void ColorWheel::drawSliderBar(QPainter &painter)
painter.resetTransform();
}
void ColorWheel::changeColor(const QColor &color)
void ColorWheel::changeColor(const NegQColor &color)
{
m_color = color;
drawWheel();
......
......@@ -23,22 +23,42 @@
#include <QPainter>
#include <QResizeEvent>
class NegQColor
{
public:
int8_t sign_r=1;
int8_t sign_g=1;
int8_t sign_b=1;
QColor qcolor;
static NegQColor fromHsvF(qreal h, qreal s, qreal l, qreal a = 1.0);
static NegQColor fromRgbF(qreal r, qreal g, qreal b, qreal a = 1.0);
qreal redF();
qreal greenF();
qreal blueF();
qreal valueF();
int hue();
qreal hueF();
qreal saturationF();
};
class ColorWheel : public QWidget
{
Q_OBJECT
public:
explicit ColorWheel(const QString &id, const QString &name, const QColor &color, QWidget *parent = nullptr);
explicit ColorWheel(const QString &id, const QString &name, const NegQColor &color, QWidget *parent = nullptr);
QSize sizeHint() const Q_DECL_OVERRIDE;
QSize minimumSizeHint() const Q_DECL_OVERRIDE;
QColor color();
void setColor(const QColor &color);
NegQColor color();
void setColor(const NegQColor &color);
void setFactorDefaultZero(qreal factor, qreal defvalue, qreal zero);
signals:
void colorChange(const QColor &color);
void colorChange(const NegQColor &color);
public slots:
void changeColor(const QColor &color);
void changeColor(const NegQColor &color);
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
......@@ -57,14 +77,18 @@ private:
int m_sliderWidth;
QRegion m_wheelRegion;
QRegion m_sliderRegion;
QColor m_color;
NegQColor m_color;
bool m_isInWheel;
bool m_isInSquare;
int m_unitSize;
QString m_name;
qreal m_sizeFactor = 1;
qreal m_defaultValue = 1;
qreal m_zeroShift = 0;
int wheelSize() const;
QColor colorForPoint(const QPoint &point);
NegQColor colorForPoint(const QPoint &point);
void drawWheel();
void drawWheelDot(QPainter &painter);
void drawSliderBar(QPainter &painter);
......
......@@ -24,6 +24,7 @@
#include <KLocalizedString>
static const double LIFT_FACTOR = 2.0;
static const double GAMMA_FACTOR = 2.0;
static const double GAIN_FACTOR = 4.0;
......@@ -45,21 +46,24 @@ LumaLiftGain::LumaLiftGain(const QDomNodeList &nodes, QWidget *parent) :
values.insert(pa.attribute(QStringLiteral("name")), val);
}
QColor lift = QColor::fromRgbF(values.value(QStringLiteral("lift_r")),
values.value(QStringLiteral("lift_g")),
values.value(QStringLiteral("lift_b")));
QColor gamma = QColor::fromRgbF(values.value(QStringLiteral("gamma_r")) / GAMMA_FACTOR,
NegQColor lift = NegQColor::fromRgbF(values.value(QStringLiteral("lift_r")) / LIFT_FACTOR,
values.value(QStringLiteral("lift_g")) / LIFT_FACTOR,
values.value(QStringLiteral("lift_b")) / LIFT_FACTOR);
NegQColor gamma = NegQColor::fromRgbF(values.value(QStringLiteral("gamma_r")) / GAMMA_FACTOR,
values.value(QStringLiteral("gamma_g")) / GAMMA_FACTOR,
values.value(QStringLiteral("gamma_b")) / GAMMA_FACTOR);
QColor gain = QColor::fromRgbF(values.value(QStringLiteral("gain_r")) / GAIN_FACTOR,
NegQColor gain = NegQColor::fromRgbF(values.value(QStringLiteral("gain_r")) / GAIN_FACTOR,
values.value(QStringLiteral("gain_g")) / GAIN_FACTOR,
values.value(QStringLiteral("gain_b")) / GAIN_FACTOR);
m_lift = new ColorWheel(QStringLiteral("lift"), i18n("Lift"), lift, this);
m_lift->setFactorDefaultZero(LIFT_FACTOR, 0, 0.5);
connect(m_lift, &ColorWheel::colorChange, this, &LumaLiftGain::valueChanged);
m_gamma = new ColorWheel(QStringLiteral("gamma"), i18n("Gamma"), gamma, this);
m_gamma->setFactorDefaultZero(GAMMA_FACTOR, 1, 0);
connect(m_gamma, &ColorWheel::colorChange, this, &LumaLiftGain::valueChanged);
m_gain = new ColorWheel(QStringLiteral("gain"), i18n("Gain"), gain, this);
m_gain->setFactorDefaultZero(GAIN_FACTOR, 1, 0);
connect(m_gain, &ColorWheel::colorChange, this, &LumaLiftGain::valueChanged);
flowLayout->addWidget(m_lift);
......@@ -78,13 +82,13 @@ LumaLiftGain::LumaLiftGain(const QDomNodeList &nodes, QWidget *parent) :
void LumaLiftGain::updateEffect(QDomElement &effect)
{
QColor lift = m_lift->color();
QColor gamma = m_gamma->color();
QColor gain = m_gain->color();
NegQColor lift = m_lift->color();
NegQColor gamma = m_gamma->color();
NegQColor gain = m_gain->color();
QMap<QString, double> values;
values.insert(QStringLiteral("lift_r"), lift.redF());
values.insert(QStringLiteral("lift_g"), lift.greenF());
values.insert(QStringLiteral("lift_b"), lift.blueF());
values.insert(QStringLiteral("lift_r"), lift.redF() * LIFT_FACTOR);
values.insert(QStringLiteral("lift_g"), lift.greenF() * LIFT_FACTOR);
values.insert(QStringLiteral("lift_b"), lift.blueF() * LIFT_FACTOR);
values.insert(QStringLiteral("gamma_r"), gamma.redF() * GAMMA_FACTOR);
values.insert(QStringLiteral("gamma_g"), gamma.greenF() * GAMMA_FACTOR);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment