From 4c066a82962a9a0634dcfe0a305de7b2a4cacc5b Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Sat, 16 Jan 2016 20:55:45 +0100 Subject: Added the Colormap component. * The Colormap component is a simple rect with a texture mapped that displays a ColorScale with a fixed number of samples. This number of samples is exported as a member const, which is used on other components (such as VoronoiSplat). * The texture mapping is reflecting the colormap lookup used in VoronoiSplat. * The ColorScale class now has a method for sampling the color scale and outputs the samples to iterator-style objects, providing easy intergration with existing code. --- colorscale.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'colorscale.h') 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 + void sample(int samples, OutputIterator it) const; + protected: float m_min, m_max; QList m_colors; }; +template +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 -- cgit v1.2.3