void KisFixedPaintDeviceTest::testFill() { const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); quint8* red = new quint8[cs->pixelSize()]; memcpy(red, KoColor(Qt::red, cs).data(), cs->pixelSize()); cs->setOpacity(red, quint8(128), 1); KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs); dev->fill(0, 0, 100, 100, red); QVERIFY(dev->bounds() == QRect(0, 0, 100, 100)); QVERIFY(cs->opacityU8(dev->data()) == 128); QVERIFY(memcmp(dev->data(), red, cs->pixelSize()) == 0); //Compare fill will normal paint device dev = new KisFixedPaintDevice(cs); dev->setRect(QRect(0, 0, 150, 150)); dev->initialize(); dev->fill(50, 50, 50, 50, red); KisPaintDeviceSP dev2 = new KisPaintDevice(cs); dev2->fill(50, 50, 50, 50, red); QImage image = dev->convertToQImage(0); QImage checkImage = dev2->convertToQImage(0, 0, 0, 150, 150); QPoint errpoint; if (!TestUtil::compareQImages(errpoint, image, checkImage)) { image.save("kis_fixed_paint_device_filled_result.png"); checkImage.save("kis_fixed_paint_device_filled_result_expected.png"); QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); } delete[] red; }
inline void setPixel(KisFixedPaintDeviceSP dev, int x, int y, quint8 alpha) { KoColor c(Qt::black, dev->colorSpace()); c.setOpacity(alpha); dev->fill(x, y, 1, 1, c.data()); }