update dev300-m58
[ooovba.git] / agg / inc / agg_span_pattern_rgb.h
blob3ad7a462e9d445c11e9b47e87f90b06bbaa9ffca
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_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"
32 namespace agg
34 //=======================================================span_pattern_rgb
35 template<class ColorT,
36 class Order,
37 class WrapModeX,
38 class WrapModeY,
39 class Allocator = span_allocator<ColorT> >
40 class span_pattern_rgb : public span_pattern_base<ColorT, Allocator>
42 public:
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;
49 enum
51 base_shift = color_type::base_shift,
52 base_mask = color_type::base_mask
55 //--------------------------------------------------------------------
56 span_pattern_rgb(alloc_type& alloc) :
57 base_type(alloc),
58 m_wrap_mode_x(1),
59 m_wrap_mode_y(1)
62 //----------------------------------------------------------------
63 span_pattern_rgb(alloc_type& alloc,
64 const rendering_buffer& src,
65 unsigned offset_x,
66 unsigned offset_y,
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(
88 m_wrap_mode_y(
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();
97 sx = ++m_wrap_mode_x;
98 ++span;
100 while(--len);
101 return base_type::allocator().span();
104 private:
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>
116 public:
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,
128 int8u alpha = 255) :
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());
140 p += sx * 3;
143 span->r = p[Order::R];
144 span->g = p[Order::G];
145 span->b = p[Order::B];
146 span->a = base_type::alpha();
147 p += 3;
148 ++sx;
149 ++span;
150 if(sx >= base_type::source_image().width())
152 sx -= base_type::source_image().width();
153 p -= wp;
156 while(--len);
157 return base_type::allocator().span();
164 #endif