Krita Source Code Documentation
Loading...
Searching...
No Matches
KisLsDropShadowFilter Class Reference

#include <kis_ls_drop_shadow_filter.h>

+ Inheritance diagram for KisLsDropShadowFilter:

Public Types

enum  Mode { DropShadow , InnerShadow , OuterGlow , InnerGlow }
 

Public Member Functions

QRect changedRect (const QRect &rect, KisPSDLayerStyleSP style, KisLayerStyleFilterEnvironment *env) const override
 
KisLayerStyleFilterclone () const override
 
 KisLsDropShadowFilter (Mode mode=DropShadow)
 
QRect neededRect (const QRect &rect, KisPSDLayerStyleSP style, KisLayerStyleFilterEnvironment *env) const override
 
void processDirectly (KisPaintDeviceSP src, KisMultipleProjection *dst, KisLayerStyleKnockoutBlower *blower, const QRect &applyRect, KisPSDLayerStyleSP style, KisLayerStyleFilterEnvironment *env) const override
 
- Public Member Functions inherited from KisLayerStyleFilter
QString id () const
 
 KisLayerStyleFilter (const KoID &id)
 
virtual ~KisLayerStyleFilter ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KisShared
bool deref ()
 
bool ref ()
 
int refCount ()
 
QAtomicInt * sharedWeakReference ()
 

Private Member Functions

void applyDropShadow (KisPaintDeviceSP srcDevice, KisMultipleProjection *dst, const QRect &applyRect, const psd_layer_effects_context *context, const psd_layer_effects_shadow_base *shadow, KisResourcesInterfaceSP resourcesInterface, KisLayerStyleFilterEnvironment *env) const
 
const psd_layer_effects_shadow_basegetShadowStruct (KisPSDLayerStyleSP style) const
 
 KisLsDropShadowFilter (const KisLsDropShadowFilter &rhs)
 

Private Attributes

const Mode m_mode
 

Additional Inherited Members

- Public Attributes inherited from KisLayerStyleFilter
KoID id
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Protected Member Functions inherited from KisLayerStyleFilter
 KisLayerStyleFilter (const KisLayerStyleFilter &rhs)
 
- Protected Member Functions inherited from KisShared
 KisShared ()
 
 ~KisShared ()
 

Detailed Description

Definition at line 17 of file kis_ls_drop_shadow_filter.h.

Member Enumeration Documentation

◆ Mode

Enumerator
DropShadow 
InnerShadow 
OuterGlow 
InnerGlow 

Definition at line 21 of file kis_ls_drop_shadow_filter.h.

Constructor & Destructor Documentation

◆ KisLsDropShadowFilter() [1/2]

KisLsDropShadowFilter::KisLsDropShadowFilter ( Mode mode = DropShadow)

Definition at line 35 of file kis_ls_drop_shadow_filter.cpp.

36 : KisLayerStyleFilter(KoID("lsdropshadow", i18n("Drop Shadow (style)")))
37 , m_mode(mode)
38{
39}
Definition KoID.h:30
KisLayerStyleFilter(const KoID &id)

◆ KisLsDropShadowFilter() [2/2]

KisLsDropShadowFilter::KisLsDropShadowFilter ( const KisLsDropShadowFilter & rhs)
private

Definition at line 41 of file kis_ls_drop_shadow_filter.cpp.

43 m_mode(rhs.m_mode)
44{
45}

Member Function Documentation

◆ applyDropShadow()

void KisLsDropShadowFilter::applyDropShadow ( KisPaintDeviceSP srcDevice,
KisMultipleProjection * dst,
const QRect & applyRect,
const psd_layer_effects_context * context,
const psd_layer_effects_shadow_base * shadow,
KisResourcesInterfaceSP resourcesInterface,
KisLayerStyleFilterEnvironment * env ) const
private

Copy selection which will be erased from the original later

Spread and blur the selection

Contour correction

Noise

Knock-out original outline of the device from the resulting shade

Definition at line 110 of file kis_ls_drop_shadow_filter.cpp.

117{
118 if (applyRect.isEmpty()) return;
119
120 ShadowRectsData d(applyRect, context, shadow, ShadowRectsData::NEED_RECT);
121
123 KisSelectionSP baseSelection = s1.selection();
124 KisLsUtils::selectionFromAlphaChannel(srcDevice, baseSelection, d.spreadNeedRect);
125
126 KisPixelSelectionSP selection = baseSelection->pixelSelection();
127
128 //selection->convertToQImage(0, QRect(0,0,300,300)).save("0_selection_initial.png");
129
130 if (shadow->invertsSelection()) {
131 selection->invert();
132 }
133
139 if (shadow->knocksOut()) {
140 knockOutSelection = s2.selection()->pixelSelection();
141 knockOutSelection->makeCloneFromRough(selection, selection->selectedRect());
142 }
143
144 if (shadow->technique() == psd_technique_precise) {
145 KisLsUtils::findEdge(selection, d.blurNeedRect, true);
146 }
147
151 if (d.spread_size) {
152 KisLsUtils::applyGaussianWithTransaction(selection, d.blurNeedRect, d.spread_size);
153
154 // TODO: find out why in libpsd we pass false here. If we do so,
155 // the result is fully black, which is not expected
156 KisLsUtils::findEdge(selection, d.blurNeedRect, true /*shadow->edgeHidden()*/);
157 }
158
159 //selection->convertToQImage(0, QRect(0,0,300,300)).save("1_selection_spread.png");
160
161 if (d.blur_size) {
162 KisLsUtils::applyGaussianWithTransaction(selection, d.noiseNeedRect, d.blur_size);
163 }
164 //selection->convertToQImage(0, QRect(0,0,300,300)).save("2_selection_blur.png");
165
166 if (shadow->range() != KisLsUtils::FULL_PERCENT_RANGE) {
167 KisLsUtils::adjustRange(selection, d.noiseNeedRect, shadow->range());
168 }
169
170 const psd_layer_effects_inner_glow *iglow = 0;
171 if ((iglow =
172 dynamic_cast<const psd_layer_effects_inner_glow *>(shadow)) &&
173 iglow->source() == psd_glow_center) {
174
175 selection->invert();
176 }
177
182 d.noiseNeedRect,
183 shadow->contourLookupTable(),
184 shadow->antiAliased(),
185 shadow->edgeHidden());
186
187 //selection->convertToQImage(0, QRect(0,0,300,300)).save("3_selection_contour.png");
188
192 if (shadow->noise() > 0) {
193 KisLsUtils::applyNoise(selection,
194 d.srcRect,
195 shadow->noise(),
196 context,
197 env);
198 }
199 //selection->convertToQImage(0, QRect(0,0,300,300)).save("4_selection_noise.png");
200
201 if (!d.offset.isNull()) {
202 selection->moveTo(selection->offset() + d.offset);
203 }
204
208 if (shadow->knocksOut()) {
209 KIS_ASSERT_RECOVER_RETURN(knockOutSelection);
210
211 QRect knockOutRect = !shadow->invertsSelection() ?
212 d.srcRect : d.spreadNeedRect;
213
214 knockOutRect &= d.dstRect;
215
216 KisPainter gc(selection);
217 gc.setCompositeOpId(COMPOSITE_ERASE);
218 gc.bitBlt(knockOutRect.topLeft(), knockOutSelection, knockOutRect);
219 }
220 //selection->convertToQImage(0, QRect(0,0,300,300)).save("5_selection_knockout.png");
221
223 baseSelection,
224 srcDevice,
225 dst,
226 d.srcRect,
227 d.dstRect,
228 context,
229 shadow,
230 resourcesInterface,
231 env);
232}
QPointF s1
QPointF s2
const QString COMPOSITE_ERASE
QPoint offset() const
psd_glow_source source() const
Definition psd.h:606
qint32 range() const
Definition psd.h:351
bool knocksOut() const
Definition psd.h:326
psd_technique_type technique() const
Definition psd.h:346
qint32 noise() const
Definition psd.h:321
bool invertsSelection() const
Definition psd.h:331
bool edgeHidden() const
Definition psd.h:336
const quint8 * contourLookupTable() const
Definition psd.h:311
bool antiAliased() const
Definition psd.h:316
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
void applyContourCorrection(KisPixelSelectionSP selection, const QRect &applyRect, const quint8 *lookup_table, bool antiAliased, bool edgeHidden)
void adjustRange(KisPixelSelectionSP selection, const QRect &applyRect, const int range)
void findEdge(KisPixelSelectionSP selection, const QRect &applyRect, const bool edgeHidden)
void applyNoise(KisPixelSelectionSP selection, const QRect &applyRect, int noise, const psd_layer_effects_context *context, KisLayerStyleFilterEnvironment *env)
void knockOutSelection(KisPixelSelectionSP selection, KisPixelSelectionSP knockOutSelection, const QRect &srcRect, const QRect &dstRect, const QRect &totalNeedRect, const bool knockOutInverted)
void selectionFromAlphaChannel(KisPaintDeviceSP srcDevice, KisSelectionSP dstSelection, const QRect &srcRect)
static const int FULL_PERCENT_RANGE
void applyGaussianWithTransaction(KisPixelSelectionSP selection, const QRect &applyRect, qreal radius)
void applyFinalSelection(const QString &projectionId, KisSelectionSP baseSelection, KisPaintDeviceSP srcDevice, KisMultipleProjection *dst, const QRect &, const QRect &dstRect, const psd_layer_effects_context *, const psd_layer_effects_shadow_base *config, KisResourcesInterfaceSP resourcesInterface, const KisLayerStyleFilterEnvironment *env)
@ psd_glow_center
Definition psd.h:130
@ psd_technique_precise
Definition psd.h:117
void moveTo(const QPoint &pt) override
KisPixelSelectionSP pixelSelection

References KisLsUtils::adjustRange(), psd_layer_effects_shadow_base::antiAliased(), KisLsUtils::applyContourCorrection(), KisLsUtils::applyFinalSelection(), KisLsUtils::applyGaussianWithTransaction(), KisLsUtils::applyNoise(), KisPainter::bitBlt(), KisLayerStyleFilterEnvironment::cachedSelection(), COMPOSITE_ERASE, psd_layer_effects_shadow_base::contourLookupTable(), KisMultipleProjection::defaultProjectionId(), psd_layer_effects_shadow_base::edgeHidden(), KisLsUtils::findEdge(), KisLsUtils::FULL_PERCENT_RANGE, KisPixelSelection::invert(), psd_layer_effects_shadow_base::invertsSelection(), KIS_ASSERT_RECOVER_RETURN, psd_layer_effects_shadow_base::knocksOut(), KisPixelSelection::moveTo(), ShadowRectsData::NEED_RECT, psd_layer_effects_shadow_base::noise(), KisPaintDevice::offset(), KisSelection::pixelSelection, psd_glow_center, psd_technique_precise, psd_layer_effects_shadow_base::range(), s1, s2, KisPixelSelection::selectedRect(), KisLsUtils::selectionFromAlphaChannel(), KisPainter::setCompositeOpId(), psd_layer_effects_inner_glow::source(), and psd_layer_effects_shadow_base::technique().

◆ changedRect()

QRect KisLsDropShadowFilter::changedRect ( const QRect & rect,
KisPSDLayerStyleSP style,
KisLayerStyleFilterEnvironment * env ) const
overridevirtual

Similar to neededRect: some filters will alter a lot of pixels that are near to each other at the same time. So when you changed a single rectangle in a device, the actual rectangle that will feel the influence of this change might be bigger. Use this function to determine that rect.

Implements KisLayerStyleFilter.

Definition at line 279 of file kis_ls_drop_shadow_filter.cpp.

280{
281 const psd_layer_effects_shadow_base *shadowStruct = getShadowStruct(style);
282 if (!shadowStruct->effectEnabled()) return rect;
283
285 ShadowRectsData d(rect, style->context(), w.config, ShadowRectsData::CHANGE_RECT);
286 return style->context()->keep_original ?
287 d.finalChangeRect() : rect | d.finalChangeRect();
288}
const psd_layer_effects_shadow_base * getShadowStruct(KisPSDLayerStyleSP style) const
bool effectEnabled() const
Definition psd.h:261

References ShadowRectsData::CHANGE_RECT, KisLayerStyleFilterEnvironment::currentLevelOfDetail(), psd_layer_effects_shadow_base::effectEnabled(), and getShadowStruct().

◆ clone()

KisLayerStyleFilter * KisLsDropShadowFilter::clone ( ) const
overridevirtual

Implements KisLayerStyleFilter.

Definition at line 47 of file kis_ls_drop_shadow_filter.cpp.

48{
49 return new KisLsDropShadowFilter(*this);
50}
KisLsDropShadowFilter(Mode mode=DropShadow)

References KisLsDropShadowFilter().

◆ getShadowStruct()

const psd_layer_effects_shadow_base * KisLsDropShadowFilter::getShadowStruct ( KisPSDLayerStyleSP style) const
private

Definition at line 235 of file kis_ls_drop_shadow_filter.cpp.

236{
237 const psd_layer_effects_shadow_base *config = 0;
238
239 if (m_mode == DropShadow) {
240 config = style->dropShadow();
241 } else if (m_mode == InnerShadow) {
242 config = style->innerShadow();
243 } else if (m_mode == OuterGlow) {
244 config = style->outerGlow();
245 } else if (m_mode == InnerGlow) {
246 config = style->innerGlow();
247 }
248
249 return config;
250}

References InnerShadow, m_mode, and OuterGlow.

◆ neededRect()

QRect KisLsDropShadowFilter::neededRect ( const QRect & rect,
KisPSDLayerStyleSP style,
KisLayerStyleFilterEnvironment * env ) const
overridevirtual

Some filters need pixels outside the current processing rect to compute the new value (for instance, convolution filters)

Implements KisLayerStyleFilter.

Definition at line 269 of file kis_ls_drop_shadow_filter.cpp.

270{
271 const psd_layer_effects_shadow_base *shadowStruct = getShadowStruct(style);
272 if (!shadowStruct->effectEnabled()) return rect;
273
275 ShadowRectsData d(rect, style->context(), w.config, ShadowRectsData::NEED_RECT);
276 return rect | d.finalNeedRect();
277}

References KisLayerStyleFilterEnvironment::currentLevelOfDetail(), psd_layer_effects_shadow_base::effectEnabled(), getShadowStruct(), and ShadowRectsData::NEED_RECT.

◆ processDirectly()

void KisLsDropShadowFilter::processDirectly ( KisPaintDeviceSP src,
KisMultipleProjection * dst,
KisLayerStyleKnockoutBlower * blower,
const QRect & applyRect,
KisPSDLayerStyleSP style,
KisLayerStyleFilterEnvironment * env ) const
overridevirtual

Implements KisLayerStyleFilter.

Definition at line 252 of file kis_ls_drop_shadow_filter.cpp.

258{
259 Q_UNUSED(blower);
261
262 const psd_layer_effects_shadow_base *config = getShadowStruct(style);
263 if (!KisLsUtils::checkEffectEnabled(config, dst)) return;
264
266 applyDropShadow(src, dst, applyRect, style->context(), w.config, style->resourcesInterface(), env);
267}
void applyDropShadow(KisPaintDeviceSP srcDevice, KisMultipleProjection *dst, const QRect &applyRect, const psd_layer_effects_context *context, const psd_layer_effects_shadow_base *shadow, KisResourcesInterfaceSP resourcesInterface, KisLayerStyleFilterEnvironment *env) const
bool checkEffectEnabled(const psd_layer_effects_shadow_base *config, KisMultipleProjection *dst)

References applyDropShadow(), KisLsUtils::checkEffectEnabled(), KisLayerStyleFilterEnvironment::currentLevelOfDetail(), getShadowStruct(), and KIS_ASSERT_RECOVER_RETURN.

Member Data Documentation

◆ m_mode

const Mode KisLsDropShadowFilter::m_mode
private

Definition at line 54 of file kis_ls_drop_shadow_filter.h.


The documentation for this class was generated from the following files: