Commit b3f6d90d authored by Halla Rempt's avatar Halla Rempt

The iterator tests now work on all available colorspaces, leading to

some new crashes. (Which is good...)

svn path=/trunk/koffice/; revision=685821
parent 49bd0bcc
......@@ -30,9 +30,35 @@
#include "kis_iterator_test.h"
#include "kis_paint_device.h"
void KisIteratorTest::writeBytes()
void KisIteratorTest::allCsApplicator(void (KisIteratorTest::* funcPtr)( KoColorSpace*cs ) )
{
QList<QString> csIds = KoColorSpaceRegistry::instance()->keys();
foreach( QString csId, csIds ) {
kDebug() << "Testing with " << csId << endl;
QList<KoColorProfile*> profiles = KoColorSpaceRegistry::instance()->profilesFor ( csId );
if ( profiles.size() == 0 ) {
KoColorSpace * cs = KoColorSpaceRegistry::instance()->colorSpace( csId, 0 );
if ( cs ) ( this->*funcPtr )( cs );
}
else {
foreach( KoColorProfile * profile, profiles ) {
KoColorSpace * cs = KoColorSpaceRegistry::instance()->colorSpace( csId, profile );
if ( cs ) ( this->*funcPtr )( cs );
}
}
}
}
void KisIteratorTest::writeBytes( KoColorSpace * colorSpace )
{
KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->colorSpace("RGBA", 0);
KisPaintDevice dev( colorSpace, "test");
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
......@@ -68,9 +94,9 @@ void KisIteratorTest::writeBytes()
QVERIFY( dev.exactBounds() == QRect( -10, -10, 640, 64 ) );
}
void KisIteratorTest::fill()
void KisIteratorTest::fill( KoColorSpace * colorSpace )
{
KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->colorSpace("RGBA", 0);
KisPaintDevice dev( colorSpace, "test");
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
......@@ -94,9 +120,9 @@ void KisIteratorTest::fill()
}
void KisIteratorTest::rectIter()
void KisIteratorTest::rectIter( KoColorSpace * colorSpace )
{
KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->colorSpace("RGBA", 0);
KisPaintDevice dev( colorSpace, "test");
quint8 * bytes = new quint8( colorSpace->pixelSize() );
......@@ -117,13 +143,13 @@ void KisIteratorTest::rectIter()
QVERIFY( dev.extent() == QRect( 0, 0, 128, 128 ) );
QVERIFY( dev.exactBounds() == QRect( 0, 0, 128, 128 ) );
// BSAR: This causes an assert: BUG!
// CBR - naturally as we still have iterators accessing the data
// BSAR: of course not, isDone() has returned true, we're done
// accessing the data.
//dev.clear();
// BSAR: This causes an assert: BUG!
// CBR - naturally as we still have iterators accessing the data
// BSAR: of course not, isDone() has returned true, we're done
// accessing the data.
//dev.clear();
//it = dev.createRectIterator(10, 10, 128, 128);
//it = dev.createRectIterator(10, 10, 128, 128);
// while ( !it.isDone() ) {
// memcpy(it.rawData(), bytes, colorSpace->pixelSize() );
// ++it;
......@@ -133,9 +159,8 @@ void KisIteratorTest::rectIter()
}
void KisIteratorTest::hLineIter()
void KisIteratorTest::hLineIter( KoColorSpace * colorSpace )
{
KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->colorSpace("RGBA", 0);
KisPaintDevice dev( colorSpace, "test");
quint8 * bytes = new quint8( colorSpace->pixelSize() );
......@@ -186,9 +211,9 @@ void KisIteratorTest::hLineIter()
}
void KisIteratorTest::vLineIter()
void KisIteratorTest::vLineIter( KoColorSpace * colorSpace )
{
KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->colorSpace("RGBA", 0);
KisPaintDevice dev( colorSpace, "test");
quint8 * bytes = new quint8( colorSpace->pixelSize() );
memset( bytes, 128, colorSpace->pixelSize() );
......@@ -224,10 +249,9 @@ void KisIteratorTest::vLineIter()
}
void KisIteratorTest::randomAccessor()
void KisIteratorTest::randomAccessor( KoColorSpace * colorSpace )
{
KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->colorSpace("RGBA", 0);
KisPaintDevice dev( colorSpace, "test");
quint8 * bytes = new quint8( colorSpace->pixelSize() );
memset( bytes, 128, colorSpace->pixelSize() );
......@@ -256,5 +280,35 @@ void KisIteratorTest::randomAccessor()
}
void KisIteratorTest::writeBytes()
{
allCsApplicator( &KisIteratorTest::writeBytes );
}
void KisIteratorTest::fill()
{
allCsApplicator( &KisIteratorTest::fill );
}
void KisIteratorTest::rectIter()
{
allCsApplicator( &KisIteratorTest::rectIter );
}
void KisIteratorTest::hLineIter()
{
allCsApplicator( &KisIteratorTest::hLineIter );
}
void KisIteratorTest::vLineIter()
{
allCsApplicator( &KisIteratorTest::vLineIter );
}
void KisIteratorTest::randomAccessor()
{
allCsApplicator( &KisIteratorTest::randomAccessor );
}
QTEST_KDEMAIN(KisIteratorTest, NoGUI)
#include "kis_iterator_test.moc"
......@@ -21,10 +21,23 @@
#include <QtTest/QtTest>
class KoColorSpace;
class KisIteratorTest : public QObject
{
Q_OBJECT
private:
void allCsApplicator(void (KisIteratorTest::* funcPtr)( KoColorSpace*cs ) );
void writeBytes( KoColorSpace * cs );
void fill( KoColorSpace * cs );
void rectIter( KoColorSpace * cs );
void hLineIter( KoColorSpace * cs );
void vLineIter( KoColorSpace * cs );
void randomAccessor( KoColorSpace * cs );
private slots:
void writeBytes();
......
......@@ -31,6 +31,9 @@
#include "kis_painter.h"
#include "kis_pixel_selection.h"
/*
Note: the bltMask tests assume the following geometry:
0,0 0,30
+---------+------+
| 10,10 | |
......@@ -44,34 +47,69 @@
+----------------+
30,30
*/
// void KisPainterTest::testPaintDeviceBltMask()
// {
// KisPaintDeviceSP dst = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8(), "dst");
void KisPainterTest::testPaintDeviceBltMask(KoColorSpace * cs)
{
KisPaintDeviceSP dst = new KisPaintDevice( cs, "dst");
KisPaintDeviceSP src = new KisPaintDevice( cs, "src" );
src->fill( 0, 0, 20, 20, KoColor( Qt::red, 128, cs ).data() );
// KisPixelSelectionSP src = new KisPaintDevice( KoColorSpaceRegistry::instance()->rgb8(), "src" );
// src->fill
// QCOMPARE( src->selectedExactRect(), QRect( 0, 0, 20, 20 ) );
QCOMPARE( src->exactBounds(), QRect( 0, 0, 20, 20 ) );
// KisPixelSelectionSP mask = KisPixelSelectionSP(new KisPixelSelection(dev));
// mask->select(QRect(10,10,20,20));
// QCOMPARE( mask->selectedExactRect(), QRect( 10, 10, 20, 20 ) );
KisPixelSelectionSP mask = KisPixelSelectionSP(new KisPixelSelection(dst));
mask->select(QRect(10,10,20,20));
QCOMPARE( mask->selectedExactRect(), QRect( 10, 10, 20, 20 ) );
// KisPixelSelectionSP dst = KisPixelSelectionSP(new KisPixelSelection(dev));
// KisPainter painter(dst);
KisPainter painter(dst);
painter.bltMask(0, 0,
dst->colorSpace()->compositeOp(COMPOSITE_OVER),
src,
mask,
OPACITY_OPAQUE,
0, 0, 30, 30);
painter.end();
// painter.bltMask(0, 0,
// dst->colorSpace()->compositeOp(COMPOSITE_OVER),
// src,
// mask,
// OPACITY_OPAQUE,
// 0, 0, 30, 30);
// painter.end();
QImage img = dst->convertToQImage(0);
img.save( "bla_" + cs->name() + ".png" );
// //dst->convertToQImage(0).save( "bla.png" );
QCOMPARE( dst->exactBounds(), QRect( 10, 10, 10, 10 ) );
}
// QCOMPARE( dst->selectedExactRect(), QRect( 10, 10, 10, 10 ) );
// }
void KisPainterTest::testPaintDeviceBltMask()
{
QList<QString> csIds = KoColorSpaceRegistry::instance()->keys();
foreach( QString csId, csIds ) {
kDebug() << "Testing with " << csId << endl;
QList<KoColorProfile*> profiles = KoColorSpaceRegistry::instance()->profilesFor ( csId );
if ( profiles.size() == 0 ) {
KoColorSpace * cs = KoColorSpaceRegistry::instance()->colorSpace( csId, 0 );
if ( cs->compositeOp( COMPOSITE_OVER ) != 0) {
testPaintDeviceBltMask( cs );
}
else {
kDebug() << "Cannot bitBlt for cs " << csId << endl;
}
}
else {
foreach( KoColorProfile * profile, profiles ) {
KoColorSpace * cs = KoColorSpaceRegistry::instance()->colorSpace( csId, profile );
if ( cs->compositeOp( COMPOSITE_OVER ) != 0) {
testPaintDeviceBltMask( cs );
}
else {
kDebug() << "Cannot bitBlt for cs " << csId << endl;
}
}
}
}
}
void KisPainterTest::testSelectionBltMask()
{
......@@ -97,9 +135,17 @@ void KisPainterTest::testSelectionBltMask()
0, 0, 30, 30);
painter.end();
//dst->convertToQImage(0).save( "bla.png" );
dst->convertToQImage(0).save( "bla.png" );
QCOMPARE( dst->selectedExactRect(), QRect( 10, 10, 10, 10 ) );
KisRectConstIteratorPixel it = dst->createRectConstIterator(10, 10, 10, 10);
while ( !it.isDone() ) {
// These are selections, so only one channel and it should
// be totally selected
QCOMPARE( it.rawData()[0], MAX_SELECTED );
++it;
}
}
/*
......
......@@ -21,15 +21,21 @@
#include <QtTest/QtTest>
class KoColorSpace;
class KisPainterTest : public QObject
{
Q_OBJECT
private:
void testPaintDeviceBltMask( KoColorSpace * cs );
private slots:
void testPaintDeviceBltMask();
void testSelectionBltMask();
void testSelectionBltMask2();
// void testPaintDeviceBltMask();
};
......
......@@ -41,6 +41,7 @@ void KisPainterlyOverlayTester::testPainterlyOverlayColorSpaceCell()
{
KisPainterlyOverlayColorSpace * cs = KisPainterlyOverlayColorSpace::instance();
Q_ASSERT( cs );
Q_ASSERT( cs->compositeOp( COMPOSITE_OVER ) == 0 );
quint8 * bytes = cs->allocPixelBuffer( 1 );
memset( bytes, 0, cs->pixelSize() );
......
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