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

#include <kis_ls_bevel_emboss_filter.h>

+ Inheritance diagram for KisLsBevelEmbossFilter:

Public Member Functions

QRect changedRect (const QRect &rect, KisPSDLayerStyleSP style, KisLayerStyleFilterEnvironment *env) const override
 
KisLayerStyleFilterclone () const override
 
 KisLsBevelEmbossFilter ()
 
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 applyBevelEmboss (KisPaintDeviceSP srcDevice, KisMultipleProjection *dst, const QRect &applyRect, const psd_layer_effects_bevel_emboss *config, KisResourcesInterfaceSP resourcesInterface, KisLayerStyleFilterEnvironment *env) const
 
 KisLsBevelEmbossFilter (const KisLsBevelEmbossFilter &rhs)
 

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_bevel_emboss_filter.h.

Constructor & Destructor Documentation

◆ KisLsBevelEmbossFilter() [1/2]

KisLsBevelEmbossFilter::KisLsBevelEmbossFilter ( )

Definition at line 44 of file kis_ls_bevel_emboss_filter.cpp.

45 : KisLayerStyleFilter(KoID("lsstroke", i18n("Stroke (style)")))
46{
47}
Definition KoID.h:30
KisLayerStyleFilter(const KoID &id)

◆ KisLsBevelEmbossFilter() [2/2]

KisLsBevelEmbossFilter::KisLsBevelEmbossFilter ( const KisLsBevelEmbossFilter & rhs)
private

Definition at line 54 of file kis_ls_bevel_emboss_filter.cpp.

56{
57}

Member Function Documentation

◆ applyBevelEmboss()

void KisLsBevelEmbossFilter::applyBevelEmboss ( KisPaintDeviceSP srcDevice,
KisMultipleProjection * dst,
const QRect & applyRect,
const psd_layer_effects_bevel_emboss * config,
KisResourcesInterfaceSP resourcesInterface,
KisLayerStyleFilterEnvironment * env ) const
private

Definition at line 261 of file kis_ls_bevel_emboss_filter.cpp.

267{
268 if (applyRect.isEmpty()) return;
269
270 BevelEmbossRectCalculator d(applyRect, config);
271
273 KisSelectionSP baseSelection = s1.selection();
274 KisLsUtils::selectionFromAlphaChannel(srcDevice, baseSelection, d.initialFetchRect);
275
276 KisPixelSelectionSP selection = baseSelection->pixelSelection();
277
278 const int size = config->size();
279
280 int limitingGrowSize = 0;
282 KisPixelSelectionSP bumpmapSelection = s2.selection()->pixelSelection();
283
284 switch (config->style()) {
286 paintBevelSelection(selection, bumpmapSelection, d.applyBevelRect, size, size, false, env);
287 limitingGrowSize = size;
288 break;
290 paintBevelSelection(selection, bumpmapSelection, d.applyBevelRect, size, 0, false, env);
291 limitingGrowSize = 0;
292 break;
293 case psd_bevel_emboss: {
294 const int initialSize = std::ceil(qreal(size) / 2.0);
295 paintBevelSelection(selection, bumpmapSelection, d.applyBevelRect, size, initialSize, false, env);
296 limitingGrowSize = initialSize;
297 break;
298 }
300 const int halfSizeF = std::floor(qreal(size) / 2.0);
301 const int halfSizeC = std::ceil(qreal(size) / 2.0);
302 // TODO: probably not correct!
303 paintBevelSelection(selection, bumpmapSelection, d.applyBevelRect, halfSizeC, halfSizeC, false, env);
304 paintBevelSelection(selection, bumpmapSelection, d.applyBevelRect, halfSizeF, 0, true, env);
305 limitingGrowSize = halfSizeC;
306 break;
307 }
309 warnKrita << "WARNING: Stroke Emboss style is not implemented yet!";
310 return;
311 }
312
314 KisPixelSelectionSP limitingSelection = s3.selection()->pixelSelection();
315 limitingSelection->makeCloneFromRough(selection, selection->selectedRect());
316 {
317 QRect changeRectUnused =
318 KisLsUtils::growSelectionUniform(limitingSelection,
319 limitingGrowSize,
320 d.applyBevelRect);
321 Q_UNUSED(changeRectUnused);
322 }
323
324 //bumpmapSelection->convertToQImage(0, QRect(0,0,300,300)).save("1_selection_xconv.png");
325
326 if (config->textureEnabled()) {
328 KisPixelSelectionSP textureSelection = s4.selection()->pixelSelection();
329
330 KisLsUtils::fillPattern(textureSelection, d.applyTextureRect, env,
331 config->textureScale(),
332 config->texturePattern(resourcesInterface),
333 config->textureHorizontalPhase(),
334 config->textureVerticalPhase(),
335 config->textureAlignWithLayer());
336
337 int contrastadj = 0;
338
339 {
340 using namespace std;
341
342 int tex_depth = config->textureDepth();
343
344 if (tex_depth >= 0.0) {
345 if (tex_depth <= 100.0) {
346 contrastadj = int(qRound((1-(tex_depth/100.0)) * -127));
347 } else {
348 contrastadj = int(qRound(((tex_depth-100.0)/900.0) * 127));
349 }
350 } else {
351 textureSelection->invert();
352 if (tex_depth >= -100.0) {
353 contrastadj = int(qRound((1-(abs(tex_depth)/100.0)) * -127));
354 } else {
355 contrastadj = int(qRound(((abs(tex_depth)-100.0)/900.0) * 127));
356 }
357 }
358 }
359
360 qreal contrast = qBound(-1.0, qreal(contrastadj) / 127.0, 1.0);
361 mapPixelValues(textureSelection, ContrastOp(contrast), d.applyTextureRect);
362
363 {
364 KisPainter gc(bumpmapSelection);
365 gc.setCompositeOpId(COMPOSITE_MULT);
366 gc.bitBlt(d.applyTextureRect.topLeft(), textureSelection, d.applyTextureRect);
367 gc.end();
368 }
369 }
370
371 //bumpmapSelection->convertToQImage(0, QRect(0,0,300,300)).save("15_selection_texture.png");
372
373 if (config->contourEnabled()) {
374 if (config->range() != KisLsUtils::FULL_PERCENT_RANGE) {
375 KisLsUtils::adjustRange(bumpmapSelection, d.applyContourRect, config->range());
376 }
377
378 KisLsUtils::applyContourCorrection(bumpmapSelection,
379 d.applyContourRect,
380 config->contourLookupTable(),
381 config->antiAliased(),
382 true);
383 }
384
385 bumpmap_vals_t bmvals;
386
387 bmvals.azimuth = config->angle();
388 bmvals.elevation = config->altitude();
389 bmvals.depth = config->depth();
390 bmvals.ambient = 0;
391 bmvals.compensate = true;
392 bmvals.invert = config->direction() == psd_direction_down;
393 bmvals.type = LINEAR;
394
395 bumpmap(bumpmapSelection, d.applyBumpmapRect, bmvals);
396
397 //bumpmapSelection->convertToQImage(0, QRect(0,0,300,300)).save("3_selection_bumpmap.png");
398
399 { // TODO: optimize!
400
401 KisLsUtils::applyContourCorrection(bumpmapSelection,
402 d.applyGlossContourRect,
403 config->glossContourLookupTable(),
404 config->glossAntiAliased(),
405 true);
406
407 }
408
409 if (config->soften()) {
410 KisLsUtils::applyGaussianWithTransaction(bumpmapSelection, d.applyGaussianRect, config->soften());
411 }
412
413
414 if (config->textureEnabled() && config->textureInvert()) {
415 bumpmapSelection->invert();
416 }
417
418 selection->clear();
419 mapPixelValues(bumpmapSelection, selection,
420 ShadowsFetchOp(), d.shadowHighlightsFinalRect);
421 selection->applySelection(limitingSelection, SELECTION_INTERSECT);
422
423 //dstDevice->convertToQImage(0, QRect(0,0,300,300)).save("4_dst_before_apply.png");
424 //selection->convertToQImage(0, QRect(0,0,300,300)).save("4_shadows_sel.png");
425
426 {
427 KisPaintDeviceSP dstDevice = dst->getProjection("00_bevel_shadow",
428 config->shadowBlendMode(),
429 config->shadowOpacity(),
430 QBitArray(),
431 srcDevice);
432
433 const KoColor fillColor(config->shadowColor(), dstDevice->colorSpace());
434 const QRect &fillRect = d.shadowHighlightsFinalRect;
435
436 KisCachedPaintDevice::Guard d1(dstDevice, *env->cachedPaintDevice());
437 KisPaintDeviceSP fillDevice = d1.device();
438 fillDevice->setDefaultPixel(fillColor);
439
440 KisPainter::copyAreaOptimized(fillRect.topLeft(), fillDevice, dstDevice, fillRect, baseSelection);
441 }
442
443 selection->clear();
444 mapPixelValues(bumpmapSelection, selection,
445 HighlightsFetchOp(), d.shadowHighlightsFinalRect);
446 selection->applySelection(limitingSelection, SELECTION_INTERSECT);
447
448 //selection->convertToQImage(0, QRect(0,0,300,300)).save("5_highlights_sel.png");
449
450 {
451 KisPaintDeviceSP dstDevice = dst->getProjection("01_bevel_highlight",
452 config->highlightBlendMode(),
453 config->highlightOpacity(),
454 QBitArray(),
455 srcDevice);
456
457 const KoColor fillColor(config->highlightColor(), dstDevice->colorSpace());
458 const QRect &fillRect = d.shadowHighlightsFinalRect;
459
460 KisCachedPaintDevice::Guard d1(dstDevice, *env->cachedPaintDevice());
461 KisPaintDeviceSP fillDevice = d1.device();
462 fillDevice->setDefaultPixel(fillColor);
463
464 KisPainter::copyAreaOptimized(fillRect.topLeft(), fillDevice, dstDevice, fillRect, baseSelection);
465 }
466}
QPointF s3
QPointF s1
QPointF s2
@ SELECTION_INTERSECT
const QString COMPOSITE_MULT
KisPaintDeviceSP getProjection(const QString &id, const QString &compositeOpId, quint8 opacity, const QBitArray &channelFlags, KisPaintDeviceSP prototype)
void setDefaultPixel(const KoColor &defPixel)
void makeCloneFromRough(KisPaintDeviceSP src, const QRect &minimalRect)
const KoColorSpace * colorSpace() const
static void copyAreaOptimized(const QPoint &dstPt, KisPaintDeviceSP src, KisPaintDeviceSP dst, const QRect &originalSrcRect)
qint32 range() const
Definition psd.h:351
qint32 angle() const
Definition psd.h:286
qint32 size() const
Definition psd.h:306
const quint8 * contourLookupTable() const
Definition psd.h:311
bool antiAliased() const
Definition psd.h:316
void bumpmap(KisPixelSelectionSP device, const QRect &selectionRect, const bumpmap_vals_t &bmvals)
#define warnKrita
Definition kis_debug.h:87
void mapPixelValues(KisPixelSelectionSP srcSelection, KisPixelSelectionSP dstSelection, MapOp mapOp, const QRect &applyRect)
void paintBevelSelection(KisPixelSelectionSP srcSelection, KisPixelSelectionSP dstSelection, const QRect &applyRect, int size, int initialSize, bool invert, KisLayerStyleFilterEnvironment *env)
Point abs(const Point &pt)
int size(const Forest< T > &forest)
Definition KisForest.h:1232
void applyContourCorrection(KisPixelSelectionSP selection, const QRect &applyRect, const quint8 *lookup_table, bool antiAliased, bool edgeHidden)
QRect growSelectionUniform(KisPixelSelectionSP selection, int growSize, const QRect &applyRect)
void adjustRange(KisPixelSelectionSP selection, const QRect &applyRect, const int range)
void fillPattern(KisPaintDeviceSP fillDevice, const QRect &applyRect, KisLayerStyleFilterEnvironment *env, int scale, KoPatternSP pattern, int horizontalPhase, int verticalPhase, bool alignWithLayer)
void selectionFromAlphaChannel(KisPaintDeviceSP srcDevice, KisSelectionSP dstSelection, const QRect &srcRect)
static const int FULL_PERCENT_RANGE
void applyGaussianWithTransaction(KisPixelSelectionSP selection, const QRect &applyRect, qreal radius)
@ LINEAR
Definition nugrid.h:26
@ psd_direction_down
Definition psd.h:142
@ psd_bevel_pillow_emboss
Definition psd.h:138
@ psd_bevel_inner_bevel
Definition psd.h:136
@ psd_bevel_stroke_emboss
Definition psd.h:139
@ psd_bevel_outer_bevel
Definition psd.h:135
@ psd_bevel_emboss
Definition psd.h:137
void clear(const QRect &r)
void applySelection(KisPixelSelectionSP selection, SelectionAction action)
KisPixelSelectionSP pixelSelection
QString shadowBlendMode() const
Definition psd.h:821
const quint8 * glossContourLookupTable() const
Definition psd.h:775
qint32 highlightOpacity() const
Definition psd.h:812
psd_bevel_style style() const
Definition psd.h:721
bool contourEnabled() const
Definition psd.h:848
psd_direction direction() const
Definition psd.h:748
bool glossAntiAliased() const
Definition psd.h:785
KoPatternSP texturePattern(KisResourcesInterfaceSP resourcesInterface) const
Definition psd.h:879
int textureVerticalPhase() const
Definition psd.h:950
bool textureInvert() const
Definition psd.h:912
qint32 shadowOpacity() const
Definition psd.h:839
bool textureEnabled() const
Definition psd.h:866
bool textureAlignWithLayer() const
Definition psd.h:921
int textureHorizontalPhase() const
Definition psd.h:941
QString highlightBlendMode() const
Definition psd.h:794
KoColor shadowColor() const
Definition psd.h:830
KoColor highlightColor() const
Definition psd.h:803

References KisLsUtils::adjustRange(), psd_layer_effects_bevel_emboss::altitude(), bumpmap_vals_t::ambient, psd_layer_effects_shadow_base::angle(), psd_layer_effects_shadow_base::antiAliased(), KisLsUtils::applyContourCorrection(), KisLsUtils::applyGaussianWithTransaction(), KisPixelSelection::applySelection(), bumpmap_vals_t::azimuth, KisPainter::bitBlt(), bumpmap(), KisLayerStyleFilterEnvironment::cachedPaintDevice(), KisLayerStyleFilterEnvironment::cachedSelection(), KisPixelSelection::clear(), KisPaintDevice::colorSpace(), bumpmap_vals_t::compensate, COMPOSITE_MULT, psd_layer_effects_bevel_emboss::contourEnabled(), psd_layer_effects_shadow_base::contourLookupTable(), KisPainter::copyAreaOptimized(), bumpmap_vals_t::depth, psd_layer_effects_bevel_emboss::depth(), KisCachedPaintDevice::Guard::device(), psd_layer_effects_bevel_emboss::direction(), bumpmap_vals_t::elevation, KisPainter::end(), KisLsUtils::fillPattern(), KisLsUtils::FULL_PERCENT_RANGE, KisMultipleProjection::getProjection(), psd_layer_effects_bevel_emboss::glossAntiAliased(), psd_layer_effects_bevel_emboss::glossContourLookupTable(), KisLsUtils::growSelectionUniform(), psd_layer_effects_bevel_emboss::highlightBlendMode(), psd_layer_effects_bevel_emboss::highlightColor(), psd_layer_effects_bevel_emboss::highlightOpacity(), KisPixelSelection::invert(), bumpmap_vals_t::invert, LINEAR, KisPaintDevice::makeCloneFromRough(), mapPixelValues(), paintBevelSelection(), KisSelection::pixelSelection, psd_bevel_emboss, psd_bevel_inner_bevel, psd_bevel_outer_bevel, psd_bevel_pillow_emboss, psd_bevel_stroke_emboss, psd_direction_down, psd_layer_effects_shadow_base::range(), s1, s2, s3, KisPixelSelection::selectedRect(), KisCachedSelection::Guard::selection(), SELECTION_INTERSECT, KisLsUtils::selectionFromAlphaChannel(), KisPainter::setCompositeOpId(), KisPaintDevice::setDefaultPixel(), psd_layer_effects_bevel_emboss::shadowBlendMode(), psd_layer_effects_bevel_emboss::shadowColor(), psd_layer_effects_bevel_emboss::shadowOpacity(), psd_layer_effects_shadow_base::size(), psd_layer_effects_bevel_emboss::soften(), psd_layer_effects_bevel_emboss::style(), psd_layer_effects_bevel_emboss::textureAlignWithLayer(), psd_layer_effects_bevel_emboss::textureDepth(), psd_layer_effects_bevel_emboss::textureEnabled(), psd_layer_effects_bevel_emboss::textureHorizontalPhase(), psd_layer_effects_bevel_emboss::textureInvert(), psd_layer_effects_bevel_emboss::texturePattern(), psd_layer_effects_bevel_emboss::textureScale(), psd_layer_effects_bevel_emboss::textureVerticalPhase(), bumpmap_vals_t::type, and warnKrita.

◆ changedRect()

QRect KisLsBevelEmbossFilter::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 497 of file kis_ls_bevel_emboss_filter.cpp.

498{
499 const psd_layer_effects_bevel_emboss *config = style->bevelAndEmboss();
500 if (!config->effectEnabled()) return rect;
501
503
505 return d.totalChangeRect(rect, w.config);
506}
bool effectEnabled() const
Definition psd.h:261

References KisLayerStyleFilterEnvironment::currentLevelOfDetail(), and psd_layer_effects_shadow_base::effectEnabled().

◆ clone()

KisLayerStyleFilter * KisLsBevelEmbossFilter::clone ( ) const
overridevirtual

Implements KisLayerStyleFilter.

Definition at line 49 of file kis_ls_bevel_emboss_filter.cpp.

50{
51 return new KisLsBevelEmbossFilter(*this);
52}

References KisLsBevelEmbossFilter().

◆ neededRect()

QRect KisLsBevelEmbossFilter::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 486 of file kis_ls_bevel_emboss_filter.cpp.

487{
488 const psd_layer_effects_bevel_emboss *config = style->bevelAndEmboss();
489 if (!config->effectEnabled()) return rect;
490
492
494 return d.totalNeedRect(rect, w.config);
495}

References KisLayerStyleFilterEnvironment::currentLevelOfDetail(), and psd_layer_effects_shadow_base::effectEnabled().

◆ processDirectly()

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

Implements KisLayerStyleFilter.

Definition at line 468 of file kis_ls_bevel_emboss_filter.cpp.

474{
475 Q_UNUSED(env);
476 Q_UNUSED(blower);
478
479 const psd_layer_effects_bevel_emboss *config = style->bevelAndEmboss();
480 if (!KisLsUtils::checkEffectEnabled(config, dst)) return;
481
483 applyBevelEmboss(src, dst, applyRect, w.config, style->resourcesInterface(), env);
484}
void applyBevelEmboss(KisPaintDeviceSP srcDevice, KisMultipleProjection *dst, const QRect &applyRect, const psd_layer_effects_bevel_emboss *config, KisResourcesInterfaceSP resourcesInterface, KisLayerStyleFilterEnvironment *env) const
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
bool checkEffectEnabled(const psd_layer_effects_shadow_base *config, KisMultipleProjection *dst)

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


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