Krita Source Code Documentation
Loading...
Searching...
No Matches
KoCachedGradient.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2004 Adrian Page <adrian@pagenet.plus.com>
3 * SPDX-FileCopyrightText: 2019 Miguel Lopez <reptillia39@live.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8
10{
11
12public:
16
19 {
20 setGradient(gradient, steps, cs);
21 }
22
23 ~KoCachedGradient() override {}
24
25 KoResourceSP clone() const override {
27 }
28
33 QGradient* toQGradient() const override
34 {
35 return m_subject->toQGradient();
36 }
37
38 void setGradient(const KoAbstractGradientSP gradient, qint32 steps, const KoColorSpace* cs) {
40 m_max = steps - 1;
41 m_colorSpace = cs;
42 m_colors.clear();
43
44 m_black = KoColor(cs);
45
46 KoColor tmpColor(m_colorSpace);
47 for (qint32 i = 0; i < steps; i++) {
48 m_subject->colorAt(tmpColor, qreal(i) / m_max);
49 m_colors << tmpColor;
50 }
51 }
52
53 void setGradient(const KoAbstractGradientSP gradient, qint32 steps) {
54 setGradient(gradient, steps, gradient->colorSpace());
55 }
56
58 const quint8* cachedAt(qreal t) const
59 {
60 qint32 tInt = t * m_max + 0.5;
61 if (m_colors.size() > tInt) {
62 return m_colors[tInt].data();
63 }
64 else {
65 return m_black.data();
66 }
67 }
68
70 void colorAt(KoColor& color, qreal t) const override
71 {
72 m_subject->colorAt(color, t);
73 }
75 {
78 for (qint32 i = 0; i < m_colors.size(); i++) {
79 m_colors[i].convertTo(m_colorSpace);
80 }
81 }
82 }
83 const KoColorSpace* colorSpace() const { return m_colorSpace; }
84
86
87 bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override {
88 return m_subject->loadFromDevice(dev, resourcesInterface);
89 }
90
91 QPair<QString, QString> resourceType() const override {
92 return m_subject->resourceType();
93 }
94
95private:
96
99 qint32 m_max = 0;
102};
KoAbstractGradientSP m_subject
KoResourceSP clone() const override
void colorAt(KoColor &color, qreal t) const override
allow access to the actual color at position 0 <= t <= 1, instead of the cached color
KoCachedGradient(const KoAbstractGradientSP gradient, qint32 steps, const KoColorSpace *cs)
void setGradient(const KoAbstractGradientSP gradient, qint32 steps, const KoColorSpace *cs)
void setColorSpace(const KoColorSpace *colorSpace)
~KoCachedGradient() override
QPair< QString, QString > resourceType() const override
KoAbstractGradientSP gradient()
const KoColorSpace * m_colorSpace
void setGradient(const KoAbstractGradientSP gradient, qint32 steps)
QGradient * toQGradient() const override
QVector< KoColor > m_colors
const quint8 * cachedAt(qreal t) const
gets the color data at position 0 <= t <= 1
bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
const KoColorSpace * colorSpace() const
quint8 * data()
Definition KoColor.h:144
QSharedPointer< KoResource > KoResourceSP
QString filename