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

#include <KisGradientMapFilterNearestCachedGradient.h>

Public Member Functions

const quint8 * cachedAt (qreal t) const
 gets the color data at position 0 <= t <= 1
 
 KisGradientMapFilterNearestCachedGradient (const KoAbstractGradientSP gradient, qint32 steps, const KoColorSpace *cs)
 

Private Attributes

const KoColor m_black
 
QVector< KoColorm_colors
 
const qint32 m_max
 

Detailed Description

Definition at line 19 of file KisGradientMapFilterNearestCachedGradient.h.

Constructor & Destructor Documentation

◆ KisGradientMapFilterNearestCachedGradient()

KisGradientMapFilterNearestCachedGradient::KisGradientMapFilterNearestCachedGradient ( const KoAbstractGradientSP gradient,
qint32 steps,
const KoColorSpace * cs )

Definition at line 17 of file KisGradientMapFilterNearestCachedGradient.cpp.

18 : m_max(steps - 1)
19 , m_black(KoColor(cs))
20{
21 if (dynamic_cast<KoStopGradient*>(gradient.data())) {
22 KoStopGradient *stopGradient = static_cast<KoStopGradient*>(gradient.data());
23 for (qint32 i = 0; i < steps; i++) {
24 qreal t = static_cast<qreal>(i) / m_max;
25 KoGradientStop leftStop, rightStop;
26 if (!stopGradient->stopsAt(leftStop, rightStop, t)) {
28 } else {
29 if (std::abs(t - leftStop.position) < std::abs(t - rightStop.position)) {
30 m_colors << leftStop.color.convertedTo(cs);
31 } else {
32 m_colors << rightStop.color.convertedTo(cs);
33 }
34 }
35 }
36 } else if (dynamic_cast<KoSegmentGradient*>(gradient.data())) {
37 KoSegmentGradient *segmentGradient = static_cast<KoSegmentGradient*>(gradient.data());
38 for (qint32 i = 0; i < steps; i++) {
39 qreal t = static_cast<qreal>(i) / m_max;
40 KoGradientSegment *segment = segmentGradient->segmentAt(t);
41 if (!segment) {
43 } else {
44 if (std::abs(t - segment->startOffset()) < std::abs(t - segment->endOffset())) {
45 m_colors << segment->startColor().convertedTo(cs);
46 } else {
47 m_colors << segment->endColor().convertedTo(cs);
48 }
49 }
50 }
51 }
52
53}
KoColor convertedTo(const KoColorSpace *cs, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const
Definition KoColor.cpp:163
Write API docs here.
const KoColor & startColor() const
const KoColor & endColor() const
KoGradientSegment * segmentAt(qreal t) const
bool stopsAt(KoGradientStop &leftStop, KoGradientStop &rightStop, qreal t) const
Find stops surrounding position, returns false if position outside gradient.

References KoGradientStop::color, KoColor::convertedTo(), KoGradientSegment::endColor(), KoGradientSegment::endOffset(), m_black, m_colors, m_max, KoGradientStop::position, KoSegmentGradient::segmentAt(), KoGradientSegment::startColor(), KoGradientSegment::startOffset(), and KoStopGradient::stopsAt().

Member Function Documentation

◆ cachedAt()

const quint8 * KisGradientMapFilterNearestCachedGradient::cachedAt ( qreal t) const

gets the color data at position 0 <= t <= 1

Definition at line 55 of file KisGradientMapFilterNearestCachedGradient.cpp.

56{
57 qint32 tInt = t * m_max + 0.5;
58 if (m_colors.size() > tInt) {
59 return m_colors[tInt].data();
60 } else {
61 return m_black.data();
62 }
63}
quint8 * data()
Definition KoColor.h:144

References KoColor::data(), m_black, m_colors, and m_max.

Member Data Documentation

◆ m_black

const KoColor KisGradientMapFilterNearestCachedGradient::m_black
private

Definition at line 30 of file KisGradientMapFilterNearestCachedGradient.h.

◆ m_colors

QVector<KoColor> KisGradientMapFilterNearestCachedGradient::m_colors
private

Definition at line 29 of file KisGradientMapFilterNearestCachedGradient.h.

◆ m_max

const qint32 KisGradientMapFilterNearestCachedGradient::m_max
private

Definition at line 28 of file KisGradientMapFilterNearestCachedGradient.h.


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