本文整理汇总了C++中KisSelectionSP类的典型用法代码示例。如果您正苦于以下问题:C++ KisSelectionSP类的具体用法?C++ KisSelectionSP怎么用?C++ KisSelectionSP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KisSelectionSP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lockTemporaryTarget
void KisSelectionBasedLayer::copyOriginalToProjection(const KisPaintDeviceSP original,
KisPaintDeviceSP projection,
const QRect& rect) const
{
lockTemporaryTarget();
m_d->selection->updateProjection();
KisSelectionSP tempSelection = m_d->selection;
KisPainter gc(projection);
if (m_d->selection) {
if (hasTemporaryTarget()) {
/**
* Cloning a selection with COW
* FIXME: check whether it's faster than usual bitBlt'ing
*/
tempSelection = new KisSelection(*tempSelection);
KisPainter gc2(tempSelection->pixelSelection());
gc2.setOpacity(temporaryOpacity());
gc2.setCompositeOp(temporaryCompositeOp());
gc2.bitBlt(rect.topLeft(), temporaryTarget(), rect);
}
projection->clear(rect);
gc.setCompositeOp(colorSpace()->compositeOp(COMPOSITE_OVER));
gc.setSelection(tempSelection);
} else
gc.setCompositeOp(colorSpace()->compositeOp(COMPOSITE_COPY));
gc.bitBlt(rect.topLeft(), original, rect);
unlockTemporaryTarget();
}
示例2: run
void KisSelectionToVectorActionFactory::run(KisView2 *view)
{
KisSelectionSP selection = view->selection();
if (selection->hasShapeSelection() ||
!selection->outlineCacheValid()) {
return;
}
QPainterPath selectionOutline = selection->outlineCache();
QTransform transform = view->canvasBase()->coordinatesConverter()->imageToDocumentTransform();
KoShape *shape = KoPathShape::createShapeFromPainterPath(transform.map(selectionOutline));
shape->setShapeId(KoPathShapeId);
/**
* Mark a shape that it belongs to a shape selection
*/
if(!shape->userData()) {
shape->setUserData(new KisShapeSelectionMarker);
}
KisProcessingApplicator *ap = beginAction(view, i18n("Convert to Vector Selection"));
ap->applyCommand(view->canvasBase()->shapeController()->addShape(shape),
KisStrokeJobData::SEQUENTIAL,
KisStrokeJobData::EXCLUSIVE);
endAction(ap, KisOperationConfiguration(id()).toXML());
}
示例3: qimage
void KisFilterTest::testDifferentSrcAndDst()
{
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "hakonepa.png");
QImage inverted(QString(FILES_DATA_DIR) + QDir::separator() + "inverted_hakonepa.png");
KisPaintDeviceSP src = new KisPaintDevice(cs);
KisPaintDeviceSP dst = new KisPaintDevice(cs);
KisSelectionSP sel = new KisSelection(new KisSelectionDefaultBounds(src));
sel->getOrCreatePixelSelection()->invert(); // select everything
sel->updateProjection();
src->convertFromQImage(qimage, 0, 0, 0);
KisFilterSP f = KisFilterRegistry::instance()->value("invert");
Q_ASSERT(f);
KisFilterConfiguration * kfc = f->defaultConfiguration(0);
Q_ASSERT(kfc);
f->process(src, dst, sel, QRect(QPoint(0,0), qimage.size()), kfc);
QPoint errpoint;
if (!TestUtil::compareQImages(errpoint, inverted, dst->convertToQImage(0, 0, 0, qimage.width(), qimage.height()))) {
dst->convertToQImage(0, 0, 0, qimage.width(), qimage.height()).save("filtertest.png");
QFAIL(QString("Failed to create inverted image, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
}
}
示例4: paintBevelSelection
void paintBevelSelection(KisPixelSelectionSP srcSelection,
KisPixelSelectionSP dstSelection,
const QRect &applyRect,
int size,
int initialSize,
bool invert)
{
KisSelectionSP tmpBaseSelection = new KisSelection(new KisSelectionEmptyBounds(0));
KisPixelSelectionSP tmpSelection = tmpBaseSelection->pixelSelection();
// NOTE: we are not using createCompositionSourceDevice() intentionally,
// because the source device doesn't have alpha channel
KisPixelSelectionSP fillDevice = new KisPixelSelection();
KisPainter gc(dstSelection);
gc.setCompositeOp(COMPOSITE_COPY);
for (int i = 0; i < size; i++) {
const int growSize = initialSize - i - 1;
quint8 selectedness = invert ?
qRound(qreal(size - i - 1) / size * 255.0) :
qRound(qreal(i + 1) / size * 255.0);
fillDevice->setDefaultPixel(KoColor(&selectedness, fillDevice->colorSpace()));
tmpSelection->makeCloneFromRough(srcSelection, srcSelection->selectedRect());
QRect changeRect = KisLsUtils::growSelectionUniform(tmpSelection, growSize, applyRect);
gc.setSelection(tmpBaseSelection);
gc.bitBlt(changeRect.topLeft(), fillDevice, changeRect);
}
}
示例5: selectionRect
void KisMaskTest::testCropUpdateBySelection()
{
TestUtil::MaskParent p;
/**
* We do not use exact selection bounds for cropping,
* so the rects should be covered by different tiles
*/
QRect selectionRect(10, 10, 20, 20);
QRect updateRect(64, 64, 20, 20);
TestMaskSP mask = new TestMask;
KisSelectionSP sel = new KisSelection();
sel->pixelSelection()->select(selectionRect, MAX_SELECTED);
mask->initSelection(sel, p.layer);
mask->apply(p.layer->projection(), updateRect);
// Here we crash! :)
/**
* If you see a crash, it means KisMask tried to update
* the area that is outside its selection.
* Please consider fixing KisMask::apply() first
*/
}
示例6: loadNodeKeyframes
bool KisKraLoadVisitor::visit(KisAdjustmentLayer* layer)
{
loadNodeKeyframes(layer);
// Adjustmentlayers are tricky: there's the 1.x style and the 2.x
// style, which has selections with selection components
bool result = true;
if (m_syntaxVersion == 1) {
KisSelectionSP selection = new KisSelection();
KisPixelSelectionSP pixelSelection = selection->pixelSelection();
result = loadPaintDevice(pixelSelection, getLocation(layer, ".selection"));
layer->setInternalSelection(selection);
} else if (m_syntaxVersion == 2) {
result = loadSelection(getLocation(layer), layer->internalSelection());
} else {
// We use the default, empty selection
}
if (!loadMetaData(layer)) {
return false;
}
loadFilterConfiguration(layer->filter().data(), getLocation(layer, DOT_FILTERCONFIG));
result = visitAll(layer);
return result;
}
示例7: KisImage
void KisMaskTest::testDeferredOffsetInitialization()
{
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisImageSP image = new KisImage(0, 100, 100, cs, "stest");
KisMaskSP mask = new TestMask;
QCOMPARE(mask->x(), 0);
QCOMPARE(mask->y(), 0);
mask->setX(10);
QCOMPARE(mask->x(), 10);
QCOMPARE(mask->y(), 0);
mask->setY(11);
QCOMPARE(mask->x(), 10);
QCOMPARE(mask->y(), 11);
mask->initSelection(image->rootLayer());
// IMPORTANT: a bit weird behavior, but it is needed for
// KisKraLoadVisitor to work properly
QCOMPARE(mask->x(), 10);
QCOMPARE(mask->y(), 11);
// Now there is no deferred initialization, so the offest
// should simply be reset
mask->initSelection(image->rootLayer());
QCOMPARE(mask->x(), 0);
QCOMPARE(mask->y(), 0);
KisSelectionSP selection = mask->selection();
QCOMPARE(selection->parentNode(), KisNodeSP(mask));
}
示例8: loadSelection
bool KisKraLoadVisitor::loadSelection(const QString& location, KisSelectionSP dstSelection)
{
// Pixel selection
bool result = true;
QString pixelSelectionLocation = location + DOT_PIXEL_SELECTION;
if (m_store->hasFile(pixelSelectionLocation)) {
KisPixelSelectionSP pixelSelection = dstSelection->pixelSelection();
result = loadPaintDevice(pixelSelection, pixelSelectionLocation);
if (!result) {
m_errorMessages << i18n("Could not load raster selection %1.", location);
}
pixelSelection->invalidateOutlineCache();
}
// Shape selection
QString shapeSelectionLocation = location + DOT_SHAPE_SELECTION;
if (m_store->hasFile(shapeSelectionLocation + "/content.xml")) {
m_store->pushDirectory();
m_store->enterDirectory(shapeSelectionLocation) ;
KisShapeSelection* shapeSelection = new KisShapeSelection(m_image, dstSelection);
dstSelection->setShapeSelection(shapeSelection);
result = shapeSelection->loadSelection(m_store);
m_store->popDirectory();
if (!result) {
m_errorMessages << i18n("Could not load vector selection %1.", location);
}
}
return result;
}
示例9: KisSelection
void KisSelectionTest::testInvertSelection()
{
KisSelectionSP selection = new KisSelection();
KisPixelSelectionSP pixelSelection = selection->getOrCreatePixelSelection();
pixelSelection->select(QRect(20, 20, 20, 20));
QCOMPARE(pixelSelection->selected(30, 30), MAX_SELECTED);
QCOMPARE(pixelSelection->selected(0, 0), MIN_SELECTED);
QCOMPARE(pixelSelection->selected(512, 512), MIN_SELECTED);
pixelSelection->invert();
QCOMPARE(pixelSelection->selected(100, 100), MAX_SELECTED);
QCOMPARE(pixelSelection->selected(22, 22), MIN_SELECTED);
QCOMPARE(pixelSelection->selected(0, 0), MAX_SELECTED);
QCOMPARE(pixelSelection->selected(512, 512), MAX_SELECTED);
pixelSelection->convertToQImage(0, 0, 0, 100, 100).save("yyy.png");
// XXX: This should happen automatically
selection->updateProjection();
selection->convertToQImage(0, 0, 0, 100, 100).save("zzz.png");
QCOMPARE(selection->selectedExactRect(), QRect(qint32_MIN/2, qint32_MIN/2, qint32_MAX, qint32_MAX));
QCOMPARE(selection->selectedRect(), QRect(qint32_MIN/2, qint32_MIN/2, qint32_MAX, qint32_MAX));
QCOMPARE(selection->selected(100, 100), MAX_SELECTED);
QCOMPARE(selection->selected(22, 22), MIN_SELECTED);
QCOMPARE(selection->selected(10, 10), MAX_SELECTED);
QCOMPARE(selection->selected(0, 0), MAX_SELECTED);
QCOMPARE(selection->selected(512, 512), MAX_SELECTED);
}
示例10: copyFromDevice
void copyFromDevice(KisViewManager *view, KisPaintDeviceSP device, bool makeSharpClip = false)
{
KisImageWSP image = view->image();
if (!image) return;
KisSelectionSP selection = view->selection();
QRect rc = (selection) ? selection->selectedExactRect() : image->bounds();
KisPaintDeviceSP clip = new KisPaintDevice(device->colorSpace());
Q_CHECK_PTR(clip);
const KoColorSpace *cs = clip->colorSpace();
// TODO if the source is linked... copy from all linked layers?!?
// Copy image data
KisPainter::copyAreaOptimized(QPoint(), device, clip, rc);
if (selection) {
// Apply selection mask.
KisPaintDeviceSP selectionProjection = selection->projection();
KisHLineIteratorSP layerIt = clip->createHLineIteratorNG(0, 0, rc.width());
KisHLineConstIteratorSP selectionIt = selectionProjection->createHLineIteratorNG(rc.x(), rc.y(), rc.width());
const KoColorSpace *selCs = selection->projection()->colorSpace();
for (qint32 y = 0; y < rc.height(); y++) {
for (qint32 x = 0; x < rc.width(); x++) {
/**
* Sharp method is an exact reverse of COMPOSITE_OVER
* so if you cover the cut/copied piece over its source
* you get an exactly the same image without any seams
*/
if (makeSharpClip) {
qreal dstAlpha = cs->opacityF(layerIt->rawData());
qreal sel = selCs->opacityF(selectionIt->oldRawData());
qreal newAlpha = sel * dstAlpha / (1.0 - dstAlpha + sel * dstAlpha);
float mask = newAlpha / dstAlpha;
cs->applyAlphaNormedFloatMask(layerIt->rawData(), &mask, 1);
} else {
cs->applyAlphaU8Mask(layerIt->rawData(), selectionIt->oldRawData(), 1);
}
layerIt->nextPixel();
selectionIt->nextPixel();
}
layerIt->nextRow();
selectionIt->nextRow();
}
}
KisClipboard::instance()->setClip(clip, rc.topLeft());
}
示例11: run
void KisImageResizeToSelectionActionFactory::run(KisViewManager *view)
{
// XXX: "Add saving of XML data for Image Resize To Selection action"
KisSelectionSP selection = view->selection();
if (!selection) return;
view->image()->cropImage(selection->selectedExactRect());
}
示例12: testShapedGradientPainterImpl
void testShapedGradientPainterImpl(const QPolygonF &selectionPolygon,
const QString &testName,
const QPolygonF &selectionErasePolygon = QPolygonF())
{
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisPaintDeviceSP dev = new KisPaintDevice(cs);
QRect imageRect(0,0,300,300);
KisSelectionSP selection = new KisSelection();
KisPixelSelectionSP pixelSelection = selection->pixelSelection();
KisPainter selPainter(pixelSelection);
selPainter.setFillStyle(KisPainter::FillStyleForegroundColor);
selPainter.setPaintColor(KoColor(Qt::white, pixelSelection->colorSpace()));
selPainter.paintPolygon(selectionPolygon);
if (!selectionErasePolygon.isEmpty()) {
selPainter.setCompositeOp(COMPOSITE_ERASE);
selPainter.setPaintColor(KoColor(Qt::white, pixelSelection->colorSpace()));
selPainter.paintPolygon(selectionErasePolygon);
}
selPainter.end();
pixelSelection->invalidateOutlineCache();
pixelSelection->convertToQImage(0, imageRect).save("sgt_selection.png");
QLinearGradient testGradient;
testGradient.setColorAt(0.0, Qt::white);
testGradient.setColorAt(0.5, Qt::green);
testGradient.setColorAt(1.0, Qt::black);
testGradient.setSpread(QGradient::ReflectSpread);
QScopedPointer<KoStopGradient> gradient(
KoStopGradient::fromQGradient(&testGradient));
KisGradientPainter gc(dev, selection);
gc.setGradient(gradient.data());
gc.setGradientShape(KisGradientPainter::GradientShapePolygonal);
gc.paintGradient(selectionPolygon.boundingRect().topLeft(),
selectionPolygon.boundingRect().bottomRight(),
KisGradientPainter::GradientRepeatNone,
0,
false,
imageRect.x(),
imageRect.y(),
imageRect.width(),
imageRect.height());
QVERIFY(TestUtil::checkQImageExternal(dev->convertToQImage(0, imageRect),
"shaped_gradient",
"fill",
testName, 1, 1, 0));
}
示例13: run
void KisImageResizeToSelectionActionFactory::run(KisView2 *view)
{
#ifdef __GNUC__
#warning "Add saving of XML data for Image Resize To Selection action"
#endif
KisSelectionSP selection = view->selection();
if (!selection) return;
view->image()->cropImage(selection->selectedExactRect());
}
示例14: KisSelection
void KisMaskTest::testSelection()
{
TestUtil::MaskParent p;
TestMaskSP mask = new TestMask;
KisSelectionSP sel = new KisSelection();
sel->pixelSelection()->select(QRect(0,0,100,100), MAX_SELECTED);
mask->initSelection(sel, p.layer);
QCOMPARE(mask->extent(), QRect(0,0,128,128));
QCOMPARE(mask->exactBounds(), QRect(0,0,100,100));
mask->select(QRect(0,0,500,500), MAX_SELECTED);;
QCOMPARE(mask->extent(), QRect(0,0,512,512));
QCOMPARE(mask->exactBounds(), QRect(0,0,500,500));
}
示例15: setInternalSelection
void KisSelectionBasedLayer::setInternalSelection(KisSelectionSP selection)
{
if (selection) {
m_d->selection = new KisSelection(*selection.data());
m_d->selection->setParentNode(this);
m_d->selection->updateProjection();
} else
m_d->selection = 0;
}