summaryrefslogtreecommitdiff
path: root/src/corelib/render/software/agg-demos/rasterizers2.dpr
blob: 33d332f9b6d316a4d7520e07ebf966838db584c3 (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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
//
// AggPas 2.4 RM3 Demo application
// Note: Press F1 key on run to see more info about this demo
//
// Paths: ..;..\ctrl;..\svg;..\util;..\platform\win;expat-wrap
//
program
 rasterizers2 ;

{DEFINE AGG_GRAY8 }
{$DEFINE AGG_BGR24 }
{DEFINE AGG_RGB24 }
{DEFINE AGG_BGRA32 }
{DEFINE AGG_RGBA32 }
{DEFINE AGG_ARGB32 }
{DEFINE AGG_ABGR32 }
{DEFINE AGG_RGB565 }
{DEFINE AGG_RGB555 }

uses
 Math ,SysUtils ,

 agg_basics ,
 agg_platform_support ,

 agg_ctrl ,
 agg_slider_ctrl ,
 agg_cbox_ctrl ,

 agg_rasterizer_scanline_aa ,
 agg_rasterizer_outline ,
 agg_rasterizer_outline_aa ,
 agg_scanline ,
 agg_scanline_p ,

 agg_renderer_base ,
 agg_renderer_scanline ,
 agg_renderer_primitives ,
 agg_renderer_outline_aa ,
 agg_renderer_outline_image ,
 agg_render_scanlines ,

 agg_gsv_text ,
 agg_conv_stroke ,
 agg_conv_transform ,
 agg_vertex_source ,
 agg_math_stroke ,
 agg_trans_affine ,
 agg_pattern_filters_rgba ,
 agg_gamma_functions

{$I pixel_formats.inc }
{$I agg_mode.inc }

const
 flip_y = true;

 pixmap_chain : array[0..113 ] of int32u = (
  16 ,7 ,
  $00ffffff ,$00ffffff ,$00ffffff ,$00ffffff ,$b4c29999 ,$ff9a5757 ,$ff9a5757 ,
  $ff9a5757 ,$ff9a5757 ,$ff9a5757 ,$ff9a5757 ,$b4c29999 ,$00ffffff ,$00ffffff ,
  $00ffffff ,$00ffffff ,$00ffffff ,$00ffffff ,$0cfbf9f9 ,$ff9a5757 ,$ff660000 ,
  $ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,
  $b4c29999 ,$00ffffff ,$00ffffff ,$00ffffff ,$00ffffff ,$5ae0cccc ,$ffa46767 ,
  $ff660000 ,$ff975252 ,$7ed4b8b8 ,$5ae0cccc ,$5ae0cccc ,$5ae0cccc ,$5ae0cccc ,
  $a8c6a0a0 ,$ff7f2929 ,$ff670202 ,$9ecaa6a6 ,$5ae0cccc ,$00ffffff ,$ff660000 ,
  $ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,$a4c7a2a2 ,$3affff00 ,
  $3affff00 ,$ff975151 ,$ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,
  $ff660000 ,$00ffffff ,$5ae0cccc ,$ffa46767 ,$ff660000 ,$ff954f4f ,$7ed4b8b8 ,
  $5ae0cccc ,$5ae0cccc ,$5ae0cccc ,$5ae0cccc ,$a8c6a0a0 ,$ff7f2929 ,$ff670202 ,
  $9ecaa6a6 ,$5ae0cccc ,$00ffffff ,$00ffffff ,$00ffffff ,$0cfbf9f9 ,$ff9a5757 ,
  $ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,$ff660000 ,
  $ff660000 ,$b4c29999 ,$00ffffff ,$00ffffff ,$00ffffff ,$00ffffff ,$00ffffff ,
  $00ffffff ,$00ffffff ,$b4c29999 ,$ff9a5757 ,$ff9a5757 ,$ff9a5757 ,$ff9a5757 ,
  $ff9a5757 ,$ff9a5757 ,$b4c29999 ,$00ffffff ,$00ffffff ,$00ffffff ,$00ffffff );

type
 pattern_pixmap_argb32 = object(pixel_source )
   m_pixmap : int32u_ptr;

   constructor Construct(pixmap : int32u_ptr );

   function  _width : unsigned; virtual;
   function  _height : unsigned; virtual;

   function  pixel(x ,y : int ) : rgba8; virtual;

  end;

 spiral = object(vertex_source )
   m_x ,m_y ,m_r1 ,m_r2 ,
   m_step   ,m_start_angle ,
   m_angle  ,m_curr_r ,m_da ,m_dr : double;

   m_start : boolean;

   constructor Construct(x ,y ,r1 ,r2 ,step : double; start_angle : double = 0 );

   procedure rewind(path_id : unsigned ); virtual;
   function  vertex(x ,y : double_ptr ) : unsigned; virtual;

  end;

 the_application = object(platform_support )
   m_step   ,
   m_width  : slider_ctrl;
   m_test   ,
   m_rotate ,

   m_accurate_joins ,
   m_scale_pattern  : cbox_ctrl;

   m_start_angle : double;

   constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
   destructor  Destruct;

   procedure draw_aliased_pix_accuracy   (ras : rasterizer_outline_ptr; prim : renderer_primitives_ptr );
   procedure draw_aliased_subpix_accuracy(ras : rasterizer_outline_ptr; prim : renderer_primitives_ptr );

   procedure draw_anti_aliased_outline(
              ras : rasterizer_outline_aa_ptr;
              ren : renderer_outline_aa_ptr );

   procedure draw_anti_aliased_scanline(
              ras : rasterizer_scanline_aa_ptr;
              sl  : scanline_ptr;
              ren : renderer_scanline_aa_solid_ptr );

   procedure draw_anti_aliased_outline_img(
              ras : rasterizer_outline_aa_ptr;
              ren : renderer_outline_ptr );

   procedure text(
              ras : rasterizer_scanline_aa_ptr;
              sl  : scanline_ptr;
              ren : renderer_scanline_aa_solid_ptr;
              x ,y : double; txt : PChar );

   procedure on_draw; virtual;
   procedure on_idle; virtual;

   procedure on_ctrl_change; virtual;

   procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;

  end;

{ CONSTRUCT }
constructor pattern_pixmap_argb32.Construct;
begin
 m_pixmap:=pixmap;

end;

{ _WIDTH }
function pattern_pixmap_argb32._width;
begin
 result:=m_pixmap^;

end;

{ _HEIGHT }
function pattern_pixmap_argb32._height;
begin
 result:=int32u_ptr(ptrcomp(m_pixmap ) + sizeof(int32u ) )^;

end;

{ PIXEL }
function pattern_pixmap_argb32.pixel;
var
 p : int32u;

begin
 p:=int32u_ptr(ptrcomp(m_pixmap ) + (y * _width + x + 2 ) * sizeof(int32u ) )^;

 result.r:=(p shr 16 ) and $FF;
 result.g:=(p shr 8 ) and $FF;
 result.b:=p and $FF;
 result.a:=p shr 24;

end;

{ ROUNDOFF }
procedure roundoff(this : trans_affine_ptr; x ,y : double_ptr );
begin
 x^:=Floor(x^ );
 y^:=Floor(y^ );

end;

{ CONSTRUCT }
constructor spiral.Construct;
begin
 m_x :=x;
 m_y :=y;
 m_r1:=r1;
 m_r2:=r2;

 m_step       :=step;
 m_start_angle:=start_angle;
 m_angle      :=start_angle;

 m_da:=deg2rad(8.0 );
 m_dr:=m_step / 45.0;

end;

{ REWIND }
procedure spiral.rewind;
begin
 m_angle :=m_start_angle;
 m_curr_r:=m_r1;
 m_start :=true;

end;

{ VERTEX }
function spiral.vertex;
begin
 if m_curr_r > m_r2 then
  result:=path_cmd_stop

 else
  begin
   x^:=m_x + Cos(m_angle ) * m_curr_r;
   y^:=m_y + Sin(m_angle ) * m_curr_r;

   m_curr_r:=m_curr_r + m_dr;
   m_angle :=m_angle + m_da;

   if m_start then
    begin
     m_start:=false;

     result:=path_cmd_move_to;

    end
   else
    result:=path_cmd_line_to;

  end;

end;

{ CONSTRUCT }
constructor the_application.Construct;
begin
 inherited Construct(format_ ,flip_y_ );

 m_step.Construct  (10.0 ,10.0 + 4.0 ,150.0 ,10.0 + 8.0 + 4.0 ,not flip_y_ );
 m_width.Construct (150.0 + 10.0 ,10.0 + 4.0 ,400 - 10.0 ,10.0 + 8.0 + 4.0 ,not flip_y_ );
 m_test.Construct  (10.0 ,10.0 + 4.0 + 16.0 ,'Test Performance' ,not flip_y_ );
 m_rotate.Construct(130 + 10.0 ,10.0 + 4.0 + 16.0 ,'Rotate' ,not flip_y_ );

 m_accurate_joins.Construct(200 + 10.0 ,10.0 + 4.0 + 16.0 ,'Accurate Joins' ,not flip_y_ );
 m_scale_pattern.Construct (310 + 10.0 ,10.0 + 4.0 + 16.0 ,'Scale Pattern' ,not flip_y_ );

 m_start_angle:=0.0;

 add_ctrl(@m_step );

 m_step.range_(0.0 ,2.0 );
 m_step.value_(0.1 );
 m_step.label_('Step=%1.2f' );
 m_step.no_transform;

 add_ctrl(@m_width );

 m_width.range_(0.0 ,7.0 );
 m_width.value_(3.0 );
 m_width.label_('Width=%1.2f' );
 m_width.no_transform;

 add_ctrl(@m_test );

 m_test.text_size_(9.0 ,7.0 );
 m_test.no_transform;

 add_ctrl(@m_rotate );

 m_rotate.text_size_(9.0 ,7.0 );
 m_rotate.no_transform;

 add_ctrl(@m_accurate_joins);

 m_accurate_joins.text_size_(9.0 ,7.0 );
 m_accurate_joins.no_transform;

 add_ctrl(@m_scale_pattern );

 m_scale_pattern.text_size_(9.0 ,7.0 );
 m_scale_pattern.status_   (true );
 m_scale_pattern.no_transform;

end;

{ DESTRUCT }
destructor the_application.Destruct;
begin
 inherited Destruct;

 m_step.Destruct;
 m_width.Destruct;
 m_test.Destruct;
 m_rotate.Destruct;

 m_accurate_joins.Destruct;
 m_scale_pattern.Destruct;

end;

{ DRAW_ANTI_ALIASED_OUTLINE }
procedure the_application.draw_anti_aliased_outline;
var
 s3 : spiral;

 rgba : aggclr;

begin
 s3.Construct(_width / 5 ,_height - _height / 4 + 20 ,5 ,70 ,8 ,m_start_angle );

 rgba.ConstrDbl(0.4 ,0.3 ,0.1 );
 ren.color_    (@rgba );
 ras.add_path  (@s3 );

end;

{ DRAW_ANTI_ALIASED_SCANLINE }
procedure the_application.draw_anti_aliased_scanline;
var
 s4 : spiral;

 rgba : aggclr;

 stroke : conv_stroke;

begin
 s4.Construct(_width / 2 ,_height - _height / 4 + 20 ,5 ,70 ,8 ,m_start_angle );

 stroke.Construct(@s4 );
 stroke.width_   (m_width._value );
 stroke.line_cap_(round_cap );

 rgba.ConstrDbl(0.4 ,0.3 ,0.1 );
 ren.color_    (@rgba );

 ras.add_path    (@stroke );
 render_scanlines(ras ,sl ,ren );

 stroke.Destruct;

end;

{ DRAW_ALIASED_PIX_ACCURACY }
procedure the_application.draw_aliased_pix_accuracy;
var
 s1 : spiral;
 rn : trans_affine;

 rgba  : aggclr;
 trans : conv_transform;

begin
 s1.Construct(_width / 5 ,_height / 4 + 50 ,5 ,70 ,8 ,m_start_angle );
 rn.Construct(@roundoff );

 trans.Construct(@s1 ,@rn );

 rgba.ConstrDbl  (0.4 ,0.3 ,0.1 );
 prim.line_color_(@rgba );
 ras.add_path    (@trans );

end;

{ DRAW_ALIASED_SUBPIX_ACCURACY }
procedure the_application.draw_aliased_subpix_accuracy;
var
 s2 : spiral;

 rgba : aggclr;

begin
 s2.Construct(_width / 2 ,_height / 4 + 50 ,5 ,70 ,8 ,m_start_angle );

 rgba.ConstrDbl  (0.4 ,0.3 ,0.1 );
 prim.line_color_(@rgba );
 ras.add_path    (@s2 );

end;

{ DRAW_ANTI_ALIASED_OUTLINE_IMG }
procedure the_application.draw_anti_aliased_outline_img;
var
 s5 : spiral;

begin
 s5.Construct(_width - _width / 5 ,_height - _height / 4 + 20 ,5 ,70 ,8 ,m_start_angle );
 ras.add_path(@s5 );

end;

{ TEXT }
procedure the_application.text;
var
 t : gsv_text;

 stroke : conv_stroke;
 rgba   : aggclr;

begin
 t.Construct;
 t.size_(8 );
 t.text_(txt );

 t.start_point_  (x ,y );
 stroke.Construct(@t );
 stroke.width_   (0.7 );

 ras.add_path  (@stroke );
 rgba.ConstrDbl(0 ,0 ,0 );
 ren.color_    (@rgba );

 render_scanlines(ras ,sl ,ren );

 t.Destruct;
 stroke.Destruct;

end;

{ ON_DRAW }
procedure the_application.on_draw;
var
 pf : pixel_formats;

 ren_base : renderer_base;
 ren_aa   : renderer_scanline_aa_solid;
 ren_prim : renderer_primitives;
 ras_aa   : rasterizer_scanline_aa;
 ras_al   : rasterizer_outline;
 sl       : scanline_p8;

 rgba : aggclr;

 prof    : line_profile_aa;
 ren_oaa : renderer_outline_aa;
 ras_oaa : rasterizer_outline_aa;

 filter     : pattern_filter_bilinear_rgba;
 src        : pattern_pixmap_argb32;
 src_scaled : line_image_scale;
 pattern    : line_image_pattern_pow2;

 ren_img : renderer_outline_image;
 ras_img : rasterizer_outline_aa;

 width_  : double;
 profile : line_profile_aa;
 gm_pw   : gamma_power;

 pixf     : pixel_formats;
 base_ren : renderer_base;
 ren      : renderer_outline_aa;
 ras      : rasterizer_outline_aa;

 fltr     : pattern_filter_bilinear_rgba;
 patt_src : pattern_pixmap_argb32;
 patt     : line_image_pattern_pow2;
 renimg   : renderer_outline_image;
 rasimg   : rasterizer_outline_aa;

begin
// Initialize structures
 pixfmt(pf ,rbuf_window );

 ren_base.Construct(@pf );
 ren_aa.Construct  (@ren_base );
 ren_prim.Construct(@ren_base );

 ras_aa.Construct;
 sl.Construct;
 ras_al.Construct(@ren_prim );

 prof.Construct;
 prof.width_(m_width._value );

 ren_oaa.Construct(@ren_base ,@prof );
 ras_oaa.Construct(@ren_oaa );

 ras_oaa.accurate_join_(m_accurate_joins._status );
 ras_oaa.round_cap_    (true );

// Image pattern
 filter.Construct;
 src.Construct(@pixmap_chain );

 src_scaled.Construct(@src ,m_width._value );
 pattern.Construct   (@filter );

 if m_scale_pattern._status then
  pattern.create(@src_scaled )
 else
  pattern.create(@src );

 ren_img.Construct(@ren_base ,@pattern );

 if m_scale_pattern._status then
  ren_img.scale_x_(m_width._value / src._height );

 ras_img.Construct(@ren_img );

// Circles
 rgba.ConstrDbl(1.0 ,1.0 ,0.95 );
 ren_base.clear(@rgba );

 draw_aliased_pix_accuracy    (@ras_al  ,@ren_prim );
 draw_aliased_subpix_accuracy (@ras_al  ,@ren_prim );
 draw_anti_aliased_outline    (@ras_oaa ,@ren_oaa );
 draw_anti_aliased_scanline   (@ras_aa  ,@sl ,@ren_aa );
 draw_anti_aliased_outline_img(@ras_img ,@ren_img );

// Text
 text(@ras_aa ,@sl ,@ren_aa ,50 ,80 ,'Bresenham lines,'#13#13'regular accuracy' );
 text(@ras_aa ,@sl ,@ren_aa ,_width / 2 - 50 ,80 ,'Bresenham lines,'#13#13'subpixel accuracy' );
 text(@ras_aa ,@sl ,@ren_aa ,50 ,_height / 2 + 50 ,'Anti-aliased lines' );
 text(@ras_aa ,@sl ,@ren_aa ,_width / 2 - 50 ,_height / 2 + 50 ,'Scanline rasterizer' );
 text(@ras_aa ,@sl ,@ren_aa ,_width - _width / 5 - 50 ,_height / 2 + 50 ,'Arbitrary Image Pattern' );

// Render the controls
 render_ctrl(@ras_aa ,@sl ,@ren_aa ,@m_step );
 render_ctrl(@ras_aa ,@sl ,@ren_aa ,@m_width );
 render_ctrl(@ras_aa ,@sl ,@ren_aa ,@m_test );
 render_ctrl(@ras_aa ,@sl ,@ren_aa ,@m_rotate );
 render_ctrl(@ras_aa ,@sl ,@ren_aa ,@m_accurate_joins );
 render_ctrl(@ras_aa ,@sl ,@ren_aa ,@m_scale_pattern );

// An example of using anti-aliased outline rasterizer.
// Uncomment it to see the result
{ width_:=5.0 + m_width.value - 3.0;

 profile.Construct;
 gm_pw.Construct(1.2 );

 profile.gamma          (@gm_pw );     //optional
 profile._min_width     (0.75 );       //optional
 profile._smoother_width(3.0);         //optional
 profile.width          (width_ );     //mandatory!

 pixfmt(pixf ,rbuf_window );

 base_ren.Construct(@pixf );
 ren.Construct     (@base_ren ,@profile );

 rgba.ConstrInt(0 ,0 ,0 );
 ren._color    (@rgba );               //mandatory!

 ras.Construct     (@ren );
 ras._round_cap    (true );            //optional
 ras._accurate_join(true );            //optional

 ras.move_to_d(100 ,100 );
 ras.line_to_d(150 ,200 );
 ras.render   (false );                // false means "don't close the polygon", i.e. polyline

 ras.Destruct;
 profile.Destruct;{}

// An example of using image pattern outline rasterizer
// Uncomment it to see the result
{ fltr.Construct;                      // Filtering functor

 patt_src.Construct(@pixmap_chain );  // Source. Must have an interface:
                                      // width() const
                                      // height() const
                                      // pixel(int x, int y) const
                                      // Any agg::renderer_base<> or derived
                                      // is good for the use as a source.

// agg::line_image_pattern is the main container for the patterns. It creates
// a copy of the patterns extended according to the needs of the filter.
// agg::line_image_pattern can operate with arbitrary image width, but if the
// width of the pattern is power of 2, it's better to use the modified
// version agg::line_image_pattern_pow2 because it works about 15-25 percent
// faster than agg::line_image_pattern (because of using simple masking instead
// of expensive '%' operation).
 patt.Construct(@fltr ,@src );

 pixfmt(pixf ,rbuf_window );

 base_ren.Construct(@pixf );
 renimg.Construct  (@base_ren ,@patt );
 //renimg._scale_x   (1.3 );            // Optional

 rasimg.Construct(@renimg );
 rasimg.move_to_d(100 ,150 );
 rasimg.line_to_d(0 ,0 );
 rasimg.line_to_d(300 ,200 );
 rasimg.render   (false );

 patt.Destruct;
 rasimg.Destruct;{}

// Free AGG resources
 ras_aa.Destruct;
 sl.Destruct;

 prof.Destruct;
 ras_oaa.Destruct;

 pattern.Destruct;
 ras_img.Destruct;

end;

{ ON_IDLE }
procedure the_application.on_idle;
begin
 m_start_angle:=m_start_angle + deg2rad(m_step._value );

 if m_start_angle > deg2rad(360.0 ) then
  m_start_angle:=m_start_angle - deg2rad(360.0 );

 force_redraw;

end;

{ ON_CTRL_CHANGE }
procedure the_application.on_ctrl_change;
var
 i : unsigned;

 t2 ,t3 ,t4 ,t5 : double;

 buf : array[0..255 ] of char;

 pf : pixel_formats;

 ren_base : renderer_base;
 ren_aa   : renderer_scanline_aa_solid;
 ren_prim : renderer_primitives;
 ras_aa   : rasterizer_scanline_aa;
 ras_al   : rasterizer_outline;
 sl       : scanline_p8;

 rgba : aggclr;

 prof    : line_profile_aa;
 ren_oaa : renderer_outline_aa;
 ras_oaa : rasterizer_outline_aa;

 filter     : pattern_filter_bilinear_rgba;
 src        : pattern_pixmap_argb32;
 src_scaled : line_image_scale;
 pattern    : line_image_pattern_pow2;

 ren_img : renderer_outline_image;
 ras_img : rasterizer_outline_aa;

begin
 wait_mode_(not m_rotate._status );

 if m_test._status then
  begin
   on_draw;
   update_window;

  // Initialize structures
   pixfmt(pf ,rbuf_window );

   ren_base.Construct(@pf );
   ren_aa.Construct  (@ren_base );
   ren_prim.Construct(@ren_base );

   ras_aa.Construct;
   sl.Construct;
   ras_al.Construct(@ren_prim );

   prof.Construct;
   prof.width_(m_width._value );

   ren_oaa.Construct(@ren_base ,@prof );
   ras_oaa.Construct(@ren_oaa );

   ras_oaa.accurate_join_(m_accurate_joins._status );
   ras_oaa.round_cap_    (true );

  // Image pattern
   filter.Construct;
   src.Construct(@pixmap_chain );

   src_scaled.Construct(@src ,m_width._value );
   pattern.Construct   (@filter );

   if m_scale_pattern._status then
    pattern.create(@src_scaled )
   else
    pattern.create(@src );

   ren_img.Construct(@ren_base ,@pattern );

   if m_scale_pattern._status then
    ren_img.scale_x_(src._height / m_width._value );

   ras_img.Construct(@ren_img );

  // Do Test
   start_timer;

   for i:=1 to 200 do
    begin
     draw_aliased_subpix_accuracy(@ras_al ,@ren_prim );

     m_start_angle:=m_start_angle + deg2rad(m_step._value );

    end;

   t2:=elapsed_time;

   start_timer;

   for i:=1 to 200 do
    begin
     draw_anti_aliased_outline(@ras_oaa ,@ren_oaa );

     m_start_angle:=m_start_angle + deg2rad(m_step._value );

    end;

   t3:=elapsed_time;

   start_timer;

   for i:=1 to 200 do
    begin
     draw_anti_aliased_scanline(@ras_aa ,@sl ,@ren_aa );

     m_start_angle:=m_start_angle + deg2rad(m_step._value );

    end;

   t4:=elapsed_time;

   start_timer;

   for i:=1 to 200 do
    begin
     draw_anti_aliased_outline_img(@ras_img ,@ren_img );

     m_start_angle:=m_start_angle + deg2rad(m_step._value );

    end;

   t5:=elapsed_time;

  // Display results
   m_test.status_(false );
   force_redraw;

   sprintf(@buf[0 ] ,'Aliased=%1.2fms, '#0 ,t2 );
   sprintf(@buf[StrLen(@buf[0 ] ) ] ,'Anti-Aliased=%1.2fms, '#0 ,t3 );
   sprintf(@buf[StrLen(@buf[0 ] ) ] ,'Scanline=%1.2fms, '#0 ,t4 );
   sprintf(@buf[StrLen(@buf[0 ] ) ] ,'Image-Pattern=%1.2fms'#0 ,t5 );

   message_(@buf[0 ] );

  // Free AGG resources
   ras_aa.Destruct;
   sl.Destruct;

   prof.Destruct;
   ras_oaa.Destruct;

   pattern.Destruct;
   ras_img.Destruct;

  end;

end;

{ ON_KEY }
procedure the_application.on_key;
begin
 if key = key_f1 then
  message_(
   'More complex example demostrating different rasterizers. Here you can see how '#13 +
   'the outline rasterizer works, and how to use an image as the line pattern. '#13 +
   'This capability can be very useful to draw geographical maps.' +
   #13#13'Note: F2 key saves current "screenshot" file in this demo''s directory.  ' );

end;

VAR
 app : the_application;

BEGIN
 app.Construct(pix_format ,flip_y );
 app.caption_ ('AGG Example. Line Join (F1-Help)' );

 if app.init(500 ,450 ,0 ) then
  app.run;

 app.Destruct;

END.