2
// AggPas 2.4 RM3 Demo application
3
// Note: Press F1 key on run to see more info about this demo
5
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
14
agg_platform_support ,
25
agg_rendering_buffer ,
27
agg_renderer_scanline ,
28
agg_rasterizer_scanline_aa ,
32
agg_render_scanlines ,
39
agg_span_interpolator_linear ,
40
agg_span_image_filter ,
41
agg_span_image_filter_rgb ,
52
g_image : array[0..47 ] of int8u = (
54
0,255,0, 0,0,255, 255,255,255, 255,0,0,
55
255,0,0, 0,0,0, 255,255,255, 255,255,255,
56
255,255,255, 255,255,255, 0,0,255, 255,0,0,
57
0,0,255, 255,255,255, 0,0,0, 0,255,0 );
60
the_application = object(platform_support )
62
m_radius : slider_ctrl;
64
m_filters : rbox_ctrl;
65
m_normalize : cbox_ctrl;
75
constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
78
procedure on_draw; virtual;
80
procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
85
constructor the_application.Construct;
90
inherited Construct(format_ ,flip_y_ );
92
m_gamma.Construct (115 ,5 ,500 - 5 ,11 ,not flip_y_ );
93
m_radius.Construct (115 ,5 + 15 ,500 - 5 ,11 + 15 ,not flip_y_ );
94
m_filters.Construct (0.0 ,0.0 ,110.0 ,210.0 ,not flip_y_ );
95
m_normalize.Construct(8.0 ,215.0 ,'Normalize Filter' ,not flip_y_ );
106
add_ctrl(@m_radius );
107
add_ctrl(@m_filters );
108
add_ctrl(@m_normalize );
110
m_normalize.text_size_(7.5 );
111
m_normalize.status_ (true );
113
m_radius.label_('Filter Radius=%.3f' );
114
m_radius.range_(2.0 ,8.0 );
115
m_radius.value_(4.0 );
117
m_gamma.label_('Gamma=%.3f' );
118
m_gamma.range_(0.5 ,3.0 );
119
m_gamma.value_(1.0 );
121
m_filters.add_item ('simple (NN)' );
122
m_filters.add_item ('bilinear' );
123
m_filters.add_item ('bicubic' );
124
m_filters.add_item ('spline16' );
125
m_filters.add_item ('spline36' );
126
m_filters.add_item ('hanning' );
127
m_filters.add_item ('hamming' );
128
m_filters.add_item ('hermite' );
129
m_filters.add_item ('kaiser' );
130
m_filters.add_item ('quadric' );
131
m_filters.add_item ('catrom' );
132
m_filters.add_item ('gaussian' );
133
m_filters.add_item ('bessel' );
134
m_filters.add_item ('mitchell' );
135
m_filters.add_item ('sinc' );
136
m_filters.add_item ('lanczos' );
137
m_filters.add_item ('blackman' );
138
m_filters.cur_item_(1 );
140
m_filters.border_width_ (0 ,0 );
141
rgba.ConstrDbl (0.0 ,0.0 ,0.0 ,0.1 );
142
m_filters.background_color_(@rgba );
143
m_filters.text_size_ (6.0 );
144
m_filters.text_thickness_ (0.85 );
149
destructor the_application.Destruct;
156
m_normalize.Destruct;
161
procedure the_application.on_draw;
163
para : array[0..7 ] of double = (200 ,40 ,200 + 300 ,40 ,200 + 300 ,40 + 300 ,200 ,40 + 300 );
166
pixf : pixel_formats;
170
rs : renderer_scanline_aa_solid;
173
ri : renderer_scanline_aa;
174
sg : span_image_filter_ptr;
175
fi : image_filter_base_ptr;
177
ras : rasterizer_scanline_aa;
182
stroke : conv_stroke;
183
filter : image_filter_lut;
185
img_rbuf : rendering_buffer;
186
img_mtx : trans_affine;
189
interpolator : span_interpolator_linear;
191
x_start ,x_end ,y_start ,y_end ,x_center ,x ,ys ,radius ,dx ,dy ,xs : double;
201
// Initialize structures
202
pixfmt_bgr24(pixf ,rbuf_window );
204
rb.Construct(@pixf );
207
rgba.ConstrDbl(1.0 ,1.0 ,1.0 );
209
rb.copy_from (rbuf_img(0 ) ,0 ,110 ,35 );
213
img_rbuf.Construct(@g_image[0 ] ,4 ,4 ,4 * 3 );
216
img_mtx.Construct(@para[0 ] ,0 ,0 ,4 ,4 );
218
interpolator.Construct(@img_mtx );
222
ras.move_to_d(para[0 ] ,para[1 ] );
223
ras.line_to_d(para[2 ] ,para[3 ] );
224
ras.line_to_d(para[4 ] ,para[5 ] );
225
ras.line_to_d(para[6 ] ,para[7 ] );
227
rgba.ConstrDbl(1 ,1 ,1 );
230
case m_filters._cur_item of
234
span_image_filter_rgb_nn_ptr ,
236
@sa ,@img_rbuf ,@rgba ,@interpolator ,bgr_order ) );
238
ri.Construct (@rb ,sg );
239
render_scanlines(@ras ,@sl ,@ri );
243
1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 ,16 :
245
norm:=m_normalize._status;
247
case m_filters._cur_item of
248
1 : fi:=new(image_filter_bilinear_ptr ,Construct );
249
2 : fi:=new(image_filter_bicubic_ptr ,Construct );
250
3 : fi:=new(image_filter_spline16_ptr ,Construct );
251
4 : fi:=new(image_filter_spline36_ptr ,Construct );
252
5 : fi:=new(image_filter_hanning_ptr ,Construct );
253
6 : fi:=new(image_filter_hamming_ptr ,Construct );
254
7 : fi:=new(image_filter_hermite_ptr ,Construct );
255
8 : fi:=new(image_filter_kaiser_ptr ,Construct );
256
9 : fi:=new(image_filter_quadric_ptr ,Construct );
257
10 : fi:=new(image_filter_catrom_ptr ,Construct );
258
11 : fi:=new(image_filter_gaussian_ptr ,Construct );
259
12 : fi:=new(image_filter_bessel_ptr ,Construct );
260
13 : fi:=new(image_filter_mitchell_ptr ,Construct );
261
14 : fi:=new(image_filter_sinc_ptr ,Construct(m_radius._value ) );
262
15 : fi:=new(image_filter_lanczos_ptr ,Construct(m_radius._value ) );
263
16 : fi:=new(image_filter_blackman_ptr ,Construct(m_radius._value ) );
267
filter.calculate(fi ,norm );
270
span_image_filter_rgb_ptr ,
272
@sa ,@img_rbuf ,@rgba ,@interpolator ,@filter ,bgr_order ) );
274
ri.Construct (@rb ,sg );
275
render_scanlines(@ras ,@sl ,@ri );
278
gamma.Construct (m_gamma._value );
279
pixf.apply_gamma_inv(@gamma ,bgr_order );
284
y_end :=_initial_height - 5.0;
285
x_center:=(x_start + x_end ) / 2;
288
stroke.Construct(@p );
289
stroke.width_ (0.8 );
293
x:=x_start + (x_end - x_start ) * i / 16.0;
296
p.move_to(x + 0.5 ,y_start );
297
p.line_to(x + 0.5 ,y_end );
299
ras.add_path(@stroke);
302
rgba.ConstrInt(0 ,0 ,0 ,255 )
304
rgba.ConstrInt(0 ,0 ,0 ,100 );
307
render_scanlines(@ras ,@sl ,@rs );
311
ys:=y_start + (y_end - y_start ) / 6.0;
314
p.move_to(x_start ,ys );
315
p.line_to(x_end ,ys );
317
ras.add_path (@stroke);
318
rgba.ConstrInt (0 ,0 ,0 );
320
render_scanlines(@ras ,@sl ,@rs );
322
radius:=filter.radius;
324
n :=trunc(radius * 256 * 2 );
325
dx:=(x_end - x_start ) * radius / 8.0;
328
weights:=filter.weight_array;
330
xs:=(x_end + x_start ) / 2.0 - (filter.diameter * (x_end - x_start ) / 32.0 );
331
nn:=filter.diameter * 256;
334
p.move_to(xs + 0.5 ,ys + dy * int16_ptr(weights )^ / image_filter_size );
341
xs + dx * i / n + 0.5 ,
342
ys + dy * int16_ptr(ptrcomp(weights ) + i * sizeof(int16 ) )^ / image_filter_size );
348
ras.add_path (@stroke );
349
rgba.ConstrInt (100 ,0 ,0 );
351
render_scanlines(@ras ,@sl ,@rs );
362
// Render the controls
363
render_ctrl(@ras ,@sl ,@rs ,@m_gamma );
365
if m_filters._cur_item >= 14 then
366
render_ctrl(@ras ,@sl ,@rs ,@m_radius );
368
render_ctrl(@ras ,@sl ,@rs ,@m_filters );
369
render_ctrl(@ras ,@sl ,@rs ,@m_normalize );
371
// Free AGG resources
380
dispose(sg ,Destruct );
388
procedure the_application.on_key;
392
'Another example that demonstrates the difference of image filters. '#13 +
393
'It just displays a simple 4x4 pixels image with huge zoom. '#13 +
394
'You can see how different filters affect the result. '#13 +
395
'Also see how gamma correction works.' +
396
#13#13'Note: F2 key saves current "screenshot" file in this demo''s directory. ' );
401
app : the_application;
404
app.Construct(pix_format_bgr24 ,flip_y );
405
app.caption_ ('Image transformation filters comparison (F1-Help)' );
407
if app.init(500 ,340 ,0 ) then
b'\\ No newline at end of file'