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 // 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.
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"
36 //---------------------------------------------------span_pattern_base
37 template<class ColorT
, class Allocator
>
38 class span_pattern_base
: public span_generator
<ColorT
, Allocator
>
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
,
56 span_generator
<color_type
, alloc_type
>(alloc
),
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 //----------------------------------------------------------------
78 const rendering_buffer
* m_src
;
85 //---------------------------------------------------wrap_mode_repeat
86 class wrap_mode_repeat
89 wrap_mode_repeat(unsigned size
) :
91 m_add(size
* (0x3FFFFFFF / size
)),
95 AGG_INLINE
unsigned operator() (int v
)
97 return m_value
= (unsigned(v
) + m_add
) % m_size
;
100 AGG_INLINE
unsigned operator++ ()
103 if(m_value
>= m_size
) m_value
= 0;
113 //---------------------------------------------wrap_mode_repeat_pow2
114 class wrap_mode_repeat_pow2
117 wrap_mode_repeat_pow2(unsigned size
) : m_value(0)
120 while(m_mask
< size
) m_mask
= (m_mask
<< 1) | 1;
123 AGG_INLINE
unsigned operator() (int v
)
125 return m_value
= unsigned(v
) & m_mask
;
127 AGG_INLINE
unsigned operator++ ()
130 if(m_value
> m_mask
) m_value
= 0;
139 //----------------------------------------wrap_mode_repeat_auto_pow2
140 class wrap_mode_repeat_auto_pow2
143 wrap_mode_repeat_auto_pow2(unsigned size
) :
145 m_add(size
* (0x3FFFFFFF / size
)),
146 m_mask((m_size
& (m_size
-1)) ? 0 : m_size
-1),
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++ ()
158 if(m_value
>= m_size
) m_value
= 0;
170 //--------------------------------------------------wrap_mode_reflect
171 class wrap_mode_reflect
174 wrap_mode_reflect(unsigned size
) :
177 m_add(m_size2
* (0x3FFFFFFF / m_size2
)),
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;
188 AGG_INLINE
unsigned operator++ ()
191 if(m_value
>= m_size2
) m_value
= 0;
192 if(m_value
>= m_size
) return m_size2
- m_value
- 1;
204 //-------------------------------------------wrap_mode_reflect_pow2
205 class wrap_mode_reflect_pow2
208 wrap_mode_reflect_pow2(unsigned size
) : m_value(0)
214 m_mask
= (m_mask
<< 1) | 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
;
224 AGG_INLINE
unsigned operator++ ()
228 if(m_value
>= m_size
) return m_mask
- m_value
;
239 //---------------------------------------wrap_mode_reflect_auto_pow2
240 class wrap_mode_reflect_auto_pow2
243 wrap_mode_reflect_auto_pow2(unsigned size
) :
246 m_add(m_size2
* (0x3FFFFFFF / m_size2
)),
247 m_mask((m_size2
& (m_size2
-1)) ? 0 : m_size2
-1),
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;
258 AGG_INLINE
unsigned operator++ ()
261 if(m_value
>= m_size2
) m_value
= 0;
262 if(m_value
>= m_size
) return m_size2
- m_value
- 1;