24 #ifndef AGG_SPAN_GOURAUD_RGBA_INCLUDED 25 #define AGG_SPAN_GOURAUD_RGBA_INCLUDED 28 #include "agg_basics.h" 29 #include "agg_color_rgba.h" 30 #include "agg_dda_line.h" 31 #include "agg_span_gouraud.h" 40 typedef ColorT color_type;
41 typedef typename ColorT::value_type value_type;
47 subpixel_scale = 1 << subpixel_shift
54 void init(
const coord_type& c1,
const coord_type& c2)
59 double dy = c2.y - c1.y;
60 m_1dy = (dy < 1e-5) ? 1e5 : 1.0 / dy;
65 m_dr = c2.color.r - m_r1;
66 m_dg = c2.color.g - m_g1;
67 m_db = c2.color.b - m_b1;
68 m_da = c2.color.a - m_a1;
73 double k = (y - m_y1) * m_1dy;
76 m_r = m_r1 + iround(m_dr * k);
77 m_g = m_g1 + iround(m_dg * k);
78 m_b = m_b1 + iround(m_db * k);
79 m_a = m_a1 + iround(m_da * k);
80 m_x = iround((m_x1 + m_dx * k) * subpixel_scale);
107 const color_type& c2,
108 const color_type& c3,
109 double x1,
double y1,
110 double x2,
double y2,
111 double x3,
double y3,
113 base_type(c1, c2, c3, x1, y1, x2, y2, x3, y3, d)
120 base_type::arrange_vertices(coord);
122 m_y2 = int(coord[1].y);
124 m_swap = cross_product(coord[0].x, coord[0].y,
125 coord[2].x, coord[2].y,
126 coord[1].x, coord[1].y) < 0.0;
128 m_rgba1.init(coord[0], coord[2]);
129 m_rgba2.init(coord[0], coord[1]);
130 m_rgba3.init(coord[1], coord[2]);
134 void generate(color_type* span,
int x,
int y,
unsigned len)
137 const rgba_calc* pc1 = &m_rgba1;
138 const rgba_calc* pc2 = &m_rgba2;
144 m_rgba2.calc(y + m_rgba2.m_1dy);
149 m_rgba3.calc(y - m_rgba3.m_1dy);
159 const rgba_calc* t = pc2;
167 int nlen = std::abs(pc2->m_x - pc1->m_x);
168 if(nlen <= 0) nlen = 1;
180 int start = pc1->m_x - (x << subpixel_shift);
188 enum lim_e { lim = color_type::base_mask };
196 while(len && start > 0)
202 if(vr < 0) { vr = 0; }
if(vr > lim) { vr = lim; }
203 if(vg < 0) { vg = 0; }
if(vg > lim) { vg = lim; }
204 if(vb < 0) { vb = 0; }
if(vb > lim) { vb = lim; }
205 if(va < 0) { va = 0; }
if(va > lim) { va = lim; }
206 span->r = (value_type)vr;
207 span->g = (value_type)vg;
208 span->b = (value_type)vb;
209 span->a = (value_type)va;
214 nlen -= subpixel_scale;
215 start -= subpixel_scale;
225 while(len && nlen > 0)
227 span->r = (value_type)r.y();
228 span->g = (value_type)g.y();
229 span->b = (value_type)b.y();
230 span->a = (value_type)a.y();
235 nlen -= subpixel_scale;
249 if(vr < 0) { vr = 0; }
if(vr > lim) { vr = lim; }
250 if(vg < 0) { vg = 0; }
if(vg > lim) { vg = lim; }
251 if(vb < 0) { vb = 0; }
if(vb > lim) { vb = lim; }
252 if(va < 0) { va = 0; }
if(va > lim) { va = lim; }
253 span->r = (value_type)vr;
254 span->g = (value_type)vg;
255 span->b = (value_type)vb;
256 span->a = (value_type)va;