Commit 6d51bd69 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Fix histogram

Patch by William Steidtmann
CCMAIL: billstei@hbci.com

svn path=/trunk/koffice/; revision=1200357
parent ab4b1d5a
......@@ -33,8 +33,8 @@ KisHistogram::KisHistogram(const KisPaintLayerSP layer,
KoHistogramProducerSP producer,
const enumHistogramType type)
{
KisPaintDeviceSP pd = layer->projection();
m_dev = pd;
m_paintDevice = layer->projection();
m_bounds = layer->image()->bounds();
m_type = type;
m_producer = producer;
m_selection = false;
......@@ -43,11 +43,13 @@ KisHistogram::KisHistogram(const KisPaintLayerSP layer,
updateHistogram();
}
// TODO: get rid of this, make all Histogram clients pass bounds (they can pass paintdev->exactBounds() if they want)
KisHistogram::KisHistogram(const KisPaintDeviceSP paintdev,
KoHistogramProducerSP producer,
const enumHistogramType type)
{
m_dev = paintdev;
m_paintDevice = paintdev;
m_bounds = m_paintDevice->exactBounds();
m_type = type;
m_producer = producer;
m_selection = false;
......@@ -56,6 +58,23 @@ KisHistogram::KisHistogram(const KisPaintDeviceSP paintdev,
updateHistogram();
}
KisHistogram::KisHistogram(const KisPaintDeviceSP paintdev,
const QRect &bounds,
KoHistogramProducerSP producer,
const enumHistogramType type)
{
m_paintDevice = paintdev;
m_bounds = bounds;
m_producer = producer;
m_type = type;
m_selection = false;
m_channel = 0;
// TODO: Why does Krita crash when updateHistogram() is *not* called here?
updateHistogram();
}
KisHistogram::~KisHistogram()
{
}
......@@ -64,10 +83,8 @@ void KisHistogram::updateHistogram()
{
if (!m_producer) return;
QRect r;
r = m_dev->exactBounds();
KisRectConstIteratorPixel srcIt = m_dev->createRectConstIterator(r.x(), r.y(), r.width(), r.height());
const KoColorSpace* cs = m_dev->colorSpace();
KisRectConstIteratorPixel srcIt = m_paintDevice->createRectConstIterator(m_bounds.left(), m_bounds.top(), m_bounds.width(), m_bounds.height());
const KoColorSpace* cs = m_paintDevice->colorSpace();
// Let the producer do it's work
m_producer->clear();
......
......@@ -20,6 +20,7 @@
#define KIS_HISTOGRAM_
#include <QVector>
#include <QRect>
#include "KoHistogramProducer.h"
......@@ -111,6 +112,11 @@ public:
KoHistogramProducerSP producer,
const enumHistogramType type);
KisHistogram(KisPaintDeviceSP paintdev,
const QRect &bounds,
KoHistogramProducerSP producer,
const enumHistogramType type);
virtual ~KisHistogram();
/** Updates the information in the producer */
......@@ -176,17 +182,15 @@ private:
QVector<Calculations> calculateForRange(double from, double to);
Calculations calculateSingleRange(int channel, double from, double to);
KisPaintDeviceSP m_device;
const KisPaintDeviceSP m_paintDevice;
QRect m_bounds;
KoHistogramProducerSP m_producer;
enumHistogramType m_type;
qint32 m_channel;
double m_selFrom, m_selTo;
bool m_selection;
const KisPaintDeviceSP m_dev;
QVector<Calculations> m_completeCalculations, m_selectionCalculations;
};
......
......@@ -61,9 +61,9 @@ DlgHistogram::~DlgHistogram()
delete m_page;
}
void DlgHistogram::setPaintDevice(KisPaintDeviceSP dev)
void DlgHistogram::setPaintDevice(KisPaintDeviceSP dev, const QRect &bounds)
{
m_page->setPaintDevice(dev);
m_page->setPaintDevice(dev, bounds);
}
void DlgHistogram::okClicked()
......
......@@ -42,7 +42,7 @@ public:
const char* name = 0);
~DlgHistogram();
void setPaintDevice(KisPaintDeviceSP dev);
void setPaintDevice(KisPaintDeviceSP dev, const QRect &bounds);
private slots:
void okClicked();
......
......@@ -98,9 +98,9 @@ void Histogram::slotActivated()
if (layer) {
KisPaintDeviceSP dev = layer->paintDevice();
if (dev)
dlgHistogram->setPaintDevice(dev);
if (dev) {
dlgHistogram->setPaintDevice(dev, layer->image()->bounds());
}
if (dlgHistogram->exec() == QDialog::Accepted) {
// Do nothing; this is an informational dialog
}
......
......@@ -51,12 +51,12 @@ KisHistogramWidget::~KisHistogramWidget()
{
}
void KisHistogramWidget::setPaintDevice(KisPaintDeviceSP dev)
void KisHistogramWidget::setPaintDevice(KisPaintDeviceSP dev, const QRect &bounds)
{
grpType->disconnect(this);
cmbChannel->disconnect(this);
m_histogramView->setPaintDevice(dev);
m_histogramView->setPaintDevice(dev, bounds);
setActiveChannel(0); // So we have the colored one if there are colors
// The channels
......
......@@ -45,7 +45,7 @@ public:
KisHistogramWidget(QWidget *parent, const char *name);
virtual ~KisHistogramWidget();
void setPaintDevice(KisPaintDeviceSP dev);
void setPaintDevice(KisPaintDeviceSP dev, const QRect &bounds);
private slots:
void setActiveChannel(int channel);
......
......@@ -59,8 +59,7 @@ KisLevelFilter::~KisLevelFilter()
KisConfigWidget * KisLevelFilter::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, const KisImageWSP image) const
{
Q_UNUSED(image);
return new KisLevelConfigWidget(parent, dev);
return new KisLevelConfigWidget(parent, dev, image->bounds());
}
bool KisLevelFilter::workWith(KoColorSpace* cs) const
......@@ -100,7 +99,7 @@ KoColorTransformation* KisLevelFilter::createTransformation(const KoColorSpace*
return cs->createBrightnessContrastAdjustment(transfer);
}
KisLevelConfigWidget::KisLevelConfigWidget(QWidget * parent, KisPaintDeviceSP dev)
KisLevelConfigWidget::KisLevelConfigWidget(QWidget * parent, KisPaintDeviceSP dev, const QRect &bounds)
: KisConfigWidget(parent)
{
m_page.setupUi(this);
......@@ -145,7 +144,7 @@ KisLevelConfigWidget::KisLevelConfigWidget(QWidget * parent, KisPaintDeviceSP de
connect((QObject*)(m_page.chkLogarithmic), SIGNAL(toggled(bool)), this, SLOT(slotDrawHistogram(bool)));
KoHistogramProducerSP producer = KoHistogramProducerSP(new KoGenericLabHistogramProducer());
histogram = new KisHistogram(dev, producer, LINEAR);
histogram = new KisHistogram(dev, bounds, producer, LINEAR);
m_histlog = false;
slotDrawHistogram();
......
......@@ -62,7 +62,7 @@ class KisLevelConfigWidget : public KisConfigWidget
{
Q_OBJECT
public:
KisLevelConfigWidget(QWidget * parent, KisPaintDeviceSP dev);
KisLevelConfigWidget(QWidget * parent, KisPaintDeviceSP dev, const QRect &bounds);
virtual ~KisLevelConfigWidget();
virtual KisPropertiesConfiguration* configuration() const;
......
......@@ -60,7 +60,7 @@ KisHistogramView::~KisHistogramView()
{
}
void KisHistogramView::setPaintDevice(KisPaintDeviceSP dev)
void KisHistogramView::setPaintDevice(KisPaintDeviceSP dev, const QRect &bounds)
{
m_cs = dev->colorSpace();
......@@ -72,7 +72,7 @@ void KisHistogramView::setPaintDevice(KisPaintDeviceSP dev)
m_from = m_currentProducer->viewFrom();
m_width = m_currentProducer->viewWidth();
m_histogram = new KisHistogram(dev, m_currentProducer, LINEAR);
m_histogram = new KisHistogram(dev, bounds, m_currentProducer, LINEAR);
updateHistogram();
}
......
......@@ -63,7 +63,7 @@ public:
virtual ~KisHistogramView();
void setPaintDevice(KisPaintDeviceSP dev);
void setPaintDevice(KisPaintDeviceSP dev, const QRect &bounds);
void setHistogram(KisHistogramSP 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