16 #ifndef AGG_SPAN_GRADIENT_ALPHA_INCLUDED 17 #define AGG_SPAN_GRADIENT_ALPHA_INCLUDED 19 #include "agg_span_gradient.h" 24 template<
class ColorT,
31 typedef Interpolator interpolator_type;
32 typedef ColorT color_type;
33 typedef typename color_type::value_type alpha_type;
35 enum downscale_shift_e
37 downscale_shift = interpolator_type::subpixel_shift - gradient_subpixel_shift
46 GradientF& gradient_function,
47 AlphaF& alpha_function,
48 double d1,
double d2) :
49 m_interpolator(&inter),
50 m_gradient_function(&gradient_function),
51 m_alpha_function(&alpha_function),
52 m_d1(iround(d1 * gradient_subpixel_scale)),
53 m_d2(iround(d2 * gradient_subpixel_scale))
57 interpolator_type& interpolator() {
return *m_interpolator; }
58 const GradientF& gradient_function()
const {
return *m_gradient_function; }
59 const AlphaF& alpha_function()
const {
return *m_alpha_function; }
60 double d1()
const {
return double(m_d1) / gradient_subpixel_scale; }
61 double d2()
const {
return double(m_d2) / gradient_subpixel_scale; }
64 void interpolator(interpolator_type& i) { m_interpolator = &i; }
65 void gradient_function(
const GradientF& gf) { m_gradient_function = &gf; }
66 void alpha_function(
const AlphaF& af) { m_alpha_function = ⁡ }
67 void d1(
double v) { m_d1 = iround(v * gradient_subpixel_scale); }
68 void d2(
double v) { m_d2 = iround(v * gradient_subpixel_scale); }
74 void generate(color_type* span,
int x,
int y,
unsigned len)
78 m_interpolator->begin(x+0.5, y+0.5, len);
81 m_interpolator->coordinates(&x, &y);
82 int d = m_gradient_function->calculate(x >> downscale_shift,
83 y >> downscale_shift, m_d2);
84 d = ((d - m_d1) * (
int)m_alpha_function->size()) / dd;
86 if(d >= (
int)m_alpha_function->size()) d = m_alpha_function->size() - 1;
87 span->a = (*m_alpha_function)[d];
95 interpolator_type* m_interpolator;
96 GradientF* m_gradient_function;
97 AlphaF* m_alpha_function;
106 typedef typename ColorT::value_type alpha_type;
107 alpha_type operator [] (alpha_type x)
const {
return x; }
113 typedef int8u alpha_type;
114 alpha_type operator [] (alpha_type x)
const {
return x; }
120 typedef int8u alpha_type;
121 alpha_type operator [] (alpha_type x)
const {
return 255-x; }