3
// AggPas 2.4 RM3 Demo application
4
// Note: Press F1 key on run to see more info about this demo
6
// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap
15
agg_platform_support ,
25
agg_rendering_buffer ,
27
agg_renderer_scanline ,
28
agg_rasterizer_scanline_aa ,
31
agg_render_scanlines ,
37
agg_trans_perspective ,
38
agg_span_interpolator_linear ,
39
agg_span_interpolator_trans ,
40
agg_span_interpolator_persp ,
41
agg_span_subdiv_adaptor ,
42
agg_span_image_filter ,
43
agg_span_image_filter_rgba ,
44
agg_span_image_resample ,
45
agg_span_image_resample_rgba ,
50
interactive_polygon_ ,
58
base_shift = agg_color.base_shift;
68
g_rasterizer : rasterizer_scanline_aa;
69
g_scanline : scanline_u8;
71
img_name ,p ,n ,x : shortstring;
74
the_application = object(platform_support )
75
m_gamma_lut : gamma_lut;
76
m_quad : interactive_polygon;
77
m_trans_type : rbox_ctrl;
82
constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
85
procedure on_init; virtual;
86
procedure on_draw; virtual;
88
procedure on_mouse_move (x ,y : int; flags : unsigned ); virtual;
89
procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
90
procedure on_mouse_button_up (x ,y : int; flags : unsigned ); virtual;
92
procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
97
constructor the_application.Construct;
99
inherited Construct(format_ ,flip_y_ );
101
m_gamma_lut.Construct(2.0 ,base_shift ,base_shift );
102
m_quad.Construct (4 ,5.0 );
104
m_trans_type.Construct(400 ,5.0 ,430 + 170.0 ,100.0 ,not flip_y_ );
105
m_gamma.Construct (5.0 ,5.0 + 15 * 0 ,400-5 ,10.0 + 15 * 0 ,not flip_y_ );
106
m_blur.Construct (5.0 ,5.0 + 15 * 1 ,400-5 ,10.0 + 15 * 1 ,not flip_y_ );
110
m_trans_type.text_size_(7 );
111
m_trans_type.add_item ('Affine No Resample' );
112
m_trans_type.add_item ('Affine Resample' );
113
m_trans_type.add_item ('Perspective No Resample LERP' );
114
m_trans_type.add_item ('Perspective No Resample Exact' );
115
m_trans_type.add_item ('Perspective Resample LERP' );
116
m_trans_type.add_item ('Perspective Resample Exact' );
117
m_trans_type.cur_item_ (4 );
119
add_ctrl(@m_trans_type );
121
m_gamma.range_(0.5 ,3.0 );
122
m_gamma.value_(2.0 );
123
m_gamma.label_('Gamma=%.3f' );
127
m_blur.range_(0.5, 2.0);
129
m_blur.label_('Blur=%.3f' );
136
destructor the_application.Destruct;
140
m_gamma_lut.Destruct;
143
m_trans_type.Destruct;
150
procedure the_application.on_init;
152
x1 ,y1 ,x2 ,y2 ,dx ,dy : double;
154
pixf : pixel_formats;
159
g_x2:=rbuf_img(0 )._width;
160
g_y2:=rbuf_img(0 )._height;
167
dx:=_width / 2.0 - (x2 - x1 ) / 2.0;
168
dy:=_height / 2.0 - (y2 - y1 ) / 2.0;
170
m_quad.xn_ptr(0 )^:=Floor(x1 + dx );
171
m_quad.yn_ptr(0 )^:=Floor(y1 + dy );// - 150;
172
m_quad.xn_ptr(1 )^:=Floor(x2 + dx );
173
m_quad.yn_ptr(1 )^:=Floor(y1 + dy );// - 110;
174
m_quad.xn_ptr(2 )^:=Floor(x2 + dx );
175
m_quad.yn_ptr(2 )^:=Floor(y2 + dy );// - 300;
176
m_quad.xn_ptr(3 )^:=Floor(x1 + dx );
177
m_quad.yn_ptr(3 )^:=Floor(y2 + dy );// - 200;
179
pixfmt_bgra32(pixf ,rbuf_img(0 ) );
181
pixf.apply_gamma_dir(@m_gamma_lut ,bgra_order );
186
procedure the_application.on_draw;
188
pixf ,pixf_pre : pixel_formats;
190
rb ,rb_pre : renderer_base;
194
r : renderer_scanline_aa_solid;
199
sg : span_image_filter_ptr;
200
ri : renderer_scanline_aa;
202
trp : trans_perspective23;
204
interpolator : span_interpolator_linear;
205
interpsubdiv : span_interpolator_linear_subdiv;
206
interp_trans : span_interpolator_trans;
207
interp_plerp : span_interpolator_persp_lerp;
208
interp_exact : span_interpolator_persp_exact;
209
subdiv_adaptor : span_subdiv_adaptor;
211
filter_kernel : image_filter_hanning;
212
filter : image_filter_lut;
215
buf : array[0..63 ] of char;
222
if m_gamma._value <> m_old_gamma then
224
m_gamma_lut.gamma_(m_gamma._value );
226
load_img(0 ,img_name );
228
pixfmt_bgra32(pixf ,rbuf_img(0 ) );
230
pixf.apply_gamma_dir(@m_gamma_lut ,bgra_order );
232
m_old_gamma:=m_gamma._value;
236
// Initialize structures
237
pixfmt_bgra32 (pixf ,rbuf_window );
238
pixfmt_bgra32_pre(pixf_pre ,rbuf_window );
240
rb.Construct (@pixf );
241
rb_pre.Construct(@pixf_pre );
245
rgba.ConstrDbl(1 ,1 ,1 );
248
if m_trans_type._cur_item < 2 then
250
// For the affine parallelogram transformations we
251
// calculate the 4-th (implicit) point of the parallelogram
252
m_quad.xn_ptr(3 )^:=m_quad.xn(0 ) + (m_quad.xn(2 ) - m_quad.xn(1 ) );
253
m_quad.yn_ptr(3 )^:=m_quad.yn(0 ) + (m_quad.yn(2 ) - m_quad.yn(1 ) );
257
// Render the "quad" tool and controls
258
g_rasterizer.add_path(@m_quad );
260
rgba.ConstrDbl (0 ,0.3 ,0.5 ,0.1 );
262
render_scanlines(@g_rasterizer ,@g_scanline ,@r );
264
// Prepare the polygon to rasterize. Here we need to fill
265
// the destination (transformed) polygon.
266
g_rasterizer.clip_box(0 ,0 ,_width ,_height );
271
g_rasterizer.move_to_d(m_quad.xn(0 ) - b ,m_quad.yn(0 ) - b );
272
g_rasterizer.line_to_d(m_quad.xn(1 ) + b ,m_quad.yn(1 ) - b );
273
g_rasterizer.line_to_d(m_quad.xn(2 ) + b ,m_quad.yn(2 ) + b );
274
g_rasterizer.line_to_d(m_quad.xn(3 ) - b ,m_quad.yn(3 ) + b );
277
filter_kernel.Construct;
278
filter.Construct(@filter_kernel ,true );
280
rgba.ConstrPre(0 ,0 ,0 ,0 );
284
case m_trans_type._cur_item of
287
tr.Construct(parallelo_ptr(m_quad.polygon ) ,g_x1 ,g_y1 ,g_x2 ,g_y2 );
289
interpolator.Construct(@tr );
292
span_image_filter_rgba_2x2_ptr ,
294
@sa ,rbuf_img(0 ) ,@rgba ,@interpolator ,@filter ,bgra_order ) );
296
ri.Construct (@rb_pre ,sg );
297
render_scanlines(@g_rasterizer ,@g_scanline ,@ri );
303
tr.Construct(parallelo_ptr(m_quad.polygon ) ,g_x1 ,g_y1 ,g_x2 ,g_y2 );
305
interpolator.Construct(@tr );
308
span_image_resample_rgba_affine_ptr ,
310
@sa ,rbuf_img(0 ) ,@rgba ,@interpolator ,@filter ,bgra_order ) );
312
span_image_resample_ptr(sg ).blur_(m_blur._value );
314
ri.Construct (@rb_pre ,sg );
315
render_scanlines(@g_rasterizer ,@g_scanline ,@ri );
321
trp.Construct(m_quad.polygon ,g_x1 ,g_y1 ,g_x2 ,g_y2 );
325
interpsubdiv.Construct(@trp );
328
span_image_filter_rgba_2x2_ptr ,
330
@sa ,rbuf_img(0 ) ,@rgba ,@interpsubdiv ,@filter ,bgra_order ) );
332
ri.Construct (@rb_pre ,sg );
333
render_scanlines(@g_rasterizer ,@g_scanline ,@ri );
341
trp.Construct(m_quad.polygon ,g_x1 ,g_y1 ,g_x2 ,g_y2 );
345
interp_trans.Construct(@trp );
348
span_image_filter_rgba_2x2_ptr ,
350
@sa ,rbuf_img(0 ) ,@rgba ,@interp_trans ,@filter ,bgra_order ) );
352
ri.Construct (@rb_pre ,sg );
353
render_scanlines(@g_rasterizer ,@g_scanline ,@ri );
361
interp_plerp.Construct (m_quad.polygon ,g_x1 ,g_y1 ,g_x2 ,g_y2 );
362
subdiv_adaptor.Construct(@interp_plerp );
364
if interp_plerp.is_valid then
367
span_image_resample_rgba_ptr ,
369
@sa ,rbuf_img(0 ) ,@rgba ,@subdiv_adaptor ,@filter ,bgra_order ) );
371
span_image_resample_ptr(sg ).blur_(m_blur._value );
373
ri.Construct (@rb_pre ,sg );
374
render_scanlines(@g_rasterizer ,@g_scanline ,@ri );
382
interp_exact.Construct (m_quad.polygon ,g_x1 ,g_y1 ,g_x2 ,g_y2 );
383
subdiv_adaptor.Construct(@interp_exact );
385
if interp_exact.is_valid then
388
span_image_resample_rgba_ptr ,
390
@sa ,rbuf_img(0 ) ,@rgba ,@subdiv_adaptor ,@filter ,bgra_order ) );
392
span_image_resample_ptr(sg ).blur_(m_blur._value );
394
ri.Construct (@rb_pre ,sg );
395
render_scanlines(@g_rasterizer ,@g_scanline ,@ri );
406
pixf.apply_gamma_inv(@m_gamma_lut ,bgra_order );
414
sprintf (@buf[0 ] ,'%3.2f ms' ,tm );
415
t.start_point_(10.0 ,70.0 );
418
g_rasterizer.add_path(@pt );
420
rgba.ConstrDbl (0 ,0 ,0 );
422
render_scanlines(@g_rasterizer ,@g_scanline ,@r );
424
// Render the controls
425
render_ctrl(@g_rasterizer ,@g_scanline ,@r ,@m_trans_type );
426
render_ctrl(@g_rasterizer ,@g_scanline ,@r ,@m_gamma );
427
render_ctrl(@g_rasterizer ,@g_scanline ,@r ,@m_blur );
429
// Free AGG resources
434
dispose(sg ,Destruct );
442
procedure the_application.on_mouse_move;
444
if flags and mouse_left <> 0 then
445
if m_quad.on_mouse_move(x ,y ) then
448
if flags and mouse_left = 0 then
449
on_mouse_button_up(x ,y ,flags );
453
{ ON_MOUSE_BUTTON_DOWN }
454
procedure the_application.on_mouse_button_down;
456
if flags and mouse_left <> 0 then
457
if m_quad.on_mouse_button_down(x ,y ) then
462
{ ON_MOUSE_BUTTON_UP }
463
procedure the_application.on_mouse_button_up;
465
if m_quad.on_mouse_button_up(x ,y ) then
471
procedure the_application.on_key;
476
tar : trans_affine_rotation;
477
tat : trans_affine_translation;
480
if key = byte(' ' ) then
482
cx:=(m_quad.xn(0 ) + m_quad.xn(1 ) + m_quad.xn(2 ) + m_quad.xn(3 ) ) / 4;
483
cy:=(m_quad.yn(0 ) + m_quad.yn(1 ) + m_quad.yn(2 ) + m_quad.yn(3 ) ) / 4;
486
tat.construct(-cx ,-cy );
490
tar.Construct(pi / 20{2.0} ); tr.multiply(@tar );
491
tat.Construct(cx ,cy ); tr.multiply(@tat );
493
tr.transform(@tr ,m_quad.xn_ptr(0 ) ,m_quad.yn_ptr(0 ) );
494
tr.transform(@tr ,m_quad.xn_ptr(1 ) ,m_quad.yn_ptr(1 ) );
495
tr.transform(@tr ,m_quad.xn_ptr(2 ) ,m_quad.yn_ptr(2 ) );
496
tr.transform(@tr ,m_quad.xn_ptr(3 ) ,m_quad.yn_ptr(3 ) );
504
'The demonstration of image transformations with resampling. '#13 +
505
'You can see the difference in quality between regular image transformers and '#13 +
506
'the ones with resampling. Of course, image tranformations with resampling work '#13 +
507
'slower because they provide the best possible quality.'#13#13 +
508
'How to play with:'#13#13 +
509
'Use the left mouse button to manipulate with image.'#13 +
510
'Press the spacebar to rotate the image by 1/20 of pi.' +
511
#13#13'Note: F2 key saves current "screenshot" file in this demo''s directory. ' );
516
app : the_application;
517
buf : array [0..255 ] of char;
528
g_rasterizer.Construct;
529
g_scanline.Construct;
531
app.Construct(pix_format_bgra32 ,flip_y );
532
app.caption_ ('AGG Example. Image Transformations with Resampling (F1-Help)' );
537
if ParamCount > 0 then
539
spread_name(ParamStr(1 ) ,p ,n ,x );
541
img_name:=fold_name(p ,n ,'' );
547
if not app.load_img(0 ,img_name ) then
549
img_name:=img_name + #0;
550
ext :=app._img_ext + #0;
552
if img_name = 'spheres'#0 then
554
sprintf(@buf[0 ] ,'File not found: %s' ,ptrcomp(@img_name[1 ] ) );
555
sprintf(@buf[StrLen(@buf ) ] ,'%s. '#13'Download http://www.antigrain.com/' ,ptrcomp(@ext[1 ] ) );
556
sprintf(@buf[StrLen(@buf ) ] ,'%s' ,ptrcomp(@img_name[1 ] ) );
557
sprintf(@buf[StrLen(@buf ) ] ,'%s'#13'or copy it from another directory if available.' ,ptrcomp(@ext[1 ] ) );
562
sprintf(@buf[0 ] ,'File not found: %s' ,ptrcomp(@img_name[1 ] ) );
563
sprintf(@buf[StrLen(@buf ) ] ,'%s' ,ptrcomp(@ext[1 ] ) );
567
app.message_(@buf[0 ] );
571
if app.init(600 ,600 ,window_resize ) then
576
g_rasterizer.Destruct;
b'\\ No newline at end of file'