Commit 0cdbd8db authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add a simple test for the projection machinery of KisPaintLayer.

svn path=/trunk/koffice/; revision=720831
parent 47408fc6
......@@ -126,7 +126,8 @@ public:
KisPainter gc(m_projection);
gc.setChannelFlags( layer->channelFlags() );
KisPaintDeviceSP source = layer->paintDevice();//projection();
layer->updateProjection(m_rc);
KisPaintDeviceSP source = layer->projection();
if (tempTarget) {
KisPaintDeviceSP temp = new KisPaintDevice(source->colorSpace());
......@@ -193,7 +194,6 @@ public:
m_rc = (layer->extent() | tempTarget->extent()) & m_rc;
}
if (m_rc.width() == 0 || m_rc.height() == 0) // Don't even try
return true;
......
......@@ -120,7 +120,6 @@ KisPaintDeviceSP KisPaintLayer::projection() const
if ( !hasEffectMasks() )
return m_d->paintDevice;
else {
Q_ASSERT( m_d->projection );
return m_d->projection;
}
}
......@@ -128,15 +127,12 @@ KisPaintDeviceSP KisPaintLayer::projection() const
void KisPaintLayer::updateProjection(const QRect & rc)
{
Q_ASSERT( rc.isValid() );
Q_ASSERT( isDirty( rc ) );
Q_ASSERT( hasEffectMasks() );
Q_ASSERT( m_d->paintDevice );
if ( !rc.isValid() ) return ;
if ( !isDirty( rc ) ) return;
if ( !hasEffectMasks() ) return;
if ( !m_d->paintDevice ) return;
if ( !isDirty( rc ) ) return;
QRegion dirty = dirtyRegion( rc );
if ( !m_d->projection ) {
m_d->projection = new KisPaintDevice( *m_d->paintDevice );
......@@ -145,10 +141,13 @@ void KisPaintLayer::updateProjection(const QRect & rc)
// Clean up the area before we re-apply the masks.
KisPainter gc( m_d->projection );
gc.setCompositeOp( colorSpace()->compositeOp( COMPOSITE_COPY ) );
gc.bitBlt( rc.topLeft(), m_d->paintDevice, rc );
foreach (QRect rect, dirty.rects() ) {
gc.bitBlt( rc.topLeft(), m_d->paintDevice, rect );
}
}
foreach ( QRect rect, dirty.rects() ) {
applyEffectMasks( m_d->projection, rect );
}
applyEffectMasks( m_d->projection, rc );
}
......
......@@ -60,6 +60,11 @@ public:
KoColorSpace * colorSpace();
void updateProjection(const QRect& r);
/**
* Return the projection paint device, or 0 if the projection does
* not exist yet. (For instance, because it hasn't been updated yet.)
*/
KisPaintDeviceSP projection() const;
QIcon icon() const;
......
......@@ -27,11 +27,14 @@ class QRect;
/**
A transparency mask is a single channel mask that applies a particular
transparency 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.
*/
* A transparency mask is a single channel mask that applies a particular
* transparency 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.
*
* XXX: Use KisConfig::useProjections() to enable/disable the caching of
* the projection.
*/
class KRITAIMAGE_EXPORT KisTransparencyMask : public KisEffectMask
{
Q_OBJECT
......
......@@ -177,3 +177,11 @@ set(kis_filter_mask_test_SRCS kis_filter_mask_test.cpp )
kde4_add_unit_test(KisFilterMaskTest TESTNAME krita-image-KisFilterMaskTest ${kis_filter_mask_test_SRCS})
target_link_libraries(KisFilterMaskTest ${KDE4_KDEUI_LIBS} komain kritaimage ${QT_QTTEST_LIBRARY})
########### next target ###############
set(kis_paint_layer_test_SRCS kis_paint_layer_test.cpp )
kde4_add_unit_test(KisPaintLayerTest TESTNAME krita-image-KisPaintLayerTest ${kis_paint_layer_test_SRCS})
target_link_libraries(KisPaintLayerTest ${KDE4_KDEUI_LIBS} komain kritaimage ${QT_QTTEST_LIBRARY})
/*
* Copyright (c) 2007 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>
#include "kis_paint_layer_test.h"
#include <QImage>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include "kis_group_layer.h"
#include "kis_types.h"
#include "kis_paint_layer.h"
#include "kis_image.h"
#include "kis_paint_device.h"
#include "kis_transparency_mask.h"
#include "testutil.h"
void KisPaintLayerTest::testProjection()
{
QImage qimg( QString(FILES_DATA_DIR) + QDir::separator() + "hakonepa.png");
KoColorSpace * cs = KoColorSpaceRegistry::instance()->colorSpace("RGBA", 0);
KisImageSP image = new KisImage(0, qimg.width(), qimg.height(), cs, "merge test");
KisPaintLayerSP layer = new KisPaintLayer( image, "test", OPACITY_OPAQUE );
layer->paintDevice()->convertFromQImage( qimg, 0, 0, 0 );
image->addNode( layer.data() );
// Make sure the projection and the paint device are the same -- we don't have masks yet
QVERIFY( layer->paintDevice().data() == layer->projection().data() );
KisTransparencyMaskSP transparencyMask = new KisTransparencyMask();
image->addNode( transparencyMask.data(), layer.data() );
// Now there are masks. Verify that
Q_ASSERT( layer->hasEffectMasks() );
// Which also means that the projection is no longer the paint device
QVERIFY( layer->paintDevice().data() != layer->projection().data() );
// And the projection is still 0, because we've updated it
QVERIFY( layer->projection().data() == 0 );
// And now we're going to update the projection, but nothing is dirty yet
layer->updateProjection( qimg.rect() );
// Which also means that the projection is no longer the paint device
QVERIFY( layer->paintDevice().data() != layer->projection().data() );
// And the projection is no longer 0, because while we've updated it, nothing is dirty,
// so nothing gets updated
QVERIFY( layer->projection().data() == 0 );
// Now the machinery will start to roll
layer->setDirty( qimg.rect() );
// And now we're going to update the projection, but nothing is dirty yet
layer->updateProjection( qimg.rect() );
// Which also means that the projection is no longer the paint device
QVERIFY( layer->paintDevice().data() != layer->projection().data() );
// And the projection is no longer 0, because while we've updated it, nothing is dirty,
// so nothing gets updated
QVERIFY( layer->projection().data() != 0 );
}
QTEST_KDEMAIN(KisPaintLayerTest, GUI)
#include "kis_paint_layer_test.moc"
/*
* Copyright (c) 2007 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_PAINT_LAYER_TEST_H
#define KIS_PAINT_LAYER_TEST_H
#include <QtTest/QtTest>
class KisPaintLayerTest : public QObject
{
Q_OBJECT
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