Commit fe48d132 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Some more work on making the dynamic masks work.

svn path=/trunk/koffice/; revision=721198
parent 9074b5e1
......@@ -24,13 +24,13 @@
#include "kis_types.h"
#include "kis_mask.h"
/**
An effect mask is a single channel mask that applies a particular
effect to the layer the mask belongs to. It differs from an
adjustment layer in that it only works on its parent layer, while
adjustment layers work on all layers below it in its layer group.
The effect could be a filter, a transformation or anything else
that messes up pixels.
*/
* An effect mask is a single channel mask that applies a particular
* effect to the layer the mask belongs to. It differs from an
* adjustment layer in that it only works on its parent layer, while
* adjustment layers work on all layers below it in its layer group.
* The effect could be a filter, a transformation or anything else
* that messes up pixels.
*/
const QString KIS_EFFECT_MASK_ID = "KisEffectMask";
class KRITAIMAGE_EXPORT KisEffectMask : public KisMask
......@@ -41,8 +41,7 @@ class KRITAIMAGE_EXPORT KisEffectMask : public KisMask
public:
/**
* Create an empty effect mask. There is filter and no layer
* associated with this mask.
* Create an empty effect mask.
*/
KisEffectMask();
......
......@@ -36,7 +36,17 @@ const KoID KisFilter::CategoryNonPhotorealistic = KoID("nonphotorealistic_filter
const KoID KisFilter::CategoryOther = KoID("other_filters", i18n("Other"));
struct KisFilter::Private {
Private() : bookmarkManager(0) {}
Private()
: bookmarkManager(0)
, cancelRequested(false)
, progressEnabled(false)
, autoUpdate(false)
, progressTotalSteps(0)
, lastProgressPerCent(0)
, progressSteps(0)
{
}
KisBookmarkedConfigurationManager* bookmarkManager;
bool cancelRequested;
bool progressEnabled;
......
......@@ -20,6 +20,7 @@
#include "kis_filter.h"
#include "kis_filter_configuration.h"
#include "kis_filter_registry.h"
#include "kis_selection.h"
class KRITAIMAGE_EXPORT KisFilterMask::Private {
public:
......@@ -62,14 +63,18 @@ void KisFilterMask::setFilter(KisFilterConfiguration * filterConfig)
void KisFilterMask::apply( KisPaintDeviceSP projection, const QRect & rc ) const
{
Q_ASSERT( m_d->filterConfig );
/*
if (!m_d->filterConfig) return;
selection()->updateProjection();
// XXX: This is actually a problem when we're running multithreaded, so we need to make
// selection a paramenter of KisFilter::process
KisSelectionSP oldSelection = 0;
if (projection->hasSelection())
oldSelection = projection->selection();
projection->setSelection( selection() );
projection->setSelection
*/
KisFilterSP filter = KisFilterRegistry::instance()->value( m_d->filterConfig->name() );
if (!filter) {
kWarning() << "Could not retrieve filter with name " << m_d->filterConfig->name();
......@@ -77,9 +82,8 @@ void KisFilterMask::apply( KisPaintDeviceSP projection, const QRect & rc ) const
}
filter->process( projection, rc, m_d->filterConfig);
/*
projection->setSelection( oldSelection );
*/
}
#include "kis_filter_mask.moc"
......@@ -27,10 +27,8 @@
#include "kis_layer.h"
#include "kis_selection.h"
class KisMask::Private
struct KisMask::Private
{
public:
KisSelectionSP selection;
};
......
......@@ -110,7 +110,7 @@ public:
private:
class Private;
struct Private;
Private * const m_d;
......
......@@ -142,9 +142,10 @@ void KisPaintLayer::updateProjection(const QRect & rc)
KisPainter gc( m_d->projection );
gc.setCompositeOp( colorSpace()->compositeOp( COMPOSITE_COPY ) );
foreach (QRect rect, dirty.rects() ) {
gc.bitBlt( rc.topLeft(), m_d->paintDevice, rect );
gc.bitBlt( rect.topLeft(), m_d->paintDevice, rect );
}
}
foreach ( QRect rect, dirty.rects() ) {
applyEffectMasks( m_d->projection, rect );
}
......
......@@ -59,6 +59,10 @@ public:
KoColorSpace * colorSpace();
/**
* Update the projection for the specified rect r, whether that rect is dirty
* or not.
*/
void updateProjection(const QRect& r);
/**
......
......@@ -104,7 +104,7 @@ public:
* Invert the selection.
*
* XXX: The extent that is inverted is the total
* extent of the selection project, not that of the selection
* extent of the selection projection, not that of the selection
* components, the parent paint device or the image. Shouldn't we
* fix this?
*/
......
......@@ -41,6 +41,8 @@ KisTransparencyMask::KisTransparencyMask( const KisTransparencyMask& rhs )
void KisTransparencyMask::apply( KisPaintDeviceSP projection, const QRect & rc ) const
{
selection()->updateProjection();
KoColorSpace * cs = projection->colorSpace();
KisHLineIteratorPixel projectionIt = projection->createHLineIterator( rc.x(), rc.y(), rc.width() );
......@@ -59,7 +61,6 @@ void KisTransparencyMask::apply( KisPaintDeviceSP projection, const QRect & rc )
maskIt.nextRow();
}
}
#include "kis_transparency_mask.moc"
......@@ -44,17 +44,16 @@ void KisFilterMaskTest::testProjection()
KisFilterConfiguration * kfc = f->defaultConfiguration(0);
Q_ASSERT( kfc );
// Without a selection
KisFilterMaskSP mask = new KisFilterMask();
mask->setFilter( kfc );
// Check basic apply()
// Check basic apply(). Shouldn't do anything, since nothing is selected yet.
KisPaintDeviceSP projection = new KisPaintDevice( cs );
projection->convertFromQImage( qimg, 0, 0, 0 );
mask->apply( projection, QRect( 0, 0, qimg.width(), qimg.height() ) );
QPoint errpoint;
if ( !TestUtil::compareQImages( errpoint, inverted, projection->convertToQImage(0, 0, 0, qimg.width(), qimg.height() ) ) ) {
if ( !TestUtil::compareQImages( errpoint, qimg, projection->convertToQImage(0, 0, 0, qimg.width(), qimg.height() ) ) ) {
QFAIL( QString( "Failed to create identical image, first different pixel: %1,%2 " ).arg( errpoint.x() ).arg( errpoint.y() ).toAscii() );
}
......
......@@ -31,6 +31,7 @@
#include "kis_paint_device.h"
#include "kis_transparency_mask.h"
#include "testutil.h"
#include "kis_selection.h"
void KisPaintLayerTest::testProjection()
{
......@@ -81,10 +82,18 @@ void KisPaintLayerTest::testProjection()
// so nothing gets updated
QVERIFY( layer->projection().data() != 0 );
// The selection is initially empty, so after an update, all pixels are still visible
layer->updateProjection( qimg.rect() );
// By default a new transparency mask blanks out the entire layer (photoshop mode "hide all")
KisRectConstIterator it = layer->projection()->createRectConstIterator(0, 0, qimg.width(), qimg.height());
while (!it.isDone()) {
QVERIFY(cs->alpha(it.rawData()) == OPACITY_TRANSPARENT);
++it;
}
}
QTEST_KDEMAIN(KisPaintLayerTest, GUI)
#include "kis_paint_layer_test.moc"
......@@ -28,7 +28,6 @@ class KisPaintLayerTest : public QObject
private slots:
void testProjection();
};
#endif
......
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