16 #ifndef AGG_GRADIENT_LUT_INCLUDED 17 #define AGG_GRADIENT_LUT_INCLUDED 19 #include "agg_array.h" 20 #include "agg_dda_line.h" 21 #include "agg_color_rgba.h" 22 #include "agg_color_gray.h" 31 typedef ColorT color_type;
47 color_type color()
const 49 return m_c1.gradient(m_c2,
double(m_count) / m_len);
80 color_type color()
const 82 return color_type(r.y(), g.y(), b.y(), a.y());
108 color_type color()
const 110 return color_type(v.y(), a.y());
118 template<
class ColorInterpolator,
122 typedef ColorInterpolator interpolator_type;
123 typedef typename interpolator_type::color_type color_type;
124 enum { color_lut_size = ColorLutSize };
139 void add_color(
double offset,
const color_type& color);
146 static unsigned size()
148 return color_lut_size;
150 const color_type& operator [] (
unsigned i)
const 152 return m_color_lut[i];
163 color_point(
double off,
const color_type& c) :
164 offset(off), color(c)
166 if(offset < 0.0) offset = 0.0;
167 if(offset > 1.0) offset = 1.0;
173 static bool offset_less(
const color_point& a,
const color_point& b)
175 return a.offset < b.offset;
177 static bool offset_equal(
const color_point& a,
const color_point& b)
179 return a.offset == b.offset;
183 color_profile_type m_color_profile;
184 color_lut_type m_color_lut;
190 template<
class T,
unsigned S>
193 m_color_profile.remove_all();
197 template<
class T,
unsigned S>
200 m_color_profile.add(color_point(offset, color));
204 template<
class T,
unsigned S>
207 quick_sort(m_color_profile, offset_less);
208 m_color_profile.cut_at(remove_duplicates(m_color_profile, offset_equal));
209 if(m_color_profile.size() >= 2)
212 unsigned start = uround(m_color_profile[0].offset * color_lut_size);
214 color_type c = m_color_profile[0].color;
215 for(i = 0; i < start; i++)
219 for(i = 1; i < m_color_profile.size(); i++)
221 end = uround(m_color_profile[i].offset * color_lut_size);
222 interpolator_type ci(m_color_profile[i-1].color,
223 m_color_profile[i ].color,
227 m_color_lut[start] = ci.color();
232 c = m_color_profile.last().color;
233 for(; end < m_color_lut.size(); end++)
235 m_color_lut[end] = c;