update dev300-m58
[ooovba.git] / agg / inc / agg_renderer_scanline.h
blobef6629e8f3fafbbe4b0ff9574e6977f1ddd15e68
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 #ifndef AGG_RENDERER_SCANLINE_INCLUDED
17 #define AGG_RENDERER_SCANLINE_INCLUDED
19 #include "agg_basics.h"
20 #include "agg_renderer_base.h"
21 #include "agg_render_scanlines.h"
23 namespace agg
26 //====================================================renderer_scanline_aa
27 template<class BaseRenderer, class SpanGenerator> class renderer_scanline_aa
29 public:
30 typedef BaseRenderer base_ren_type;
32 //--------------------------------------------------------------------
33 renderer_scanline_aa(base_ren_type& ren, SpanGenerator& span_gen) :
34 m_ren(&ren),
35 m_span_gen(&span_gen)
39 //--------------------------------------------------------------------
40 void prepare(unsigned max_span_len)
42 m_span_gen->prepare(max_span_len);
45 //--------------------------------------------------------------------
46 template<class Scanline> void render(const Scanline& sl)
48 int y = sl.y();
49 m_ren->first_clip_box();
52 int xmin = m_ren->xmin();
53 int xmax = m_ren->xmax();
55 if(y >= m_ren->ymin() && y <= m_ren->ymax())
57 unsigned num_spans = sl.num_spans();
58 typename Scanline::const_iterator span = sl.begin();
61 int x = span->x;
62 int len = span->len;
63 bool solid = false;
64 const typename Scanline::cover_type* covers = span->covers;
66 if(len < 0)
68 solid = true;
69 len = -len;
72 if(x < xmin)
74 len -= xmin - x;
75 if(!solid)
77 covers += xmin - x;
79 x = xmin;
82 if(len > 0)
84 if(x + len > xmax)
86 len = xmax - x + 1;
88 if(len > 0)
90 m_ren->blend_color_hspan_no_clip(
91 x, y, len,
92 m_span_gen->generate(x, y, len),
93 solid ? 0 : covers,
94 *covers);
97 ++span;
99 while(--num_spans);
102 while(m_ren->next_clip_box());
105 private:
106 base_ren_type* m_ren;
107 SpanGenerator* m_span_gen;
113 //==============================================renderer_scanline_aa_opaque
114 template<class BaseRenderer, class SpanGenerator> class renderer_scanline_aa_opaque
116 public:
117 typedef BaseRenderer base_ren_type;
119 //--------------------------------------------------------------------
120 renderer_scanline_aa_opaque(base_ren_type& ren, SpanGenerator& span_gen) :
121 m_ren(&ren),
122 m_span_gen(&span_gen)
126 //--------------------------------------------------------------------
127 void prepare(unsigned max_span_len)
129 m_span_gen->prepare(max_span_len);
132 //--------------------------------------------------------------------
133 template<class Scanline> void render(const Scanline& sl)
135 int y = sl.y();
136 m_ren->first_clip_box();
139 int xmin = m_ren->xmin();
140 int xmax = m_ren->xmax();
142 if(y >= m_ren->ymin() && y <= m_ren->ymax())
144 unsigned num_spans = sl.num_spans();
145 typename Scanline::const_iterator span = sl.begin();
148 int x = span->x;
149 int len = span->len;
150 bool solid = false;
151 const typename Scanline::cover_type* covers = span->covers;
153 if(len < 0)
155 solid = true;
156 len = -len;
159 if(x < xmin)
161 len -= xmin - x;
162 if(!solid)
164 covers += xmin - x;
166 x = xmin;
169 if(len > 0)
171 if(x + len > xmax)
173 len = xmax - x + 1;
175 if(len > 0)
177 m_ren->blend_opaque_color_hspan_no_clip(
178 x, y, len,
179 m_span_gen->generate(x, y, len),
180 solid ? 0 : covers,
181 *covers);
184 ++span;
186 while(--num_spans);
189 while(m_ren->next_clip_box());
192 private:
193 base_ren_type* m_ren;
194 SpanGenerator* m_span_gen;
199 //==============================================renderer_scanline_aa_solid
200 template<class BaseRenderer> class renderer_scanline_aa_solid
202 public:
203 typedef BaseRenderer base_ren_type;
204 typedef typename base_ren_type::color_type color_type;
206 //--------------------------------------------------------------------
207 renderer_scanline_aa_solid(base_ren_type& ren) :
208 m_ren(&ren)
212 //--------------------------------------------------------------------
213 void color(const color_type& c) { m_color = c; }
214 const color_type& color() const { return m_color; }
216 //--------------------------------------------------------------------
217 void prepare(unsigned) {}
219 //--------------------------------------------------------------------
220 template<class Scanline> void render(const Scanline& sl)
222 int y = sl.y();
223 unsigned num_spans = sl.num_spans();
224 typename Scanline::const_iterator span = sl.begin();
228 int x = span->x;
229 if(span->len > 0)
231 m_ren->blend_solid_hspan(x, y, (unsigned)span->len,
232 m_color,
233 span->covers);
235 else
237 m_ren->blend_hline(x, y, (unsigned)(x - span->len - 1),
238 m_color,
239 *(span->covers));
241 ++span;
243 while(--num_spans);
246 private:
247 base_ren_type* m_ren;
248 color_type m_color;
257 //===================================================renderer_scanline_bin
258 template<class BaseRenderer, class SpanGenerator> class renderer_scanline_bin
260 public:
261 typedef BaseRenderer base_ren_type;
263 //--------------------------------------------------------------------
264 renderer_scanline_bin(base_ren_type& ren, SpanGenerator& span_gen) :
265 m_ren(&ren),
266 m_span_gen(&span_gen)
270 //--------------------------------------------------------------------
271 void prepare(unsigned max_span_len)
273 m_span_gen->prepare(max_span_len);
276 //--------------------------------------------------------------------
277 template<class Scanline> void render(const Scanline& sl)
279 int y = sl.y();
280 m_ren->first_clip_box();
283 int xmin = m_ren->xmin();
284 int xmax = m_ren->xmax();
286 if(y >= m_ren->ymin() && y <= m_ren->ymax())
288 unsigned num_spans = sl.num_spans();
289 typename Scanline::const_iterator span = sl.begin();
292 int x = span->x;
293 int len = span->len;
295 if(len < 0) len = -len;
296 if(x < xmin)
298 len -= xmin - x;
299 x = xmin;
301 if(len > 0)
303 if(x + len > xmax)
305 len = xmax - x + 1;
307 if(len > 0)
309 m_ren->blend_color_hspan_no_clip(
310 x, y, len,
311 m_span_gen->generate(x, y, len),
315 ++span;
317 while(--num_spans);
320 while(m_ren->next_clip_box());
323 private:
324 base_ren_type* m_ren;
325 SpanGenerator* m_span_gen;
330 //===============================================renderer_scanline_bin_opaque
331 template<class BaseRenderer, class SpanGenerator> class renderer_scanline_bin_opaque
333 public:
334 typedef BaseRenderer base_ren_type;
336 //--------------------------------------------------------------------
337 renderer_scanline_bin_opaque(base_ren_type& ren, SpanGenerator& span_gen) :
338 m_ren(&ren),
339 m_span_gen(&span_gen)
343 //--------------------------------------------------------------------
344 void prepare(unsigned max_span_len)
346 m_span_gen->prepare(max_span_len);
349 //--------------------------------------------------------------------
350 template<class Scanline> void render(const Scanline& sl)
352 int y = sl.y();
353 m_ren->first_clip_box();
356 int xmin = m_ren->xmin();
357 int xmax = m_ren->xmax();
359 if(y >= m_ren->ymin() && y <= m_ren->ymax())
361 unsigned num_spans = sl.num_spans();
362 typename Scanline::const_iterator span = sl.begin();
365 int x = span->x;
366 int len = span->len;
368 if(len < 0) len = -len;
369 if(x < xmin)
371 len -= xmin - x;
372 x = xmin;
374 if(len > 0)
376 if(x + len > xmax)
378 len = xmax - x + 1;
380 if(len > 0)
382 m_ren->blend_opaque_color_hspan_no_clip(
383 x, y, len,
384 m_span_gen->generate(x, y, len),
388 ++span;
390 while(--num_spans);
393 while(m_ren->next_clip_box());
396 private:
397 base_ren_type* m_ren;
398 SpanGenerator* m_span_gen;
404 //=============================================renderer_scanline_bin_solid
405 template<class BaseRenderer> class renderer_scanline_bin_solid
407 public:
408 typedef BaseRenderer base_ren_type;
409 typedef typename base_ren_type::color_type color_type;
411 //--------------------------------------------------------------------
412 renderer_scanline_bin_solid(base_ren_type& ren) :
413 m_ren(&ren)
417 //--------------------------------------------------------------------
418 void color(const color_type& c) { m_color = c; }
419 const color_type& color() const { return m_color; }
421 //--------------------------------------------------------------------
422 void prepare(unsigned) {}
424 //--------------------------------------------------------------------
425 template<class Scanline> void render(const Scanline& sl)
427 unsigned num_spans = sl.num_spans();
428 typename Scanline::const_iterator span = sl.begin();
431 m_ren->blend_hline(span->x,
432 sl.y(),
433 span->x - 1 + ((span->len < 0) ?
434 -span->len :
435 span->len),
436 m_color,
437 cover_full);
438 ++span;
440 while(--num_spans);
443 private:
444 base_ren_type* m_ren;
445 color_type m_color;
450 #endif