Krita Source Code Documentation
Loading...
Searching...
No Matches
ActionHelper Namespace Reference

Functions

KisImageSP makeImage (KisViewManager *view, KisNodeList nodes)
 
void trimDevice (KisViewManager *view, KisPaintDeviceSP device, bool makeSharpClip=false, const KisTimeSpan &range=KisTimeSpan())
 

Function Documentation

◆ makeImage()

KisImageSP ActionHelper::makeImage ( KisViewManager * view,
KisNodeList nodes )

Definition at line 130 of file kis_selection_action_factories.cpp.

131 {
132 KisImageWSP image = view->image();
133
134 KisImageSP clipImage = new KisImage(0, image->width(), image->height(), image->colorSpace(), "ClipImage");
135 clipImage->setResolution(image->xRes(), image->yRes());
136 Q_FOREACH (KisNodeSP node, nodes) {
137 clipImage->addNode(node, clipImage->root());
138 }
139
140 clipImage->refreshGraphAsync();
141 clipImage->waitForDone();
142
143 return clipImage;
144 }
void waitForDone()
void refreshGraphAsync(KisNodeSP root, const QVector< QRect > &rects, const QRect &cropRect, KisProjectionUpdateFlags flags=KisProjectionUpdateFlag::None) override
const KoColorSpace * colorSpace() const
qint32 width() const
double xRes() const
double yRes() const
qint32 height() const
void setResolution(double xres, double yres)
KisImageWSP image() const
Return the image this view is displaying.
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)

References KisNodeFacade::addNode(), KisImage::colorSpace(), KisImage::height(), KisViewManager::image(), KisImage::refreshGraphAsync(), KisNodeFacade::root, KisImage::setResolution(), KisImage::waitForDone(), KisImage::width(), KisImage::xRes(), and KisImage::yRes().

◆ trimDevice()

void ActionHelper::trimDevice ( KisViewManager * view,
KisPaintDeviceSP device,
bool makeSharpClip = false,
const KisTimeSpan & range = KisTimeSpan() )

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

Definition at line 70 of file kis_selection_action_factories.cpp.

74 {
75 Q_UNUSED(range); // TODO: Allow multiple frame operation across a timespan.
76
77 KisImageWSP image = view->image();
78 if (!image) return;
79
80 KisSelectionSP selection = view->selection();
81
82 QRect rc = (selection) ? selection->selectedExactRect() : image->bounds();
83
84 const KoColorSpace *cs = device->colorSpace();
85
86 // We need to allow for trimming from non-transparent defaultPixel layers.
87 // Default color should be phased out of use when the area in question is not aligned with image bounds.
88 // Otherwise, we can maintain default pixel.
89 const bool hasNonTransparentDefaultPixel = device->defaultPixel() != KoColor::createTransparent(device->colorSpace());
90 const bool needsTransparentPixel = selection && rc != image->bounds() && hasNonTransparentDefaultPixel;
91
92 if (selection) {
93 // Apply selection mask.
94 KisPaintDeviceSP selectionProjection = selection->projection();
95 const KoColorSpace *selCs = selection->projection()->colorSpace();
96
97 KisSequentialIterator layerIt(device, rc);
98 KisSequentialConstIterator selectionIt(selectionProjection, rc);
99
100 while (layerIt.nextPixel() && selectionIt.nextPixel()) {
101
107 if (makeSharpClip) {
108 qreal dstAlpha = cs->opacityF(layerIt.rawData());
109 qreal sel = selCs->opacityF(selectionIt.oldRawData());
110 qreal newAlpha = sel * dstAlpha / (1.0 - dstAlpha + sel * dstAlpha);
111 float mask = newAlpha / dstAlpha;
112
113 cs->applyAlphaNormedFloatMask(layerIt.rawData(), &mask, 1);
114 } else {
115 cs->applyAlphaU8Mask(layerIt.rawData(), selectionIt.oldRawData(), 1);
116 }
117 }
118 }
119
120
121
122 if ( needsTransparentPixel ) {
124 device->purgeDefaultPixels();
125 }
126
127 device->crop(rc);
128 }
QRect bounds() const override
void crop(qint32 x, qint32 y, qint32 w, qint32 h)
void setDefaultPixel(const KoColor &defPixel)
const KoColorSpace * colorSpace() const
KoColor defaultPixel() const
KisSelectionSP selection()
virtual void applyAlphaU8Mask(quint8 *pixels, const quint8 *alpha, qint32 nPixels) const =0
virtual qreal opacityF(const quint8 *pixel) const =0
virtual void applyAlphaNormedFloatMask(quint8 *pixels, const float *alpha, qint32 nPixels) const =0
static KoColor createTransparent(const KoColorSpace *cs)
Definition KoColor.cpp:681
KisPixelSelectionSP projection() const
QRect selectedExactRect() const
Slow, but exact way of determining the rectangle that encloses the selection.

References KoColorSpace::applyAlphaNormedFloatMask(), KoColorSpace::applyAlphaU8Mask(), KisImage::bounds(), KisPaintDevice::colorSpace(), KoColor::createTransparent(), KisPaintDevice::crop(), KisPaintDevice::defaultPixel(), KisViewManager::image(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData(), KoColorSpace::opacityF(), KisSelection::projection(), KisPaintDevice::purgeDefaultPixels(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisSelection::selectedExactRect(), KisViewManager::selection(), and KisPaintDevice::setDefaultPixel().