aboutsummaryrefslogtreecommitdiff
path: root/colorscale.h
diff options
context:
space:
mode:
authorSamuel Fadel <samuel@nihil.ws>2023-05-23 11:22:33 +0200
committerSamuel Fadel <samuel@nihil.ws>2023-05-23 11:22:33 +0200
commit0f34fd437efb936ef29ac91186321aa7251fbfb1 (patch)
tree271e994828f4bb19c35b2630f2705cb64b8d4552 /colorscale.h
parentbedf6936885694688ddb8bd3452f6bd68ef8d29c (diff)
Massive changes in initial port away from Qt.
Diffstat (limited to 'colorscale.h')
-rw-r--r--colorscale.h41
1 files changed, 31 insertions, 10 deletions
diff --git a/colorscale.h b/colorscale.h
index ffc3439..c50deb0 100644
--- a/colorscale.h
+++ b/colorscale.h
@@ -2,20 +2,41 @@
#define COLORSCALE_H
#include <initializer_list>
+#include <vector>
-#include <QColor>
-#include <QList>
+class Color
+{
+public:
+ Color();
+ Color(int r, int g, int b);
+ Color(int r, int g, int b, int a);
+ Color(float r, float g, float b);
+ Color(float r, float g, float b, float a);
+
+ void getRgbF(float *r, float *g, float *b) const;
+ void getRgbF(float *r, float *g, float *b, float *a) const;
+
+ void setRgb(int r, int g, int b);
+ void setRgb(int r, int g, int b, int a);
+
+ void setRgbF(float r, float g, float b);
+ void setRgbF(float r, float g, float b, float a);
+
+ float r, g, b, a;
+};
+
+using QColor = Color;
class ColorScale
{
public:
- ColorScale(const QColor &firstColor, const QColor &lastColor);
- ColorScale(std::initializer_list<QColor> colors);
- ColorScale(const QList<QColor> &colors);
+ ColorScale(const Color &firstColor, const Color &lastColor);
+ ColorScale(std::initializer_list<Color> colors);
+ ColorScale(const std::vector<Color> &colors);
virtual ~ColorScale();
- QColor operator ()(float t) const { return color(t); }
- virtual QColor color(float t) const;
+ Color operator ()(float t) const { return color(t); }
+ virtual Color color(float t) const;
void setExtents(float min, float max);
float min() const { return m_min; }
@@ -25,11 +46,11 @@ public:
template<typename OutputIterator>
void sample(int samples, OutputIterator it) const;
- static QColor lerp(const QColor &c1, const QColor &c2, float _t);
+ static Color lerp(const Color &c1, const Color &c2, float _t);
protected:
float m_min, m_max;
- QList<QColor> m_colors;
+ std::vector<Color> m_colors;
};
template<typename OutputIterator>
@@ -40,7 +61,7 @@ void ColorScale::sample(int samples, OutputIterator it) const
}
float step = (max() - min()) / samples;
- qreal r, g, b;
+ float r, g, b;
for (float t = min(); samples-- > 0; t += step) {
color(t).getRgbF(&r, &g, &b);
*it++ = r;