Commit bcf9f684 authored by Halla Rempt's avatar Halla Rempt

Fix the iterator test (it doesn't crash anymore -- but it does fail)

and add a painter test that shows that bltMask is broken for ordinary 
paint devices, too.

svn path=/trunk/koffice/; revision=685961
parent 1a8371a9
......@@ -22,6 +22,7 @@
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <KoColorSpace.h>
#include <KoColorProfile.h>
#include "kis_iterators_pixel.h"
#include "kis_random_accessor.h"
......@@ -59,6 +60,7 @@ void KisIteratorTest::allCsApplicator(void (KisIteratorTest::* funcPtr)( KoColor
void KisIteratorTest::writeBytes( KoColorSpace * colorSpace )
{
KisPaintDevice dev( colorSpace, "test");
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
......@@ -92,6 +94,8 @@ void KisIteratorTest::writeBytes( KoColorSpace * colorSpace )
QVERIFY( dev.extent() == QRect( -64, -64, 64 * 11, 64 * 2 ) );
QVERIFY( dev.exactBounds() == QRect( -10, -10, 640, 64 ) );
delete[] bytes;
}
void KisIteratorTest::fill( KoColorSpace * colorSpace )
......@@ -101,7 +105,7 @@ void KisIteratorTest::fill( KoColorSpace * colorSpace )
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
quint8 * bytes = new quint8( colorSpace->pixelSize() );
quint8 * bytes = colorSpace->allocPixelBuffer( 1 );
memset( bytes, 128, colorSpace->pixelSize() );
dev.fill( 0, 0, 5, 5, bytes );
......@@ -118,6 +122,7 @@ void KisIteratorTest::fill( KoColorSpace * colorSpace )
QVERIFY( dev.extent() == QRect( 0, 0, 8 * 64, 8 * 64 ) );
QVERIFY( dev.exactBounds() == QRect( 5, 5, 500, 500 ) );
delete[] bytes;
}
void KisIteratorTest::rectIter( KoColorSpace * colorSpace )
......@@ -125,45 +130,50 @@ void KisIteratorTest::rectIter( KoColorSpace * colorSpace )
KisPaintDevice dev( colorSpace, "test");
quint8 * bytes = new quint8( colorSpace->pixelSize() );
quint8 * bytes = colorSpace->allocPixelBuffer( 1 );
memset( bytes, 128, colorSpace->pixelSize() );
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
KisRectConstIteratorPixel cit = dev.createRectConstIterator(0, 0, 128, 128);
while ( !cit.isDone() ) ++cit;
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
QVERIFY( dev.exactBounds() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
{
// Const does not extend the extent
KisRectIteratorPixel it = dev.createRectIterator(0, 0, 128, 128);
while ( !it.isDone() ) {
memcpy(it.rawData(), bytes, colorSpace->pixelSize() );
++it;
KisRectConstIteratorPixel cit = dev.createRectConstIterator(0, 0, 128, 128);
while ( !cit.isDone() ) ++cit;
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
QVERIFY( dev.exactBounds() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
// Non-const does
KisRectIteratorPixel it = dev.createRectIterator(0, 0, 128, 128);
while ( !it.isDone() ) {
memcpy(it.rawData(), bytes, colorSpace->pixelSize() );
++it;
}
QVERIFY( dev.extent() == QRect( 0, 0, 128, 128 ) );
QVERIFY( dev.exactBounds() == QRect( 0, 0, 128, 128 ) );
}
dev.clear();
{
KisRectIteratorPixel it = dev.createRectIterator(10, 10, 128, 128);
while ( !it.isDone() ) {
memcpy(it.rawData(), bytes, colorSpace->pixelSize() );
++it;
}
QVERIFY( dev.extent() == QRect( 0, 0, 3 * 64, 3 * 64 ) );
QVERIFY( dev.exactBounds() == QRect( 10, 10, 128, 128 ) );
}
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();
//it = dev.createRectIterator(10, 10, 128, 128);
// while ( !it.isDone() ) {
// memcpy(it.rawData(), bytes, colorSpace->pixelSize() );
// ++it;
// }
// QVERIFY( dev.extent() == QRect( 0, 0, 3 * 64, 3 * 64 ) );
// QVERIFY( dev.exactBounds() == QRect( 10, 10, 128, 128 ) );
delete[] bytes;
}
void KisIteratorTest::hLineIter( KoColorSpace * colorSpace )
{
KisPaintDevice dev( colorSpace, "test");
quint8 * bytes = new quint8( colorSpace->pixelSize() );
quint8 * bytes = colorSpace->allocPixelBuffer( 1 );
memset( bytes, 128, colorSpace->pixelSize() );
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
......@@ -183,7 +193,6 @@ void KisIteratorTest::hLineIter( KoColorSpace * colorSpace )
kDebug() << "XXXXXXXXXXXXXX BUG: 147191" << endl;
QVERIFY( dev.extent() == QRect( 0, 0, 128, 64) );
kDebug () << dev.exactBounds() << endl;
QVERIFY( dev.exactBounds() == QRect( 0, 0, 128, 1 ) );
dev.clear();
......@@ -195,7 +204,6 @@ void KisIteratorTest::hLineIter( KoColorSpace * colorSpace )
}
QVERIFY( dev.extent() == QRect( 0, 0, 128, 64) );
kDebug () << dev.exactBounds() << endl;
QVERIFY( dev.exactBounds() == QRect( 0, 1, 128, 1 ) );
dev.clear();
......@@ -209,13 +217,14 @@ void KisIteratorTest::hLineIter( KoColorSpace * colorSpace )
QVERIFY( dev.extent() == QRect( 0, 0, 192, 64) );
QVERIFY( dev.exactBounds() == QRect( 10, 10, 128, 1 ) );
delete[] bytes;
}
void KisIteratorTest::vLineIter( KoColorSpace * colorSpace )
{
KisPaintDevice dev( colorSpace, "test");
quint8 * bytes = new quint8( colorSpace->pixelSize() );
quint8 * bytes = colorSpace->allocPixelBuffer( 1 );
memset( bytes, 128, colorSpace->pixelSize() );
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
......@@ -232,7 +241,6 @@ void KisIteratorTest::vLineIter( KoColorSpace * colorSpace )
++it;
}
QVERIFY( dev.extent() == QRect( 0, 0, 64, 128) );
kDebug () << dev.exactBounds() << endl;
QVERIFY( dev.exactBounds() == QRect( 0, 0, 1, 128 ) );
dev.clear();
......@@ -246,6 +254,7 @@ void KisIteratorTest::vLineIter( KoColorSpace * colorSpace )
QVERIFY( dev.extent() == QRect( 0, 0, 64, 192) );
QVERIFY( dev.exactBounds() == QRect( 10, 10, 1, 128 ) );
delete[] bytes;
}
......@@ -253,7 +262,7 @@ void KisIteratorTest::randomAccessor( KoColorSpace * colorSpace )
{
KisPaintDevice dev( colorSpace, "test");
quint8 * bytes = new quint8( colorSpace->pixelSize() );
quint8 * bytes = colorSpace->allocPixelBuffer( 1 );
memset( bytes, 128, colorSpace->pixelSize() );
QVERIFY( dev.extent() == QRect(qint32_MAX, qint32_MAX, 0, 0) );
......@@ -273,10 +282,10 @@ void KisIteratorTest::randomAccessor( KoColorSpace * colorSpace )
memcpy( ac.rawData(), bytes, colorSpace->pixelSize() );
}
}
kDebug() << dev.extent() << endl;
QVERIFY( dev.extent() == QRect(0, 0, 128, 128 ) );
QVERIFY( dev.exactBounds() == QRect(0, 0, 128, 128 ) );
delete[] bytes;
}
......@@ -293,6 +302,7 @@ void KisIteratorTest::fill()
void KisIteratorTest::rectIter()
{
allCsApplicator( &KisIteratorTest::rectIter );
rectIter( KoColorSpaceRegistry::instance()->colorSpace( "RGBAF32", 0 ) );
}
void KisIteratorTest::hLineIter()
......
......@@ -30,6 +30,41 @@
#include "kis_paint_device.h"
#include "kis_painter.h"
#include "kis_pixel_selection.h"
void KisPainterTest::allCsApplicator(void (KisPainterTest::* 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->compositeOp( COMPOSITE_OVER ) != 0) {
if ( cs ) ( this->*funcPtr )( 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) {
if ( cs ) ( this->*funcPtr )( cs );
}
else {
kDebug() << "Cannot bitBlt for cs " << csId << endl;
}
}
}
}
}
/*
Note: the bltMask tests assume the following geometry:
......@@ -80,37 +115,55 @@ void KisPainterTest::testPaintDeviceBltMask(KoColorSpace * cs)
void KisPainterTest::testPaintDeviceBltMask()
{
QList<QString> csIds = KoColorSpaceRegistry::instance()->keys();
allCsApplicator( &KisPainterTest::testPaintDeviceBltMask );
}
foreach( QString csId, csIds ) {
void KisPainterTest::testPaintDeviceBltMaskIrregular(KoColorSpace * cs)
{
kDebug() << "Testing with " << csId << endl;
KisPaintDeviceSP dst = new KisPaintDevice( cs, "dst");
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;
}
}
KisPaintDeviceSP src = new KisPaintDevice( cs, "src" );
src->fill( 0, 0, 20, 20, KoColor( Qt::red, 128, cs ).data() );
}
}
QCOMPARE( src->exactBounds(), QRect( 0, 0, 20, 20 ) );
KisPixelSelectionSP mask = KisPixelSelectionSP(new KisPixelSelection(dst));
mask->select(QRect(10,15,20,15));
mask->select(QRect(15,10,15,5));
QCOMPARE( mask->selectedExactRect(), QRect( 10, 10, 20, 20 ) );
QCOMPARE( mask->selected(13,13), MIN_SELECTED);
KisPainter painter(dst);
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" );
QCOMPARE( dst->exactBounds(), QRect( 10, 10, 10, 10 ) );
QColor c;
quint8 alpha;
dst->pixel( 13, 13, &c, &alpha );
QCOMPARE( alpha, OPACITY_TRANSPARENT );
QCOMPARE( c.red(), 0 );
QCOMPARE( c.blue(), 0 );
QCOMPARE( c.green(), 0 );
}
void KisPainterTest::testPaintDeviceBltMaskIrregular()
{
allCsApplicator( &KisPainterTest::testPaintDeviceBltMaskIrregular );
}
void KisPainterTest::testSelectionBltMask()
{
KisPaintDeviceSP dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8(), "temporary");
......@@ -149,6 +202,9 @@ void KisPainterTest::testSelectionBltMask()
}
/*
Test with non-square selection
0,0 0,30
+-----------+------+
| 13,13 | |
......@@ -162,8 +218,9 @@ void KisPainterTest::testSelectionBltMask()
+------------------+
30,30
*/
void KisPainterTest::testSelectionBltMask2()
void KisPainterTest::testSelectionBltMaskIrregular()
{
KisPaintDeviceSP dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8(), "temporary");
KisPixelSelectionSP src = KisPixelSelectionSP(new KisPixelSelection(dev));
......@@ -174,6 +231,7 @@ void KisPainterTest::testSelectionBltMask2()
mask->select(QRect(10,15,20,15));
mask->select(QRect(15,10,15,5));
QCOMPARE( mask->selectedExactRect(), QRect( 10, 10, 20, 20 ) );
QCOMPARE( mask->selected(13,13), MIN_SELECTED);
KisPixelSelectionSP dst = KisPixelSelectionSP(new KisPixelSelection(dev));
KisPainter painter(dst);
......@@ -187,6 +245,8 @@ void KisPainterTest::testSelectionBltMask2()
0, 0, 30, 30);
painter.end();
dst->convertToQImage(0).save( "bla.png" );
QCOMPARE( dst->selectedExactRect(), QRect( 10, 10, 10, 10 ) );
QCOMPARE( dst->selected(13,13), MIN_SELECTED);
}
......
......@@ -28,14 +28,15 @@ class KisPainterTest : public QObject
Q_OBJECT
private:
void allCsApplicator(void (KisPainterTest::* funcPtr)( KoColorSpace*cs ) );
void testPaintDeviceBltMask( KoColorSpace * cs );
void testPaintDeviceBltMaskIrregular( KoColorSpace * cs );
private slots:
void testPaintDeviceBltMask();
void testSelectionBltMask();
void testSelectionBltMask2();
void testPaintDeviceBltMask(); // Square selection
void testPaintDeviceBltMaskIrregular(); // Irregular selection
void testSelectionBltMask(); // Square selection
void testSelectionBltMaskIrregular(); // Irregular selection
};
......
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