1// 2// AggPas 2.4 RM3 Demo application 3// Note: Press F1 key on run to see more info about this demo 4// 5// Paths: src;src\ctrl;src\svg;src\util;src\platform\win;expat-wrap 6// 7program 8 gradients ; 9 10{DEFINE AGG_GRAY8 } 11{$DEFINE AGG_BGR24 } 12{DEFINE AGG_RGB24 } 13{DEFINE AGG_BGRA32 } 14{DEFINE AGG_RGBA32 } 15{DEFINE AGG_ARGB32 } 16{DEFINE AGG_ABGR32 } 17{DEFINE AGG_RGB565 } 18{DEFINE AGG_RGB555 } 19 20uses 21 Math ,SysUtils , 22 23 agg_basics , 24 agg_platform_support , 25 26 agg_ctrl , 27 agg_spline_ctrl , 28 agg_rbox_ctrl , 29 agg_gamma_ctrl , 30 31 agg_rasterizer_scanline_aa , 32 agg_scanline , 33 agg_scanline_u , 34 agg_scanline_p , 35 36 agg_renderer_base , 37 agg_renderer_scanline , 38 agg_render_scanlines , 39 40 agg_array , 41 agg_conv_transform , 42 agg_span_gradient , 43 agg_span_interpolator_linear , 44 agg_span_allocator , 45 agg_trans_affine , 46 agg_ellipse 47 48{$I pixel_formats.inc } 49{$I agg_mode.inc } 50{$I- } 51const 52 flip_y = true; 53 54 center_x : double = 350; 55 center_y : double = 280; 56 57type 58 color_function_profile = object(array_base ) 59 m_colors : aggclr_ptr; 60 m_profile : int8u_ptr; 61 62 constructor Construct(colors : aggclr_ptr; profile : int8u_ptr ); 63 64 function size : unsigned; virtual; 65 function array_operator(i : unsigned ) : pointer; virtual; 66 67 end; 68 69 the_application = object(platform_support ) 70 m_profile : gamma_ctrl; 71 m_spline_r , 72 m_spline_g , 73 m_spline_b , 74 m_spline_a : spline_ctrl; 75 m_rbox : rbox_ctrl; 76 77 m_pdx , 78 m_pdy , 79 m_center_x , 80 m_center_y , 81 m_scale , 82 m_prev_scale , 83 m_angle , 84 m_prev_angle , 85 m_scale_x , 86 m_prev_scale_x , 87 m_scale_y , 88 m_prev_scale_y : double; 89 m_mouse_move : boolean; 90 91 constructor Construct(format_ : pix_format_e; flip_y_ : boolean ); 92 destructor Destruct; 93 94 procedure on_draw; virtual; 95 96 procedure on_mouse_move (x ,y : int; flags : unsigned ); virtual; 97 procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual; 98 procedure on_mouse_button_up (x ,y : int; flags : unsigned ); virtual; 99 100 procedure on_key(x ,y : int; key ,flags : unsigned ); virtual; 101 102 end; 103 104{ CONSTRUCT } 105constructor color_function_profile.Construct; 106begin 107 m_colors :=colors; 108 m_profile:=profile; 109 110end; 111 112{ SIZE } 113function color_function_profile.size; 114begin 115 result:=256; 116 117end; 118 119{ ARRAY_OPERATOR } 120function color_function_profile.array_operator; 121begin 122 result:= 123 aggclr_ptr( 124 ptrcomp(m_colors ) + 125 int8u_ptr(ptrcomp(m_profile ) + i * sizeof(int8u ) )^ * sizeof(aggclr ) ); 126 127end; 128 129{ CONSTRUCT } 130constructor the_application.Construct; 131var 132 rgba : aggclr; 133 134 fd : text; 135 err : integer; 136 137 x ,y ,x2 ,y2 ,t : double; 138 139begin 140 inherited Construct(format_ ,flip_y_ ); 141 142 m_profile.Construct (10.0 ,10.0 ,200.0 ,170.0 - 5.0 ,not flip_y_ ); 143 m_spline_r.Construct(210 ,10 ,210 + 250 ,5 + 40 ,6 ,not flip_y_ ); 144 m_spline_g.Construct(210 ,10 + 40 ,210 + 250 ,5 + 80 ,6 ,not flip_y_ ); 145 m_spline_b.Construct(210 ,10 + 80 ,210 + 250 ,5 + 120 ,6 ,not flip_y_ ); 146 m_spline_a.Construct(210 ,10 + 120 ,210 + 250 ,5 + 160 ,6 ,not flip_y_ ); 147 m_rbox.Construct (10.0 ,180.0 ,200.0 ,300.0 ,not flip_y_ ); 148 149 m_pdx:=0.0; 150 m_pdy:=0.0; 151 152 m_center_x:=center_x; 153 m_center_y:=center_y; 154 155 m_scale :=1.0; 156 m_prev_scale :=1.0; 157 m_angle :=0.0; 158 m_prev_angle :=0.0; 159 m_scale_x :=1.0; 160 m_prev_scale_x:=1.0; 161 m_scale_y :=1.0; 162 m_prev_scale_y:=1.0; 163 164 m_mouse_move:=false; 165 166 add_ctrl(@m_profile ); 167 add_ctrl(@m_spline_r ); 168 add_ctrl(@m_spline_g ); 169 add_ctrl(@m_spline_b ); 170 add_ctrl(@m_spline_a ); 171 add_ctrl(@m_rbox ); 172 173 m_profile.border_width_(2.0 ,2.0 ); 174 175 rgba.ConstrDbl (1.0 ,0.8 ,0.8 ); 176 m_spline_r.background_color_(@rgba ); 177 rgba.ConstrDbl (0.8 ,1.0 ,0.8 ); 178 m_spline_g.background_color_(@rgba ); 179 rgba.ConstrDbl (0.8 ,0.8 ,1.0 ); 180 m_spline_b.background_color_(@rgba ); 181 rgba.ConstrDbl (1.0 ,1.0 ,1.0 ); 182 m_spline_a.background_color_(@rgba ); 183 184 m_spline_r.border_width_(1.0 ,2.0 ); 185 m_spline_g.border_width_(1.0 ,2.0 ); 186 m_spline_b.border_width_(1.0 ,2.0 ); 187 m_spline_a.border_width_(1.0 ,2.0 ); 188 m_rbox.border_width_ (2.0 ,2.0 ); 189 190 m_spline_r.point_(0 ,0.0 ,1.0 ); 191 m_spline_r.point_(1 ,1.0 / 5.0 ,1.0 - 1.0 / 5.0 ); 192 m_spline_r.point_(2 ,2.0 / 5.0 ,1.0 - 2.0 / 5.0 ); 193 m_spline_r.point_(3 ,3.0 / 5.0 ,1.0 - 3.0 / 5.0 ); 194 m_spline_r.point_(4 ,4.0 / 5.0 ,1.0 - 4.0 / 5.0 ); 195 m_spline_r.point_(5 ,1.0 ,0.0 ); 196 m_spline_r.update_spline; 197 198 m_spline_g.point_(0 ,0.0 ,1.0 ); 199 m_spline_g.point_(1 ,1.0 / 5.0 ,1.0 - 1.0 / 5.0 ); 200 m_spline_g.point_(2 ,2.0 / 5.0 ,1.0 - 2.0 / 5.0 ); 201 m_spline_g.point_(3 ,3.0 / 5.0 ,1.0 - 3.0 / 5.0 ); 202 m_spline_g.point_(4 ,4.0 / 5.0 ,1.0 - 4.0 / 5.0 ); 203 m_spline_g.point_(5 ,1.0 ,0.0 ); 204 m_spline_g.update_spline; 205 206 m_spline_b.point_(0 ,0.0 ,1.0 ); 207 m_spline_b.point_(1 ,1.0 / 5.0 ,1.0 - 1.0 / 5.0 ); 208 m_spline_b.point_(2 ,2.0 / 5.0 ,1.0 - 2.0 / 5.0 ); 209 m_spline_b.point_(3 ,3.0 / 5.0 ,1.0 - 3.0 / 5.0 ); 210 m_spline_b.point_(4 ,4.0 / 5.0 ,1.0 - 4.0 / 5.0 ); 211 m_spline_b.point_(5 ,1.0 ,0.0 ); 212 m_spline_b.update_spline; 213 214 m_spline_a.point_(0 ,0.0 ,1.0 ); 215 m_spline_a.point_(1 ,1.0 / 5.0 , 1.0 ); 216 m_spline_a.point_(2 ,2.0 / 5.0 , 1.0 ); 217 m_spline_a.point_(3 ,3.0 / 5.0 , 1.0 ); 218 m_spline_a.point_(4 ,4.0 / 5.0 , 1.0 ); 219 m_spline_a.point_(5 ,1.0 ,1.0 ); 220 m_spline_a.update_spline; 221 222 m_rbox.add_item ('Circular' ); 223 m_rbox.add_item ('Diamond' ); 224 m_rbox.add_item ('Linear' ); 225 m_rbox.add_item ('XY' ); 226 m_rbox.add_item ('sqrt(XY)' ); 227 m_rbox.add_item ('Conic' ); 228 m_rbox.cur_item_(0 ); 229 230 err:=IOResult; 231 232 AssignFile(fd ,'settings.dat' ); 233 reset (fd ); 234 235 err:=IOResult; 236 237 if err = 0 then 238 begin 239 readln(fd ,t ); m_center_x:=t; 240 readln(fd ,t ); m_center_y:=t; 241 readln(fd ,t ); m_scale:=t; 242 readln(fd ,t ); m_angle:=t; 243 readln(fd ,x ); 244 readln(fd ,y ); m_spline_r.point_(0 ,x ,y ); 245 readln(fd ,x ); 246 readln(fd ,y ); m_spline_r.point_(1 ,x ,y ); 247 readln(fd ,x ); 248 readln(fd ,y ); m_spline_r.point_(2 ,x ,y ); 249 readln(fd ,x ); 250 readln(fd ,y ); m_spline_r.point_(3 ,x ,y ); 251 readln(fd ,x ); 252 readln(fd ,y ); m_spline_r.point_(4 ,x ,y ); 253 readln(fd ,x ); 254 readln(fd ,y ); m_spline_r.point_(5 ,x ,y ); 255 readln(fd ,x ); 256 readln(fd ,y ); m_spline_g.point_(0 ,x ,y ); 257 readln(fd ,x ); 258 readln(fd ,y ); m_spline_g.point_(1 ,x ,y ); 259 readln(fd ,x ); 260 readln(fd ,y ); m_spline_g.point_(2 ,x ,y ); 261 readln(fd ,x ); 262 readln(fd ,y ); m_spline_g.point_(3 ,x ,y ); 263 readln(fd ,x ); 264 readln(fd ,y ); m_spline_g.point_(4 ,x ,y ); 265 readln(fd ,x ); 266 readln(fd ,y ); m_spline_g.point_(5 ,x ,y ); 267 readln(fd ,x ); 268 readln(fd ,y ); m_spline_b.point_(0 ,x ,y ); 269 readln(fd ,x ); 270 readln(fd ,y ); m_spline_b.point_(1 ,x ,y ); 271 readln(fd ,x ); 272 readln(fd ,y ); m_spline_b.point_(2 ,x ,y ); 273 readln(fd ,x ); 274 readln(fd ,y ); m_spline_b.point_(3 ,x ,y ); 275 readln(fd ,x ); 276 readln(fd ,y ); m_spline_b.point_(4 ,x ,y ); 277 readln(fd ,x ); 278 readln(fd ,y ); m_spline_b.point_(5 ,x ,y ); 279 readln(fd ,x ); 280 readln(fd ,y ); m_spline_a.point_(0 ,x ,y ); 281 readln(fd ,x ); 282 readln(fd ,y ); m_spline_a.point_(1 ,x ,y ); 283 readln(fd ,x ); 284 readln(fd ,y ); m_spline_a.point_(2 ,x ,y ); 285 readln(fd ,x ); 286 readln(fd ,y ); m_spline_a.point_(3 ,x ,y ); 287 readln(fd ,x ); 288 readln(fd ,y ); m_spline_a.point_(4 ,x ,y ); 289 readln(fd ,x ); 290 readln(fd ,y ); m_spline_a.point_(5 ,x ,y ); 291 292 m_spline_r.update_spline; 293 m_spline_g.update_spline; 294 m_spline_b.update_spline; 295 m_spline_a.update_spline; 296 297 readln(fd ,x ); 298 readln(fd ,y ); 299 readln(fd ,x2 ); 300 readln(fd ,y2 ); 301 302 m_profile.values(x ,y ,x2 ,y2 ); 303 304 close(fd ); 305 306 end; 307 308end; 309 310{ DESTRUCT } 311destructor the_application.Destruct; 312var 313 fd : text; 314 315 x1 ,y1 ,x2 ,y2 : double; 316 317begin 318 AssignFile(fd ,'settings.dat' ); 319 rewrite (fd ); 320 321 writeln(fd ,m_center_x:0:6 ); 322 writeln(fd ,m_center_y:0:6 ); 323 writeln(fd ,m_scale:0:6 ); 324 writeln(fd ,m_angle:0:6 ); 325 writeln(fd ,m_spline_r._x(0 ):0:6 ); 326 writeln(fd ,m_spline_r._y(0 ):0:6 ); 327 writeln(fd ,m_spline_r._x(1 ):0:6 ); 328 writeln(fd ,m_spline_r._y(1 ):0:6 ); 329 writeln(fd ,m_spline_r._x(2 ):0:6 ); 330 writeln(fd ,m_spline_r._y(2 ):0:6 ); 331 writeln(fd ,m_spline_r._x(3 ):0:6 ); 332 writeln(fd ,m_spline_r._y(3 ):0:6 ); 333 writeln(fd ,m_spline_r._x(4 ):0:6 ); 334 writeln(fd ,m_spline_r._y(4 ):0:6 ); 335 writeln(fd ,m_spline_r._x(5 ):0:6 ); 336 writeln(fd ,m_spline_r._y(5 ):0:6 ); 337 writeln(fd ,m_spline_g._x(0 ):0:6 ); 338 writeln(fd ,m_spline_g._y(0 ):0:6 ); 339 writeln(fd ,m_spline_g._x(1 ):0:6 ); 340 writeln(fd ,m_spline_g._y(1 ):0:6 ); 341 writeln(fd ,m_spline_g._x(2 ):0:6 ); 342 writeln(fd ,m_spline_g._y(2 ):0:6 ); 343 writeln(fd ,m_spline_g._x(3 ):0:6 ); 344 writeln(fd ,m_spline_g._y(3 ):0:6 ); 345 writeln(fd ,m_spline_g._x(4 ):0:6 ); 346 writeln(fd ,m_spline_g._y(4 ):0:6 ); 347 writeln(fd ,m_spline_g._x(5 ):0:6 ); 348 writeln(fd ,m_spline_g._y(5 ):0:6 ); 349 writeln(fd ,m_spline_b._x(0 ):0:6 ); 350 writeln(fd ,m_spline_b._y(0 ):0:6 ); 351 writeln(fd ,m_spline_b._x(1 ):0:6 ); 352 writeln(fd ,m_spline_b._y(1 ):0:6 ); 353 writeln(fd ,m_spline_b._x(2 ):0:6 ); 354 writeln(fd ,m_spline_b._y(2 ):0:6 ); 355 writeln(fd ,m_spline_b._x(3 ):0:6 ); 356 writeln(fd ,m_spline_b._y(3 ):0:6 ); 357 writeln(fd ,m_spline_b._x(4 ):0:6 ); 358 writeln(fd ,m_spline_b._y(4 ):0:6 ); 359 writeln(fd ,m_spline_b._x(5 ):0:6 ); 360 writeln(fd ,m_spline_b._y(5 ):0:6 ); 361 writeln(fd ,m_spline_a._x(0 ):0:6 ); 362 writeln(fd ,m_spline_a._y(0 ):0:6 ); 363 writeln(fd ,m_spline_a._x(1 ):0:6 ); 364 writeln(fd ,m_spline_a._y(1 ):0:6 ); 365 writeln(fd ,m_spline_a._x(2 ):0:6 ); 366 writeln(fd ,m_spline_a._y(2 ):0:6 ); 367 writeln(fd ,m_spline_a._x(3 ):0:6 ); 368 writeln(fd ,m_spline_a._y(3 ):0:6 ); 369 writeln(fd ,m_spline_a._x(4 ):0:6 ); 370 writeln(fd ,m_spline_a._y(4 ):0:6 ); 371 writeln(fd ,m_spline_a._x(5 ):0:6 ); 372 writeln(fd ,m_spline_a._y(5 ):0:6 ); 373 374 m_profile.values(@x1 ,@y1 ,@x2 ,@y2 ); 375 376 writeln(fd ,x1:0:6 ); 377 writeln(fd ,y1:0:6 ); 378 writeln(fd ,x2:0:6 ); 379 writeln(fd ,y2:0:6 ); 380 381 close(fd ); 382 383 inherited Destruct; 384 385 m_profile.Destruct; 386 m_spline_r.Destruct; 387 m_spline_g.Destruct; 388 m_spline_b.Destruct; 389 m_spline_a.Destruct; 390 m_rbox.Destruct; 391 392end; 393 394{ ON_DRAW } 395procedure the_application.on_draw; 396var 397 pf : rasterizer_scanline_aa; 398 sl : scanline_u8; 399 rb : renderer_base; 400 r : renderer_scanline_aa_solid; 401 402 pixf : pixel_formats; 403 rgba : aggclr; 404 405 ini_scale : double; 406 407 color_profile : array[0..255 ] of aggclr; 408 409 mtx1 ,mtx_g1 : trans_affine; 410 411 tas : trans_affine_scaling; 412 tar : trans_affine_rotation; 413 tat : trans_affine_translation; 414 415 e1 : ellipse; 416 i : int; 417 t1 : conv_transform; 418 419 gr_circle : gradient_radial; 420 gr_diamond : gradient_diamond; 421 gr_x : gradient_x; 422 gr_xy : gradient_xy; 423 gr_sqrt_xy : gradient_sqrt_xy; 424 gr_conic : gradient_conic; 425 426 gr_ptr : gradient_reflect_adaptor; 427 428 span_alloc : span_allocator; 429 colors : color_function_profile; 430 inter : span_interpolator_linear; 431 span_gen : span_gradient; 432 433 r1 : renderer_scanline_aa; 434 435begin 436// Initialize structures 437 pf.Construct; 438 sl.Construct; 439 440 pixfmt(pixf ,rbuf_window ); 441 442 rb.Construct(@pixf ); 443 r.Construct (@rb ); 444 445 rgba.ConstrDbl(0 ,0 ,0 ); 446 rb.clear (@rgba ); 447 448// Render the controls 449 m_profile.text_size_(8.0 ); 450 451 render_ctrl(@pf ,@sl ,@r ,@m_profile ); 452 render_ctrl(@pf ,@sl ,@r ,@m_spline_r ); 453 render_ctrl(@pf ,@sl ,@r ,@m_spline_g ); 454 render_ctrl(@pf ,@sl ,@r ,@m_spline_b ); 455 render_ctrl(@pf ,@sl ,@r ,@m_spline_a ); 456 render_ctrl(@pf ,@sl ,@r ,@m_rbox ); 457 458// Render 459 ini_scale:=1.0; 460 461 mtx1.Construct; 462 463 tas.Construct(ini_scale ,ini_scale ); mtx1.multiply(@tas ); 464 tar.Construct(deg2rad(0.0 ) ); mtx1.multiply(@tar ); 465 tat.Construct(center_x ,center_y ); mtx1.multiply(@tat ); 466 467 mtx1.multiply(_trans_affine_resizing ); 468 469 e1.Construct; 470 e1.init(0.0 ,0.0 ,110.0 ,110.0 ,64 ); 471 472 mtx_g1.Construct; 473 474 tas.Construct(ini_scale ,ini_scale ); mtx_g1.multiply(@tas ); 475 tas.Construct(m_scale ,m_scale ); mtx_g1.multiply(@tas ); 476 tas.Construct(m_scale_x ,m_scale_y ); mtx_g1.multiply(@tas ); 477 tar.Construct(m_angle ); mtx_g1.multiply(@tar ); 478 tat.Construct(m_center_x ,m_center_y ); mtx_g1.multiply(@tat ); 479 480 mtx_g1.multiply(_trans_affine_resizing ); 481 mtx_g1.invert; 482 483 for i:=0 to 255 do 484 begin 485 rgba.ConstrDbl( 486 double_ptr(ptrcomp(m_spline_r._spline ) + i * sizeof(double ) )^ , 487 double_ptr(ptrcomp(m_spline_g._spline ) + i * sizeof(double ) )^ , 488 double_ptr(ptrcomp(m_spline_b._spline ) + i * sizeof(double ) )^ , 489 double_ptr(ptrcomp(m_spline_a._spline ) + i * sizeof(double ) )^ ); 490 491 color_profile[i ]:=rgba; 492 493 end; 494 495 t1.Construct(@e1 ,@mtx1 ); 496 497 case m_rbox._cur_item of 498 0 : 499 begin 500 gr_circle.Construct; 501 gr_ptr.Construct(@gr_circle ); 502 503 end; 504 505 1 : 506 begin 507 gr_diamond.Construct; 508 gr_ptr.Construct(@gr_diamond ); 509 510 end; 511 512 2 : 513 begin 514 gr_x.Construct; 515 gr_ptr.Construct(@gr_x ); 516 517 end; 518 519 3 : 520 begin 521 gr_xy.Construct; 522 gr_ptr.Construct(@gr_xy ); 523 524 end; 525 526 4 : 527 begin 528 gr_sqrt_xy.Construct; 529 gr_ptr.Construct(@gr_sqrt_xy ); 530 531 end; 532 533 5 : 534 begin 535 gr_conic.Construct; 536 gr_ptr.Construct(@gr_conic ); 537 538 end; 539 540 end; 541 542 span_alloc.Construct; 543 colors.Construct (@color_profile ,int8u_ptr(m_profile.gamma ) ); 544 inter.Construct (@mtx_g1); 545 span_gen.Construct(@span_alloc ,@inter ,@gr_ptr ,@colors ,0 ,150 ); 546 r1.construct (@rb ,@span_gen ); 547 548 pf.add_path (@t1 ); 549 render_scanlines(@pf ,@sl ,@r1 ); 550 551// Free AGG resources 552 pf.Destruct; 553 sl.Destruct; 554 555 span_alloc.Destruct; 556 557end; 558 559{ ON_MOUSE_MOVE } 560procedure the_application.on_mouse_move; 561var 562 x2 ,y2 ,dx ,dy : double; 563 564begin 565 if m_mouse_move then 566 begin 567 x2:=x; 568 y2:=y; 569 570 _trans_affine_resizing.inverse_transform(_trans_affine_resizing ,@x2 ,@y2 ); 571 572 if flags and kbd_ctrl <> 0 then 573 begin 574 dx:=x2 - m_center_x; 575 dy:=y2 - m_center_y; 576 577 m_scale_x:=m_prev_scale_x * dx / m_pdx; 578 m_scale_y:=m_prev_scale_y * dy / m_pdy; 579 580 force_redraw; 581 582 end 583 else 584 begin 585 if flags and mouse_left <> 0 then 586 begin 587 m_center_x:=x2 + m_pdx; 588 m_center_y:=y2 + m_pdy; 589 590 force_redraw; 591 592 end; 593 594 if flags and mouse_right <> 0 then 595 begin 596 dx:=x2 - m_center_x; 597 dy:=y2 - m_center_y; 598 599 m_scale:= 600 m_prev_scale * 601 Sqrt(dx * dx + dy * dy ) / 602 Sqrt(m_pdx * m_pdx + m_pdy * m_pdy ); 603 604 m_angle:=m_prev_angle + ArcTan2(dy ,dx ) - ArcTan2(m_pdy ,m_pdx ); 605 606 force_redraw; 607 608 end; 609 610 end; 611 612 end; 613 614end; 615 616{ ON_MOUSE_BUTTON_DOWN } 617procedure the_application.on_mouse_button_down; 618var 619 x2 ,y2 : double; 620 621begin 622 m_mouse_move:=true; 623 624 x2:=x; 625 y2:=y; 626 627 _trans_affine_resizing.inverse_transform(_trans_affine_resizing ,@x2 ,@y2 ); 628 629 m_pdx:=m_center_x - x2; 630 m_pdy:=m_center_y - y2; 631 632 m_prev_scale :=m_scale; 633 m_prev_angle :=m_angle + pi; 634 m_prev_scale_x:=m_scale_x; 635 m_prev_scale_y:=m_scale_y; 636 637 force_redraw; 638 639end; 640 641{ ON_MOUSE_BUTTON_UP } 642procedure the_application.on_mouse_button_up; 643begin 644 m_mouse_move:=false; 645 646end; 647 648{ ON_KEY } 649procedure the_application.on_key; 650var 651 i : int; 652 fd : text; 653 654 buf : array[0..511 ] of char; 655 rgba : aggclr; 656 657begin 658 if key = byte(' ' ) then 659 begin 660 AssignFile(fd ,'colors.dat' ); 661 rewrite (fd ); 662 663 for i:=0 to 255 do 664 begin 665 rgba.ConstrDbl( 666 double_ptr(ptrcomp(m_spline_r._spline ) + i * sizeof(double ) )^ , 667 double_ptr(ptrcomp(m_spline_g._spline ) + i * sizeof(double ) )^ , 668 double_ptr(ptrcomp(m_spline_b._spline ) + i * sizeof(double ) )^ , 669 double_ptr(ptrcomp(m_spline_a._spline ) + i * sizeof(double ) )^ ); 670 671 sprintf(@buf[0 ] ,' %3d, ' ,rgba.r ); 672 sprintf(@buf[StrLen(@buf ) ] ,'%3d, ' ,rgba.g ); 673 sprintf(@buf[StrLen(@buf ) ] ,'%3d, ' ,rgba.b ); 674 sprintf(@buf[StrLen(@buf ) ] ,'%3d,' ,rgba.a ); 675 676 writeln(fd ,PChar(@buf[0 ] ) ); 677 678 end; 679 680 close(fd ); 681 682 AssignFile(fd ,'profile.dat' ); 683 rewrite (fd ); 684 685 for i:=0 to 255 do 686 begin 687 sprintf(@buf[0 ] ,'%3d, ' ,int8u_ptr(ptrcomp(m_profile.gamma ) + i * sizeof(int8u ) )^ ); 688 689 write(fd ,PChar(@buf[0 ] ) ); 690 691 if (i and $F) = $F then 692 writeln(fd ); 693 694 end; 695 696 close(fd ); 697 698 end; 699 700 if key = key_f1 then 701 message_( 702 'This "sphere" is rendered with color gradients only. Initially there was an idea '#13 + 703 'to compensate so called Mach Bands effect. To do so I added a gradient profile '#13 + 704 'functor. Then the concept was extended to set a color profile. As a result you '#13 + 705 'can render simple geometrical objects in 2D looking like 3D ones. In this example '#13 + 706 'you can construct your own color profile and select the gradient function. '#13 + 707 'There''re not so many gradient functions in AGG, but you can easily add your own.'#13#13 + 708 'How to play with:'#13#13 + 709 'Use the left mouse button to drag the "gradient".'#13 + 710 'Use the right mouse button to scale and rotate the "gradient".'#13 + 711 'Press the spacebar to write down the "colors.dat" file.' + 712 #13#13'Note: F2 key saves current "screenshot" file in this demo''s directory. ' ); 713 714end; 715 716VAR 717 app : the_application; 718 719BEGIN 720 app.Construct(pix_format ,flip_y ); 721 app.caption_ ('AGG gradients with Mach bands compensation (F1-Help)' ); 722 723 if app.init(512 ,400 ,window_resize or window_hw_buffer ) then 724 app.run; 725 726 app.Destruct; 727 728END.