1
//----------------------------------------------------------------------------
2
// Anti-Grain Geometry - Version 2.4 (Public License)
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5
// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3)
6
// Pascal Port By: Milan Marusinec alias Milano
8
// http://www.aggpas.org
9
// Copyright (c) 2005-2006
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.
16
//----------------------------------------------------------------------------
17
// Contact: mcseem@antigrain.com
18
// mcseemagg@yahoo.com
19
// http://www.antigrain.com
21
// [Pascal Port History] -----------------------------------------------------
23
// 23.06.2006-Milano: ptrcomp adjustments
24
// 06.03.2006-Milano: Unit port establishment
26
{ agg_span_pattern_resample_gray.pas {untested}
28
agg_span_pattern_resample_gray ;
39
agg_span_image_resample ,
40
agg_span_interpolator_linear ,
41
agg_rendering_buffer ,
47
base_shift = agg_color.base_shift;
48
base_mask = agg_color.base_mask;
49
downscale_shift = image_filter_shift;
52
span_pattern_resample_gray_affine_ptr = ^span_pattern_resample_gray_affine;
53
span_pattern_resample_gray_affine = object(span_image_resample_affine )
55
m_wrap_mode_y : wrap_mode_ptr;
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;
65
procedure source_image_(src : rendering_buffer_ptr );
67
function generate(x ,y : int; len : unsigned ) : aggclr_ptr; virtual;
71
span_pattern_resample_gray_ptr = ^span_pattern_resample_gray;
72
span_pattern_resample_gray = object(span_image_resample )
74
m_wrap_mode_y : wrap_mode_ptr;
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;
84
procedure source_image_(src : rendering_buffer_ptr );
86
function generate(x ,y : int; len : unsigned ) : aggclr_ptr; virtual;
94
{ LOCAL VARIABLES & CONSTANTS }
95
{ UNIT IMPLEMENTATION }
97
constructor span_pattern_resample_gray_affine.Construct(alloc : span_allocator_ptr; WX ,WY : wrap_mode_ptr );
99
inherited Construct(alloc );
104
m_wrap_mode_x.init(1 );
105
m_wrap_mode_y.init(1 );
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 );
120
rgba.ConstrInt(0 ,0 );
122
inherited Construct(alloc ,src ,@rgba ,interpolator ,filter );
127
m_wrap_mode_x.init(src._width );
128
m_wrap_mode_y.init(src._height );
133
procedure span_pattern_resample_gray_affine.source_image_;
135
inherited source_image_(src );
137
m_wrap_mode_x.init(src._width );
138
m_wrap_mode_y.init(src._height );
143
function span_pattern_resample_gray_affine.generate;
146
intr : span_interpolator_ptr;
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;
151
row_ptr ,fg_ptr : int8u_ptr;
153
weight_array : int16_ptr;
156
span:=_allocator.span;
159
intr.begin_(x + filter_dx_dbl ,y + filter_dy_dbl ,len );
161
diameter :=_filter.diameter;
162
filter_size:=diameter shl image_subpixel_shift;
164
radius_x:=shr_int32(diameter * m_rx ,1 );
165
radius_y:=shr_int32(diameter * m_ry ,1 );
167
maxx:=_source_image._width - 1;
168
maxy:=_source_image._height - 1;
170
weight_array:=_filter.weight_array;
173
intr.coordinates(@x ,@y );
175
inc(x ,filter_dx_int - radius_x );
176
inc(y ,filter_dy_int - radius_y );
178
fg:=image_filter_size div 2;
180
y_lr:=m_wrap_mode_y.func_operator(shr_int32(y ,image_subpixel_shift ) );
183
(image_subpixel_mask - (y and image_subpixel_mask ) ) *
184
m_ry_inv ,image_subpixel_shift );
188
x_lr_ini:=shr_int32(x ,image_subpixel_shift );
191
(image_subpixel_mask - (x and image_subpixel_mask ) ) *
192
m_rx_inv ,image_subpixel_shift );
195
weight_y:=int16_ptr(ptrcomp(weight_array ) + y_hr * sizeof(int16 ) )^;
197
x_lr:=m_wrap_mode_x.func_operator(x_lr_ini );
200
row_ptr:=_source_image.row(y_lr );
203
fg_ptr:=int8u_ptr(ptrcomp(row_ptr ) + x_lr * sizeof(int8u ) );
207
int16_ptr(ptrcomp(weight_array ) + x_hr * sizeof(int16 ) )^ +
208
image_filter_size div 2 ,downscale_shift );
210
inc(fg ,fg_ptr^ * weight );
211
inc(total_weight ,weight );
212
inc(x_hr ,m_rx_inv );
214
x_lr:=m_wrap_mode_x.inc_operator;
216
until x_hr >= filter_size;
218
inc(y_hr ,m_ry_inv );
220
y_lr:=m_wrap_mode_y.inc_operator;
222
until y_hr >= filter_size;
224
fg:=fg div total_weight;
229
if fg > base_mask then
233
span.a:=int8u(base_mask );
235
inc(ptrcomp(span ) ,sizeof(aggclr ) );
243
result:=_allocator.span;
248
constructor span_pattern_resample_gray.Construct(alloc : span_allocator_ptr; WX ,WY : wrap_mode_ptr );
250
inherited Construct(alloc );
255
m_wrap_mode_x.init(1 );
256
m_wrap_mode_y.init(1 );
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 );
271
rgba.ConstrInt(0 ,0 );
273
inherited Construct(alloc ,src ,@rgba ,interpolator ,filter );
278
m_wrap_mode_x.init(src._width );
279
m_wrap_mode_y.init(src._height );
284
procedure span_pattern_resample_gray.source_image_;
286
inherited source_image_(src );
288
m_wrap_mode_x.init(src._width );
289
m_wrap_mode_y.init(src._height );
294
function span_pattern_resample_gray.generate;
297
intr : span_interpolator_ptr;
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;
303
row_ptr ,fg_ptr : int8u_ptr;
305
weight_array : int16_ptr;
308
span:=_allocator.span;
311
intr.begin_(x + filter_dx_dbl ,y + filter_dy_dbl ,len );
313
diameter :=_filter.diameter;
314
filter_size :=diameter shl image_subpixel_shift;
315
weight_array:=_filter.weight_array;
318
rx_inv:=image_subpixel_size;
319
ry_inv:=image_subpixel_size;
321
intr.coordinates(@x ,@y );
322
intr.local_scale(@rx ,@ry );
324
rx:=shr_int32(rx * m_blur_x ,image_subpixel_shift );
325
ry:=shr_int32(ry * m_blur_y ,image_subpixel_shift );
327
if rx < image_subpixel_size then
328
rx:=image_subpixel_size
331
if rx > image_subpixel_size * m_scale_limit then
332
rx:=image_subpixel_size * m_scale_limit;
334
rx_inv:=image_subpixel_size * image_subpixel_size div rx;
338
if ry < image_subpixel_size then
339
ry:=image_subpixel_size
342
if ry > image_subpixel_size * m_scale_limit then
343
ry:=image_subpixel_size * m_scale_limit;
345
ry_inv:=image_subpixel_size * image_subpixel_size div ry;
349
radius_x:=shr_int32(diameter * rx ,1 );
350
radius_y:=shr_int32(diameter * ry ,1 );
352
maxx:=_source_image._width - 1;
353
maxy:=_source_image._height - 1;
355
inc(x ,filter_dx_int - radius_x );
356
inc(y ,filter_dy_int - radius_y );
358
fg:=image_filter_size div 2;
360
y_lr:=m_wrap_mode_y.func_operator(shr_int32(y ,image_subpixel_shift ) );
363
(image_subpixel_mask - (y and image_subpixel_mask ) ) *
364
ry_inv ,image_subpixel_shift );
368
x_lr_ini:=shr_int32(x ,image_subpixel_shift );
371
(image_subpixel_mask - (x and image_subpixel_mask ) ) *
372
rx_inv ,image_subpixel_shift );
375
weight_y:=int16_ptr(ptrcomp(weight_array ) + y_hr * sizeof(int16 ) )^;
377
x_lr:=m_wrap_mode_x.func_operator(x_lr_ini );
380
row_ptr:=_source_image.row(y_lr );
383
fg_ptr:=int8u_ptr(ptrcomp(row_ptr ) + x_lr * sizeof(int8u ) );
387
int16_ptr(ptrcomp(weight_array ) + x_hr * sizeof(int16 ) )^ +
388
image_filter_size div 2 ,downscale_shift );
390
inc(fg ,fg_ptr^ * weight );
391
inc(total_weight ,weight );
394
x_lr:=m_wrap_mode_x.inc_operator;
396
until x_hr > filter_size;
400
y_lr:=m_wrap_mode_y.inc_operator;
402
until y_hr >= filter_size;
404
fg:=fg div total_weight;
409
if fg > base_mask then
413
span.a:=int8u(base_mask );
415
inc(ptrcomp(span ) ,sizeof(aggclr ) );
423
result:=_allocator.span;