Commit 048c141f authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fixed two bugs in filters/histogram code

1) Histogram should not crash when the source device is empty
2) The preview (and histogram) devices for an adjustment layer
   should be created not from the previous layer, but from the
   layers stack below.

BUG:318621
parent 4bc6afaf
......@@ -83,12 +83,6 @@ public:
return true;
}
KisSafeFilterConfigurationSP filterConfig = layer->filter();
if (!filterConfig) return true;
KisFilterSP filter = KisFilterRegistry::instance()->value(filterConfig->name());
if (!filter) return false;
KisPaintDeviceSP originalDevice = layer->original();
originalDevice->clear(m_updateRect);
......@@ -98,6 +92,22 @@ public:
// null, we are finish here.
if(applyRect.isNull()) return true;
KisSafeFilterConfigurationSP filterConfig = layer->filter();
if (!filterConfig) {
/**
* When an adjustment layer is just created, it may have no
* filter inside. Then the layer has work as a pass-through
* node. Just copy the merged data to the layer's original.
*/
KisPainter gc(originalDevice);
gc.setCompositeOp(COMPOSITE_COPY);
gc.bitBlt(applyRect.topLeft(), m_projection, applyRect);
return true;
}
KisFilterSP filter = KisFilterRegistry::instance()->value(filterConfig->name());
if (!filter) return false;
Q_ASSERT(layer->nodeProgressProxy());
KoProgressUpdater updater(layer->nodeProgressProxy());
......
......@@ -33,6 +33,8 @@ KisHistogram::KisHistogram(const KisPaintLayerSP layer,
KoHistogramProducerSP producer,
const enumHistogramType type)
{
Q_ASSERT(producer);
m_paintDevice = layer->projection();
m_bounds = layer->image()->bounds();
m_type = type;
......@@ -48,6 +50,8 @@ KisHistogram::KisHistogram(const KisPaintDeviceSP paintdev,
KoHistogramProducerSP producer,
const enumHistogramType type)
{
Q_ASSERT(producer);
m_paintDevice = paintdev;
m_bounds = bounds;
m_producer = producer;
......@@ -66,7 +70,17 @@ KisHistogram::~KisHistogram()
void KisHistogram::updateHistogram()
{
if (!m_producer) return;
if (m_bounds.isEmpty()) {
int numChannels = m_producer->channels().count();
m_completeCalculations.clear();
m_completeCalculations.resize(numChannels);
m_completeCalculations.clear();
m_completeCalculations.resize(numChannels);
return;
}
KisRectConstIteratorSP srcIt = m_paintDevice->createRectConstIteratorNG(m_bounds.left(), m_bounds.top(), m_bounds.width(), m_bounds.height());
const KoColorSpace* cs = m_paintDevice->colorSpace();
......
......@@ -567,13 +567,18 @@ void KisLayerManager::addAdjustmentLayer(KisNodeSP parent, KisNodeSP above)
KisLayerSP l = activeLayer();
KisPaintDeviceSP dev = l->projection();
KisSelectionSP selection = l->selection();
KisAdjustmentLayerSP adjl = addAdjustmentLayer(parent, above, QString(), 0, selection);
KisDlgAdjustmentLayer dlg(adjl, adjl.data(), dev, image->nextLayerName(), i18n("New Filter Layer"), m_view);
KisPaintDeviceSP previewDevice = new KisPaintDevice(*adjl->original());
KisDlgAdjustmentLayer dlg(adjl, adjl.data(), previewDevice, image->nextLayerName(), i18n("New Filter Layer"), m_view);
dlg.resize(dlg.minimumSizeHint());
// ensure that the device may be free'd by the dialog
// when it is not needed anymore
previewDevice = 0;
if (dlg.exec() != QDialog::Accepted) {
m_commandsAdapter->undoLastCommand();
} else {
......@@ -592,6 +597,7 @@ KisAdjustmentLayerSP KisLayerManager::addAdjustmentLayer(KisNodeSP parent, KisNo
KisAdjustmentLayerSP l = new KisAdjustmentLayer(image, name, filter, selection);
m_commandsAdapter->addNode(l.data(), parent, above);
l->setDirty(image->bounds());
image->waitForDone();
return l;
}
......
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