aboutsummaryrefslogtreecommitdiff
path: root/colorscale.h
diff options
context:
space:
mode:
Diffstat (limited to 'colorscale.h')
-rw-r--r--colorscale.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/colorscale.h b/colorscale.h
index af74b5c..90671eb 100644
--- a/colorscale.h
+++ b/colorscale.h
@@ -20,9 +20,32 @@ public:
float min() const { return m_min; }
float max() const { return m_max; }
+ template<typename OutputIterator>
+ void sample(int samples, OutputIterator it) const;
+
protected:
float m_min, m_max;
QList<QColor> m_colors;
};
+template<typename OutputIterator>
+void ColorScale::sample(int samples, OutputIterator it) const
+{
+ if (samples < 1) {
+ return;
+ }
+
+ float t = min();
+ float step = (max() - min()) / samples;
+ qreal r, g, b;
+ for (unsigned i = 0; i < 3*samples; i += 3) {
+ color(t).getRgbF(&r, &g, &b);
+ *it = r; it++;
+ *it = g; it++;
+ *it = b; it++;
+
+ t += step;
+ }
+}
+
#endif // COLORSCALE_H