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

« back to all changes in this revision

Viewing changes to components/aggpas/src/agg_span_pattern_resample_gray.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
 
// [Pascal Port History] -----------------------------------------------------
22
 
//
23
 
// 23.06.2006-Milano: ptrcomp adjustments
24
 
// 06.03.2006-Milano: Unit port establishment
25
 
//
26
 
{ agg_span_pattern_resample_gray.pas {untested}
27
 
unit
28
 
 agg_span_pattern_resample_gray ;
29
 
 
30
 
INTERFACE
31
 
 
32
 
{$I agg_mode.inc }
33
 
{$Q- }
34
 
{$R- }
35
 
uses
36
 
 agg_basics ,
37
 
 agg_color ,
38
 
 agg_span_pattern ,
39
 
 agg_span_image_resample ,
40
 
 agg_span_interpolator_linear ,
41
 
 agg_rendering_buffer ,
42
 
 agg_span_allocator ,
43
 
 agg_image_filters ;
44
 
 
45
 
{ TYPES DEFINITION }
46
 
const
47
 
 base_shift      = agg_color.base_shift;
48
 
 base_mask       = agg_color.base_mask;
49
 
 downscale_shift = image_filter_shift;
50
 
 
51
 
type
52
 
 span_pattern_resample_gray_affine_ptr = ^span_pattern_resample_gray_affine;
53
 
 span_pattern_resample_gray_affine = object(span_image_resample_affine )
54
 
   m_wrap_mode_x ,
55
 
   m_wrap_mode_y : wrap_mode_ptr;
56
 
 
57
 
   constructor Construct(alloc : span_allocator_ptr; WX ,WY : wrap_mode_ptr ); overload;
58
 
   constructor Construct(
59
 
                alloc : span_allocator_ptr;
60
 
                src : rendering_buffer_ptr;
61
 
                interpolator : span_interpolator_ptr;
62
 
                filter : image_filter_lut_ptr;
63
 
                WX ,WY : wrap_mode_ptr ); overload;
64
 
 
65
 
   procedure source_image_(src : rendering_buffer_ptr );
66
 
 
67
 
   function  generate(x ,y : int; len : unsigned ) : aggclr_ptr; virtual;
68
 
 
69
 
  end;
70
 
 
71
 
 span_pattern_resample_gray_ptr = ^span_pattern_resample_gray; 
72
 
 span_pattern_resample_gray = object(span_image_resample )
73
 
   m_wrap_mode_x ,
74
 
   m_wrap_mode_y : wrap_mode_ptr;
75
 
 
76
 
   constructor Construct(alloc : span_allocator_ptr; WX ,WY : wrap_mode_ptr ); overload;
77
 
   constructor Construct(
78
 
                alloc : span_allocator_ptr;
79
 
                src : rendering_buffer_ptr;
80
 
                interpolator : span_interpolator_ptr;
81
 
                filter : image_filter_lut_ptr;
82
 
                WX ,WY : wrap_mode_ptr ); overload;
83
 
 
84
 
   procedure source_image_(src : rendering_buffer_ptr );
85
 
 
86
 
   function  generate(x ,y : int; len : unsigned ) : aggclr_ptr; virtual;
87
 
 
88
 
  end;
89
 
 
90
 
{ GLOBAL PROCEDURES }
91
 
 
92
 
 
93
 
IMPLEMENTATION
94
 
{ LOCAL VARIABLES & CONSTANTS }
95
 
{ UNIT IMPLEMENTATION }
96
 
{ CONSTRUCT }
97
 
constructor span_pattern_resample_gray_affine.Construct(alloc : span_allocator_ptr; WX ,WY : wrap_mode_ptr );
98
 
begin
99
 
 inherited Construct(alloc );
100
 
 
101
 
 m_wrap_mode_x:=WX;
102
 
 m_wrap_mode_y:=WY;
103
 
 
104
 
 m_wrap_mode_x.init(1 );
105
 
 m_wrap_mode_y.init(1 );
106
 
 
107
 
end;
108
 
 
109
 
{ CONSTRUCT }
110
 
constructor span_pattern_resample_gray_affine.Construct(
111
 
             alloc : span_allocator_ptr;
112
 
             src : rendering_buffer_ptr;
113
 
             interpolator : span_interpolator_ptr;
114
 
             filter : image_filter_lut_ptr;
115
 
             WX ,WY : wrap_mode_ptr );
116
 
var
117
 
 rgba : aggclr;
118
 
 
119
 
begin
120
 
 rgba.ConstrInt(0 ,0 );
121
 
 
122
 
 inherited Construct(alloc ,src ,@rgba ,interpolator ,filter );
123
 
 
124
 
 m_wrap_mode_x:=WX;
125
 
 m_wrap_mode_y:=WY;
126
 
 
127
 
 m_wrap_mode_x.init(src._width );
128
 
 m_wrap_mode_y.init(src._height );
129
 
 
130
 
end;
131
 
 
132
 
{ SOURCE_IMAGE_ }
133
 
procedure span_pattern_resample_gray_affine.source_image_;
134
 
begin
135
 
 inherited source_image_(src );
136
 
 
137
 
 m_wrap_mode_x.init(src._width );
138
 
 m_wrap_mode_y.init(src._height );
139
 
 
140
 
end;
141
 
 
142
 
{ GENERATE }
143
 
function span_pattern_resample_gray_affine.generate;
144
 
var
145
 
 span : aggclr_ptr;
146
 
 intr : span_interpolator_ptr;
147
 
 
148
 
 fg ,diameter ,filter_size ,radius_x ,radius_y ,maxx ,maxy ,y_lr ,y_hr ,
149
 
 total_weight ,x_lr_ini ,x_hr_ini ,weight_y ,x_lr ,x_hr ,weight : int;
150
 
 
151
 
 row_ptr ,fg_ptr : int8u_ptr;
152
 
 
153
 
 weight_array : int16_ptr;
154
 
 
155
 
begin
156
 
 span:=_allocator.span;
157
 
 intr:=_interpolator;
158
 
 
159
 
 intr.begin_(x + filter_dx_dbl ,y + filter_dy_dbl ,len );
160
 
 
161
 
 diameter   :=_filter.diameter;
162
 
 filter_size:=diameter shl image_subpixel_shift;
163
 
 
164
 
 radius_x:=shr_int32(diameter * m_rx ,1 );
165
 
 radius_y:=shr_int32(diameter * m_ry ,1 );
166
 
 
167
 
 maxx:=_source_image._width - 1;
168
 
 maxy:=_source_image._height - 1;
169
 
 
170
 
 weight_array:=_filter.weight_array;
171
 
 
172
 
 repeat
173
 
  intr.coordinates(@x ,@y );
174
 
 
175
 
  inc(x ,filter_dx_int - radius_x );
176
 
  inc(y ,filter_dy_int - radius_y );
177
 
 
178
 
  fg:=image_filter_size div 2;
179
 
 
180
 
  y_lr:=m_wrap_mode_y.func_operator(shr_int32(y ,image_subpixel_shift ) );
181
 
  y_hr:=
182
 
   shr_int32(
183
 
    (image_subpixel_mask - (y and image_subpixel_mask ) ) *
184
 
    m_ry_inv ,image_subpixel_shift );
185
 
 
186
 
  total_weight:=0;
187
 
 
188
 
  x_lr_ini:=shr_int32(x ,image_subpixel_shift );
189
 
  x_hr_ini:=
190
 
   shr_int32(
191
 
    (image_subpixel_mask - (x and image_subpixel_mask ) ) *
192
 
    m_rx_inv ,image_subpixel_shift );
193
 
 
194
 
  repeat
195
 
   weight_y:=int16_ptr(ptrcomp(weight_array ) + y_hr * sizeof(int16 ) )^;
196
 
 
197
 
   x_lr:=m_wrap_mode_x.func_operator(x_lr_ini );
198
 
   x_hr:=x_hr_ini;
199
 
 
200
 
   row_ptr:=_source_image.row(y_lr );
201
 
 
202
 
   repeat
203
 
    fg_ptr:=int8u_ptr(ptrcomp(row_ptr ) + x_lr * sizeof(int8u ) );
204
 
    weight:=
205
 
     shr_int32(
206
 
      weight_y *
207
 
      int16_ptr(ptrcomp(weight_array ) + x_hr * sizeof(int16 ) )^ +
208
 
      image_filter_size div 2 ,downscale_shift );
209
 
 
210
 
    inc(fg ,fg_ptr^ * weight );
211
 
    inc(total_weight ,weight );
212
 
    inc(x_hr ,m_rx_inv );
213
 
 
214
 
    x_lr:=m_wrap_mode_x.inc_operator;
215
 
 
216
 
   until x_hr >= filter_size;
217
 
 
218
 
   inc(y_hr ,m_ry_inv );
219
 
 
220
 
   y_lr:=m_wrap_mode_y.inc_operator;
221
 
 
222
 
  until y_hr >= filter_size;
223
 
 
224
 
  fg:=fg div total_weight;
225
 
 
226
 
  if fg < 0 then
227
 
   fg:=0;
228
 
 
229
 
  if fg > base_mask then
230
 
   fg:=base_mask;
231
 
 
232
 
  span.v:=int8u(fg );
233
 
  span.a:=int8u(base_mask );
234
 
 
235
 
  inc(ptrcomp(span ) ,sizeof(aggclr ) );
236
 
 
237
 
  intr.inc_operator;
238
 
 
239
 
  dec(len );
240
 
 
241
 
 until len = 0;
242
 
 
243
 
 result:=_allocator.span;
244
 
 
245
 
end;
246
 
 
247
 
{ CONSTRUCT }
248
 
constructor span_pattern_resample_gray.Construct(alloc : span_allocator_ptr; WX ,WY : wrap_mode_ptr );
249
 
begin
250
 
 inherited Construct(alloc );
251
 
 
252
 
 m_wrap_mode_x:=WX;
253
 
 m_wrap_mode_y:=WY;
254
 
 
255
 
 m_wrap_mode_x.init(1 );
256
 
 m_wrap_mode_y.init(1 );
257
 
 
258
 
end;
259
 
 
260
 
{ CONSTRUCT }
261
 
constructor span_pattern_resample_gray.Construct(
262
 
             alloc : span_allocator_ptr;
263
 
             src : rendering_buffer_ptr;
264
 
             interpolator : span_interpolator_ptr;
265
 
             filter : image_filter_lut_ptr;
266
 
             WX ,WY : wrap_mode_ptr );
267
 
var
268
 
 rgba : aggclr;
269
 
 
270
 
begin
271
 
 rgba.ConstrInt(0 ,0 );
272
 
 
273
 
 inherited Construct(alloc ,src ,@rgba ,interpolator ,filter );
274
 
 
275
 
 m_wrap_mode_x:=WX;
276
 
 m_wrap_mode_y:=WY;
277
 
 
278
 
 m_wrap_mode_x.init(src._width );
279
 
 m_wrap_mode_y.init(src._height );
280
 
 
281
 
end;
282
 
 
283
 
{ SOURCE_IMAGE_ }
284
 
procedure span_pattern_resample_gray.source_image_;
285
 
begin
286
 
 inherited source_image_(src );
287
 
 
288
 
 m_wrap_mode_x.init(src._width );
289
 
 m_wrap_mode_y.init(src._height );
290
 
 
291
 
end;
292
 
 
293
 
{ GENERATE }
294
 
function span_pattern_resample_gray.generate;
295
 
var
296
 
 span : aggclr_ptr;
297
 
 intr : span_interpolator_ptr;
298
 
 
299
 
 fg ,diameter ,filter_size ,rx ,ry ,rx_inv ,ry_inv ,radius_x ,radius_y ,
300
 
 maxx ,maxy ,y_lr ,y_hr ,total_weight ,x_lr_ini ,x_hr_ini ,weight_y ,
301
 
 x_lr ,x_hr ,weight : int;
302
 
 
303
 
 row_ptr ,fg_ptr : int8u_ptr;
304
 
 
305
 
 weight_array : int16_ptr;
306
 
 
307
 
begin
308
 
 span:=_allocator.span;
309
 
 intr:=_interpolator;
310
 
 
311
 
 intr.begin_(x + filter_dx_dbl ,y + filter_dy_dbl ,len );
312
 
 
313
 
 diameter    :=_filter.diameter;
314
 
 filter_size :=diameter shl image_subpixel_shift;
315
 
 weight_array:=_filter.weight_array;
316
 
 
317
 
 repeat
318
 
  rx_inv:=image_subpixel_size;
319
 
  ry_inv:=image_subpixel_size;
320
 
 
321
 
  intr.coordinates(@x ,@y );
322
 
  intr.local_scale(@rx ,@ry );
323
 
 
324
 
  rx:=shr_int32(rx * m_blur_x ,image_subpixel_shift );
325
 
  ry:=shr_int32(ry * m_blur_y ,image_subpixel_shift );
326
 
 
327
 
  if rx < image_subpixel_size then
328
 
   rx:=image_subpixel_size
329
 
  else
330
 
   begin
331
 
    if rx > image_subpixel_size * m_scale_limit then
332
 
     rx:=image_subpixel_size * m_scale_limit;
333
 
 
334
 
    rx_inv:=image_subpixel_size * image_subpixel_size div rx;
335
 
 
336
 
   end;
337
 
 
338
 
  if ry < image_subpixel_size then
339
 
   ry:=image_subpixel_size
340
 
  else
341
 
   begin
342
 
    if ry > image_subpixel_size * m_scale_limit then
343
 
     ry:=image_subpixel_size * m_scale_limit;
344
 
 
345
 
    ry_inv:=image_subpixel_size * image_subpixel_size div ry;
346
 
 
347
 
   end;
348
 
 
349
 
  radius_x:=shr_int32(diameter * rx ,1 );
350
 
  radius_y:=shr_int32(diameter * ry ,1 );
351
 
 
352
 
  maxx:=_source_image._width - 1;
353
 
  maxy:=_source_image._height - 1;
354
 
 
355
 
  inc(x ,filter_dx_int - radius_x );
356
 
  inc(y ,filter_dy_int - radius_y );
357
 
 
358
 
  fg:=image_filter_size div 2;
359
 
 
360
 
  y_lr:=m_wrap_mode_y.func_operator(shr_int32(y ,image_subpixel_shift ) );
361
 
  y_hr:=
362
 
   shr_int32(
363
 
    (image_subpixel_mask - (y and image_subpixel_mask ) ) *
364
 
    ry_inv ,image_subpixel_shift );
365
 
 
366
 
  total_weight:=0;
367
 
 
368
 
  x_lr_ini:=shr_int32(x ,image_subpixel_shift );
369
 
  x_hr_ini:=
370
 
   shr_int32(
371
 
    (image_subpixel_mask - (x and image_subpixel_mask ) ) *
372
 
    rx_inv ,image_subpixel_shift );
373
 
 
374
 
  repeat
375
 
   weight_y:=int16_ptr(ptrcomp(weight_array ) + y_hr * sizeof(int16 ) )^;
376
 
 
377
 
   x_lr:=m_wrap_mode_x.func_operator(x_lr_ini );
378
 
   x_hr:=x_hr_ini;
379
 
 
380
 
   row_ptr:=_source_image.row(y_lr );
381
 
 
382
 
   repeat
383
 
    fg_ptr:=int8u_ptr(ptrcomp(row_ptr ) + x_lr * sizeof(int8u ) );
384
 
    weight:=
385
 
     shr_int32(
386
 
      weight_y *
387
 
      int16_ptr(ptrcomp(weight_array ) + x_hr * sizeof(int16 ) )^ +
388
 
      image_filter_size div 2 ,downscale_shift );
389
 
 
390
 
    inc(fg ,fg_ptr^ * weight );
391
 
    inc(total_weight ,weight );
392
 
    inc(x_hr ,rx_inv );
393
 
 
394
 
    x_lr:=m_wrap_mode_x.inc_operator;
395
 
 
396
 
   until x_hr > filter_size;
397
 
 
398
 
   inc(y_hr ,ry_inv );
399
 
 
400
 
   y_lr:=m_wrap_mode_y.inc_operator;
401
 
 
402
 
  until y_hr >= filter_size;
403
 
 
404
 
  fg:=fg div total_weight;
405
 
 
406
 
  if fg < 0 then
407
 
   fg:=0;
408
 
 
409
 
  if fg > base_mask then
410
 
   fg:=base_mask;
411
 
 
412
 
  span.v:=int8u(fg );
413
 
  span.a:=int8u(base_mask );
414
 
 
415
 
  inc(ptrcomp(span ) ,sizeof(aggclr ) );
416
 
 
417
 
  intr.inc_operator;
418
 
 
419
 
  dec(len );
420
 
 
421
 
 until len = 0;
422
 
 
423
 
 result:=_allocator.span;
424
 
 
425
 
end;
426
 
 
427
 
END.
428