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 // 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"
27 //==============================================================scanline_p
29 // This is a general purpose scaline container which supports the interface
30 // used in the rasterizer::render(). See description of agg_scanline_u
33 //------------------------------------------------------------------------
34 template<class T
> class scanline_p
42 int16 len
; // If negative, it's a solid span, covers is valid
46 typedef span
* iterator
;
47 typedef const span
* const_iterator
;
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_
; }
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; }
77 scanline_p(const scanline_p
<T
>&);
78 const scanline_p
<T
>& operator = (const scanline_p
<T
>&);
90 //------------------------------------------------------------------------
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
)
99 m_covers
= new T
[max_len
];
100 m_spans
= new span
[max_len
];
103 m_last_x
= 0x7FFFFFF0;
104 m_cover_ptr
= m_covers
;
105 m_cur_span
= m_spans
;
110 //------------------------------------------------------------------------
112 void scanline_p
<T
>::reset_spans()
114 m_last_x
= 0x7FFFFFF0;
115 m_cover_ptr
= m_covers
;
116 m_cur_span
= m_spans
;
121 //------------------------------------------------------------------------
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)
133 m_cur_span
->covers
= m_cover_ptr
;
134 m_cur_span
->x
= (int16
)x
;
142 //------------------------------------------------------------------------
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
;
154 m_cur_span
->covers
= m_cover_ptr
;
155 m_cur_span
->x
= (int16
)x
;
156 m_cur_span
->len
= (int16
)len
;
159 m_last_x
= x
+ len
- 1;
163 //------------------------------------------------------------------------
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
;
175 *m_cover_ptr
= (T
)cover
;
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
;