update dev300-m57
[ooovba.git] / agg / inc / agg_pixfmt_amask_adaptor.h
blobb28f8eb97592dc50a11810938f417218a49ddd81
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_PIXFMT_AMASK_ADAPTOR_INCLUDED
17 #define AGG_PIXFMT_AMASK_ADAPTOR_INCLUDED
20 #include <string.h>
21 #include "agg_rendering_buffer.h"
24 namespace agg
26 //==================================================pixfmt_amask_adaptor
27 template<class PixFmt, class AlphaMask> class pixfmt_amask_adaptor
29 public:
30 typedef PixFmt pixfmt_type;
31 typedef typename pixfmt_type::color_type color_type;
32 typedef AlphaMask amask_type;
33 typedef typename amask_type::cover_type cover_type;
35 private:
36 enum { span_extra_tail = 256 };
38 void realloc_span(unsigned len)
40 if(len > m_max_len)
42 delete [] m_span;
43 m_span = new cover_type[m_max_len = len + span_extra_tail];
47 void init_span(unsigned len)
49 realloc_span(len);
51 // ATTN! May work incorrectly if cover_type is more that one byte
52 memset(m_span, amask_type::cover_full, len * sizeof(cover_type));
55 void init_span(unsigned len, const cover_type* covers)
57 realloc_span(len);
58 memcpy(m_span, covers, len * sizeof(cover_type));
62 public:
63 ~pixfmt_amask_adaptor() { delete [] m_span; }
65 pixfmt_amask_adaptor(pixfmt_type& pixf, const amask_type& mask) :
66 m_pixf(&pixf), m_mask(&mask), m_span(0), m_max_len(0)
69 void attach_pixfmt(pixfmt_type& pixf) { m_pixf = &pixf; }
70 void attach_alpha_mask(const amask_type& mask) { m_mask = &mask; }
72 //--------------------------------------------------------------------
73 unsigned width() const { return m_pixf->width(); }
74 unsigned height() const { return m_pixf->height(); }
76 //--------------------------------------------------------------------
77 color_type pixel(int x, int y)
79 return m_pixf->pixel(x, y);
82 //--------------------------------------------------------------------
83 void copy_pixel(int x, int y, const color_type& c)
85 m_pixf->blend_pixel(x, y, c, m_mask->pixel(x, y));
88 //--------------------------------------------------------------------
89 void blend_pixel(int x, int y, const color_type& c, cover_type cover)
91 m_pixf->blend_pixel(x, y, c, m_mask->combine_pixel(x, y, cover));
94 //--------------------------------------------------------------------
95 void copy_hline(int x, int y,
96 unsigned len,
97 const color_type& c)
99 realloc_span(len);
100 m_mask->fill_hspan(x, y, m_span, len);
101 m_pixf->blend_solid_hspan(x, y, len, c, m_span);
104 //--------------------------------------------------------------------
105 void blend_hline(int x, int y,
106 unsigned len,
107 const color_type& c,
108 cover_type cover)
110 init_span(len);
111 m_mask->combine_hspan(x, y, m_span, len);
112 m_pixf->blend_solid_hspan(x, y, len, c, m_span);
115 //--------------------------------------------------------------------
116 void copy_vline(int x, int y,
117 unsigned len,
118 const color_type& c)
120 realloc_span(len);
121 m_mask->fill_vspan(x, y, m_span, len);
122 m_pixf->blend_solid_vspan(x, y, len, c, m_span);
125 //--------------------------------------------------------------------
126 void blend_vline(int x, int y,
127 unsigned len,
128 const color_type& c,
129 cover_type cover)
131 init_span(len);
132 m_mask->combine_vspan(x, y, m_span, len);
133 m_pixf->blend_solid_vspan(x, y, len, c, m_span);
136 //--------------------------------------------------------------------
137 void copy_from(const rendering_buffer& from,
138 int xdst, int ydst,
139 int xsrc, int ysrc,
140 unsigned len)
142 m_pixf->copy_from(from, xdst, ydst, xsrc, ysrc, len);
146 //--------------------------------------------------------------------
147 void blend_solid_hspan(int x, int y,
148 unsigned len,
149 const color_type& c,
150 const cover_type* covers)
152 init_span(len, covers);
153 m_mask->combine_hspan(x, y, m_span, len);
154 m_pixf->blend_solid_hspan(x, y, len, c, m_span);
158 //--------------------------------------------------------------------
159 void blend_solid_vspan(int x, int y,
160 unsigned len,
161 const color_type& c,
162 const cover_type* covers)
164 init_span(len, covers);
165 m_mask->combine_vspan(x, y, m_span, len);
166 m_pixf->blend_solid_vspan(x, y, len, c, m_span);
170 //--------------------------------------------------------------------
171 void blend_color_hspan(int x, int y,
172 unsigned len,
173 const color_type* colors,
174 const cover_type* covers,
175 cover_type cover = cover_full)
177 if(covers)
179 init_span(len, covers);
180 m_mask->combine_hspan(x, y, m_span, len);
182 else
184 realloc_span(len);
185 m_mask->fill_hspan(x, y, m_span, len);
187 m_pixf->blend_color_hspan(x, y, len, colors, m_span, cover);
191 //--------------------------------------------------------------------
192 void blend_color_vspan(int x, int y,
193 unsigned len,
194 const color_type* colors,
195 const cover_type* covers,
196 cover_type cover = cover_full)
198 if(covers)
200 init_span(len, covers);
201 m_mask->combine_vspan(x, y, m_span, len);
203 else
205 realloc_span(len);
206 m_mask->fill_vspan(x, y, m_span, len);
208 m_pixf->blend_color_vspan(x, y, len, colors, m_span, cover);
212 //--------------------------------------------------------------------
213 void blend_opaque_color_hspan(int x, int y,
214 unsigned len,
215 const color_type* colors,
216 const cover_type* covers,
217 cover_type cover = cover_full)
219 if(covers)
221 init_span(len, covers);
222 m_mask->combine_hspan(x, y, m_span, len);
224 else
226 realloc_span(len);
227 m_mask->fill_hspan(x, y, m_span, len);
229 m_pixf->blend_opaque_color_hspan(x, y, len, colors, m_span, cover);
233 //--------------------------------------------------------------------
234 void blend_opaque_color_vspan(int x, int y,
235 unsigned len,
236 const color_type* colors,
237 const cover_type* covers,
238 cover_type cover = cover_full)
240 if(covers)
242 init_span(len, covers);
243 m_mask->combine_vspan(x, y, m_span, len);
245 else
247 realloc_span(len);
248 m_mask->fill_vspan(x, y, m_span, len);
250 m_pixf->blend_opaque_color_vspan(x, y, len, colors, m_span, cover);
254 private:
255 pixfmt_type* m_pixf;
256 const amask_type* m_mask;
258 cover_type* m_span;
259 unsigned m_max_len;
264 #endif