1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4 (Public License)
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
6 // Pascal Port By: Milan Marusinec alias Milano
7 //                 milan@marusinec.sk
8 //                 http://www.aggpas.org
9 // Copyright (c) 2005-2006
10 //
11 // Permission to copy, use, modify, sell and distribute this software
12 // is granted provided this copyright notice appears in all copies.
13 // This software is provided "as is" without express or implied
14 // warranty, and with no claim as to its suitability for any purpose.
15 //
16 //----------------------------------------------------------------------------
17 // Contact: mcseem@antigrain.com
18 //          mcseemagg@yahoo.com
19 //          http://www.antigrain.com
20 //
21 //----------------------------------------------------------------------------
22 //
23 // Class scanline_bin - binary scanline.
24 //
25 //----------------------------------------------------------------------------
26 //
27 // Adaptation for 32-bit screen coordinates (scanline32_bin) has been sponsored by
28 // Liberty Technology Systems, Inc., visit http://lib-sys.com
29 //
30 // Liberty Technology Systems, Inc. is the provider of
31 // PostScript and PDF technology for software developers.
32 //
33 // [Pascal Port History] -----------------------------------------------------
34 //
35 // 23.06.2006-Milano: ptrcomp adjustments
36 // 15.01.2006-Milano: Unit port establishment
37 //
38 { agg_scanline_bin.pas }
39 unit
40  agg_scanline_bin ;
41 
42 INTERFACE
43 
44 {$I agg_mode.inc }
45 
46 uses
47  agg_basics ,
48  agg_scanline ;
49 
50 { TYPES DEFINITION }
51 type
52  span_bin_ptr = ^span_bin;
53  span_bin = record
54    x   ,
55    len : int16;
56 
57   end;
58 
59 //=============================================================scanline_bin
60 //
61 // This is binary scaline container which supports the interface
62 // used in the rasterizer::render(). See description of agg_scanline_u8
63 // for details.
64 //
65 //------------------------------------------------------------------------
66  scanline_bin = object(scanline )
67    m_max_len : unsigned;
68    m_last_x  ,
69    m_y       : int;
70 
71    m_spans    ,
72    m_cur_span : span_bin_ptr;
73 
74    constructor Construct;
75    destructor  Destruct;
76 
77    procedure reset(min_x ,max_x : int ); virtual;
78    procedure reset_spans; virtual;
79 
80    procedure finalize(y_ : int ); virtual;
81    procedure add_cell(x : int; cover : unsigned ); virtual;
82    procedure add_span(x : int; len ,cover : unsigned ); virtual;
83 
ynull84    function  y : int; virtual;
num_spansnull85    function  num_spans : unsigned; virtual;
begin_null86    function  begin_ : pointer; virtual;
87 
sz_of_spannull88    function  sz_of_span : unsigned; virtual;
89 
90   end;
91 
92 { GLOBAL PROCEDURES }
93 
94 
95 IMPLEMENTATION
96 { LOCAL VARIABLES & CONSTANTS }
97 { UNIT IMPLEMENTATION }
98 { CONSTRUCT }
99 constructor scanline_bin.Construct;
100 begin
101  m_max_len:=0;
102  m_last_x :=$7FFFFFF0;
103 
104  m_spans   :=NIL;
105  m_cur_span:=NIL;
106 
107 end;
108 
109 { DESTRUCT }
110 destructor scanline_bin.Destruct;
111 begin
112  agg_freemem(pointer(m_spans ) ,m_max_len * sizeof(span_bin ) );
113 
114 end;
115 
116 { RESET }
117 procedure scanline_bin.reset;
118 var
119  max_len : unsigned;
120 
121 begin
122  max_len:=max_x - min_x + 3;
123 
124  if max_len > m_max_len then
125   begin
126    agg_freemem(pointer(m_spans ) ,m_max_len * sizeof(span_bin ) );
127    agg_getmem (pointer(m_spans ) ,max_len * sizeof(span_bin ) );
128 
129    m_max_len:=max_len;
130 
131   end;
132 
133  m_last_x  :=$7FFFFFF0;
134  m_cur_span:=m_spans;
135 
136 end;
137 
138 { RESET_SPANS }
139 procedure scanline_bin.reset_spans;
140 begin
141  m_last_x  :=$7FFFFFF0;
142  m_cur_span:=m_spans;
143 
144 end;
145 
146 { FINALIZE }
147 procedure scanline_bin.finalize;
148 begin
149  m_y:=y_;
150 
151 end;
152 
153 { ADD_CELL }
154 procedure scanline_bin.add_cell;
155 begin
156  if x = m_last_x + 1 then
157   inc(m_cur_span.len )
158 
159  else
160   begin
161    inc(ptrcomp(m_cur_span ) ,sizeof(span_bin ) );
162 
163    m_cur_span.x  :=int16(x );
164    m_cur_span.len:=1;
165 
166   end;
167 
168  m_last_x:=x;
169 
170 end;
171 
172 { ADD_SPAN }
173 procedure scanline_bin.add_span;
174 begin
175  if x = m_last_x + 1 then
176   m_cur_span.len:=int16(m_cur_span.len + len )
177 
178  else
179   begin
180    inc(ptrcomp(m_cur_span ) ,sizeof(span_bin ) );
181 
182    m_cur_span.x  :=int16(x );
183    m_cur_span.len:=int16(len );
184 
185   end;
186 
187  m_last_x:=x + len - 1;
188 
189 end;
190 
191 { Y }
scanline_bin.ynull192 function scanline_bin.y;
193 begin
194  result:=m_y
195 
196 end;
197 
198 { NUM_SPANS }
scanline_bin.num_spansnull199 function scanline_bin.num_spans;
200 begin
201  result:=(ptrcomp(m_cur_span ) - ptrcomp(m_spans ) ) div sizeof(span_bin );
202 
203 end;
204 
205 { BEGIN_ }
scanline_bin.begin_null206 function scanline_bin.begin_;
207 begin
208  result:=span_bin_ptr(ptrcomp(m_spans ) + sizeof(span_bin ) );
209 
210 end;
211 
212 { SZ_OF_SPAN }
scanline_bin.sz_of_spannull213 function scanline_bin.sz_of_span;
214 begin
215  result:=sizeof(span_bin );
216 
217 end;
218 
219 END.
220 
221