Commit 1ed09df2 authored by Boudewijn Rempt's avatar Boudewijn Rempt

commit antiquark's level filter patches

svn path=/trunk/koffice/; revision=933691
parent 8ee57eed
......@@ -35,7 +35,8 @@ class KGradientSlider : public QWidget
typedef enum {
BlackCursor,
GammaCursor,
WhiteCursor
WhiteCursor,
None
} eCursor;
public:
......@@ -44,22 +45,25 @@ public:
virtual ~KGradientSlider();
public slots:
void modifyBlack(int);
void modifyWhite(int);
void modifyGamma(double);
void slotModifyBlack(int);
void slotModifyWhite(int);
void slotModifyGamma(double);
signals:
void modifiedBlack(int);
void modifiedWhite(int);
void modifiedGamma(double);
void sigModifiedBlack(int);
void sigModifiedWhite(int);
void sigModifiedGamma(double);
protected:
void paintEvent(QPaintEvent *);
void resizeEvent(QResizeEvent *);
void mousePressEvent(QMouseEvent * e);
void mouseReleaseEvent(QMouseEvent * e);
void mouseMoveEvent(QMouseEvent * e);
void leaveEvent(QEvent *);
private:
void calculateCursorPositions();
unsigned int calculateGammaCursor();
public:
void enableGamma(bool b);
......@@ -68,16 +72,21 @@ public:
private:
int m_leftmost;
int m_rightmost;
eCursor m_grab_cursor;
unsigned int m_grab_index;
bool m_dragging;
eCursor m_grabCursor;
unsigned int m_grabIndex;
double m_scalingFactor;
int m_blackcursor;
int m_whitecursor;
int m_gammacursor;
int m_blackCursor;
int m_whiteCursor;
int m_gammaCursor;
int m_black;
int m_white;
bool m_gammaEnabled;
double m_gamma;
bool m_gammaEnabled;
bool m_feedback;
};
......
......@@ -19,15 +19,15 @@
*/
#include "kis_level_filter.h"
#include <math.h>
#include <cmath>
#include <klocale.h>
#include <qlayout.h>
#include <qpixmap.h>
#include <qpainter.h>
#include <qlabel.h>
#include <qspinbox.h>
#include <QLayout>
#include <QPixmap>
#include <QPainter>
#include <QLabel>
#include <QSpinBox>
#include <KoBasicHistogramProducers.h>
#include <KoColorSpace.h>
......@@ -183,39 +183,45 @@ KisLevelConfigWidget::KisLevelConfigWidget(QWidget * parent, KisPaintDeviceSP de
m_page.ingradient->enableGamma(true);
m_page.blackspin->setValue(0);
m_page.whitespin->setValue(255);
m_page.gammaspin->setNum(1.0);
m_page.ingradient->modifyGamma(1.0);
m_page.gammaspin->setValue(1.0);
m_page.ingradient->slotModifyGamma(1.0);
m_page.outblackspin->setValue(0);
m_page.outwhitespin->setValue(255);
connect(m_page.blackspin, SIGNAL(valueChanged(int)), SIGNAL(sigConfigChanged()));
connect(m_page.whitespin, SIGNAL(valueChanged(int)), SIGNAL(sigConfigChanged()));
connect(m_page.ingradient, SIGNAL(modifiedGamma(double)), SIGNAL(sigConfigChanged()));
connect(m_page.ingradient, SIGNAL(sigModifiedGamma(double)), SIGNAL(sigConfigChanged()));
connect(m_page.blackspin, SIGNAL(valueChanged(int)), m_page.ingradient, SLOT(modifyBlack(int)));
connect(m_page.whitespin, SIGNAL(valueChanged(int)), m_page.ingradient, SLOT(modifyWhite(int)));
//connect( m_page.whitespin, SIGNAL(valueChanged(int)), m_page.ingradient, SLOT(modifyGamma()));
connect(m_page.blackspin, SIGNAL(valueChanged(int)), m_page.ingradient, SLOT(slotModifyBlack(int)));
connect(m_page.whitespin, SIGNAL(valueChanged(int)), m_page.ingradient, SLOT(slotModifyWhite(int)));
connect(m_page.gammaspin, SIGNAL(valueChanged(double)), m_page.ingradient, SLOT(slotModifyGamma(double)));
connect(m_page.ingradient, SIGNAL(modifiedBlack(int)), m_page.blackspin, SLOT(setValue(int)));
connect(m_page.ingradient, SIGNAL(modifiedWhite(int)), m_page.whitespin, SLOT(setValue(int)));
connect(m_page.ingradient, SIGNAL(modifiedGamma(double)), m_page.gammaspin, SLOT(setNum(double)));
connect(m_page.blackspin, SIGNAL(valueChanged(int)), this, SLOT(slotModifyInWhiteLimit(int)));
connect(m_page.whitespin, SIGNAL(valueChanged(int)), this, SLOT(slotModifyInBlackLimit(int)));
connect(m_page.ingradient, SIGNAL(sigModifiedBlack(int)), m_page.blackspin, SLOT(setValue(int)));
connect(m_page.ingradient, SIGNAL(sigModifiedWhite(int)), m_page.whitespin, SLOT(setValue(int)));
connect(m_page.ingradient, SIGNAL(sigModifiedGamma(double)), m_page.gammaspin, SLOT(setValue(double)));
connect(m_page.outblackspin, SIGNAL(valueChanged(int)), SIGNAL(sigConfigChanged()));
connect(m_page.outwhitespin, SIGNAL(valueChanged(int)), SIGNAL(sigConfigChanged()));
connect(m_page.outblackspin, SIGNAL(valueChanged(int)), m_page.outgradient, SLOT(modifyBlack(int)));
connect(m_page.outwhitespin, SIGNAL(valueChanged(int)), m_page.outgradient, SLOT(modifyWhite(int)));
connect(m_page.outblackspin, SIGNAL(valueChanged(int)), m_page.outgradient, SLOT(slotModifyBlack(int)));
connect(m_page.outwhitespin, SIGNAL(valueChanged(int)), m_page.outgradient, SLOT(slotModifyWhite(int)));
connect(m_page.outblackspin, SIGNAL(valueChanged(int)), this, SLOT(slotModifyOutWhiteLimit(int)));
connect(m_page.outwhitespin, SIGNAL(valueChanged(int)), this, SLOT(slotModifyOutBlackLimit(int)));
connect(m_page.outgradient, SIGNAL(modifiedBlack(int)), m_page.outblackspin, SLOT(setValue(int)));
connect(m_page.outgradient, SIGNAL(modifiedWhite(int)), m_page.outwhitespin, SLOT(setValue(int)));
connect(m_page.outgradient, SIGNAL(sigModifiedBlack(int)), m_page.outblackspin, SLOT(setValue(int)));
connect(m_page.outgradient, SIGNAL(sigModifiedWhite(int)), m_page.outwhitespin, SLOT(setValue(int)));
connect((QObject*)(m_page.chkLogarithmic), SIGNAL(toggled(bool)), this, SLOT(drawHistogram(bool)));
connect((QObject*)(m_page.chkLogarithmic), SIGNAL(toggled(bool)), this, SLOT(slotDrawHistogram(bool)));
KoHistogramProducerSP producer = KoHistogramProducerSP(new KoGenericLabHistogramProducer());
histogram = new KisHistogram(dev, producer, LINEAR);
m_histlog = false;
drawHistogram();
slotDrawHistogram();
}
......@@ -224,9 +230,11 @@ KisLevelConfigWidget::~KisLevelConfigWidget()
delete histogram;
}
void KisLevelConfigWidget::drawHistogram(bool logarithmic)
void KisLevelConfigWidget::slotDrawHistogram(bool logarithmic)
{
int height = 256;
int wHeight = height();
int wHeightMinusOne = wHeight - 1;
int wWidth = width();
if (m_histlog != logarithmic) {
// Update the histogram
......@@ -237,29 +245,56 @@ void KisLevelConfigWidget::drawHistogram(bool logarithmic)
m_histlog = logarithmic;
}
QPixmap pix(256, height);
QPixmap pix(wWidth, wHeight);
pix.fill();
QPainter p(&pix);
p.setPen(QPen::QPen(Qt::gray, 1, Qt::SolidLine));
double highest = (double)histogram->calculations().getHighest();
Q_INT32 bins = histogram->producer()->numberOfBins();
// use nearest neighbour interpolation
if (histogram->getHistogramType() == LINEAR) {
double factor = (double)height / highest;
for (int i = 0; i < bins; ++i) {
p.drawLine(i, height, i, height - int(histogram->getValue(i) * factor));
double factor = (double)(wHeight - wHeight / 5.0) / highest;
for (int i = 0; i < wWidth; i++)
{
int binNo = (int)round((double)i / wWidth * (bins - 1));
if ((int)histogram->getValue(binNo) != 0)
p.drawLine(i, wHeightMinusOne, i, wHeightMinusOne - (int)histogram->getValue(binNo) * factor);
}
} else {
double factor = (double)height / (double)log(highest);
for (int i = 0; i < bins; ++i) {
p.drawLine(i, height, i, height - int(log((double)histogram->getValue(i)) * factor));
double factor = (double)(wHeight - wHeight / 5.0) / (double)log(highest);
for (int i = 0; i < wWidth; i++) {
int binNo = (int)round((double)i / wWidth * (bins - 1)) ;
if ((int)histogram->getValue(binNo) != 0)
p.drawLine(i, wHeightMinusOne, i, wHeightMinusOne - log(histogram->getValue(binNo)) * factor);
}
}
m_page.histview->setPixmap(pix);
}
void KisLevelConfigWidget::slotModifyInBlackLimit(int limit)
{
m_page.blackspin->setMaximum(limit - 1);
}
void KisLevelConfigWidget::slotModifyInWhiteLimit(int limit)
{
m_page.whitespin->setMinimum(limit + 1);
}
void KisLevelConfigWidget::slotModifyOutBlackLimit(int limit)
{
m_page.outblackspin->setMaximum(limit - 1);
}
void KisLevelConfigWidget::slotModifyOutWhiteLimit(int limit)
{
m_page.outwhitespin->setMinimum(limit + 1);
}
KisPropertiesConfiguration * KisLevelConfigWidget::configuration() const
{
KisFilterConfiguration * config = new KisFilterConfiguration(KisLevelFilter::id().id(), 1);
......@@ -278,18 +313,22 @@ void KisLevelConfigWidget::setConfiguration(const KisPropertiesConfiguration * c
QVariant value;
if (config->getProperty("blackvalue", value)) {
m_page.blackspin->setValue(value.toUInt());
m_page.ingradient->slotModifyBlack(value.toUInt());
}
if (config->getProperty("whitevalue", value)) {
m_page.whitespin->setValue(value.toUInt());
m_page.ingradient->slotModifyWhite(value.toUInt());
}
if (config->getProperty("gammavalue", value)) {
m_page.ingradient->modifyGamma(value.toDouble());
m_page.gammaspin->setValue(value.toUInt());
m_page.ingradient->slotModifyGamma(value.toDouble());
}
if (config->getProperty("outblackvalue", value)) {
m_page.outblackspin->setValue(value.toUInt());
m_page.outgradient->slotModifyBlack(value.toUInt());
}
if (config->getProperty("outwhitevalue", value)) {
m_page.outwhitespin->setValue(value.toUInt());
m_page.outgradient->slotModifyWhite(value.toUInt());
}
}
......@@ -31,26 +31,6 @@ class QWidget;
class KisColorAdjustment;
class KisHistogram;
#if 0
class KisLevelFilterConfiguration : public KisFilterConfiguration
{
public:
KisLevelFilterConfiguration();
virtual ~KisLevelFilterConfiguration();
virtual void fromXML(const QString&);
virtual QString toString();
public:
Q_UINT8 blackvalue, whitevalue;
double gammavalue;
Q_UINT16 outblackvalue, outwhitevalue;
KisColorAdjustment * m_adjustment;
};
#endif
/**
* This class affect Intensity Y of the image
......@@ -96,7 +76,12 @@ public:
Ui::WdgLevel m_page;
protected slots:
void drawHistogram(bool logarithmic = false);
void slotDrawHistogram(bool logarithmic = false);
void slotModifyInBlackLimit(int);
void slotModifyInWhiteLimit(int);
void slotModifyOutBlackLimit(int);
void slotModifyOutWhiteLimit(int);
protected:
KisHistogram *histogram;
......
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