16 #ifndef AGG_PIXFMT_AMASK_ADAPTOR_INCLUDED 17 #define AGG_PIXFMT_AMASK_ADAPTOR_INCLUDED 21 #include "agg_array.h" 22 #include "agg_rendering_buffer.h" 31 typedef PixFmt pixfmt_type;
32 typedef typename pixfmt_type::color_type color_type;
33 typedef typename pixfmt_type::row_data row_data;
34 typedef AlphaMask amask_type;
35 typedef typename amask_type::cover_type cover_type;
38 enum span_extra_tail_e { span_extra_tail = 256 };
40 void realloc_span(
unsigned len)
42 if(len > m_span.size())
44 m_span.resize(len + span_extra_tail);
48 void init_span(
unsigned len)
51 std::memset(&m_span[0], amask_type::cover_full, len *
sizeof(cover_type));
54 void init_span(
unsigned len,
const cover_type* covers)
57 std::memcpy(&m_span[0], covers, len *
sizeof(cover_type));
63 m_pixf(&pixf), m_mask(&mask), m_span()
66 void attach_pixfmt(pixfmt_type& pixf) { m_pixf = &pixf; }
67 void attach_alpha_mask(amask_type& mask) { m_mask = &mask; }
70 template<
class PixFmt2>
71 bool attach_pixfmt(PixFmt2& pixf,
int x1,
int y1,
int x2,
int y2)
73 return m_pixf->attach(pixf, x1, y1, x2, y2);
77 unsigned width()
const {
return m_pixf->width(); }
78 unsigned height()
const {
return m_pixf->height(); }
81 color_type pixel(
int x,
int y)
83 return m_pixf->pixel(x, y);
87 void copy_pixel(
int x,
int y,
const color_type& c)
89 m_pixf->blend_pixel(x, y, c, m_mask->pixel(x, y));
93 void blend_pixel(
int x,
int y,
const color_type& c, cover_type cover)
95 m_pixf->blend_pixel(x, y, c, m_mask->combine_pixel(x, y, cover));
99 void copy_hline(
int x,
int y,
104 m_mask->fill_hspan(x, y, &m_span[0], len);
105 m_pixf->blend_solid_hspan(x, y, len, c, &m_span[0]);
109 void blend_hline(
int x,
int y,
115 m_mask->combine_hspan(x, y, &m_span[0], len);
116 m_pixf->blend_solid_hspan(x, y, len, c, &m_span[0]);
120 void copy_vline(
int x,
int y,
125 m_mask->fill_vspan(x, y, &m_span[0], len);
126 m_pixf->blend_solid_vspan(x, y, len, c, &m_span[0]);
130 void blend_vline(
int x,
int y,
136 m_mask->combine_vspan(x, y, &m_span[0], len);
137 m_pixf->blend_solid_vspan(x, y, len, c, &m_span[0]);
146 m_pixf->copy_from(from, xdst, ydst, xsrc, ysrc, len);
151 void blend_solid_hspan(
int x,
int y,
154 const cover_type* covers)
156 init_span(len, covers);
157 m_mask->combine_hspan(x, y, &m_span[0], len);
158 m_pixf->blend_solid_hspan(x, y, len, c, &m_span[0]);
163 void blend_solid_vspan(
int x,
int y,
166 const cover_type* covers)
168 init_span(len, covers);
169 m_mask->combine_vspan(x, y, &m_span[0], len);
170 m_pixf->blend_solid_vspan(x, y, len, c, &m_span[0]);
175 void copy_color_hspan(
int x,
int y,
unsigned len,
const color_type* colors)
178 m_mask->fill_hspan(x, y, &m_span[0], len);
179 m_pixf->blend_color_hspan(x, y, len, colors, &m_span[0], cover_full);
183 void copy_color_vspan(
int x,
int y,
unsigned len,
const color_type* colors)
186 m_mask->fill_vspan(x, y, &m_span[0], len);
187 m_pixf->blend_color_vspan(x, y, len, colors, &m_span[0], cover_full);
191 void blend_color_hspan(
int x,
int y,
193 const color_type* colors,
194 const cover_type* covers,
195 cover_type cover = cover_full)
199 init_span(len, covers);
200 m_mask->combine_hspan(x, y, &m_span[0], len);
205 m_mask->fill_hspan(x, y, &m_span[0], len);
207 m_pixf->blend_color_hspan(x, y, len, colors, &m_span[0], cover);
212 void blend_color_vspan(
int x,
int y,
214 const color_type* colors,
215 const cover_type* covers,
216 cover_type cover = cover_full)
220 init_span(len, covers);
221 m_mask->combine_vspan(x, y, &m_span[0], len);
226 m_mask->fill_vspan(x, y, &m_span[0], len);
228 m_pixf->blend_color_vspan(x, y, len, colors, &m_span[0], cover);
233 const amask_type* m_mask;