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_RGB_INCLUDED
26 #define AGG_SPAN_PATTERN_RGB_INCLUDED
28 #include "agg_basics.h"
29 #include "agg_pixfmt_rgb.h"
30 #include "agg_span_pattern.h"
34 //=======================================================span_pattern_rgb
35 template<class ColorT
,
39 class Allocator
= span_allocator
<ColorT
> >
40 class span_pattern_rgb
: public span_pattern_base
<ColorT
, Allocator
>
43 typedef ColorT color_type
;
44 typedef Order order_type
;
45 typedef Allocator alloc_type
;
46 typedef span_pattern_base
<color_type
, alloc_type
> base_type
;
47 typedef typename
color_type::value_type value_type
;
48 typedef typename
color_type::calc_type calc_type
;
51 base_shift
= color_type::base_shift
,
52 base_mask
= color_type::base_mask
55 //--------------------------------------------------------------------
56 span_pattern_rgb(alloc_type
& alloc
) :
62 //----------------------------------------------------------------
63 span_pattern_rgb(alloc_type
& alloc
,
64 const rendering_buffer
& src
,
67 value_type alpha
= base_mask
) :
68 base_type(alloc
, src
, offset_x
, offset_y
, alpha
),
69 m_wrap_mode_x(src
.width()),
70 m_wrap_mode_y(src
.height())
73 //-------------------------------------------------------------------
74 void source_image(const rendering_buffer
& src
)
76 base_type::source_image(src
);
77 m_wrap_mode_x
= WrapModeX(src
.width());
78 m_wrap_mode_y
= WrapModeY(src
.height());
81 //--------------------------------------------------------------------
82 color_type
* generate(int x
, int y
, unsigned len
)
84 color_type
* span
= base_type::allocator().span();
85 unsigned sx
= m_wrap_mode_x(base_type::offset_x() + x
);
86 const value_type
* row_ptr
=
87 (const value_type
*)base_type::source_image().row(
89 base_type::offset_y() + y
));
92 const value_type
* p
= row_ptr
+ sx
+ sx
+ sx
;
93 span
->r
= p
[order_type::R
];
94 span
->g
= p
[order_type::G
];
95 span
->b
= p
[order_type::B
];
96 span
->a
= base_type::alpha_int();
101 return base_type::allocator().span();
105 WrapModeX m_wrap_mode_x
;
106 WrapModeY m_wrap_mode_y
;
112 //=========================================================span_pattern_rgb
113 template<class ColorT, class Order, class Allocator = span_allocator<ColorT> >
114 class span_pattern_rgb : public span_pattern<rgba8, int8u, Allocator>
117 typedef Allocator alloc_type;
118 typedef rgba8 color_type;
119 typedef span_pattern<color_type, int8u, alloc_type> base_type;
121 //--------------------------------------------------------------------
122 span_pattern_rgb24(alloc_type& alloc) : base_type(alloc) {}
124 //----------------------------------------------------------------
125 span_pattern_rgb24(alloc_type& alloc,
126 const rendering_buffer& src,
127 unsigned offset_x, unsigned offset_y,
129 base_type(alloc, src, offset_x, offset_y, alpha)
133 //--------------------------------------------------------------------
134 color_type* generate(int x, int y, unsigned len)
136 color_type* span = base_type::allocator().span();
137 unsigned sx = (base_type::offset_x() + x) % base_type::source_image().width();
138 unsigned wp = base_type::source_image().width() * 3;
139 const int8u* p = base_type::source_image().row((base_type::offset_y() + y) % base_type::source_image().height());
143 span->r = p[Order::R];
144 span->g = p[Order::G];
145 span->b = p[Order::B];
146 span->a = base_type::alpha();
150 if(sx >= base_type::source_image().width())
152 sx -= base_type::source_image().width();
157 return base_type::allocator().span();