xref: /haiku/src/servers/app/drawing/Painter/agg_scanline_u_subpix.h (revision d02b8b81e884bd0090ef9bd2d7a62af673eca354)
1*d02b8b81SStephan Aßmus /*
2*d02b8b81SStephan Aßmus  * Copyright 2008, Andrej Spielmann <andrej.spielmann@seh.ox.ac.uk>.
3*d02b8b81SStephan Aßmus  * All rights reserved. Distributed under the terms of the MIT License.
4*d02b8b81SStephan Aßmus  *
5*d02b8b81SStephan Aßmus  * Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
6*d02b8b81SStephan Aßmus  *
7*d02b8b81SStephan Aßmus  *
8*d02b8b81SStephan Aßmus  * Class scanline_u8_subpix, a slightly modified version of
9*d02b8b81SStephan Aßmus  * scanline_u8 customized to store 3 covers per pixel
10*d02b8b81SStephan Aßmus  *
11*d02b8b81SStephan Aßmus  */
12*d02b8b81SStephan Aßmus 
13*d02b8b81SStephan Aßmus #ifndef AGG_SCANLINE_U_SUBPIX_INCLUDED
14*d02b8b81SStephan Aßmus #define AGG_SCANLINE_U_SUBPIX_INCLUDED
15*d02b8b81SStephan Aßmus 
16*d02b8b81SStephan Aßmus #include <agg_array.h>
17*d02b8b81SStephan Aßmus 
18*d02b8b81SStephan Aßmus namespace agg
19*d02b8b81SStephan Aßmus {
20*d02b8b81SStephan Aßmus 	//======================================================scanline_u8_subpix
21*d02b8b81SStephan Aßmus 	//------------------------------------------------------------------------
22*d02b8b81SStephan Aßmus 	class scanline_u8_subpix
23*d02b8b81SStephan Aßmus 	{
24*d02b8b81SStephan Aßmus 	public:
25*d02b8b81SStephan Aßmus 		typedef scanline_u8_subpix self_type;
26*d02b8b81SStephan Aßmus 		typedef int8u		cover_type;
27*d02b8b81SStephan Aßmus 		typedef int16		coord_type;
28*d02b8b81SStephan Aßmus 
29*d02b8b81SStephan Aßmus 		//--------------------------------------------------------------------
30*d02b8b81SStephan Aßmus 		struct span
31*d02b8b81SStephan Aßmus 		{
32*d02b8b81SStephan Aßmus 			coord_type	x;
33*d02b8b81SStephan Aßmus 			coord_type	len;
34*d02b8b81SStephan Aßmus 			cover_type* covers;
35*d02b8b81SStephan Aßmus 		};
36*d02b8b81SStephan Aßmus 
37*d02b8b81SStephan Aßmus 		typedef span* iterator;
38*d02b8b81SStephan Aßmus 		typedef const span* const_iterator;
39*d02b8b81SStephan Aßmus 
40*d02b8b81SStephan Aßmus 		//--------------------------------------------------------------------
scanline_u8_subpix()41*d02b8b81SStephan Aßmus 		scanline_u8_subpix() :
42*d02b8b81SStephan Aßmus 			m_min_x(0),
43*d02b8b81SStephan Aßmus 			m_last_x(0x7FFFFFF0),
44*d02b8b81SStephan Aßmus 			m_cur_span(0)
45*d02b8b81SStephan Aßmus 		{}
46*d02b8b81SStephan Aßmus 
47*d02b8b81SStephan Aßmus 		//--------------------------------------------------------------------
reset(int min_x,int max_x)48*d02b8b81SStephan Aßmus 		void reset(int min_x, int max_x)
49*d02b8b81SStephan Aßmus 		{
50*d02b8b81SStephan Aßmus 			unsigned max_len = 3*(max_x - min_x + 2);
51*d02b8b81SStephan Aßmus 			if(max_len > m_spans.size())
52*d02b8b81SStephan Aßmus 			{
53*d02b8b81SStephan Aßmus 				m_spans.resize(max_len);
54*d02b8b81SStephan Aßmus 				m_covers.resize(max_len);
55*d02b8b81SStephan Aßmus 			}
56*d02b8b81SStephan Aßmus 			m_last_x   = 0x7FFFFFF0;
57*d02b8b81SStephan Aßmus 			m_min_x	   = min_x;
58*d02b8b81SStephan Aßmus 			m_cur_span = &m_spans[0];
59*d02b8b81SStephan Aßmus 		}
60*d02b8b81SStephan Aßmus 
61*d02b8b81SStephan Aßmus 		//--------------------------------------------------------------------
add_cell(int x,unsigned cover1,unsigned cover2,unsigned cover3)62*d02b8b81SStephan Aßmus 		void add_cell(int x, unsigned cover1, unsigned cover2, unsigned cover3)
63*d02b8b81SStephan Aßmus 		{
64*d02b8b81SStephan Aßmus 			x -= m_min_x;
65*d02b8b81SStephan Aßmus 			m_covers[3 * x] = (cover_type)cover1;
66*d02b8b81SStephan Aßmus 			m_covers[3 * x + 1] = (cover_type)cover2;
67*d02b8b81SStephan Aßmus 			m_covers[3 * x + 2] = (cover_type)cover3;
68*d02b8b81SStephan Aßmus 			if(x == m_last_x + 1)
69*d02b8b81SStephan Aßmus 			{
70*d02b8b81SStephan Aßmus 				m_cur_span->len += 3;
71*d02b8b81SStephan Aßmus 			}
72*d02b8b81SStephan Aßmus 			else
73*d02b8b81SStephan Aßmus 			{
74*d02b8b81SStephan Aßmus 				m_cur_span++;
75*d02b8b81SStephan Aßmus 				m_cur_span->x	   = (coord_type)(x + m_min_x);
76*d02b8b81SStephan Aßmus 				m_cur_span->len	   = 3;
77*d02b8b81SStephan Aßmus 				m_cur_span->covers = &m_covers[3 * x];
78*d02b8b81SStephan Aßmus 			}
79*d02b8b81SStephan Aßmus 			m_last_x = x;
80*d02b8b81SStephan Aßmus 		}
81*d02b8b81SStephan Aßmus 
82*d02b8b81SStephan Aßmus 		//--------------------------------------------------------------------
add_span(int x,unsigned len,unsigned cover)83*d02b8b81SStephan Aßmus 		void add_span(int x, unsigned len, unsigned cover)
84*d02b8b81SStephan Aßmus 		{
85*d02b8b81SStephan Aßmus 			x -= m_min_x;
86*d02b8b81SStephan Aßmus 			memset(&m_covers[3 * x], cover, 3 * len);
87*d02b8b81SStephan Aßmus 			if(x == m_last_x+1)
88*d02b8b81SStephan Aßmus 			{
89*d02b8b81SStephan Aßmus 				m_cur_span->len += 3 * (coord_type)len;
90*d02b8b81SStephan Aßmus 			}
91*d02b8b81SStephan Aßmus 			else
92*d02b8b81SStephan Aßmus 			{
93*d02b8b81SStephan Aßmus 				m_cur_span++;
94*d02b8b81SStephan Aßmus 				m_cur_span->x	   = (coord_type)(x + m_min_x);
95*d02b8b81SStephan Aßmus 				m_cur_span->len	   = 3 * (coord_type)len;
96*d02b8b81SStephan Aßmus 				m_cur_span->covers = &m_covers[3 * x];
97*d02b8b81SStephan Aßmus 			}
98*d02b8b81SStephan Aßmus 			m_last_x = x + len - 1;
99*d02b8b81SStephan Aßmus 		}
100*d02b8b81SStephan Aßmus 
101*d02b8b81SStephan Aßmus 		//--------------------------------------------------------------------
finalize(int y)102*d02b8b81SStephan Aßmus 		void finalize(int y)
103*d02b8b81SStephan Aßmus 		{
104*d02b8b81SStephan Aßmus 			m_y = y;
105*d02b8b81SStephan Aßmus 		}
106*d02b8b81SStephan Aßmus 
107*d02b8b81SStephan Aßmus 		//--------------------------------------------------------------------
reset_spans()108*d02b8b81SStephan Aßmus 		void reset_spans()
109*d02b8b81SStephan Aßmus 		{
110*d02b8b81SStephan Aßmus 			m_last_x	= 0x7FFFFFF0;
111*d02b8b81SStephan Aßmus 			m_cur_span	= &m_spans[0];
112*d02b8b81SStephan Aßmus 		}
113*d02b8b81SStephan Aßmus 
114*d02b8b81SStephan Aßmus 		//--------------------------------------------------------------------
y()115*d02b8b81SStephan Aßmus 		int		 y()		   const { return m_y; }
num_spans()116*d02b8b81SStephan Aßmus 		unsigned num_spans()   const { return unsigned(m_cur_span - &m_spans[0]); }
begin()117*d02b8b81SStephan Aßmus 		const_iterator begin() const { return &m_spans[1]; }
begin()118*d02b8b81SStephan Aßmus 		iterator	   begin()		 { return &m_spans[1]; }
119*d02b8b81SStephan Aßmus 
120*d02b8b81SStephan Aßmus 	private:
121*d02b8b81SStephan Aßmus 		scanline_u8_subpix(const self_type&);
122*d02b8b81SStephan Aßmus 		const self_type& operator = (const self_type&);
123*d02b8b81SStephan Aßmus 
124*d02b8b81SStephan Aßmus 	private:
125*d02b8b81SStephan Aßmus 		int					  m_min_x;
126*d02b8b81SStephan Aßmus 		int					  m_last_x;
127*d02b8b81SStephan Aßmus 		int					  m_y;
128*d02b8b81SStephan Aßmus 		pod_array<cover_type> m_covers;
129*d02b8b81SStephan Aßmus 		pod_array<span>		  m_spans;
130*d02b8b81SStephan Aßmus 		span*				  m_cur_span;
131*d02b8b81SStephan Aßmus 	};
132*d02b8b81SStephan Aßmus 
133*d02b8b81SStephan Aßmus }
134*d02b8b81SStephan Aßmus 
135*d02b8b81SStephan Aßmus #endif
136*d02b8b81SStephan Aßmus 
137