~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/aggpas/image_filters2.dpr

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
//
7
 
program
8
 
 image_filters2 ;
9
 
 
10
 
uses
11
 
 SysUtils ,
12
 
 
13
 
 agg_basics ,
14
 
 agg_platform_support ,
15
 
 
16
 
 agg_color ,
17
 
 agg_pixfmt ,
18
 
 agg_pixfmt_rgb ,
19
 
 
20
 
 agg_ctrl ,
21
 
 agg_slider_ctrl ,
22
 
 agg_rbox_ctrl ,
23
 
 agg_cbox_ctrl ,
24
 
 
25
 
 agg_rendering_buffer ,
26
 
 agg_renderer_base ,
27
 
 agg_renderer_scanline ,
28
 
 agg_rasterizer_scanline_aa ,
29
 
 agg_scanline ,
30
 
 agg_scanline_u ,
31
 
 agg_scanline_p ,
32
 
 agg_render_scanlines ,
33
 
 
34
 
 agg_ellipse ,
35
 
 agg_trans_affine ,
36
 
 agg_conv_transform ,
37
 
 agg_conv_stroke ,
38
 
 agg_span_allocator ,
39
 
 agg_span_interpolator_linear ,
40
 
 agg_span_image_filter ,
41
 
 agg_span_image_filter_rgb ,
42
 
 agg_image_filters ,
43
 
 agg_gsv_text ,
44
 
 agg_gamma_lut ,
45
 
 agg_path_storage ;
46
 
 
47
 
{$I agg_mode.inc }
48
 
 
49
 
const
50
 
 flip_y = true;
51
 
 
52
 
 g_image : array[0..47 ] of int8u = (
53
 
 
54
 
   0,255,0,     0,0,255,     255,255,255,   255,0,0,
55
 
   255,0,0,     0,0,0,       255,255,255,   255,255,255,
56
 
   255,255,255, 255,255,255, 0,0,255,       255,0,0,
57
 
   0,0,255,     255,255,255, 0,0,0,         0,255,0 );
58
 
 
59
 
type
60
 
 the_application = object(platform_support )
61
 
   m_gamma  ,
62
 
   m_radius : slider_ctrl;
63
 
 
64
 
   m_filters   : rbox_ctrl;
65
 
   m_normalize : cbox_ctrl;
66
 
 
67
 
   m_cur_angle  : double;
68
 
   m_cur_filter ,
69
 
   m_num_steps  : int;
70
 
 
71
 
   m_num_pix ,
72
 
   m_time1   ,
73
 
   m_time2   : double;
74
 
 
75
 
   constructor Construct(format_ : pix_format_e; flip_y_ : boolean );
76
 
   destructor  Destruct;
77
 
 
78
 
   procedure on_draw; virtual;
79
 
 
80
 
   procedure on_key(x ,y : int; key ,flags : unsigned ); virtual;
81
 
 
82
 
  end;
83
 
 
84
 
{ CONSTRUCT }
85
 
constructor the_application.Construct;
86
 
var
87
 
 rgba : aggclr;
88
 
 
89
 
begin
90
 
 inherited Construct(format_ ,flip_y_ );
91
 
 
92
 
 m_gamma.Construct    (115 ,5 ,500 - 5 ,11 ,not flip_y_ );
93
 
 m_radius.Construct   (115 ,5 + 15 ,500 - 5 ,11 + 15 ,not flip_y_ );
94
 
 m_filters.Construct  (0.0 ,0.0 ,110.0 ,210.0 ,not flip_y_ );
95
 
 m_normalize.Construct(8.0 ,215.0 ,'Normalize Filter' ,not flip_y_ );
96
 
 
97
 
 m_cur_angle :=0.0;
98
 
 m_cur_filter:=1;
99
 
 m_num_steps :=0;
100
 
 
101
 
 m_num_pix:=0.0;
102
 
 m_time1  :=0;
103
 
 m_time2  :=0;
104
 
 
105
 
 add_ctrl(@m_gamma );
106
 
 add_ctrl(@m_radius );
107
 
 add_ctrl(@m_filters );
108
 
 add_ctrl(@m_normalize );
109
 
 
110
 
 m_normalize.text_size_(7.5 );
111
 
 m_normalize.status_  (true );
112
 
 
113
 
 m_radius.label_('Filter Radius=%.3f' );
114
 
 m_radius.range_(2.0 ,8.0 );
115
 
 m_radius.value_(4.0 );
116
 
 
117
 
 m_gamma.label_('Gamma=%.3f' );
118
 
 m_gamma.range_(0.5 ,3.0 );
119
 
 m_gamma.value_(1.0 );
120
 
 
121
 
 m_filters.add_item ('simple (NN)' );
122
 
 m_filters.add_item ('bilinear' );
123
 
 m_filters.add_item ('bicubic' );
124
 
 m_filters.add_item ('spline16' );
125
 
 m_filters.add_item ('spline36' );
126
 
 m_filters.add_item ('hanning' );
127
 
 m_filters.add_item ('hamming' );
128
 
 m_filters.add_item ('hermite' );
129
 
 m_filters.add_item ('kaiser' );
130
 
 m_filters.add_item ('quadric' );
131
 
 m_filters.add_item ('catrom' );
132
 
 m_filters.add_item ('gaussian' );
133
 
 m_filters.add_item ('bessel' );
134
 
 m_filters.add_item ('mitchell' );
135
 
 m_filters.add_item ('sinc' );
136
 
 m_filters.add_item ('lanczos' );
137
 
 m_filters.add_item ('blackman' );
138
 
 m_filters.cur_item_(1 );
139
 
 
140
 
 m_filters.border_width_    (0 ,0 );
141
 
 rgba.ConstrDbl             (0.0 ,0.0 ,0.0 ,0.1 );
142
 
 m_filters.background_color_(@rgba );
143
 
 m_filters.text_size_       (6.0 );
144
 
 m_filters.text_thickness_  (0.85 );
145
 
 
146
 
end;
147
 
 
148
 
{ DESTRUCT }
149
 
destructor the_application.Destruct;
150
 
begin
151
 
 inherited Destruct;
152
 
 
153
 
 m_gamma.Destruct;
154
 
 m_radius.Destruct;
155
 
 m_filters.Destruct;
156
 
 m_normalize.Destruct;
157
 
 
158
 
end;
159
 
 
160
 
{ ON_DRAW }
161
 
procedure the_application.on_draw;
162
 
const
163
 
 para : array[0..7 ] of double = (200 ,40 ,200 + 300 ,40 ,200 + 300 ,40 + 300 ,200 ,40 + 300 );
164
 
 
165
 
var
166
 
 pixf : pixel_formats;
167
 
 rgba : aggclr;
168
 
 
169
 
 rb : renderer_base;
170
 
 rs : renderer_scanline_aa_solid;
171
 
 sl : scanline_u8;
172
 
 sa : span_allocator;
173
 
 ri : renderer_scanline_aa;
174
 
 sg : span_image_filter_ptr;
175
 
 fi : image_filter_base_ptr;
176
 
 
177
 
 ras : rasterizer_scanline_aa;
178
 
 
179
 
 norm : boolean;
180
 
 
181
 
 gamma  : gamma_lut;
182
 
 stroke : conv_stroke;
183
 
 filter : image_filter_lut;
184
 
 
185
 
 img_rbuf : rendering_buffer;
186
 
 img_mtx  : trans_affine;
187
 
 weights  : int16_ptr;
188
 
 
189
 
 interpolator : span_interpolator_linear;
190
 
 
191
 
 x_start ,x_end ,y_start ,y_end ,x_center ,x ,ys ,radius ,dx ,dy ,xs : double;
192
 
 
193
 
 i ,n ,nn : unsigned;
194
 
 
195
 
 p : path_storage;
196
 
 
197
 
begin
198
 
 sg:=NIL;
199
 
 fi:=NIL;
200
 
 
201
 
// Initialize structures
202
 
 pixfmt_bgr24(pixf ,rbuf_window );
203
 
 
204
 
 rb.Construct(@pixf );
205
 
 rs.Construct(@rb );
206
 
 
207
 
 rgba.ConstrDbl(1.0 ,1.0 ,1.0 );
208
 
 rb.clear      (@rgba );
209
 
 rb.copy_from  (rbuf_img(0 ) ,0 ,110 ,35 );
210
 
 
211
 
 ras.Construct;
212
 
 sl.Construct;
213
 
 img_rbuf.Construct(@g_image[0 ] ,4 ,4 ,4 * 3 );
214
 
 
215
 
// Render
216
 
 img_mtx.Construct(@para[0 ] ,0 ,0 ,4 ,4 );
217
 
 
218
 
 interpolator.Construct(@img_mtx );
219
 
 sa.Construct;
220
 
 
221
 
 ras.reset;
222
 
 ras.move_to_d(para[0 ] ,para[1 ] );
223
 
 ras.line_to_d(para[2 ] ,para[3 ] );
224
 
 ras.line_to_d(para[4 ] ,para[5 ] );
225
 
 ras.line_to_d(para[6 ] ,para[7 ] );
226
 
 
227
 
 rgba.ConstrDbl(1 ,1 ,1 );
228
 
 filter.Construct;
229
 
 
230
 
 case m_filters._cur_item of
231
 
  0 :
232
 
   begin
233
 
    sg:=new(
234
 
     span_image_filter_rgb_nn_ptr ,
235
 
     Construct(
236
 
      @sa ,@img_rbuf ,@rgba ,@interpolator ,bgr_order ) );
237
 
 
238
 
    ri.Construct    (@rb ,sg );
239
 
    render_scanlines(@ras ,@sl ,@ri );
240
 
 
241
 
   end;
242
 
 
243
 
  1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 ,16 :
244
 
   begin
245
 
    norm:=m_normalize._status;
246
 
 
247
 
    case m_filters._cur_item of
248
 
     1  : fi:=new(image_filter_bilinear_ptr ,Construct );
249
 
     2  : fi:=new(image_filter_bicubic_ptr ,Construct );
250
 
     3  : fi:=new(image_filter_spline16_ptr ,Construct );
251
 
     4  : fi:=new(image_filter_spline36_ptr ,Construct );
252
 
     5  : fi:=new(image_filter_hanning_ptr ,Construct );
253
 
     6  : fi:=new(image_filter_hamming_ptr ,Construct );
254
 
     7  : fi:=new(image_filter_hermite_ptr ,Construct );
255
 
     8  : fi:=new(image_filter_kaiser_ptr ,Construct );
256
 
     9  : fi:=new(image_filter_quadric_ptr ,Construct );
257
 
     10 : fi:=new(image_filter_catrom_ptr ,Construct );
258
 
     11 : fi:=new(image_filter_gaussian_ptr ,Construct );
259
 
     12 : fi:=new(image_filter_bessel_ptr ,Construct );
260
 
     13 : fi:=new(image_filter_mitchell_ptr ,Construct );
261
 
     14 : fi:=new(image_filter_sinc_ptr ,Construct(m_radius._value ) );
262
 
     15 : fi:=new(image_filter_lanczos_ptr ,Construct(m_radius._value ) );
263
 
     16 : fi:=new(image_filter_blackman_ptr ,Construct(m_radius._value ) );
264
 
 
265
 
    end;
266
 
 
267
 
    filter.calculate(fi ,norm );
268
 
 
269
 
    sg:=new(
270
 
     span_image_filter_rgb_ptr ,
271
 
     Construct(
272
 
      @sa ,@img_rbuf ,@rgba ,@interpolator ,@filter ,bgr_order ) );
273
 
 
274
 
    ri.Construct    (@rb ,sg );
275
 
    render_scanlines(@ras ,@sl ,@ri );
276
 
 
277
 
   // Draw Graph
278
 
    gamma.Construct     (m_gamma._value );
279
 
    pixf.apply_gamma_inv(@gamma ,bgr_order );
280
 
 
281
 
    x_start :=5.0;
282
 
    x_end   :=195.0;
283
 
    y_start :=235.0;
284
 
    y_end   :=_initial_height - 5.0;
285
 
    x_center:=(x_start + x_end ) / 2;
286
 
 
287
 
    p.Construct;
288
 
    stroke.Construct(@p );
289
 
    stroke.width_   (0.8 );
290
 
 
291
 
    for i:=0 to 16 do
292
 
     begin
293
 
      x:=x_start + (x_end - x_start ) * i / 16.0;
294
 
 
295
 
      p.remove_all;
296
 
      p.move_to(x + 0.5 ,y_start );
297
 
      p.line_to(x + 0.5 ,y_end );
298
 
 
299
 
      ras.add_path(@stroke);
300
 
 
301
 
      if i = 8 then
302
 
       rgba.ConstrInt(0 ,0 ,0 ,255 )
303
 
      else
304
 
       rgba.ConstrInt(0 ,0 ,0 ,100 );
305
 
 
306
 
      rs.color_       (@rgba );
307
 
      render_scanlines(@ras ,@sl ,@rs );
308
 
 
309
 
     end;
310
 
 
311
 
    ys:=y_start + (y_end - y_start ) / 6.0;
312
 
 
313
 
    p.remove_all;
314
 
    p.move_to(x_start ,ys );
315
 
    p.line_to(x_end ,ys );
316
 
 
317
 
    ras.add_path    (@stroke);
318
 
    rgba.ConstrInt  (0 ,0 ,0 );
319
 
    rs.color_       (@rgba );
320
 
    render_scanlines(@ras ,@sl ,@rs );
321
 
 
322
 
    radius:=filter.radius;
323
 
 
324
 
    n :=trunc(radius * 256 * 2 );
325
 
    dx:=(x_end - x_start ) * radius / 8.0;
326
 
    dy:=y_end - ys;
327
 
 
328
 
    weights:=filter.weight_array;
329
 
 
330
 
    xs:=(x_end + x_start ) / 2.0 - (filter.diameter * (x_end - x_start ) / 32.0 );
331
 
    nn:=filter.diameter * 256;
332
 
 
333
 
    p.remove_all();
334
 
    p.move_to(xs + 0.5 ,ys + dy * int16_ptr(weights )^ / image_filter_size );
335
 
 
336
 
    i:=1;
337
 
 
338
 
    while i < nn do
339
 
     begin
340
 
      p.line_to(
341
 
       xs + dx * i / n + 0.5 ,
342
 
       ys + dy * int16_ptr(ptrcomp(weights ) + i * sizeof(int16 ) )^ / image_filter_size );
343
 
 
344
 
      inc(i );
345
 
 
346
 
     end;
347
 
 
348
 
    ras.add_path    (@stroke );
349
 
    rgba.ConstrInt  (100 ,0 ,0 );
350
 
    rs.color_       (@rgba );
351
 
    render_scanlines(@ras ,@sl ,@rs );
352
 
 
353
 
   // Free
354
 
    gamma.Destruct;
355
 
    p.Destruct;
356
 
    stroke.Destruct;
357
 
 
358
 
   end;
359
 
 
360
 
  end;
361
 
 
362
 
// Render the controls
363
 
 render_ctrl(@ras ,@sl ,@rs ,@m_gamma );
364
 
 
365
 
 if m_filters._cur_item >= 14 then
366
 
  render_ctrl(@ras ,@sl ,@rs ,@m_radius );
367
 
 
368
 
 render_ctrl(@ras ,@sl ,@rs ,@m_filters );
369
 
 render_ctrl(@ras ,@sl ,@rs ,@m_normalize );
370
 
 
371
 
// Free AGG resources
372
 
 ras.Destruct;
373
 
 sl.Destruct;
374
 
 img_rbuf.Destruct;
375
 
 
376
 
 sa.Destruct;
377
 
 filter.Destruct;
378
 
 
379
 
 if sg <> NIL then
380
 
  dispose(sg ,Destruct );
381
 
 
382
 
 if fi <> NIL then
383
 
  dispose(fi );
384
 
 
385
 
end;
386
 
 
387
 
{ ON_KEY }
388
 
procedure the_application.on_key;
389
 
begin
390
 
 if key = key_f1 then
391
 
  message_(
392
 
   'Another example that demonstrates the difference of image filters. '#13 +
393
 
   'It just displays a simple 4x4 pixels image with huge zoom. '#13 +
394
 
   'You can see how different filters affect the result. '#13 +
395
 
   'Also see how gamma correction works.' +
396
 
   #13#13'Note: F2 key saves current "screenshot" file in this demo''s directory.  ' );
397
 
 
398
 
end;
399
 
 
400
 
VAR
401
 
 app : the_application;
402
 
 
403
 
BEGIN
404
 
 app.Construct(pix_format_bgr24 ,flip_y );
405
 
 app.caption_ ('Image transformation filters comparison (F1-Help)' );
406
 
 
407
 
 if app.init(500 ,340 ,0 ) then
408
 
  app.run;
409
 
 
410
 
 app.Destruct;
411
 
 
412
 
END.
 
 
b'\\ No newline at end of file'