summaryrefslogtreecommitdiff
path: root/src/corelib/render/software/agg_rendering_buffer_dynarow.pas
blob: bd32a9118216fcde72fd3ea6d19922b85ceed40a (plain)
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
//----------------------------------------------------------------------------
// 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-2007
//
// 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 rendering_buffer_dynarow
//
// [Pascal Port History] -----------------------------------------------------
//
// 06.10.2007-Milano: Unit port establishment
//
{ agg_rendering_buffer_dynarow.pas }
unit
 agg_rendering_buffer_dynarow ;

INTERFACE

{$I agg_mode.inc }

uses
 agg_basics ,
 agg_rendering_buffer ;

{ TYPES DEFINITION }
type
//===============================================rendering_buffer_dynarow
// Rendering buffer class with dynamic allocation of the rows.
// The rows are allocated as needed when requesting for span_ptr().
// The class automatically calculates min_x and max_x for each row.
// Generally it's more efficient to use this class as a temporary buffer
// for rendering a few lines and then to blend it with another buffer.
 rendering_buffer_dynarow_ptr = ^rendering_buffer_dynarow;
 rendering_buffer_dynarow = object(rendering_buffer )
  private
   m_buff   : row_data_type_ptr; // Pointers to each row of the buffer
   m_alloc  ,

   m_byte_width : unsigned;      // Width in bytes

  public
   constructor Construct(width ,height ,byte_width : unsigned );
   destructor  Destruct; virtual;

   procedure init(width ,height ,byte_width : unsigned );

   function  _width : unsigned;
   function  _height : unsigned;
   function  _byte_width : unsigned;

   function  row_xy(x ,y : int; len : unsigned ) : int8u_ptr; virtual;
   function  row   (y : unsigned ) : int8u_ptr; virtual;

  end;

{ GLOBAL VARIABLES & CONSTANTS }
{ GLOBAL PROCEDURES }


IMPLEMENTATION
{ LOCAL VARIABLES & CONSTANTS }
{ UNIT IMPLEMENTATION }
{ CONSTRUCT }
// Allocate and clear the buffer
constructor rendering_buffer_dynarow.Construct(width ,height ,byte_width : unsigned );
begin
 m_alloc:=sizeof(row_data_type ) * height;

 agg_getmem(pointer(m_buff ) ,m_alloc );

 m_width :=width;
 m_height:=height;

 m_byte_width:=byte_width;

 FillChar(m_buff^ ,m_alloc ,0 );

end;

{ DESTRUCT }
destructor rendering_buffer_dynarow.Destruct;
begin
 init(0 ,0 ,0 );

end;

{ INIT }
// Allocate and clear the buffer
procedure rendering_buffer_dynarow.init(width ,height ,byte_width : unsigned );
var
 i : unsigned;

begin
 i:=0;

 while i < m_height do
  begin
   agg_freemem(
    pointer(
     row_data_type_ptr(ptrcomp(m_buff ) + i * sizeof(row_data_type ) ).ptr ) ,
     m_byte_width );

   inc(i );

  end;

 agg_freemem(pointer(m_buff ) ,m_alloc );

 m_buff:=NIL;

 if (width <> 0 ) and
    (height <> 0 ) then
  begin
   m_width :=width;
   m_height:=height;

   m_byte_width:=byte_width;

   m_alloc:=sizeof(row_data_type ) * height;

   agg_getmem(pointer(m_buff ) ,m_alloc );
   FillChar  (m_buff^ ,m_alloc ,0 );

  end;

end;

{ _WIDTH }
function rendering_buffer_dynarow._width : unsigned;
begin
 result:=m_width;

end;

{ _HEIGHT }
function rendering_buffer_dynarow._height : unsigned;
begin
 result:=m_height;

end;

{ _BYTE_WIDTH }
function rendering_buffer_dynarow._byte_width : unsigned;
begin
 result:=m_byte_width;

end;

{ ROW_XY }
// The main function used for rendering. Returns pointer to the
// pre-allocated span. Memory for the row is allocated as needed.
function rendering_buffer_dynarow.row_xy(x ,y : int; len : unsigned ) : int8u_ptr;
var
 r : row_data_type_ptr;
 p : int8u_ptr;

 x2 : int;

begin
 r :=row_data_type_ptr(ptrcomp(m_buff ) + y * sizeof(row_data_type ) );
 x2:=x + len - 1;

 if r.ptr <> NIL then
  begin
   if x  < r.x1 then
    r.x1:=x;

   if x2 > r.x2 then
    r.x2:=x2;

  end
 else
  begin
   agg_getmem(pointer(p ) ,m_byte_width );

   r.ptr:=p;
   r.x1 :=x;
   r.x2 :=x2;

   FillChar(p^ ,m_byte_width ,0 );

  end;

 result:=r.ptr;

end;

{ ROW }
function rendering_buffer_dynarow.row(y : unsigned ) : int8u_ptr;
begin
 result:=row_xy(0 ,y ,m_width );

end;

END.