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

« back to all changes in this revision

Viewing changes to components/aggpas/src/agg_image_filters.pas

  • 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
 
// Anti-Grain Geometry - Version 2.4 (Public License)
3
 
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
 
//
5
 
// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
6
 
// Pascal Port By: Milan Marusinec alias Milano
7
 
//                 milan@marusinec.sk
8
 
//                 http://www.aggpas.org
9
 
// Copyright (c) 2005-2006
10
 
//
11
 
// Permission to copy, use, modify, sell and distribute this software
12
 
// is granted provided this copyright notice appears in all copies.
13
 
// This software is provided "as is" without express or implied
14
 
// warranty, and with no claim as to its suitability for any purpose.
15
 
//
16
 
//----------------------------------------------------------------------------
17
 
// Contact: mcseem@antigrain.com
18
 
//          mcseemagg@yahoo.com
19
 
//          http://www.antigrain.com
20
 
//
21
 
//----------------------------------------------------------------------------
22
 
//
23
 
// Image transformation filters,
24
 
// Filtering classes (image_filter_lut, image_filter),
25
 
// Basic filter shape classes
26
 
//
27
 
// [Pascal Port History] -----------------------------------------------------
28
 
//
29
 
// 23.06.2006-Milano: ptrcomp adjustments
30
 
// 01.03.2006-Milano: Unit port establishment
31
 
//
32
 
{ agg_image_filters.pas }
33
 
unit
34
 
 agg_image_filters ;
35
 
 
36
 
INTERFACE
37
 
 
38
 
{$I agg_mode.inc }
39
 
{$Q- }
40
 
{$R- }
41
 
uses
42
 
 Math ,
43
 
 agg_basics ,
44
 
 agg_math ;
45
 
 
46
 
{ TYPES DEFINITION }
47
 
const
48
 
 image_filter_shift = 14;                       //----image_filter_shift
49
 
 image_filter_size  = 1 shl image_filter_shift; //----image_filter_size
50
 
 image_filter_mask  = image_filter_size - 1;    //----image_filter_mask
51
 
 
52
 
 image_subpixel_shift = 8;                          //----image_subpixel_shift
53
 
 image_subpixel_size  = 1 shl image_subpixel_shift; //----image_subpixel_size
54
 
 image_subpixel_mask  = image_subpixel_size - 1;    //----image_subpixel_mask
55
 
 
56
 
type
57
 
 image_filter_base_ptr = ^image_filter_base;
58
 
 image_filter_base = object
59
 
   constructor Construct;
60
 
 
61
 
   function  radius : double; virtual; abstract;
62
 
   function  calc_weight(x : double ) : double; virtual; abstract;
63
 
 
64
 
   procedure set_radius(r : double ); virtual;
65
 
 
66
 
  end;
67
 
 
68
 
 image_filter_lut_ptr = ^image_filter_lut; 
69
 
 image_filter_lut = object
70
 
   m_radius   : double;
71
 
   m_diameter : unsigned;
72
 
   m_start    : int;
73
 
 
74
 
   m_weight_array : int16_ptr;
75
 
   m_max_size     : unsigned;
76
 
 
77
 
   constructor Construct; overload;
78
 
   constructor Construct(filter : image_filter_base_ptr; normalization : boolean = true ); overload;
79
 
   destructor  Destruct;
80
 
 
81
 
   procedure calculate(filter : image_filter_base_ptr; normalization : boolean = true );
82
 
 
83
 
   function  radius : double;
84
 
   function  diameter : unsigned;
85
 
   function  start : int;
86
 
   function  weight_array : int16_ptr;
87
 
 
88
 
   procedure normalize;
89
 
   procedure realloc_lut(radius_ : double );
90
 
 
91
 
  end;
92
 
 
93
 
 image_filter_ptr = ^image_filter; 
94
 
 image_filter = object(image_filter_lut )
95
 
   m_filter_function : image_filter_base_ptr;
96
 
 
97
 
   constructor Construct(filter : image_filter_base_ptr );
98
 
 
99
 
  end;
100
 
 
101
 
 image_filter_bilinear_ptr = ^image_filter_bilinear;
102
 
 image_filter_bilinear = object(image_filter_base )
103
 
   function  radius : double; virtual;
104
 
   function  calc_weight(x : double ) : double; virtual;
105
 
 
106
 
  end;
107
 
 
108
 
 image_filter_hanning_ptr = ^image_filter_hanning;
109
 
 image_filter_hanning = object(image_filter_base )
110
 
   function  radius : double; virtual;
111
 
   function  calc_weight(x : double ) : double; virtual;
112
 
 
113
 
  end;
114
 
 
115
 
 image_filter_hamming_ptr = ^image_filter_hamming;
116
 
 image_filter_hamming = object(image_filter_base )
117
 
   function  radius : double; virtual;
118
 
   function  calc_weight(x : double ) : double; virtual;
119
 
 
120
 
  end;
121
 
 
122
 
 image_filter_hermite_ptr = ^image_filter_hermite;
123
 
 image_filter_hermite = object(image_filter_base )
124
 
   function  radius : double; virtual;
125
 
   function  calc_weight(x : double ) : double; virtual;
126
 
 
127
 
  end;
128
 
 
129
 
 image_filter_quadric_ptr = ^image_filter_quadric;
130
 
 image_filter_quadric = object(image_filter_base )
131
 
   function  radius : double; virtual;
132
 
   function  calc_weight(x : double ) : double; virtual;
133
 
 
134
 
  end;
135
 
 
136
 
 image_filter_bicubic_ptr = ^image_filter_bicubic;
137
 
 image_filter_bicubic = object(image_filter_base )
138
 
   function  pow3(x : double ) : double;
139
 
 
140
 
   function  radius : double; virtual;
141
 
   function  calc_weight(x : double ) : double; virtual;
142
 
 
143
 
  end;
144
 
 
145
 
 image_filter_kaiser_ptr = ^image_filter_kaiser;
146
 
 image_filter_kaiser = object(image_filter_base )
147
 
   a ,i0a ,epsilon : double;
148
 
 
149
 
   constructor Construct(b : double = 6.33 );
150
 
 
151
 
   function  radius : double; virtual;
152
 
   function  calc_weight(x : double ) : double; virtual;
153
 
 
154
 
   function  bessel_i0(x : double ) : double;
155
 
 
156
 
  end;
157
 
 
158
 
 image_filter_catrom_ptr = ^image_filter_catrom;
159
 
 image_filter_catrom = object(image_filter_base )
160
 
   function  radius : double; virtual;
161
 
   function  calc_weight(x : double ) : double; virtual;
162
 
 
163
 
  end;
164
 
 
165
 
 image_filter_mitchell_ptr = ^image_filter_mitchell;
166
 
 image_filter_mitchell = object(image_filter_base )
167
 
   p0 ,p2 ,p3 ,
168
 
   q0 ,q1 ,q2 ,q3 : double;
169
 
 
170
 
   constructor Construct(b : double = 1.0 / 3.0; c : double = 1.0 / 3.0 );
171
 
 
172
 
   function  radius : double; virtual;
173
 
   function  calc_weight(x : double ) : double; virtual;
174
 
 
175
 
  end;
176
 
 
177
 
 image_filter_spline16_ptr = ^image_filter_spline16;
178
 
 image_filter_spline16 = object(image_filter_base )
179
 
   function  radius : double; virtual;
180
 
   function  calc_weight(x : double ) : double; virtual;
181
 
 
182
 
  end;
183
 
 
184
 
 image_filter_spline36_ptr = ^image_filter_spline36;
185
 
 image_filter_spline36 = object(image_filter_base )
186
 
   function  radius : double; virtual;
187
 
   function  calc_weight(x : double ) : double; virtual;
188
 
 
189
 
  end;
190
 
 
191
 
 image_filter_gaussian_ptr = ^image_filter_gaussian;
192
 
 image_filter_gaussian = object(image_filter_base )
193
 
   function  radius : double; virtual;
194
 
   function  calc_weight(x : double ) : double; virtual;
195
 
 
196
 
  end;
197
 
 
198
 
 image_filter_bessel_ptr = ^image_filter_bessel;
199
 
 image_filter_bessel = object(image_filter_base )
200
 
   function  radius : double; virtual;
201
 
   function  calc_weight(x : double ) : double; virtual;
202
 
 
203
 
  end;
204
 
 
205
 
 image_filter_sinc_ptr = ^image_filter_sinc;
206
 
 image_filter_sinc = object(image_filter_base )
207
 
   m_radius : double;
208
 
 
209
 
   constructor Construct(r : double );
210
 
 
211
 
   function  radius : double; virtual;
212
 
   function  calc_weight(x : double ) : double; virtual;
213
 
 
214
 
   procedure set_radius(r : double ); virtual;
215
 
 
216
 
  end;
217
 
 
218
 
 image_filter_lanczos_ptr = ^image_filter_lanczos;
219
 
 image_filter_lanczos = object(image_filter_base )
220
 
   m_radius : double;
221
 
 
222
 
   constructor Construct(r : double );
223
 
 
224
 
   function  radius : double; virtual;
225
 
   function  calc_weight(x : double ) : double; virtual;
226
 
 
227
 
   procedure set_radius(r : double ); virtual;
228
 
 
229
 
  end;
230
 
 
231
 
 image_filter_blackman_ptr = ^image_filter_blackman;
232
 
 image_filter_blackman = object(image_filter_base )
233
 
   m_radius : double;
234
 
 
235
 
   constructor Construct(r : double );
236
 
 
237
 
   function  radius : double; virtual;
238
 
   function  calc_weight(x : double ) : double; virtual;
239
 
 
240
 
   procedure set_radius(r : double ); virtual;
241
 
 
242
 
  end;
243
 
 
244
 
 image_filter_sinc36_ptr = ^image_filter_sinc36;
245
 
 image_filter_sinc36 = object(image_filter_sinc )
246
 
   constructor Construct;
247
 
 
248
 
  end;
249
 
 
250
 
 image_filter_sinc64_ptr = ^image_filter_sinc64;
251
 
 image_filter_sinc64 = object(image_filter_sinc )
252
 
   constructor Construct;
253
 
 
254
 
  end;
255
 
 
256
 
 image_filter_sinc100_ptr = ^image_filter_sinc100;
257
 
 image_filter_sinc100 = object(image_filter_sinc )
258
 
   constructor Construct;
259
 
 
260
 
  end;
261
 
 
262
 
 image_filter_sinc144_ptr = ^image_filter_sinc144;
263
 
 image_filter_sinc144 = object(image_filter_sinc )
264
 
   constructor Construct;
265
 
 
266
 
  end;
267
 
 
268
 
 image_filter_sinc196_ptr = ^image_filter_sinc196; 
269
 
 image_filter_sinc196 = object(image_filter_sinc )
270
 
   constructor Construct;
271
 
 
272
 
  end;
273
 
 
274
 
 image_filter_sinc256_ptr = ^image_filter_sinc256;
275
 
 image_filter_sinc256 = object(image_filter_sinc )
276
 
   constructor Construct;
277
 
 
278
 
  end;
279
 
 
280
 
 image_filter_lanczos36_ptr = ^image_filter_lanczos36;
281
 
 image_filter_lanczos36 = object(image_filter_lanczos )
282
 
   constructor Construct;
283
 
 
284
 
  end;
285
 
 
286
 
 image_filter_lanczos64_ptr = ^image_filter_lanczos64;
287
 
 image_filter_lanczos64 = object(image_filter_lanczos )
288
 
   constructor Construct;
289
 
 
290
 
  end;
291
 
 
292
 
 image_filter_lanczos100_ptr = ^image_filter_lanczos100;
293
 
 image_filter_lanczos100 = object(image_filter_lanczos )
294
 
   constructor Construct;
295
 
 
296
 
  end;
297
 
 
298
 
 image_filter_lanczos144_ptr = ^image_filter_lanczos144;
299
 
 image_filter_lanczos144 = object(image_filter_lanczos )
300
 
   constructor Construct;
301
 
 
302
 
  end;
303
 
 
304
 
 image_filter_lanczos196_ptr = ^image_filter_lanczos196;
305
 
 image_filter_lanczos196 = object(image_filter_lanczos )
306
 
   constructor Construct;
307
 
 
308
 
  end;
309
 
 
310
 
 image_filter_lanczos256_ptr = ^image_filter_lanczos256;
311
 
 image_filter_lanczos256 = object(image_filter_lanczos )
312
 
   constructor Construct;
313
 
 
314
 
  end;
315
 
 
316
 
 image_filter_blackman36_ptr = ^image_filter_blackman36;
317
 
 image_filter_blackman36 = object(image_filter_blackman )
318
 
   constructor Construct;
319
 
 
320
 
  end;
321
 
 
322
 
 image_filter_blackman64_ptr = ^image_filter_blackman64;
323
 
 image_filter_blackman64 = object(image_filter_blackman )
324
 
   constructor Construct;
325
 
 
326
 
  end;
327
 
 
328
 
 image_filter_blackman100_ptr = ^image_filter_blackman100;
329
 
 image_filter_blackman100 = object(image_filter_blackman )
330
 
   constructor Construct;
331
 
 
332
 
  end;
333
 
 
334
 
 image_filter_blackman144_ptr = ^image_filter_blackman144;
335
 
 image_filter_blackman144 = object(image_filter_blackman )
336
 
   constructor Construct;
337
 
 
338
 
  end;
339
 
 
340
 
 image_filter_blackman196_ptr = ^image_filter_blackman196;
341
 
 image_filter_blackman196 = object(image_filter_blackman )
342
 
   constructor Construct;
343
 
 
344
 
  end;
345
 
 
346
 
 image_filter_blackman256_ptr = ^image_filter_blackman256; 
347
 
 image_filter_blackman256 = object(image_filter_blackman )
348
 
   constructor Construct;
349
 
 
350
 
  end;
351
 
 
352
 
{ GLOBAL PROCEDURES }
353
 
 
354
 
 
355
 
IMPLEMENTATION
356
 
{ LOCAL VARIABLES & CONSTANTS }
357
 
{ UNIT IMPLEMENTATION }
358
 
{ CONSTRUCT }
359
 
constructor image_filter_base.Construct;
360
 
begin
361
 
end;
362
 
 
363
 
{ SET_RADIUS }
364
 
procedure image_filter_base.set_radius;
365
 
begin
366
 
end;
367
 
 
368
 
{ CONSTRUCT }
369
 
constructor image_filter_lut.Construct;
370
 
begin
371
 
 m_weight_array:=NIL;
372
 
 m_max_size    :=0;
373
 
 
374
 
end;
375
 
 
376
 
{ CONSTRUCT }
377
 
constructor image_filter_lut.Construct(filter : image_filter_base_ptr; normalization : boolean = true );
378
 
begin
379
 
 m_weight_array:=NIL;
380
 
 m_max_size    :=0;
381
 
 
382
 
 calculate(filter ,normalization );
383
 
 
384
 
end;
385
 
 
386
 
{ DESTRUCT }
387
 
destructor image_filter_lut.Destruct;
388
 
begin
389
 
 agg_freemem(pointer(m_weight_array ) ,m_max_size * sizeof(int16 ) );
390
 
 
391
 
end;
392
 
 
393
 
{ CALCULATE }
394
 
procedure image_filter_lut.calculate;
395
 
var
396
 
 r ,x ,y : double;
397
 
 
398
 
 i ,pivot ,end_ : unsigned;
399
 
 
400
 
begin
401
 
 r:=filter.radius;
402
 
 
403
 
 realloc_lut(r );
404
 
 
405
 
 pivot:=diameter shl (image_subpixel_shift - 1 );
406
 
 
407
 
 i:=0;
408
 
 
409
 
 while i < pivot do
410
 
  begin
411
 
   x:=i / image_subpixel_size;
412
 
   y:=filter.calc_weight(x );
413
 
 
414
 
   int16_ptr(ptrcomp(m_weight_array ) + (pivot + i ) * sizeof(int16 ) )^:=
415
 
    int16(trunc(y * image_filter_size + 0.5 ) );
416
 
 
417
 
   int16_ptr(ptrcomp(m_weight_array ) + (pivot - i ) * sizeof(int16 ) )^:=
418
 
    int16_ptr(ptrcomp(m_weight_array ) + (pivot + i ) * sizeof(int16 ) )^;
419
 
 
420
 
   inc(i );
421
 
 
422
 
  end;
423
 
 
424
 
 end_:=(diameter shl image_subpixel_shift ) - 1;
425
 
 
426
 
 int16_ptr(ptrcomp(m_weight_array ) + 0 * sizeof(int16 ) )^:=
427
 
  int16_ptr(ptrcomp(m_weight_array ) + end_ * sizeof(int16 ) )^;
428
 
 
429
 
 if normalization then
430
 
  normalize;
431
 
 
432
 
end;
433
 
 
434
 
{ RADIUS }
435
 
function image_filter_lut.radius;
436
 
begin
437
 
 result:=m_radius;
438
 
 
439
 
end;
440
 
 
441
 
{ DIAMETER }
442
 
function image_filter_lut.diameter;
443
 
begin
444
 
 result:=m_diameter;
445
 
 
446
 
end;
447
 
 
448
 
{ START }
449
 
function image_filter_lut.start;
450
 
begin
451
 
 result:=m_start;
452
 
 
453
 
end;
454
 
 
455
 
{ WEIGHT_ARRAY }
456
 
function image_filter_lut.weight_array;
457
 
begin
458
 
 result:=m_weight_array;
459
 
 
460
 
end;
461
 
 
462
 
{ NORMALIZE }
463
 
// This function normalizes integer values and corrects the rounding
464
 
// errors. It doesn't do anything with the source floating point values
465
 
// (m_weight_array_dbl), it corrects only integers according to the rule
466
 
// of 1.0 which means that any sum of pixel weights must be equal to 1.0.
467
 
// So, the filter function must produce a graph of the proper shape.
468
 
procedure image_filter_lut.normalize;
469
 
var
470
 
 k : double;
471
 
 
472
 
 i ,j ,idx ,pivot ,end_ : unsigned;
473
 
 
474
 
 flip ,sum ,inc_ ,v : int;
475
 
 
476
 
begin
477
 
 flip:=1;
478
 
 i   :=0;
479
 
 
480
 
 while i < image_subpixel_size do
481
 
  begin
482
 
   repeat
483
 
    sum:=0;
484
 
 
485
 
    for j:=0 to m_diameter - 1 do
486
 
     inc(
487
 
      sum ,
488
 
      int16_ptr(ptrcomp(m_weight_array ) + (j * image_subpixel_size + i ) * sizeof(int16 ) )^ );
489
 
 
490
 
    if sum = image_filter_size then
491
 
     break;
492
 
 
493
 
    k  :=image_filter_size / sum;
494
 
    sum:=0;
495
 
 
496
 
    for j:=0 to m_diameter - 1 do
497
 
     begin
498
 
      int16_ptr(ptrcomp(m_weight_array ) + (j * image_subpixel_size + i ) * sizeof(int16 ) )^:=
499
 
       int16(trunc(int16_ptr(ptrcomp(m_weight_array ) + (j * image_subpixel_size + i ) * sizeof(int16 ) )^ * k ) );
500
 
 
501
 
      inc(sum ,int16_ptr(ptrcomp(m_weight_array ) + (j * image_subpixel_size + i ) * sizeof(int16 ) )^ );
502
 
 
503
 
     end;
504
 
 
505
 
    dec(sum ,image_filter_size );
506
 
 
507
 
    if sum > 0 then
508
 
     inc_:=-1
509
 
    else
510
 
     inc_:=1;
511
 
 
512
 
    j:=0;
513
 
 
514
 
    while (j < m_diameter ) and
515
 
          (sum <> 0 ) do
516
 
     begin
517
 
      flip:=flip xor 1;
518
 
 
519
 
      if flip <> 0 then
520
 
       idx:=m_diameter div 2 + j div 2
521
 
      else
522
 
       idx:=m_diameter div 2 - j div 2;
523
 
 
524
 
      v:=int16_ptr(ptrcomp(m_weight_array ) + (idx * image_subpixel_size + i ) * sizeof(int16 ) )^;
525
 
 
526
 
      if v < image_filter_size then
527
 
       begin
528
 
        inc(
529
 
         int16_ptr(ptrcomp(m_weight_array ) + (idx * image_subpixel_size + i ) * sizeof(int16 ) )^ ,
530
 
         inc_ );
531
 
 
532
 
        inc(sum ,inc_ );
533
 
 
534
 
       end;
535
 
 
536
 
      inc(j );
537
 
 
538
 
     end;
539
 
 
540
 
   until false;
541
 
 
542
 
   inc(i );
543
 
 
544
 
  end;
545
 
 
546
 
 pivot:=m_diameter shl (image_subpixel_shift - 1 );
547
 
 
548
 
 for i:=0 to pivot - 1 do
549
 
  int16_ptr(ptrcomp(m_weight_array ) + (pivot + i ) * sizeof(int16 ) )^:=
550
 
   int16_ptr(ptrcomp(m_weight_array ) + (pivot - i ) * sizeof(int16 ) )^;
551
 
 
552
 
 end_:=(diameter shl image_subpixel_shift ) - 1;
553
 
 
554
 
 int16_ptr(ptrcomp(m_weight_array ) + 0 * sizeof(int16 ) )^:=
555
 
  int16_ptr(ptrcomp(m_weight_array ) + end_ * sizeof(int16 ) )^;
556
 
 
557
 
end;
558
 
 
559
 
{ REALLOC_LUT }
560
 
procedure image_filter_lut.realloc_lut;
561
 
var
562
 
 size : unsigned;
563
 
 
564
 
begin
565
 
 m_radius  :=radius_;
566
 
 m_diameter:=unsigned(trunc(Ceil(radius_ ) ) ) * 2 ;
567
 
 m_start   :=-int(m_diameter div 2 - 1 );
568
 
 
569
 
 size:=m_diameter shl image_subpixel_shift;
570
 
 
571
 
 if size > m_max_size then
572
 
  begin
573
 
   agg_freemem(pointer(m_weight_array ) ,m_max_size * sizeof(int16 ) );
574
 
   agg_getmem (pointer(m_weight_array ) ,size * sizeof(int16 ) );
575
 
 
576
 
   m_max_size:=size;
577
 
 
578
 
  end;
579
 
 
580
 
end;
581
 
 
582
 
{ CONSTRUCT }
583
 
constructor image_filter.Construct;
584
 
begin
585
 
 inherited Construct;
586
 
 
587
 
 m_filter_function:=filter;
588
 
 
589
 
 calculate(m_filter_function );
590
 
 
591
 
end;
592
 
 
593
 
{ RADIUS }
594
 
function image_filter_bilinear.radius;
595
 
begin
596
 
 result:=1.0;
597
 
end;
598
 
 
599
 
{ CALC_WEIGHT }
600
 
function image_filter_bilinear.calc_weight;
601
 
begin
602
 
 result:=1.0 - x;
603
 
 
604
 
end;
605
 
 
606
 
{ RADIUS }
607
 
function image_filter_hanning.radius;
608
 
begin
609
 
 result:=1.0;
610
 
 
611
 
end;
612
 
 
613
 
{ CALC_WEIGHT }
614
 
function image_filter_hanning.calc_weight;
615
 
begin
616
 
 result:=0.5 + 0.5 * Cos(pi * x );
617
 
 
618
 
end;
619
 
 
620
 
{ RADIUS }
621
 
function image_filter_hamming.radius;
622
 
begin
623
 
 result:=1.0;
624
 
 
625
 
end;
626
 
 
627
 
{ CALC_WEIGHT }
628
 
function image_filter_hamming.calc_weight;
629
 
begin
630
 
 result:=0.54 + 0.46 * Cos(pi * x );
631
 
 
632
 
end;
633
 
 
634
 
{ RADIUS }
635
 
function image_filter_hermite.radius;
636
 
begin
637
 
 result:=1.0;
638
 
 
639
 
end;
640
 
 
641
 
{ CALC_WEIGHT }
642
 
function image_filter_hermite.calc_weight;
643
 
begin
644
 
 result:=(2.0 * x - 3.0 ) * x * x + 1.0;
645
 
 
646
 
end;
647
 
 
648
 
{ RADIUS }
649
 
function image_filter_quadric.radius;
650
 
begin
651
 
 result:=1.5;
652
 
 
653
 
end;
654
 
 
655
 
{ CALC_WEIGHT }
656
 
function image_filter_quadric.calc_weight;
657
 
var
658
 
 t : double;
659
 
 
660
 
begin
661
 
 if x < 0.5 then
662
 
  result:=0.75 - x * x
663
 
 else
664
 
  if x <  1.5 then
665
 
   begin
666
 
    t:=x - 1.5;
667
 
 
668
 
    result:=0.5 * t * t;
669
 
 
670
 
   end
671
 
  else
672
 
   result:=0.0;
673
 
 
674
 
end;
675
 
 
676
 
{ POW3 }
677
 
function image_filter_bicubic.pow3;
678
 
begin
679
 
 if x <= 0.0 then
680
 
  result:=0.0
681
 
 else
682
 
  result:=x * x * x;
683
 
 
684
 
end;
685
 
 
686
 
{ RADIUS }
687
 
function image_filter_bicubic.radius;
688
 
begin
689
 
 result:=2.0;
690
 
 
691
 
end;
692
 
 
693
 
{ CALC_WEIGHT }
694
 
function image_filter_bicubic.calc_weight;
695
 
begin
696
 
 result:=
697
 
  (1.0 / 6.0 ) *
698
 
  (pow3(x + 2 ) - 4 * pow3(x + 1 ) + 6 * pow3(x ) - 4 * pow3(x - 1 ) );
699
 
 
700
 
end;
701
 
 
702
 
{ CONSTRUCT }
703
 
constructor image_filter_kaiser.Construct;
704
 
begin
705
 
 a:=b;
706
 
 
707
 
 epsilon:=1e-12;
708
 
 
709
 
 i0a:=1.0 / bessel_i0(b );
710
 
 
711
 
end;
712
 
 
713
 
{ RADIUS }
714
 
function image_filter_kaiser.radius;
715
 
begin
716
 
 result:=1.0;
717
 
 
718
 
end;
719
 
 
720
 
{ CALC_WEIGHT }
721
 
function image_filter_kaiser.calc_weight;
722
 
begin
723
 
 result:=bessel_i0(a * Sqrt(1.0 - x * x ) ) * i0a;
724
 
 
725
 
end;
726
 
 
727
 
{ BESSEL_I0 }
728
 
function image_filter_kaiser.bessel_i0;
729
 
var
730
 
 i : int;
731
 
 
732
 
 sum ,y ,t : double;
733
 
 
734
 
begin
735
 
 sum:=1;
736
 
 
737
 
 y:=x * x / 4.;
738
 
 t:=y;
739
 
 i:=2;
740
 
 
741
 
 while t > epsilon do
742
 
  begin
743
 
   sum:=sum + t;
744
 
 
745
 
   t:=t * (y / (i * i ) );
746
 
 
747
 
   inc(i );
748
 
 
749
 
  end;
750
 
 
751
 
 result:=sum;
752
 
 
753
 
end;
754
 
 
755
 
{ RADIUS }
756
 
function image_filter_catrom.radius;
757
 
begin
758
 
 result:=2.0;
759
 
 
760
 
end;
761
 
 
762
 
{ CALC_WEIGHT }
763
 
function image_filter_catrom.calc_weight;
764
 
begin
765
 
 if x < 1.0 then
766
 
  result:=0.5 * (2.0 + x * x * (-5.0 + x * 3.0 ) )
767
 
 else
768
 
  if x < 2.0 then
769
 
   result:=0.5 * (4.0 + x * (-8.0 + x * (5.0 - x ) ) )
770
 
  else
771
 
   result:=0.0;
772
 
 
773
 
end;
774
 
 
775
 
{ CONSTRUCT }
776
 
constructor image_filter_mitchell.Construct;
777
 
begin
778
 
 p0:=(6.0 - 2.0 * b ) / 6.0;
779
 
 p2:=(-18.0 + 12.0 * b + 6.0 * c ) / 6.0;
780
 
 p3:=(12.0 - 9.0 * b - 6.0 * c ) / 6.0;
781
 
 q0:=(8.0 * b + 24.0 * c ) / 6.0;
782
 
 q1:=(-12.0 * b - 48.0 * c ) / 6.0;
783
 
 q2:=(6.0 * b + 30.0 * c ) / 6.0;
784
 
 q3:=(-b - 6.0 * c ) / 6.0;
785
 
 
786
 
end;
787
 
 
788
 
{ RADIUS }
789
 
function image_filter_mitchell.radius;
790
 
begin
791
 
 result:=2.0;
792
 
 
793
 
end;
794
 
 
795
 
{ CALC_WEIGHT }
796
 
function image_filter_mitchell.calc_weight;
797
 
begin
798
 
 if x < 1.0 then
799
 
  result:=p0 + x * x * (p2 + x * p3 )
800
 
 else
801
 
  if x < 2.0 then
802
 
   result:=q0 + x * (q1 + x * (q2 + x * q3 ) )
803
 
  else
804
 
   result:=0.0;
805
 
 
806
 
end;
807
 
 
808
 
{ RADIUS }
809
 
function image_filter_spline16.radius;
810
 
begin
811
 
 result:=2.0;
812
 
 
813
 
end;
814
 
 
815
 
{ CALC_WEIGHT }
816
 
function image_filter_spline16.calc_weight;
817
 
begin
818
 
 if x < 1.0 then
819
 
  result:=((x - 9.0 / 5.0 ) * x - 1.0 / 5.0 ) * x + 1.0
820
 
 else
821
 
  result:=((-1.0 / 3.0 * (x - 1 ) + 4.0 / 5.0) * (x - 1 ) - 7.0 / 15.0 ) * (x - 1 );
822
 
 
823
 
end;
824
 
 
825
 
{ RADIUS }
826
 
function image_filter_spline36.radius;
827
 
begin
828
 
 result:=3.0;
829
 
 
830
 
end;
831
 
 
832
 
{ CALC_WEIGHT }
833
 
function image_filter_spline36.calc_weight;
834
 
begin
835
 
 if x < 1.0 then
836
 
  result:=((13.0 / 11.0 * x - 453.0 / 209.0 ) * x - 3.0 / 209.0 ) * x + 1.0
837
 
 else
838
 
  if x < 2.0 then
839
 
   result:=((-6.0 / 11.0 * (x - 1 ) + 270.0 / 209.0 ) * (x - 1 ) - 156.0 / 209.0 ) * (x - 1 )
840
 
  else
841
 
   result:=((1.0 / 11.0 * (x - 2 ) - 45.0 / 209.0 ) * (x - 2 ) +  26.0 / 209.0 ) * (x - 2 );
842
 
 
843
 
end;
844
 
 
845
 
{ RADIUS }
846
 
function image_filter_gaussian.radius;
847
 
begin
848
 
 result:=2.0;
849
 
 
850
 
end;
851
 
 
852
 
{ CALC_WEIGHT }
853
 
function image_filter_gaussian.calc_weight;
854
 
begin
855
 
 result:=Exp(-2.0 * x * x ) * Sqrt(2.0 / pi );
856
 
 
857
 
end;
858
 
 
859
 
{ RADIUS }
860
 
function image_filter_bessel.radius;
861
 
begin
862
 
 result:=3.2383;
863
 
 
864
 
end;
865
 
 
866
 
{ CALC_WEIGHT }
867
 
function image_filter_bessel.calc_weight;
868
 
begin
869
 
 if x = 0.0 then
870
 
  result:=pi / 4.0
871
 
 else
872
 
  result:=besj(pi * x ,1 ) / (2.0 * x );
873
 
 
874
 
end;
875
 
 
876
 
{ CONSTRUCT }
877
 
constructor image_filter_sinc.Construct;
878
 
begin
879
 
 if r < 2.0 then
880
 
  m_radius:=2.0
881
 
 else
882
 
  m_radius:=r;
883
 
 
884
 
end;
885
 
 
886
 
{ RADIUS }
887
 
function image_filter_sinc.radius;
888
 
begin
889
 
 result:=m_radius;
890
 
 
891
 
end;
892
 
 
893
 
{ CALC_WEIGHT }
894
 
function image_filter_sinc.calc_weight;
895
 
begin
896
 
 if x = 0.0 then
897
 
  result:=1.0
898
 
 else
899
 
  begin
900
 
   x:=x * pi;
901
 
 
902
 
   result:=Sin(x ) / x;
903
 
 
904
 
  end;
905
 
 
906
 
end;
907
 
 
908
 
{ SET_RADIUS }
909
 
procedure image_filter_sinc.set_radius;
910
 
begin
911
 
 if r < 2.0 then
912
 
  m_radius:=2.0
913
 
 else
914
 
  m_radius:=r;
915
 
 
916
 
end;
917
 
 
918
 
{ CONSTRUCT }
919
 
constructor image_filter_lanczos.Construct;
920
 
begin
921
 
 if r < 2.0 then
922
 
  m_radius:=2.0
923
 
 else
924
 
  m_radius:=r;
925
 
 
926
 
end;
927
 
 
928
 
{ RADIUS }
929
 
function image_filter_lanczos.radius;
930
 
begin
931
 
 result:=m_radius;
932
 
 
933
 
end;
934
 
 
935
 
{ CALC_WEIGHT }
936
 
function image_filter_lanczos.calc_weight;
937
 
var
938
 
 xr : double;
939
 
 
940
 
begin
941
 
 if x = 0.0 then
942
 
  result:=1.0
943
 
 else
944
 
  if x > m_radius then
945
 
   result:=0.0
946
 
  else
947
 
   begin
948
 
    x :=x * pi;
949
 
    xr:=x / m_radius;
950
 
 
951
 
    result:=(Sin(x ) / x ) * (Sin(xr ) / xr );
952
 
 
953
 
   end;
954
 
 
955
 
end;
956
 
 
957
 
{ SET_RADIUS }
958
 
procedure image_filter_lanczos.set_radius;
959
 
begin
960
 
 if r < 2.0 then
961
 
  m_radius:=2.0
962
 
 else
963
 
  m_radius:=r;
964
 
 
965
 
end;
966
 
 
967
 
{ CONSTRUCT }
968
 
constructor image_filter_blackman.Construct;
969
 
begin
970
 
 if r < 2.0 then
971
 
  m_radius:=2.0
972
 
 else
973
 
  m_radius:=r;
974
 
 
975
 
end;
976
 
 
977
 
{ RADIUS }
978
 
function image_filter_blackman.radius;
979
 
begin
980
 
 result:=m_radius;
981
 
 
982
 
end;
983
 
 
984
 
{ CALC_WEIGHT }
985
 
function image_filter_blackman.calc_weight;
986
 
var
987
 
 xr : double;
988
 
 
989
 
begin
990
 
 if x = 0.0 then
991
 
  result:=1.0
992
 
 else
993
 
  if x > m_radius then
994
 
   result:=0.0
995
 
  else
996
 
   begin
997
 
    x :=x * pi;
998
 
    xr:= x / m_radius;
999
 
 
1000
 
    result:=(Sin(x ) / x ) * (0.42 + 0.5 * Cos(xr ) + 0.08 * Cos(2 * xr ) );
1001
 
 
1002
 
   end;
1003
 
 
1004
 
end;
1005
 
 
1006
 
{ SET_RADIUS }
1007
 
procedure image_filter_blackman.set_radius;
1008
 
begin
1009
 
 if r < 2.0 then
1010
 
  m_radius:=2.0
1011
 
 else
1012
 
  m_radius:=r;
1013
 
 
1014
 
end;
1015
 
 
1016
 
{ CONSTRUCT }
1017
 
constructor image_filter_sinc36.Construct;
1018
 
begin
1019
 
 inherited Construct(3.0 );
1020
 
 
1021
 
end;
1022
 
 
1023
 
{ CONSTRUCT }
1024
 
constructor image_filter_sinc64.Construct;
1025
 
begin
1026
 
 inherited Construct(4.0 );
1027
 
 
1028
 
end;
1029
 
 
1030
 
{ CONSTRUCT }
1031
 
constructor image_filter_sinc100.Construct;
1032
 
begin
1033
 
 inherited Construct(5.0 );
1034
 
 
1035
 
end;
1036
 
 
1037
 
{ CONSTRUCT }
1038
 
constructor image_filter_sinc144.Construct;
1039
 
begin
1040
 
 inherited Construct(6.0 );
1041
 
 
1042
 
end;
1043
 
 
1044
 
{ CONSTRUCT }
1045
 
constructor image_filter_sinc196.Construct;
1046
 
begin
1047
 
 inherited Construct(7.0 );
1048
 
 
1049
 
end;
1050
 
 
1051
 
{ CONSTRUCT }
1052
 
constructor image_filter_sinc256.Construct;
1053
 
begin
1054
 
 inherited Construct(8.0 );
1055
 
 
1056
 
end;
1057
 
 
1058
 
{ CONSTRUCT }
1059
 
constructor image_filter_lanczos36.Construct;
1060
 
begin
1061
 
 inherited Construct(3.0 );
1062
 
 
1063
 
end;
1064
 
 
1065
 
{ CONSTRUCT }
1066
 
constructor image_filter_lanczos64.Construct;
1067
 
begin
1068
 
 inherited Construct(4.0 );
1069
 
 
1070
 
end;
1071
 
 
1072
 
{ CONSTRUCT }
1073
 
constructor image_filter_lanczos100.Construct;
1074
 
begin
1075
 
 inherited Construct(5.0 );
1076
 
 
1077
 
end;
1078
 
 
1079
 
{ CONSTRUCT }
1080
 
constructor image_filter_lanczos144.Construct;
1081
 
begin
1082
 
 inherited Construct(6.0 );
1083
 
 
1084
 
end;
1085
 
 
1086
 
{ CONSTRUCT }
1087
 
constructor image_filter_lanczos196.Construct;
1088
 
begin
1089
 
 inherited Construct(7.0 );
1090
 
 
1091
 
end;
1092
 
 
1093
 
{ CONSTRUCT }
1094
 
constructor image_filter_lanczos256.Construct;
1095
 
begin
1096
 
 inherited Construct(8.0 );
1097
 
 
1098
 
end;
1099
 
 
1100
 
{ CONSTRUCT }
1101
 
constructor image_filter_blackman36.Construct;
1102
 
begin
1103
 
 inherited Construct(3.0 );
1104
 
 
1105
 
end;
1106
 
 
1107
 
{ CONSTRUCT }
1108
 
constructor image_filter_blackman64.Construct;
1109
 
begin
1110
 
 inherited Construct(4.0 );
1111
 
 
1112
 
end;
1113
 
 
1114
 
{ CONSTRUCT }
1115
 
constructor image_filter_blackman100.Construct;
1116
 
begin
1117
 
 inherited Construct(5.0 );
1118
 
 
1119
 
end;
1120
 
 
1121
 
{ CONSTRUCT }
1122
 
constructor image_filter_blackman144.Construct;
1123
 
begin
1124
 
 inherited Construct(6.0 );
1125
 
 
1126
 
end;
1127
 
 
1128
 
{ CONSTRUCT }
1129
 
constructor image_filter_blackman196.Construct;
1130
 
begin
1131
 
 inherited Construct(7.0 );
1132
 
 
1133
 
end;
1134
 
 
1135
 
{ CONSTRUCT }
1136
 
constructor image_filter_blackman256.Construct;
1137
 
begin
1138
 
 inherited Construct(8.0 );
1139
 
 
1140
 
end;
1141
 
 
1142
 
END.
1143