本文整理汇总了C++中KisFixedPaintDeviceSP::setRect方法的典型用法代码示例。如果您正苦于以下问题:C++ KisFixedPaintDeviceSP::setRect方法的具体用法?C++ KisFixedPaintDeviceSP::setRect怎么用?C++ KisFixedPaintDeviceSP::setRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KisFixedPaintDeviceSP
的用法示例。
在下文中一共展示了KisFixedPaintDeviceSP::setRect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testFill
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;
}
示例2: testMaskGeneration
void KisAutoBrushTest::testMaskGeneration()
{
KisCircleMaskGenerator* circle = new KisCircleMaskGenerator(10, 1.0, 1.0, 1.0, 2, false);
KisBrushSP a = new KisAutoBrush(circle, 0.0, 0.0);
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisPaintInformation info(QPointF(100.0, 100.0), 0.5);
// check masking an existing paint device
KisFixedPaintDeviceSP fdev = new KisFixedPaintDevice(cs);
fdev->setRect(QRect(0, 0, 100, 100));
fdev->initialize();
cs->setOpacity(fdev->data(), OPACITY_OPAQUE_U8, 100 * 100);
QPoint errpoint;
QImage result(QString(FILES_DATA_DIR) + QDir::separator() + "result_autobrush_1.png");
QImage image = fdev->convertToQImage(0);
if (!TestUtil::compareQImages(errpoint, image, result)) {
image.save("kis_autobrush_test_1.png");
QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
}
// Check creating a mask dab with a single color
fdev = new KisFixedPaintDevice(cs);
a->mask(fdev, KoColor(Qt::black, cs), KisDabShape(), info);
result = QImage(QString(FILES_DATA_DIR) + QDir::separator() + "result_autobrush_3.png");
image = fdev->convertToQImage(0);
if (!TestUtil::compareQImages(errpoint, image, result)) {
image.save("kis_autobrush_test_3.png");
QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
}
// Check creating a mask dab with a color taken from a paint device
KoColor red(Qt::red, cs);
cs->setOpacity(red.data(), quint8(128), 1);
KisPaintDeviceSP dev = new KisPaintDevice(cs);
dev->fill(0, 0, 100, 100, red.data());
fdev = new KisFixedPaintDevice(cs);
a->mask(fdev, dev, KisDabShape(), info);
result = QImage(QString(FILES_DATA_DIR) + QDir::separator() + "result_autobrush_4.png");
image = fdev->convertToQImage(0);
if (!TestUtil::compareQImages(errpoint, image, result)) {
image.save("kis_autobrush_test_4.png");
QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
}
}
示例3: createBrushPreview
QImage KisAutoBrush::createBrushPreview()
{
srand(0);
srand48(0);
int width = maskWidth(1.0, 0.0, 0.0, 0.0, KisPaintInformation());
int height = maskHeight(1.0, 0.0, 0.0, 0.0, KisPaintInformation());
KisPaintInformation info(QPointF(width * 0.5, height * 0.5), 0.5, 0, 0, 0, 0);
KisFixedPaintDeviceSP fdev = new KisFixedPaintDevice( KoColorSpaceRegistry::instance()->rgb8() );
fdev->setRect(QRect(0, 0, width, height));
fdev->initialize();
mask(fdev,KoColor(Qt::black, fdev->colorSpace()),1.0, 1.0, 0.0, info);
return fdev->convertToQImage(0);
}
示例4: testCreation
void KisFixedPaintDeviceTest::testCreation()
{
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs);
dev = new KisFixedPaintDevice(cs);
QVERIFY(dev->bounds() == QRect());
QVERIFY(*dev->colorSpace() == *cs);
QVERIFY(dev->pixelSize() == cs->pixelSize());
dev->setRect(QRect(0, 0, 100, 100));
QVERIFY(dev->bounds() == QRect(0, 0, 100, 100));
dev->initialize();
QVERIFY(dev->data() != 0);
quint8* data = dev->data();
for (uint i = 0; i < 100 * 100 * cs->pixelSize(); ++i) {
QVERIFY(data[i] == 0);
}
}
示例5: benchmarkSIMD
void benchmarkSIMD(qreal fade) {
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs);
dev->setRect(QRect(0, 0, 1000, 1000));
dev->initialize();
MaskProcessingData data(dev, cs,
0.0, 1.0,
500, 500, 0);
KisCircleMaskGenerator gen(1000, 1.0, fade, fade, 2, false);
KisBrushMaskApplicatorBase *applicator = gen.applicator();
applicator->initializeData(&data);
QVector<QRect> rects = KritaUtils::splitRectIntoPatches(dev->bounds(), QSize(63, 63));
QBENCHMARK{
Q_FOREACH (const QRect &rc, rects) {
applicator->process(rc);
}
}
示例6: generateMaskAndApplyMaskOrCreateDab
void KisAutoBrush::generateMaskAndApplyMaskOrCreateDab(KisFixedPaintDeviceSP dst,
KisBrush::ColoringInformation* coloringInformation,
double scaleX, double scaleY, double angle,
const KisPaintInformation& info,
double subPixelX , double subPixelY, qreal softnessFactor) const
{
Q_UNUSED(info);
// Generate the paint device from the mask
const KoColorSpace* cs = dst->colorSpace();
quint32 pixelSize = cs->pixelSize();
// mask dimension methods already includes KisBrush::angle()
int dstWidth = maskWidth(scaleX, angle, subPixelX, subPixelY, info);
int dstHeight = maskHeight(scaleY, angle, subPixelX, subPixelY, info);
QPointF hotSpot = this->hotSpot(scaleX, scaleY, angle, info);
// mask size and hotSpot function take the KisBrush rotation into account
angle += KisBrush::angle();
// if there's coloring information, we merely change the alpha: in that case,
// the dab should be big enough!
if (coloringInformation) {
// old bounds
QRect oldBounds = dst->bounds();
// new bounds. we don't care if there is some extra memory occcupied.
dst->setRect(QRect(0, 0, dstWidth, dstHeight));
if (dstWidth * dstHeight <= oldBounds.width() * oldBounds.height()) {
// just clear the data in dst,
memset(dst->data(), OPACITY_TRANSPARENT_U8, dstWidth * dstHeight * dst->pixelSize());
} else {
// enlarge the data
dst->initialize();
}
} else {
if (dst->data() == 0 || dst->bounds().isEmpty()) {
qWarning() << "Creating a default black dab: no coloring info and no initialized paint device to mask";
dst->clear(QRect(0, 0, dstWidth, dstHeight));
}
Q_ASSERT(dst->bounds().width() >= dstWidth && dst->bounds().height() >= dstHeight);
}
quint8* dabPointer = dst->data();
quint8* color = 0;
if (coloringInformation) {
if (dynamic_cast<PlainColoringInformation*>(coloringInformation)) {
color = const_cast<quint8*>(coloringInformation->color());
}
}
double invScaleX = 1.0 / scaleX;
double invScaleY = 1.0 / scaleY;
double centerX = hotSpot.x() - 0.5 + subPixelX;
double centerY = hotSpot.y() - 0.5 + subPixelY;
d->shape->setSoftness( softnessFactor );
if (coloringInformation) {
if (color && pixelSize == 4) {
fillPixelOptimized_4bytes(color, dabPointer, dstWidth * dstHeight);
} else if (color) {
fillPixelOptimized_general(color, dabPointer, dstWidth * dstHeight, pixelSize);
} else {
for (int y = 0; y < dstHeight; y++) {
for (int x = 0; x < dstWidth; x++) {
memcpy(dabPointer, coloringInformation->color(), pixelSize);
coloringInformation->nextColumn();
dabPointer += pixelSize;
}
coloringInformation->nextRow();
}
}
}
MaskProcessingData data(dst, cs, d->randomness, d->density,
centerX, centerY,
invScaleX, invScaleY,
angle);
KisBrushMaskApplicatorBase *applicator = d->shape->applicator();
applicator->initializeData(&data);
int jobs = d->idealThreadCountCached;
if(dstHeight > 100 && jobs >= 4) {
int splitter = dstHeight/jobs;
QVector<QRect> rects;
for(int i = 0; i < jobs - 1; i++) {
rects << QRect(0, i*splitter, dstWidth, splitter);
}
rects << QRect(0, (jobs - 1)*splitter, dstWidth, dstHeight - (jobs - 1)*splitter);
OperatorWrapper wrapper(applicator);
QtConcurrent::blockingMap(rects, wrapper);
} else {
QRect rect(0, 0, dstWidth, dstHeight);
applicator->process(rect);
//.........这里部分代码省略.........
示例7: testMirroring
void KisFixedPaintDeviceTest::testMirroring()
{
QFETCH(QRect, rc);
QFETCH(bool, mirrorHorizontally);
QFETCH(bool, mirrorVertically);
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8();
KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs);
dev->setRect(rc);
dev->initialize();
KoColor c(Qt::black, cs);
qsrand(1);
int value = 0;
for (int i = rc.x(); i < rc.x() + rc.width(); i++) {
for (int j = rc.y(); j < rc.y() + rc.height(); j++) {
setPixel(dev, i, j, value);
value = qrand() % 255;
}
value = qrand() % 255;
}
//dev->convertToQImage(0).save("0_a.png");
dev->mirror(mirrorHorizontally, mirrorVertically);
//dev->convertToQImage(0).save("0_b.png");
int startX;
int endX;
int incX;
int startY;
int endY;
int incY;
if (mirrorHorizontally) {
startX = rc.x() + rc.width() - 1;
endX = rc.x() - 1;
incX = -1;
} else {
startX = rc.x();
endX = rc.x() + rc.width();
incX = 1;
}
if (mirrorVertically) {
startY = rc.y() + rc.height() - 1;
endY = rc.y() - 1;
incY = -1;
} else {
startY = rc.y();
endY = rc.y() + rc.height();
incY = 1;
}
qsrand(1);
value = 0;
for (int i = startX; i != endX ; i += incX) {
for (int j = startY; j != endY; j += incY) {
QCOMPARE(pixel(dev, i, j), (quint8)value);
value = qrand() % 255;
}
value = qrand() % 255;
}
}
示例8: paintAt
qreal KisFilterOp::paintAt(const KisPaintInformation& info)
{
if (!painter()) {
return 1.0;
}
if (!m_filter) {
return 1.0;
}
if (!source()) {
return 1.0;
}
KisBrushSP brush = m_brush;;
if (!brush) return 1.0;
if (! brush->canPaintFor(info))
return 1.0;
qreal scale = KisPaintOp::scaleForPressure(m_sizeOption.apply(info));
if ((scale * brush->width()) <= 0.01 || (scale * brush->height()) <= 0.01) return spacing(scale);
setCurrentScale(scale);
QPointF hotSpot = brush->hotSpot(scale, scale);
QPointF pt = info.pos() - hotSpot;
// Split the coordinates into integer plus fractional parts. The integer
// is where the dab will be positioned and the fractional part determines
// the sub-pixel positioning.
qint32 x;
qreal xFraction;
qint32 y;
qreal yFraction;
splitCoordinate(pt.x(), &x, &xFraction);
splitCoordinate(pt.y(), &y, &yFraction);
qint32 maskWidth = brush->maskWidth(scale, 0.0);
qint32 maskHeight = brush->maskHeight(scale, 0.0);
// Filter the paint device
m_filter->process(KisConstProcessingInformation(source(), QPoint(x, y)),
KisProcessingInformation(m_tmpDevice, QPoint(0, 0)),
QSize(maskWidth, maskHeight),
m_filterConfiguration, 0);
// Apply the mask on the paint device (filter before mask because edge pixels may be important)
KisFixedPaintDeviceSP fixedDab = new KisFixedPaintDevice(m_tmpDevice->colorSpace());
fixedDab->setRect(m_tmpDevice->extent());
fixedDab->initialize();
m_tmpDevice->readBytes(fixedDab->data(), fixedDab->bounds());
brush->mask(fixedDab, scale, scale, 0.0, info, xFraction, yFraction);
m_tmpDevice->writeBytes(fixedDab->data(), fixedDab->bounds());
if (!m_ignoreAlpha) {
KisHLineIteratorPixel itTmpDev = m_tmpDevice->createHLineIterator(0, 0, maskWidth);
KisHLineIteratorPixel itSrc = source()->createHLineIterator(x, y, maskWidth);
const KoColorSpace* cs = m_tmpDevice->colorSpace();
for (int y = 0; y < maskHeight; ++y) {
while (!itTmpDev.isDone()) {
quint8 alphaTmpDev = cs->opacityU8(itTmpDev.rawData());
quint8 alphaSrc = cs->opacityU8(itSrc.rawData());
cs->setOpacity(itTmpDev.rawData(), qMin(alphaTmpDev, alphaSrc), 1);
++itTmpDev;
++itSrc;
}
itTmpDev.nextRow();
itSrc.nextRow();
}
}
// Blit the paint device onto the layer
QRect dabRect = QRect(0, 0, maskWidth, maskHeight);
QRect dstRect = QRect(x, y, dabRect.width(), dabRect.height());
if (dstRect.isNull() || dstRect.isEmpty() || !dstRect.isValid()) return 1.0;
qint32 sx = dstRect.x() - x;
qint32 sy = dstRect.y() - y;
qint32 sw = dstRect.width();
qint32 sh = dstRect.height();
painter()->bitBlt(dstRect.x(), dstRect.y(), m_tmpDevice, sx, sy, sw, sh);
return spacing(scale);
}