File: agg_scanline_p.pas

package info (click to toggle)
lazarus 4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 275,760 kB
  • sloc: pascal: 2,341,904; xml: 509,420; makefile: 348,726; cpp: 93,608; sh: 3,387; java: 609; perl: 297; sql: 222; ansic: 137
file content (278 lines) | stat: -rw-r--r-- 5,657 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4 (Public License)
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
// Pascal Port By: Milan Marusinec alias Milano
//                 milan@marusinec.sk
//                 http://www.aggpas.org
// Copyright (c) 2005-2006
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
//          mcseemagg@yahoo.com
//          http://www.antigrain.com
//
//----------------------------------------------------------------------------
//
// Class scanline_p - a general purpose scanline container with packed spans.
//
//----------------------------------------------------------------------------
//
// Adaptation for 32-bit screen coordinates (scanline32_p) has been sponsored by
// Liberty Technology Systems, Inc., visit http://lib-sys.com
//
// Liberty Technology Systems, Inc. is the provider of
// PostScript and PDF technology for software developers.
//
// [Pascal Port History] -----------------------------------------------------
//
// 23.06.2006-Milano: ptrcomp adjustments
// 23.11.2005-Milano: ...
// 18.11.2005-Milano: Unit port establishment
//
{ agg_scanline_p.pas }
unit
 agg_scanline_p ;

INTERFACE

{$I agg_mode.inc }

uses
 agg_basics ,
 agg_scanline ;

{ TYPES DEFINITION }
type
 span_p8_ptr = ^span_p8;
 span_p8 = record
   x   ,
   len : int16; // If negative, it's a solid span, covers is valid

   covers : int8u_ptr;

  end;

 scanline_p8_ptr = ^scanline_p8;
 scanline_p8 = object(scanline )
   m_max_len : unsigned;
   m_last_x  ,
   m_y       : int;

   m_covers    ,
   m_cover_ptr : int8u_ptr;

   m_spans    ,
   m_cur_span : span_p8_ptr;

   constructor Construct;
   destructor  Destruct;

   procedure reset(min_x ,max_x : int ); virtual;
   procedure reset_spans; virtual;

   procedure finalize (y_ : int ); virtual;
   procedure add_cell (x : int; cover : unsigned ); virtual;
   procedure add_cells(x : int; len : unsigned; covers : int8u_ptr ); virtual;
   procedure add_span (x : int; len ,cover : unsigned ); virtual;

   function  y : int; virtual;
   function  num_spans : unsigned; virtual;
   function  begin_ : pointer; virtual;

   function  sz_of_span : unsigned; virtual;

  end;

{ GLOBAL PROCEDURES }


IMPLEMENTATION
{ LOCAL VARIABLES & CONSTANTS }
{ UNIT IMPLEMENTATION }
{ CONSTRUCT }
constructor scanline_p8.Construct;
begin
 m_max_len:=0;
 m_last_x :=$7FFFFFF0;

 m_y:=0;

 m_covers   :=NIL;
 m_cover_ptr:=NIL;

 m_spans   :=NIL;
 m_cur_span:=NIL;

end;

{ DESTRUCT }
destructor scanline_p8.Destruct;
begin
 agg_freemem(pointer(m_spans ) ,m_max_len * sizeof(span_p8 ) );
 agg_freemem(pointer(m_covers ) ,m_max_len * sizeof(int8u ) );

end;

{ RESET }
procedure scanline_p8.reset;
var
 max_len : unsigned;

begin
 max_len:=max_x - min_x + 3;

 if max_len > m_max_len then
  begin
   agg_freemem(pointer(m_covers ) ,m_max_len * sizeof(int8u ) );
   agg_freemem(pointer(m_spans ) ,m_max_len * sizeof(span_p8 ) );

   agg_getmem(pointer(m_covers ) ,max_len * sizeof(int8u ) );
   agg_getmem(pointer(m_spans ) ,max_len * sizeof(span_p8 ) );

   m_max_len:=max_len;

  end;

 m_last_x:=$7FFFFFF0;

 m_cover_ptr:=m_covers;
 m_cur_span :=m_spans;

 m_cur_span.len:=0;

end;

{ RESET_SPANS }
procedure scanline_p8.reset_spans;
begin
 m_last_x:=$7FFFFFF0;

 m_cover_ptr:=m_covers;
 m_cur_span :=m_spans;

 m_cur_span.len:=0;

end;

{ FINALIZE }
procedure scanline_p8.finalize;
begin
 m_y:=y_; 

end;

{ ADD_CELL }
procedure scanline_p8.add_cell;
begin
 m_cover_ptr^:=int8u(cover );

 if (x = m_last_x + 1 ) and
    (m_cur_span.len > 0 ) then
  inc(m_cur_span.len )

 else
  begin
   inc(ptrcomp(m_cur_span ) ,sizeof(span_p8 ) );

   m_cur_span.covers:=m_cover_ptr;

   m_cur_span.x  :=int16(x );
   m_cur_span.len:=1;

  end;

 m_last_x:=x;

 inc(ptrcomp(m_cover_ptr ) ,sizeof(int8u ) );

end;

{ ADD_CELLS }
procedure scanline_p8.add_cells;
begin
 move(covers^ ,m_cover_ptr^ ,len * sizeof(int8u ) );

 if (x = m_last_x + 1 ) and
    (m_cur_span.len > 0 ) then
  inc(m_cur_span.len ,int16(len ) )

 else
  begin
   inc(ptrcomp(m_cur_span ) ,sizeof(span_p8 ) );

   m_cur_span.covers:=m_cover_ptr;
   m_cur_span.x     :=int16(x );
   m_cur_span.len   :=int16(len );

  end;

 inc(ptrcomp(m_cover_ptr ) ,len * sizeof(int8u ) );

 m_last_x:=x + len - 1;

end;

{ ADD_SPAN }
procedure scanline_p8.add_span;
begin
 if (x = m_last_x + 1 ) and
    (m_cur_span.len < 0 ) and
    (cover = m_cur_span.covers^ ) then
  dec(m_cur_span.len ,int16(len ) )

 else
  begin
   m_cover_ptr^:=int8u(cover );

   inc(ptrcomp(m_cur_span ) ,sizeof(span_p8 ) );

   m_cur_span.covers:=m_cover_ptr;
   m_cur_span.x     :=int16(x );
   m_cur_span.len   :=int16(len );
   m_cur_span.len   :=-m_cur_span.len;

   inc(ptrcomp(m_cover_ptr ) ,sizeof(int8u ) );

  end;

 m_last_x:=x + len - 1; 

end;

{ Y }
function scanline_p8.y;
begin
 result:=m_y;

end;

{ NUM_SPANS }
function scanline_p8.num_spans;
begin
 result:=(ptrcomp(m_cur_span ) - ptrcomp(m_spans ) ) div sizeof(span_p8 );

end;

{ BEGIN_ }
function scanline_p8.begin_;
begin
 result:=span_p8_ptr(ptrcomp(m_spans ) + sizeof(span_p8 ) );

end;

{ SZ_OF_SPAN }
function scanline_p8.sz_of_span;
begin
 result:=sizeof(span_p8 );

end;

END.