update dev300-m58
[ooovba.git] / agg / inc / agg_scanline_p.h
blob633119a1ae1cf4c83d549aa51bff64fe1b3d895a
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 // Class scanline_p - a general purpose scanline container with packed spans.
18 //----------------------------------------------------------------------------
19 #ifndef AGG_SCANLINE_P_INCLUDED
20 #define AGG_SCANLINE_P_INCLUDED
22 #include "agg_basics.h"
24 namespace agg
27 //==============================================================scanline_p
28 //
29 // This is a general purpose scaline container which supports the interface
30 // used in the rasterizer::render(). See description of agg_scanline_u
31 // for details.
32 //
33 //------------------------------------------------------------------------
34 template<class T> class scanline_p
36 public:
37 typedef T cover_type;
39 struct span
41 int16 x;
42 int16 len; // If negative, it's a solid span, covers is valid
43 const T* covers;
46 typedef span* iterator;
47 typedef const span* const_iterator;
49 ~scanline_p()
51 delete [] m_spans;
52 delete [] m_covers;
55 scanline_p() :
56 m_max_len(0),
57 m_last_x(0x7FFFFFF0),
58 m_covers(0),
59 m_cover_ptr(0),
60 m_spans(0),
61 m_cur_span(0)
65 void reset(int min_x, int max_x);
66 void add_cell(int x, unsigned cover);
67 void add_cells(int x, unsigned len, const T* covers);
68 void add_span(int x, unsigned len, unsigned cover);
69 void finalize(int y_) { m_y = y_; }
70 void reset_spans();
72 int y() const { return m_y; }
73 unsigned num_spans() const { return unsigned(m_cur_span - m_spans); }
74 const_iterator begin() const { return m_spans + 1; }
76 private:
77 scanline_p(const scanline_p<T>&);
78 const scanline_p<T>& operator = (const scanline_p<T>&);
80 unsigned m_max_len;
81 int m_last_x;
82 int m_y;
83 T* m_covers;
84 T* m_cover_ptr;
85 span* m_spans;
86 span* m_cur_span;
90 //------------------------------------------------------------------------
91 template<class T>
92 void scanline_p<T>::reset(int min_x, int max_x)
94 unsigned max_len = max_x - min_x + 3;
95 if(max_len > m_max_len)
97 delete [] m_spans;
98 delete [] m_covers;
99 m_covers = new T [max_len];
100 m_spans = new span [max_len];
101 m_max_len = max_len;
103 m_last_x = 0x7FFFFFF0;
104 m_cover_ptr = m_covers;
105 m_cur_span = m_spans;
106 m_cur_span->len = 0;
110 //------------------------------------------------------------------------
111 template<class T>
112 void scanline_p<T>::reset_spans()
114 m_last_x = 0x7FFFFFF0;
115 m_cover_ptr = m_covers;
116 m_cur_span = m_spans;
117 m_cur_span->len = 0;
121 //------------------------------------------------------------------------
122 template<class T>
123 void scanline_p<T>::add_cell(int x, unsigned cover)
125 *m_cover_ptr = (T)cover;
126 if(x == m_last_x+1 && m_cur_span->len > 0)
128 m_cur_span->len++;
130 else
132 m_cur_span++;
133 m_cur_span->covers = m_cover_ptr;
134 m_cur_span->x = (int16)x;
135 m_cur_span->len = 1;
137 m_last_x = x;
138 m_cover_ptr++;
142 //------------------------------------------------------------------------
143 template<class T>
144 void scanline_p<T>::add_cells(int x, unsigned len, const T* covers)
146 memcpy(m_cover_ptr, covers, len * sizeof(T));
147 if(x == m_last_x+1 && m_cur_span->len > 0)
149 m_cur_span->len += (int16)len;
151 else
153 m_cur_span++;
154 m_cur_span->covers = m_cover_ptr;
155 m_cur_span->x = (int16)x;
156 m_cur_span->len = (int16)len;
158 m_cover_ptr += len;
159 m_last_x = x + len - 1;
163 //------------------------------------------------------------------------
164 template<class T>
165 void scanline_p<T>::add_span(int x, unsigned len, unsigned cover)
167 if(x == m_last_x+1 &&
168 m_cur_span->len < 0 &&
169 cover == *m_cur_span->covers)
171 m_cur_span->len -= (int16)len;
173 else
175 *m_cover_ptr = (T)cover;
176 m_cur_span++;
177 m_cur_span->covers = m_cover_ptr++;
178 m_cur_span->x = (int16)x;
179 m_cur_span->len = -((int16)len);
181 m_last_x = x + len - 1;
185 //=============================================================scanline_p8
186 typedef scanline_p<int8u> scanline_p8;
188 //============================================================scanline_p16
189 typedef scanline_p<int16u> scanline_p16;
191 //============================================================scanline_p32
192 typedef scanline_p<int32u> scanline_p32;
196 #endif