1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
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_array.h"
22 #include "agg_rendering_buffer.h"
27 //==================================================pixfmt_amask_adaptor
28 template<class PixFmt
, class AlphaMask
> class pixfmt_amask_adaptor
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 memset(&m_span
[0], amask_type::cover_full
, len
* sizeof(cover_type
));
54 void init_span(unsigned len
, const cover_type
* covers
)
57 memcpy(&m_span
[0], covers
, len
* sizeof(cover_type
));
62 pixfmt_amask_adaptor(pixfmt_type
& pixf
, const amask_type
& mask
) :
63 m_pixf(&pixf
), m_mask(&mask
), m_span()
66 void attach_pixfmt(pixfmt_type
& pixf
) { m_pixf
= &pixf
; }
67 void attach_alpha_mask(const amask_type
& mask
) { m_mask
= &mask
; }
69 //--------------------------------------------------------------------
70 template<class PixFmt_
>
71 bool attach_pixfmt(PixFmt_
& pixf
, int x1
, int y1
, int x2
, int y2
)
73 return m_pixf
->attach(pixf
, x1
, y1
, x2
, y2
);
76 //--------------------------------------------------------------------
77 unsigned width() const { return m_pixf
->width(); }
78 unsigned height() const { return m_pixf
->height(); }
80 //--------------------------------------------------------------------
81 color_type
pixel(int x
, int y
)
83 return m_pixf
->pixel(x
, y
);
86 //--------------------------------------------------------------------
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
));
92 //--------------------------------------------------------------------
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
));
98 //--------------------------------------------------------------------
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]);
108 //--------------------------------------------------------------------
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]);
119 //--------------------------------------------------------------------
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]);
129 //--------------------------------------------------------------------
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]);
140 //--------------------------------------------------------------------
141 void copy_from(const rendering_buffer
& from
,
146 m_pixf
->copy_from(from
, xdst
, ydst
, xsrc
, ysrc
, len
);
150 //--------------------------------------------------------------------
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]);
162 //--------------------------------------------------------------------
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]);
174 //--------------------------------------------------------------------
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
);
182 //--------------------------------------------------------------------
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
);
190 //--------------------------------------------------------------------
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
);
211 //--------------------------------------------------------------------
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
;
234 pod_array
<cover_type
> m_span
;