xref: /haiku/src/servers/app/drawing/Painter/agg_renderer_scanline_subpix.h (revision c9060eb991e10e477ece52478d6743fc7691c143)
1 /*
2  * Copyright 2008, Andrej Spielmann <andrej.spielmann@seh.ox.ac.uk>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  *
5  * Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
6  *
7  *
8  */
9 
10 #include <Region.h>
11 
12 #include "agg_basics.h"
13 #include "agg_array.h"
14 #include "agg_renderer_base.h"
15 #include "agg_renderer_scanline.h"
16 
17 
18 namespace agg
19 {
20 
21     //============================================render_scanline_subpix_solid
22     template<class Scanline, class BaseRenderer, class ColorT>
23     void render_scanline_subpix_solid(const Scanline& sl,
24                                   BaseRenderer& ren,
25                                   const ColorT& color)
26     {
27         int y = sl.y();
28         unsigned num_spans = sl.num_spans();
29         typename Scanline::const_iterator span = sl.begin();
30 
31         for(;;)
32         {
33             int x = span->x;
34             if(span->len > 0)
35             {
36                 ren.blend_solid_hspan_subpix(x, y, (unsigned)span->len,
37                                       color,
38                                       span->covers);
39             }
40             else
41             {
42                 ren.blend_hline_subpix(x, y, (unsigned)(x - span->len - 1),
43                                 color,
44                                 *(span->covers));
45             }
46             if(--num_spans == 0) break;
47             ++span;
48         }
49     }
50 
51 
52     //==========================================renderer_scanline_subpix_solid
53     template<class BaseRenderer> class renderer_scanline_subpix_solid
54     {
55     public:
56         typedef BaseRenderer base_ren_type;
57         typedef typename base_ren_type::color_type color_type;
58 
59         //--------------------------------------------------------------------
60         renderer_scanline_subpix_solid() : m_ren(0) {}
61         renderer_scanline_subpix_solid(base_ren_type& ren) : m_ren(&ren) {}
62         void attach(base_ren_type& ren)
63         {
64             m_ren = &ren;
65         }
66 
67         //--------------------------------------------------------------------
68         void color(const color_type& c) { m_color = c; }
69         const color_type& color() const { return m_color; }
70 
71         //--------------------------------------------------------------------
72         void prepare() {}
73 
74         //--------------------------------------------------------------------
75         template<class Scanline> void render(const Scanline& sl)
76         {
77             render_scanline_subpix_solid(sl, *m_ren, m_color);
78         }
79 
80     private:
81         base_ren_type* m_ren;
82         color_type m_color;
83     };
84 
85 }
86