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 blend_color ; 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 20{$IFDEF AGG_GRAY8 } 21{$DEFINE AGG_PF8 } 22{$ELSE } 23 {$IFDEF AGG_BGR24 } 24 {$DEFINE AGG_PF24 } 25 {$ELSE } 26 {$IFDEF AGG_RGB24 } 27 {$DEFINE AGG_PF24 } 28 {$ELSE } 29 {$IFDEF AGG_BGRA32 } 30 {$DEFINE AGG_PF32 } 31 {$ELSE } 32 {$IFDEF AGG_RGBA32 } 33 {$DEFINE AGG_PF32 } 34 {$ELSE } 35 {$IFDEF AGG_ARGB32 } 36 {$DEFINE AGG_PF32 } 37 {$ELSE } 38 {$IFDEF AGG_ABGR32 } 39 {$DEFINE AGG_PF32 } 40 {$ELSE } 41 {$IFDEF AGG_RGB555 } 42 {$DEFINE AGG_PF16 } 43 {$ELSE } 44 {$IFDEF AGG_RGB565 } 45 {$DEFINE AGG_PF16 } 46 {$ELSE } 47 {$ENDIF } 48 {$ENDIF } 49 {$ENDIF } 50 {$ENDIF } 51 {$ENDIF } 52 {$ENDIF } 53 {$ENDIF } 54 {$ENDIF } 55{$ENDIF } 56 57uses 58 agg_basics , 59{$IFNDEF AGG_PF8 } 60 agg_pixfmt_gray , 61{$ENDIF } 62{$IFNDEF AGG_PF32 } 63 agg_pixfmt_rgba , 64{$ENDIF } 65 agg_array , 66 agg_platform_support , 67 agg_ctrl , 68 agg_slider_ctrl , 69 agg_rbox_ctrl , 70 agg_cbox_ctrl , 71 agg_polygon_ctrl , 72 agg_renderer_base , 73 agg_rendering_buffer , 74 agg_rasterizer_scanline_aa , 75 agg_conv_curve , 76 agg_conv_contour , 77 agg_conv_stroke , 78 agg_conv_transform , 79 agg_gsv_text , 80 agg_scanline_p , 81 agg_renderer_scanline , 82 agg_bounding_rect , 83 agg_trans_perspective , 84 agg_blur , 85 agg_path_storage , 86 agg_trans_affine 87 88{$I pixel_formats.inc } 89{$I agg_mode.inc } 90 91const 92 flip_y = true; 93 94 g_gradient_colors : array[0..1023 ] of int8u = ( 95 96 255, 255, 255, 255, 97 255, 255, 254, 255, 98 255, 255, 254, 255, 99 255, 255, 254, 255, 100 255, 255, 253, 255, 101 255, 255, 253, 255, 102 255, 255, 252, 255, 103 255, 255, 251, 255, 104 255, 255, 250, 255, 105 255, 255, 248, 255, 106 255, 255, 246, 255, 107 255, 255, 244, 255, 108 255, 255, 241, 255, 109 255, 255, 238, 255, 110 255, 255, 235, 255, 111 255, 255, 231, 255, 112 255, 255, 227, 255, 113 255, 255, 222, 255, 114 255, 255, 217, 255, 115 255, 255, 211, 255, 116 255, 255, 206, 255, 117 255, 255, 200, 255, 118 255, 254, 194, 255, 119 255, 253, 188, 255, 120 255, 252, 182, 255, 121 255, 250, 176, 255, 122 255, 249, 170, 255, 123 255, 247, 164, 255, 124 255, 246, 158, 255, 125 255, 244, 152, 255, 126 254, 242, 146, 255, 127 254, 240, 141, 255, 128 254, 238, 136, 255, 129 254, 236, 131, 255, 130 253, 234, 126, 255, 131 253, 232, 121, 255, 132 253, 229, 116, 255, 133 252, 227, 112, 255, 134 252, 224, 108, 255, 135 251, 222, 104, 255, 136 251, 219, 100, 255, 137 251, 216, 96, 255, 138 250, 214, 93, 255, 139 250, 211, 89, 255, 140 249, 208, 86, 255, 141 249, 205, 83, 255, 142 248, 202, 80, 255, 143 247, 199, 77, 255, 144 247, 196, 74, 255, 145 246, 193, 72, 255, 146 246, 190, 69, 255, 147 245, 187, 67, 255, 148 244, 183, 64, 255, 149 244, 180, 62, 255, 150 243, 177, 60, 255, 151 242, 174, 58, 255, 152 242, 170, 56, 255, 153 241, 167, 54, 255, 154 240, 164, 52, 255, 155 239, 161, 51, 255, 156 239, 157, 49, 255, 157 238, 154, 47, 255, 158 237, 151, 46, 255, 159 236, 147, 44, 255, 160 235, 144, 43, 255, 161 235, 141, 41, 255, 162 234, 138, 40, 255, 163 233, 134, 39, 255, 164 232, 131, 37, 255, 165 231, 128, 36, 255, 166 230, 125, 35, 255, 167 229, 122, 34, 255, 168 228, 119, 33, 255, 169 227, 116, 31, 255, 170 226, 113, 30, 255, 171 225, 110, 29, 255, 172 224, 107, 28, 255, 173 223, 104, 27, 255, 174 222, 101, 26, 255, 175 221, 99, 25, 255, 176 220, 96, 24, 255, 177 219, 93, 23, 255, 178 218, 91, 22, 255, 179 217, 88, 21, 255, 180 216, 86, 20, 255, 181 215, 83, 19, 255, 182 214, 81, 18, 255, 183 213, 79, 17, 255, 184 212, 77, 17, 255, 185 211, 74, 16, 255, 186 210, 72, 15, 255, 187 209, 70, 14, 255, 188 207, 68, 13, 255, 189 206, 66, 13, 255, 190 205, 64, 12, 255, 191 204, 62, 11, 255, 192 203, 60, 10, 255, 193 202, 58, 10, 255, 194 201, 56, 9, 255, 195 199, 55, 9, 255, 196 198, 53, 8, 255, 197 197, 51, 7, 255, 198 196, 50, 7, 255, 199 195, 48, 6, 255, 200 193, 46, 6, 255, 201 192, 45, 5, 255, 202 191, 43, 5, 255, 203 190, 42, 4, 255, 204 188, 41, 4, 255, 205 187, 39, 3, 255, 206 186, 38, 3, 255, 207 185, 37, 2, 255, 208 183, 35, 2, 255, 209 182, 34, 1, 255, 210 181, 33, 1, 255, 211 179, 32, 1, 255, 212 178, 30, 0, 255, 213 177, 29, 0, 255, 214 175, 28, 0, 255, 215 174, 27, 0, 255, 216 173, 26, 0, 255, 217 171, 25, 0, 255, 218 170, 24, 0, 255, 219 168, 23, 0, 255, 220 167, 22, 0, 255, 221 165, 21, 0, 255, 222 164, 21, 0, 255, 223 163, 20, 0, 255, 224 161, 19, 0, 255, 225 160, 18, 0, 255, 226 158, 17, 0, 255, 227 156, 17, 0, 255, 228 155, 16, 0, 255, 229 153, 15, 0, 255, 230 152, 14, 0, 255, 231 150, 14, 0, 255, 232 149, 13, 0, 255, 233 147, 12, 0, 255, 234 145, 12, 0, 255, 235 144, 11, 0, 255, 236 142, 11, 0, 255, 237 140, 10, 0, 255, 238 139, 10, 0, 255, 239 137, 9, 0, 255, 240 135, 9, 0, 255, 241 134, 8, 0, 255, 242 132, 8, 0, 255, 243 130, 7, 0, 255, 244 128, 7, 0, 255, 245 126, 6, 0, 255, 246 125, 6, 0, 255, 247 123, 5, 0, 255, 248 121, 5, 0, 255, 249 119, 4, 0, 255, 250 117, 4, 0, 255, 251 115, 4, 0, 255, 252 113, 3, 0, 255, 253 111, 3, 0, 255, 254 109, 2, 0, 255, 255 107, 2, 0, 255, 256 105, 2, 0, 255, 257 103, 1, 0, 255, 258 101, 1, 0, 255, 259 99, 1, 0, 255, 260 97, 0, 0, 255, 261 95, 0, 0, 255, 262 93, 0, 0, 255, 263 91, 0, 0, 255, 264 90, 0, 0, 255, 265 88, 0, 0, 255, 266 86, 0, 0, 255, 267 84, 0, 0, 255, 268 82, 0, 0, 255, 269 80, 0, 0, 255, 270 78, 0, 0, 255, 271 77, 0, 0, 255, 272 75, 0, 0, 255, 273 73, 0, 0, 255, 274 72, 0, 0, 255, 275 70, 0, 0, 255, 276 68, 0, 0, 255, 277 67, 0, 0, 255, 278 65, 0, 0, 255, 279 64, 0, 0, 255, 280 63, 0, 0, 255, 281 61, 0, 0, 255, 282 60, 0, 0, 255, 283 59, 0, 0, 255, 284 58, 0, 0, 255, 285 57, 0, 0, 255, 286 56, 0, 0, 255, 287 55, 0, 0, 255, 288 54, 0, 0, 255, 289 53, 0, 0, 255, 290 53, 0, 0, 255, 291 52, 0, 0, 255, 292 52, 0, 0, 255, 293 51, 0, 0, 255, 294 51, 0, 0, 255, 295 51, 0, 0, 255, 296 50, 0, 0, 255, 297 50, 0, 0, 255, 298 51, 0, 0, 255, 299 51, 0, 0, 255, 300 51, 0, 0, 255, 301 51, 0, 0, 255, 302 52, 0, 0, 255, 303 52, 0, 0, 255, 304 53, 0, 0, 255, 305 54, 1, 0, 255, 306 55, 2, 0, 255, 307 56, 3, 0, 255, 308 57, 4, 0, 255, 309 58, 5, 0, 255, 310 59, 6, 0, 255, 311 60, 7, 0, 255, 312 62, 8, 0, 255, 313 63, 9, 0, 255, 314 64, 11, 0, 255, 315 66, 12, 0, 255, 316 68, 13, 0, 255, 317 69, 14, 0, 255, 318 71, 16, 0, 255, 319 73, 17, 0, 255, 320 75, 18, 0, 255, 321 77, 20, 0, 255, 322 79, 21, 0, 255, 323 81, 23, 0, 255, 324 83, 24, 0, 255, 325 85, 26, 0, 255, 326 87, 28, 0, 255, 327 90, 29, 0, 255, 328 92, 31, 0, 255, 329 94, 33, 0, 255, 330 97, 34, 0, 255, 331 99, 36, 0, 255, 332 102, 38, 0, 255, 333 104, 40, 0, 255, 334 107, 41, 0, 255, 335 109, 43, 0, 255, 336 112, 45, 0, 255, 337 115, 47, 0, 255, 338 117, 49, 0, 255, 339 120, 51, 0, 255, 340 123, 52, 0, 255, 341 126, 54, 0, 255, 342 128, 56, 0, 255, 343 131, 58, 0, 255, 344 134, 60, 0, 255, 345 137, 62, 0, 255, 346 140, 64, 0, 255, 347 143, 66, 0, 255, 348 145, 68, 0, 255, 349 148, 70, 0, 255, 350 151, 72, 0, 255, 351 154, 74, 0, 255 ); 352 353type 354 the_application = object(platform_support ) 355 private 356 m_method , 357 m_comp_op : rbox_ctrl; 358 m_radius : slider_ctrl; 359 360 m_r , 361 m_g , 362 m_b : cbox_ctrl; 363 364 m_shadow_ctrl : polygon_ctrl; 365 366 m_path : path_storage; 367 m_shape : conv_curve; 368 369 m_ras : rasterizer_scanline_aa; 370 m_sl : scanline_p8; 371 372 m_shape_bounds : rect_d; 373 374 m_gray8_buf : pod_array; 375 m_gray8_rbuf , 376 m_gray8_rbuf2 : rendering_buffer; 377 378 m_color_lut : pod_array; 379 380 public 381 constructor Construct(format_ : pix_format_e; flip_y_ : boolean ); 382 destructor Destruct; 383 384 procedure on_resize(sx ,sy : int ); virtual; 385 procedure on_draw; virtual; 386 387 procedure on_mouse_move (x ,y : int; flags : unsigned ); virtual; 388 procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual; 389 procedure on_mouse_button_up (x ,y : int; flags : unsigned ); virtual; 390 391 procedure on_key(x ,y : int; key ,flags : unsigned ); virtual; 392 393 end; 394 395{ CONSTRUCT } 396constructor the_application.Construct; 397var 398 shape_mtx : trans_affine; 399 400 tas : trans_affine_scaling; 401 tat : trans_affine_translation; 402 403 i : unsigned; 404 p : int8u_ptr; 405 406 rgba : aggclr; 407 408begin 409 inherited Construct(format_ ,flip_y_ ); 410 411 m_method.Construct (10.0 ,10.0 ,130.0 ,55.0 ,not flip_y_ ); 412 m_comp_op.Construct(420 + 20.0 ,5.0 ,420 + 140.0 ,395.0 ,not flip_y_ ); 413 m_radius.Construct (130 + 10.0 ,10.0 + 4.0 ,130 + 300.0 ,10.0 + 8.0 + 4.0 ,not flip_y_ ); 414 415 m_r.Construct(10.0 ,95.0 - 30 ,'Red' ,not flip_y_ ); 416 m_g.Construct(10.0 ,110.0 - 30 ,'Green' ,not flip_y_ ); 417 m_b.Construct(10.0 ,125.0 - 30 ,'Blue' ,not flip_y_ ); 418 419 m_shadow_ctrl.Construct(4 ); 420 421 m_path.Construct; 422 m_shape.Construct(@m_path ); 423 424 m_ras.Construct; 425 m_sl.Construct; 426 427 m_shape_bounds.Construct; 428 429 m_gray8_buf.Construct(sizeof(int8u ) ); 430 m_gray8_rbuf.Construct; 431 m_gray8_rbuf2.Construct; 432 433 m_color_lut.Construct(sizeof(aggclr ) ); 434 435 add_ctrl(@m_method ); 436 437 m_method.text_size_(8 ); 438 m_method.add_item ('Single Color' ); 439 m_method.add_item ('Color LUT' ); 440 m_method.cur_item_ (1 ); 441 442 add_ctrl(@m_radius ); 443 444 m_radius.range_(0.0 ,40.0 ); 445 m_radius.value_(15.0 ); 446 m_radius.label_('Blur Radius=%1.2f' ); 447 448 add_ctrl(@m_r ); 449 add_ctrl(@m_g ); 450 add_ctrl(@m_b ); 451 452 m_r.status_(true ); 453 m_b.status_(true ); 454 455 add_ctrl(@m_comp_op ); 456 457 m_comp_op.text_size_(6.6 ); 458 m_comp_op.add_item ('no compositions' ); 459 m_comp_op.add_item ('clear' ); 460 m_comp_op.add_item ('src' ); 461 m_comp_op.add_item ('dst' ); 462 m_comp_op.add_item ('src-over' ); 463 m_comp_op.add_item ('dst-over' ); 464 m_comp_op.add_item ('src-in' ); 465 m_comp_op.add_item ('dst-in' ); 466 m_comp_op.add_item ('src-out' ); 467 m_comp_op.add_item ('dst-out' ); 468 m_comp_op.add_item ('src-atop' ); 469 m_comp_op.add_item ('dst-atop' ); 470 m_comp_op.add_item ('xor' ); 471 m_comp_op.add_item ('plus' ); 472 m_comp_op.add_item ('minus' ); 473 m_comp_op.add_item ('multiply' ); 474 m_comp_op.add_item ('screen' ); 475 m_comp_op.add_item ('overlay' ); 476 m_comp_op.add_item ('darken' ); 477 m_comp_op.add_item ('lighten' ); 478 m_comp_op.add_item ('color-dodge' ); 479 m_comp_op.add_item ('color-burn' ); 480 m_comp_op.add_item ('hard-light' ); 481 m_comp_op.add_item ('soft-light' ); 482 m_comp_op.add_item ('difference' ); 483 m_comp_op.add_item ('exclusion' ); 484 m_comp_op.add_item ('contrast' ); 485 m_comp_op.add_item ('invert' ); 486 m_comp_op.add_item ('invert-rgb' ); 487 m_comp_op.cur_item_ (0 ); 488 489 add_ctrl(@m_shadow_ctrl ); 490 491 m_shadow_ctrl.in_polygon_check_(true ); 492 493 m_path.remove_all; 494 m_path.move_to(28.47 ,6.45 ); 495 m_path.curve3 (21.58 ,1.12 ,19.82 ,0.29 ); 496 m_path.curve3 (17.19 ,-0.93 ,14.21 ,-0.93 ); 497 m_path.curve3 (9.57 ,-0.93 ,6.57 ,2.25 ); 498 m_path.curve3 (3.56 ,5.42 ,3.56 ,10.60 ); 499 m_path.curve3 (3.56 ,13.87 ,5.03 ,16.26 ); 500 m_path.curve3 (7.03 ,19.58 ,11.99 ,22.51 ); 501 m_path.curve3 (16.94 ,25.44 ,28.47 ,29.64 ); 502 m_path.line_to(28.47 ,31.40 ); 503 m_path.curve3 (28.47 ,38.09 ,26.34 ,40.58 ); 504 m_path.curve3 (24.22 ,43.07 ,20.17 ,43.07 ); 505 m_path.curve3 (17.09 ,43.07 ,15.28 ,41.41 ); 506 m_path.curve3 (13.43 ,39.75 ,13.43 ,37.60 ); 507 m_path.line_to(13.53 ,34.77 ); 508 m_path.curve3 (13.53 ,32.52 ,12.38 ,31.30 ); 509 m_path.curve3 (11.23 ,30.08 ,9.38 ,30.08 ); 510 m_path.curve3 (7.57 ,30.08 ,6.42 ,31.35 ); 511 m_path.curve3 (5.27 ,32.62 ,5.27 ,34.81 ); 512 m_path.curve3 (5.27 ,39.01 ,9.57 ,42.53 ); 513 m_path.curve3 (13.87 ,46.04 ,21.63 ,46.04 ); 514 m_path.curve3 (27.59 ,46.04 ,31.40 ,44.04 ); 515 m_path.curve3 (34.28 ,42.53 ,35.64 ,39.31 ); 516 m_path.curve3 (36.52 ,37.21 ,36.52 ,30.71 ); 517 m_path.line_to(36.52 ,15.53 ); 518 m_path.curve3 (36.52 ,9.13 ,36.77 ,7.69 ); 519 m_path.curve3 (37.01 ,6.25 ,37.57 ,5.76 ); 520 m_path.curve3 (38.13 ,5.27 ,38.87 ,5.27 ); 521 m_path.curve3 (39.65 ,5.27 ,40.23 ,5.62 ); 522 m_path.curve3 (41.26 ,6.25 ,44.19 ,9.18 ); 523 m_path.line_to(44.19 ,6.45 ); 524 m_path.curve3 (38.72 ,-0.88 ,33.74 ,-0.88 ); 525 m_path.curve3 (31.35 ,-0.88 ,29.93 ,0.78 ); 526 m_path.curve3 (28.52 ,2.44 ,28.47 ,6.45 ); 527 m_path.close_polygon; 528 529 m_path.move_to(28.47 ,9.62 ); 530 m_path.line_to(28.47 ,26.66 ); 531 m_path.curve3 (21.09 ,23.73 ,18.95, 22.51 ); 532 m_path.curve3 (15.09 ,20.36 ,13.43, 18.02 ); 533 m_path.curve3 (11.77 ,15.67 ,11.77, 12.89 ); 534 m_path.curve3 (11.77 ,9.38 ,13.87, 7.06 ); 535 m_path.curve3 (15.97 ,4.74 ,18.70, 4.74 ); 536 m_path.curve3 (22.41 ,4.74 ,28.47, 9.62 ); 537 m_path.close_polygon; 538 539 shape_mtx.Construct; 540 tas.Construct (4.0 ); 541 shape_mtx.multiply(@tas ); 542 tat.Construct (150 ,100 ); 543 shape_mtx.multiply(@tat ); 544 545 m_path.transform(@shape_mtx ); 546 547 bounding_rect_single( 548 @m_shape ,0 , 549 @m_shape_bounds.x1 ,@m_shape_bounds.y1 , 550 @m_shape_bounds.x2 ,@m_shape_bounds.y2 ); 551 552 m_shadow_ctrl.xn_ptr(0 )^:=m_shape_bounds.x1; 553 m_shadow_ctrl.yn_ptr(0 )^:=m_shape_bounds.y1; 554 m_shadow_ctrl.xn_ptr(1 )^:=m_shape_bounds.x2; 555 m_shadow_ctrl.yn_ptr(1 )^:=m_shape_bounds.y1; 556 m_shadow_ctrl.xn_ptr(2 )^:=m_shape_bounds.x2; 557 m_shadow_ctrl.yn_ptr(2 )^:=m_shape_bounds.y2; 558 m_shadow_ctrl.xn_ptr(3 )^:=m_shape_bounds.x1; 559 m_shadow_ctrl.yn_ptr(3 )^:=m_shape_bounds.y2; 560 561 rgba.ConstrDbl (0 ,0.3 ,0.5 ,0.3 ); 562 m_shadow_ctrl.line_color_(@rgba ); 563 564 m_color_lut.resize(256 ); 565 566 p:=@g_gradient_colors[0 ]; 567 i:=0; 568 569 while i < 256 do 570 begin 571 if i > 63 then 572 aggclr_ptr(m_color_lut.array_operator(i ) ).ConstrInt( 573 int8u_ptr(ptrcomp(p ) + 0 * sizeof(int8u ) )^ , 574 int8u_ptr(ptrcomp(p ) + 1 * sizeof(int8u ) )^ , 575 int8u_ptr(ptrcomp(p ) + 2 * sizeof(int8u ) )^ , 576 255 ) 577 else 578 aggclr_ptr(m_color_lut.array_operator(i ) ).ConstrInt( 579 int8u_ptr(ptrcomp(p ) + 0 * sizeof(int8u ) )^ , 580 int8u_ptr(ptrcomp(p ) + 1 * sizeof(int8u ) )^ , 581 int8u_ptr(ptrcomp(p ) + 2 * sizeof(int8u ) )^ , 582 i * 4 ); 583 584 //aggclr_ptr(m_color_lut.array_operator(i ) ).premultiply; 585 586 inc(ptrcomp(p ) ,4 * sizeof(int8u ) ); 587 inc(i ); 588 589 end; 590 591end; 592 593{ DESTRUCT } 594destructor the_application.Destruct; 595begin 596 inherited Destruct; 597 598 m_method.Destruct; 599 m_comp_op.Destruct; 600 m_radius.Destruct; 601 m_r.Destruct; 602 m_g.Destruct; 603 m_b.Destruct; 604 605 m_shadow_ctrl.Destruct; 606 607 m_path.Destruct; 608 m_shape.Destruct; 609 610 m_ras.Destruct; 611 m_sl.Destruct; 612 613 m_gray8_buf.Destruct; 614 m_gray8_rbuf.Destruct; 615 m_gray8_rbuf2.Destruct; 616 617 m_color_lut.Destruct; 618 619end; 620 621{ ON_RESIZE } 622procedure the_application.on_resize(sx ,sy : int ); 623begin 624 m_gray8_buf.resize (sx * sy); 625 m_gray8_rbuf.attach(m_gray8_buf.data ,sx ,sy ,sx ); 626 627end; 628 629{ ON_DRAW } 630procedure the_application.on_draw; 631var 632 rgba : aggclr; 633 rens : renderer_scanline_aa_solid; 634 635 pixf_gray8 ,pixf ,pixf2 ,pixf_blend : pixel_formats; 636 637 renb_gray8 ,renb ,renb_blend : renderer_base; 638 639 shadow_persp : trans_perspective; 640 shadow_trans : conv_transform; 641 642 bbox ,cl : rect_d; 643 644 tm : double; 645 buf : array[0..63 ] of char; 646 t : gsv_text; 647 st : conv_stroke; 648 649 r ,g ,b : int; 650 651begin 652// Initialize structures 653 m_ras.clip_box(0 ,0 ,_width ,_height ); 654 655 pixfmt_gray8(pixf_gray8 ,@m_gray8_rbuf ); 656 657 renb_gray8.Construct(@pixf_gray8 ); 658 659 rgba.ConstrInt (0 ); 660 renb_gray8.clear(@rgba ); 661 662// Testing enhanced compositing operations. 663// Uncomment and replace renb.blend_from_* to renb_blend.blend_from_* 664 pixfmt_custom_blend_rgba(pixf_blend ,rbuf_window ,comp_op_adaptor_rgba ,bgra_order ); 665 renb_blend.Construct (@pixf_blend ); 666 667 if m_comp_op._cur_item > 0 then 668 pixf_blend.comp_op_(m_comp_op._cur_item - 1 ); 669 670 pixfmt(pixf ,rbuf_window ); 671 672 renb.Construct(@pixf ); 673 rens.Construct(@renb ); 674 675 rgba.ConstrDbl(1 ,0.95 ,0.95 ); 676 renb.clear (@rgba ); 677 678 shadow_persp.Construct( 679 m_shape_bounds.x1 ,m_shape_bounds.y1 , 680 m_shape_bounds.x2 ,m_shape_bounds.y2 , 681 pointer(m_shadow_ctrl._polygon ) ); 682 683 shadow_trans.Construct(@m_shape ,@shadow_persp ); 684 685// Render the controls Before 686 render_ctrl(@m_ras ,@m_sl ,@rens ,@m_method ); 687 render_ctrl(@m_ras ,@m_sl ,@rens ,@m_radius ); 688 render_ctrl(@m_ras ,@m_sl ,@rens ,@m_r ); 689 render_ctrl(@m_ras ,@m_sl ,@rens ,@m_g ); 690 render_ctrl(@m_ras ,@m_sl ,@rens ,@m_b ); 691 render_ctrl(@m_ras ,@m_sl ,@rens ,@m_shadow_ctrl ); 692 693 if m_r._status then 694 r:=100 695 else 696 r:=0; 697 698 if m_g._status then 699 g:=100 700 else 701 g:=0; 702 703 if m_b._status then 704 b:=100 705 else 706 b:=0; 707 708 start_timer; 709 710// Render shadow 711 m_ras.add_path(@shadow_trans ); 712 713 rgba.ConstrInt (255 ); 714 render_scanlines_aa_solid(@m_ras ,@m_sl ,@renb_gray8 ,@rgba ); 715 716// Calculate the bounding box and extend it by the blur radius 717 bbox.Construct; 718 719 bounding_rect_single(@shadow_trans ,0 ,@bbox.x1 ,@bbox.y1 ,@bbox.x2 ,@bbox.y2 ); 720 721 bbox.x1:=bbox.x1 - m_radius._value; 722 bbox.y1:=bbox.y1 - m_radius._value; 723 bbox.x2:=bbox.x2 + m_radius._value; 724 bbox.y2:=bbox.y2 + m_radius._value; 725 726 cl.Construct(0 ,0 ,_width ,_height ); 727 728 if bbox.clip(@cl ) then 729 begin 730 // Create a new pixel renderer and attach it to the main one as a child image. 731 // It returns true if the attachment suceeded. It fails if the rectangle 732 // (bbox) is fully clipped. 733 pixfmt_gray8(pixf2 ,@m_gray8_rbuf2 ); 734 735 if pixf2.attach(@pixf_gray8 ,Trunc(bbox.x1 ) ,Trunc(bbox.y1 ) ,Trunc(bbox.x2 ) ,Trunc(bbox.y2 ) ) then 736 stack_blur_gray8(@pixf2 ,uround(m_radius._value ) ,uround(m_radius._value ) ); 737 738 if m_method._cur_item = 0 then 739 begin 740 rgba.ConstrInt(r ,g ,b ); 741 742 if m_comp_op._cur_item = 0 then 743 renb.blend_from_color(@pixf2 ,@rgba ,NIL ,Trunc(bbox.x1 ) ,Trunc(bbox.y1 ) ) 744 else 745 renb_blend.blend_from_color(@pixf2 ,@rgba ,NIL ,Trunc(bbox.x1 ) ,Trunc(bbox.y1 ) ); 746 747 end 748 else 749 if m_comp_op._cur_item = 0 then 750 renb.blend_from_lut(@pixf2 ,m_color_lut.data ,NIL ,Trunc(bbox.x1 ) ,Trunc(bbox.y1 ) ) 751 else 752 renb_blend.blend_from_lut(@pixf2 ,m_color_lut.data ,NIL ,Trunc(bbox.x1 ) ,Trunc(bbox.y1 ) ); 753 754 end; 755 756 tm:=elapsed_time; 757 758// Info 759 t.Construct; 760 t.size_(10.0 ); 761 762 st.Construct(@t ); 763 st.width_ (1.5 ); 764 765 sprintf(@buf[0 ] ,'%3.2f ms' ,tm ); 766 767 t.start_point_(140.0 ,30.0 ); 768 t.text_ (@buf[0 ] ); 769 770 m_ras.add_path(@st ); 771 772 rgba.ConstrDbl (0 ,0 , 0 ); 773 render_scanlines_aa_solid(@m_ras ,@m_sl ,@renb ,@rgba ); 774 775// Render the controls After 776 render_ctrl(@m_ras ,@m_sl ,@rens ,@m_comp_op ); 777 778// Free AGG resources 779 t.Destruct; 780 st.Destruct; 781 782end; 783 784{ ON_MOUSE_MOVE } 785procedure the_application.on_mouse_move; 786begin 787 if flags and mouse_left <> 0 then 788 if m_shadow_ctrl.on_mouse_move(x ,y ,false ) then 789 force_redraw; 790 791 if flags and mouse_left = 0 then 792 on_mouse_button_up(x ,y ,flags ); 793 794end; 795 796{ ON_MOUSE_BUTTON_DOWN } 797procedure the_application.on_mouse_button_down; 798begin 799 if flags and mouse_left <> 0 then 800 if m_shadow_ctrl.on_mouse_button_down(x ,y ) then 801 force_redraw; 802 803end; 804 805{ ON_MOUSE_BUTTON_UP } 806procedure the_application.on_mouse_button_up; 807begin 808 if m_shadow_ctrl.on_mouse_button_up(x ,y ) then 809 force_redraw; 810 811end; 812 813{ ON_KEY } 814procedure the_application.on_key; 815begin 816 if key = key_f1 then 817 message_( 818 'Now you can blur rendered images rather fast!'#13 + 819 'There two algorithms are used: Stack Blur by Mario Klingemann '#13 + 820 'and Fast Recursive Gaussian Filter. The speed of both methods'#13 + 821 'does not depend on the filter radius. Mario''s method works 3-5'#13 + 822 'times faster; it doesn''t produce exactly Gaussian response,'#13 + 823 'but pretty fair for most practical purposes. The recursive filter'#13 + 824 'uses floating point arithmetic and works slower. But it is true'#13 + 825 'Gaussian filter, with theoretically infinite impulse response.'#13 + 826 'The radius (actually 2*sigma value) can be fractional and the'#13 + 827 'filter produces quite adequate result.' ); 828 829end; 830 831VAR 832 app : the_application; 833 834BEGIN 835 app.Construct(pix_format ,flip_y ); 836 app.caption_ ('AGG Example. Gaussian and Stack Blur (F1-Help)' ); 837 838 if app.init(570 ,400 ,0 ) then 839 app.run; 840 841 app.Destruct; 842 843END.