1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
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.
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
21 #include "agg_rendering_buffer.h"
26 //==================================================pixfmt_amask_adaptor
27 template<class PixFmt
, class AlphaMask
> class pixfmt_amask_adaptor
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
;
36 enum { span_extra_tail
= 256 };
38 void realloc_span(unsigned len
)
43 m_span
= new cover_type
[m_max_len
= len
+ span_extra_tail
];
47 void init_span(unsigned 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
)
58 memcpy(m_span
, covers
, len
* sizeof(cover_type
));
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
,
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
,
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
,
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
,
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
,
142 m_pixf
->copy_from(from
, xdst
, ydst
, xsrc
, ysrc
, len
);
146 //--------------------------------------------------------------------
147 void blend_solid_hspan(int x
, int y
,
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
,
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
,
173 const color_type
* colors
,
174 const cover_type
* covers
,
175 cover_type cover
= cover_full
)
179 init_span(len
, covers
);
180 m_mask
->combine_hspan(x
, y
, m_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
,
194 const color_type
* colors
,
195 const cover_type
* covers
,
196 cover_type cover
= cover_full
)
200 init_span(len
, covers
);
201 m_mask
->combine_vspan(x
, y
, m_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
,
215 const color_type
* colors
,
216 const cover_type
* covers
,
217 cover_type cover
= cover_full
)
221 init_span(len
, covers
);
222 m_mask
->combine_hspan(x
, y
, m_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
,
236 const color_type
* colors
,
237 const cover_type
* covers
,
238 cover_type cover
= cover_full
)
242 init_span(len
, covers
);
243 m_mask
->combine_vspan(x
, y
, m_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
);
256 const amask_type
* m_mask
;