1
{mac_copy:compositing.bmp}
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 ,
42
agg_span_interpolator_linear ,
50
base_shift = agg_color.base_shift;
53
gradient_linear_color = object(array_base )
58
constructor Construct; overload;
59
constructor Construct(c1 ,c2 : aggclr_ptr ); overload;
61
procedure colors(c1 ,c2 : aggclr_ptr );
63
function size : unsigned; virtual;
64
function array_operator(i : unsigned ) : pointer; virtual;
68
the_application = object(platform_support )
70
m_alpha_dst : slider_ctrl;
71
m_comp_op : rbox_ctrl;
73
constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
76
procedure render_scene(rbuf : rendering_buffer_ptr; pixf : pixel_formats_ptr );
78
procedure on_init; virtual;
79
procedure on_draw; virtual;
81
procedure on_mouse_move (x ,y : int; flags : unsigned ); virtual;
82
procedure on_mouse_button_down(x ,y : int; flags : unsigned ); virtual;
83
procedure on_mouse_button_up (x ,y : int; flags : unsigned ); virtual;
85
procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
90
procedure gradient_affine(var mtx : trans_affine; x1 ,y1 ,x2 ,y2 : double; gradient_d2 : double = 100.0 );
94
tas : trans_affine_scaling;
95
tar : trans_affine_rotation;
96
tat : trans_affine_translation;
106
tas.Construct(Sqrt(dx * dx + dy * dy ) / gradient_d2 ); mtx.multiply(@tas );
107
tar.Construct(ArcTan2(dy ,dx ) ); mtx.multiply(@tar );
108
tat.Construct(x1 ,y1 ); mtx.multiply(@tat );
115
procedure circle(rbase : renderer_base_ptr; c1 ,c2 : aggclr_ptr; x1 ,y1 ,x2 ,y2 ,shadow_alpha : double );
117
color_func : gradient_linear_color;
119
gradient_func : gradient_x;
120
gradient_mtx : trans_affine;
121
span_gradient_ : span_gradient;
122
ren_gradient : renderer_scanline_aa;
123
ren_solid : renderer_scanline_aa_solid;
125
span_interpolator : span_interpolator_linear;
126
span_allocator_ : span_allocator;
130
ras : rasterizer_scanline_aa;
137
gradient_func.Construct; // The gradient function
138
gradient_affine(gradient_mtx ,x1 ,y1 ,x2 ,y2 ,100 );
140
span_interpolator.Construct(@gradient_mtx ); // Span interpolator
141
span_allocator_.Construct; // Span Allocator
142
color_func.Construct(c1 ,c2 );
144
span_gradient_.Construct(
151
ren_gradient.Construct(rbase ,@span_gradient_ );
155
r:=calc_distance(x1 ,y1 ,x2 ,y2 ) / 2;
157
ell.Construct ((x1 + x2 ) / 2 + 5 ,(y1 + y2 ) / 2 - 3 ,r ,r ,100 );
158
ren_solid.Construct(rbase );
159
rgba.ConstrDbl (0.6 ,0.6 ,0.6 ,0.7 * shadow_alpha );
160
ren_solid.color_ (@rgba );
161
ras.add_path (@ell );
162
render_scanlines (@ras ,@sl ,@ren_solid );
164
ell.init ((x1 + x2 ) / 2 ,(y1 + y2 ) / 2 ,r ,r ,100 );
165
ras.add_path (@ell );
166
render_scanlines(@ras ,@sl ,@ren_gradient );
171
span_allocator_.Destruct;
176
procedure dst_shape(rbase : renderer_base_ptr; c1 ,c2 : aggclr_ptr; x1 ,y1 ,x2 ,y2 : double );
178
color_func : gradient_linear_color;
179
shape : rounded_rect;
181
gradient_func : gradient_x;
182
gradient_mtx : trans_affine;
183
ren_gradient : renderer_scanline_aa;
185
span_interpolator : span_interpolator_linear;
186
span_allocator_ : span_allocator;
187
span_gradient_ : span_gradient;
189
ras : rasterizer_scanline_aa;
193
gradient_func.Construct; // The gradient function
194
gradient_affine(gradient_mtx ,x1 ,y1 ,x2 ,y2 ,100 );
196
span_interpolator.Construct(@gradient_mtx); // Span interpolator
197
span_allocator_.Construct; // Span Allocator
198
color_func.Construct(c1 ,c2 );
200
span_gradient_.Construct(
207
ren_gradient.Construct(rbase ,@span_gradient_ );
211
shape.Construct (x1 ,y1 ,x2 ,y2 ,40 );
212
ras.add_path (@shape );
213
render_scanlines(@ras ,@sl ,@ren_gradient );
218
span_allocator_.Destruct;
223
constructor gradient_linear_color.Construct;
232
constructor gradient_linear_color.Construct(c1 ,c2 : aggclr_ptr );
242
procedure gradient_linear_color.colors;
250
function gradient_linear_color.size;
257
function gradient_linear_color.array_operator;
259
i:=i shl (base_shift - 8 );
261
m_res.r:=int8u((((m_c2.r - m_c1.r ) * i ) + (m_c1.r shl base_shift ) ) shr base_shift );
262
m_res.g:=int8u((((m_c2.g - m_c1.g ) * i ) + (m_c1.g shl base_shift ) ) shr base_shift );
263
m_res.b:=int8u((((m_c2.b - m_c1.b ) * i ) + (m_c1.b shl base_shift ) ) shr base_shift );
264
m_res.a:=int8u((((m_c2.a - m_c1.a ) * i ) + (m_c1.a shl base_shift ) ) shr base_shift );
271
constructor the_application.Construct;
273
inherited Construct(format_ ,flip_y_ );
275
m_alpha_src.Construct(5 ,5 ,400 ,11 ,not flip_y_ );
276
m_alpha_dst.Construct(5 ,5 + 15 ,400 ,11 + 15 ,not flip_y_ );
277
m_comp_op.Construct (420 ,5.0 ,420 + 170.0 ,395.0 ,not flip_y_ );
279
m_alpha_src.label_('Src Alpha=%.2f' );
280
m_alpha_src.value_(1.0 );
282
add_ctrl(@m_alpha_src );
284
m_alpha_dst.label_('Dst Alpha=%.2f' );
285
m_alpha_dst.value_(0.75 );
287
add_ctrl(@m_alpha_dst );
289
m_comp_op.text_size_(7 );
290
m_comp_op.add_item ('clear' );
291
m_comp_op.add_item ('src' );
292
m_comp_op.add_item ('dst' );
293
m_comp_op.add_item ('src-over' );
294
m_comp_op.add_item ('dst-over' );
295
m_comp_op.add_item ('src-in' );
296
m_comp_op.add_item ('dst-in' );
297
m_comp_op.add_item ('src-out' );
298
m_comp_op.add_item ('dst-out' );
299
m_comp_op.add_item ('src-atop' );
300
m_comp_op.add_item ('dst-atop' );
301
m_comp_op.add_item ('xor' );
302
m_comp_op.add_item ('plus' );
303
m_comp_op.add_item ('minus' );
304
m_comp_op.add_item ('multiply' );
305
m_comp_op.add_item ('screen' );
306
m_comp_op.add_item ('overlay' );
307
m_comp_op.add_item ('darken' );
308
m_comp_op.add_item ('lighten' );
309
m_comp_op.add_item ('color-dodge' );
310
m_comp_op.add_item ('color-burn' );
311
m_comp_op.add_item ('hard-light' );
312
m_comp_op.add_item ('soft-light' );
313
m_comp_op.add_item ('difference' );
314
m_comp_op.add_item ('exclusion' );
315
m_comp_op.add_item ('contrast' );
316
m_comp_op.cur_item_(3 );
318
add_ctrl(@m_comp_op );
323
destructor the_application.Destruct;
327
m_alpha_src.Destruct;
328
m_alpha_dst.Destruct;
334
procedure the_application.render_scene;
336
ren_pixf ,px : pixel_formats;
337
renderer ,rb : renderer_base;
344
pixfmt_custom_blend_rgba(ren_pixf ,rbuf ,@comp_op_adaptor_rgba ,bgra_order );
346
renderer.Construct(@ren_pixf );
347
rb.Construct (pixf );
349
pixfmt_bgra32(px ,rbuf_img(1 ) );
350
rb.blend_from(@px ,NIL ,250 ,180 ,unsigned(trunc(m_alpha_src._value * 255 ) ) );
352
rgba.ConstrInt($FD ,$F0 ,$6F ,unsigned(trunc(m_alpha_src._value * 255 ) ) );
353
rgbb.ConstrInt($FE ,$9F ,$34 ,unsigned(trunc(m_alpha_src._value * 255 ) ) );
357
70 * 3 ,100 + 24 * 3 ,37 * 3 ,100 + 79 * 3 ,
358
m_alpha_src._value );
360
ren_pixf.comp_op_(m_comp_op._cur_item );
362
if m_comp_op._cur_item = 25 then // Contrast
364
v:=m_alpha_dst._value;
366
rgba.ConstrDbl(v ,v ,v );
371
300 + 50 ,100 + 24 * 3 ,107 + 50 ,100 + 79 * 3 );
376
rgba.ConstrInt($7F ,$C1 ,$FF ,unsigned(trunc(m_alpha_dst._value * 255 ) ) );
377
rgbb.ConstrInt($05 ,$00 ,$5F ,unsigned(trunc(m_alpha_dst._value * 255 ) ) );
382
300 + 50 ,100 + 24 * 3 ,107 + 50 ,100 + 79 * 3 );
389
procedure the_application.on_init;
394
procedure the_application.on_draw;
396
pixf ,pixf2 ,pixf_pre : pixel_formats;
400
rb ,rb2 ,rb_pre : renderer_base;
402
ras : rasterizer_scanline_aa;
404
ren : renderer_scanline_aa_solid;
409
buf : array[0..63 ] of char;
414
// Initialize structures
415
pixfmt_bgra32(pixf ,rbuf_window );
416
rb.Construct (@pixf );
418
rgba.ConstrInt(255 ,255 ,255 );
423
while y < rb.height do
425
x:=((y shr 3 ) and 1) shl 3;
427
while x < rb.width do
429
rgba.ConstrInt($df ,$df ,$df );
431
rb.copy_bar(x ,y ,x + 7 ,y + 7 ,@rgba );
441
create_img(0 ,rbuf_window._width ,rbuf_window._height ); // agg_platform_support functionality
443
pixfmt_bgra32(pixf2 ,rbuf_img(0 ) );
444
rb2.Construct(@pixf2 );
446
rgba.ConstrInt(0 ,0 ,0 ,0 );
449
pixfmt_bgra32_pre(pixf_pre ,rbuf_window );
450
rb_pre.Construct (@pixf_pre );
455
render_scene(rbuf_img(0 ) ,@pixf2 );
459
rb_pre.blend_from(@pixf2 );
472
sprintf (@buf[0 ] ,'%3.2f ms' ,tm );
473
t.start_point_(10.0 ,35.0 );
477
rgba.ConstrDbl (0 ,0 ,0 );
479
render_scanlines(@ras ,@sl ,@ren );
481
// Render the controls
482
render_ctrl(@ras ,@sl ,@ren ,@m_alpha_src );
483
render_ctrl(@ras ,@sl ,@ren ,@m_alpha_dst );
484
render_ctrl(@ras ,@sl ,@ren ,@m_comp_op );
486
// Free AGG resources
496
procedure the_application.on_mouse_move;
500
{ ON_MOUSE_BUTTON_DOWN }
501
procedure the_application.on_mouse_button_down;
505
{ ON_MOUSE_BUTTON_UP }
506
procedure the_application.on_mouse_button_up;
511
procedure the_application.on_key;
515
'AGG is fully compatible with all SVG 1.2 extended compositing modes. '#13#13 +
516
'How to play with:'#13#13 +
517
'Try to change the alpha values of the source an destination images,'#13 +
518
'to see, how a particular operation composes the resulting image.' +
519
#13#13'Note: F2 key saves current "screenshot" file in this demo''s directory. ' );
524
app : the_application;
525
buf : array [0..255 ] of char;
528
img_name ,p ,n ,x : shortstring;
531
app.Construct(pix_format_bgra32 ,flip_y );
532
app.caption_ ('AGG Example. Compositing Modes (F1-Help)' );
534
img_name:='compositing';
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(1 ,img_name ) then
549
img_name:=img_name + #0;
550
ext :=app._img_ext + #0;
552
if img_name = 'compositing'#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 ,400 ,window_resize ) then
b'\\ No newline at end of file'