update dev300-m58
[ooovba.git] / agg / inc / agg_span_pattern.h
blob0ad8025f2e70f0a983939247eae4d359a24b6ddd
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 // Adaptation for high precision colors has been sponsored by
17 // Liberty Technology Systems, Inc., visit http://lib-sys.com
19 // Liberty Technology Systems, Inc. is the provider of
20 // PostScript and PDF technology for software developers.
21 //
22 //----------------------------------------------------------------------------
25 #ifndef AGG_SPAN_PATTERN_INCLUDED
26 #define AGG_SPAN_PATTERN_INCLUDED
28 #include "agg_basics.h"
29 #include "agg_rendering_buffer.h"
30 #include "agg_span_generator.h"
33 namespace agg
36 //---------------------------------------------------span_pattern_base
37 template<class ColorT, class Allocator>
38 class span_pattern_base : public span_generator<ColorT, Allocator>
40 public:
41 typedef ColorT color_type;
42 typedef typename ColorT::value_type value_type;
43 typedef Allocator alloc_type;
44 enum { base_mask = color_type::base_mask };
46 //----------------------------------------------------------------
47 span_pattern_base(alloc_type& alloc) :
48 span_generator<color_type, alloc_type>(alloc)
51 //----------------------------------------------------------------
52 span_pattern_base(alloc_type& alloc,
53 const rendering_buffer& src,
54 unsigned offset_x, unsigned offset_y,
55 double alpha) :
56 span_generator<color_type, alloc_type>(alloc),
57 m_src(&src),
58 m_offset_x(offset_x),
59 m_offset_y(offset_y),
60 m_alpha(value_type(alpha * double(base_mask)))
63 //----------------------------------------------------------------
64 const rendering_buffer& source_image() const { return *m_src; }
65 unsigned offset_x() const { return m_offset_x; }
66 unsigned offset_y() const { return m_offset_y; }
67 double alpha() const { return m_alpha / double(base_mask); }
68 value_type alpha_int() const { return m_alpha; }
70 //----------------------------------------------------------------
71 void source_image(const rendering_buffer& v) { m_src = &v; }
72 void offset_x(unsigned v) { m_offset_x = v; }
73 void offset_y(unsigned v) { m_offset_y = v; }
74 void alpha(double v) { m_alpha = value_type(v * double(base_mask)); }
76 //----------------------------------------------------------------
77 private:
78 const rendering_buffer* m_src;
79 unsigned m_offset_x;
80 unsigned m_offset_y;
81 value_type m_alpha;
85 //---------------------------------------------------wrap_mode_repeat
86 class wrap_mode_repeat
88 public:
89 wrap_mode_repeat(unsigned size) :
90 m_size(size),
91 m_add(size * (0x3FFFFFFF / size)),
92 m_value(0)
95 AGG_INLINE unsigned operator() (int v)
97 return m_value = (unsigned(v) + m_add) % m_size;
100 AGG_INLINE unsigned operator++ ()
102 ++m_value;
103 if(m_value >= m_size) m_value = 0;
104 return m_value;
106 private:
107 unsigned m_size;
108 unsigned m_add;
109 unsigned m_value;
113 //---------------------------------------------wrap_mode_repeat_pow2
114 class wrap_mode_repeat_pow2
116 public:
117 wrap_mode_repeat_pow2(unsigned size) : m_value(0)
119 m_mask = 1;
120 while(m_mask < size) m_mask = (m_mask << 1) | 1;
121 m_mask >>= 1;
123 AGG_INLINE unsigned operator() (int v)
125 return m_value = unsigned(v) & m_mask;
127 AGG_INLINE unsigned operator++ ()
129 ++m_value;
130 if(m_value > m_mask) m_value = 0;
131 return m_value;
133 private:
134 unsigned m_mask;
135 unsigned m_value;
139 //----------------------------------------wrap_mode_repeat_auto_pow2
140 class wrap_mode_repeat_auto_pow2
142 public:
143 wrap_mode_repeat_auto_pow2(unsigned size) :
144 m_size(size),
145 m_add(size * (0x3FFFFFFF / size)),
146 m_mask((m_size & (m_size-1)) ? 0 : m_size-1),
147 m_value(0)
150 AGG_INLINE unsigned operator() (int v)
152 if(m_mask) return m_value = unsigned(v) & m_mask;
153 return m_value = (unsigned(v) + m_add) % m_size;
155 AGG_INLINE unsigned operator++ ()
157 ++m_value;
158 if(m_value >= m_size) m_value = 0;
159 return m_value;
162 private:
163 unsigned m_size;
164 unsigned m_add;
165 unsigned m_mask;
166 unsigned m_value;
170 //--------------------------------------------------wrap_mode_reflect
171 class wrap_mode_reflect
173 public:
174 wrap_mode_reflect(unsigned size) :
175 m_size(size),
176 m_size2(size * 2),
177 m_add(m_size2 * (0x3FFFFFFF / m_size2)),
178 m_value(0)
181 AGG_INLINE unsigned operator() (int v)
183 m_value = (unsigned(v) + m_add) % m_size2;
184 if(m_value >= m_size) return m_size2 - m_value - 1;
185 return m_value;
188 AGG_INLINE unsigned operator++ ()
190 ++m_value;
191 if(m_value >= m_size2) m_value = 0;
192 if(m_value >= m_size) return m_size2 - m_value - 1;
193 return m_value;
195 private:
196 unsigned m_size;
197 unsigned m_size2;
198 unsigned m_add;
199 unsigned m_value;
204 //-------------------------------------------wrap_mode_reflect_pow2
205 class wrap_mode_reflect_pow2
207 public:
208 wrap_mode_reflect_pow2(unsigned size) : m_value(0)
210 m_mask = 1;
211 m_size = 1;
212 while(m_mask < size)
214 m_mask = (m_mask << 1) | 1;
215 m_size <<= 1;
218 AGG_INLINE unsigned operator() (int v)
220 m_value = unsigned(v) & m_mask;
221 if(m_value >= m_size) return m_mask - m_value;
222 return m_value;
224 AGG_INLINE unsigned operator++ ()
226 ++m_value;
227 m_value &= m_mask;
228 if(m_value >= m_size) return m_mask - m_value;
229 return m_value;
231 private:
232 unsigned m_size;
233 unsigned m_mask;
234 unsigned m_value;
239 //---------------------------------------wrap_mode_reflect_auto_pow2
240 class wrap_mode_reflect_auto_pow2
242 public:
243 wrap_mode_reflect_auto_pow2(unsigned size) :
244 m_size(size),
245 m_size2(size * 2),
246 m_add(m_size2 * (0x3FFFFFFF / m_size2)),
247 m_mask((m_size2 & (m_size2-1)) ? 0 : m_size2-1),
248 m_value(0)
251 AGG_INLINE unsigned operator() (int v)
253 m_value = m_mask ? unsigned(v) & m_mask :
254 (unsigned(v) + m_add) % m_size2;
255 if(m_value >= m_size) return m_size2 - m_value - 1;
256 return m_value;
258 AGG_INLINE unsigned operator++ ()
260 ++m_value;
261 if(m_value >= m_size2) m_value = 0;
262 if(m_value >= m_size) return m_size2 - m_value - 1;
263 return m_value;
266 private:
267 unsigned m_size;
268 unsigned m_size2;
269 unsigned m_add;
270 unsigned m_mask;
271 unsigned m_value;
277 #endif