merge the formfield patch from ooo-build
[ooovba.git] / agg / source / agg_line_profile_aa.cpp
blobc880704ae0ded82fc8b804850fedb85b33d8c05f
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 #include "agg_renderer_outline_aa.h"
18 namespace agg
21 //---------------------------------------------------------------------
22 void line_profile_aa::width(double w)
24 if(w < 0.0) w = 0.0;
26 if(w < m_smoother_width) w += w;
27 else w += m_smoother_width;
29 w *= 0.5;
31 w -= m_smoother_width;
32 double s = m_smoother_width;
33 if(w < 0.0)
35 s += w;
36 w = 0.0;
38 set(w, s);
42 //---------------------------------------------------------------------
43 line_profile_aa::value_type* line_profile_aa::profile(double w)
45 m_subpixel_width = int(w * subpixel_size);
46 unsigned size = m_subpixel_width + subpixel_size * 6;
47 if(size > m_size)
49 delete [] m_profile;
50 m_profile = new value_type[m_size = size];
52 return m_profile;
56 //---------------------------------------------------------------------
57 void line_profile_aa::set(double center_width, double _smoother_width)
59 double base_val = 1.0;
60 if(center_width == 0.0) center_width = 1.0 / subpixel_size;
61 if(_smoother_width == 0.0) _smoother_width = 1.0 / subpixel_size;
63 double _width = center_width + _smoother_width;
64 if(_width < m_min_width)
66 double k = _width / m_min_width;
67 base_val *= k;
68 center_width /= k;
69 _smoother_width /= k;
72 value_type* ch = profile(center_width + _smoother_width);
74 unsigned subpixel_center_width = unsigned(center_width * subpixel_size);
75 unsigned subpixel_smoother_width = unsigned(_smoother_width * subpixel_size);
77 value_type* ch_center = ch + subpixel_size*2;
78 value_type* ch_smoother = ch_center + subpixel_center_width;
80 unsigned i;
82 unsigned val = m_gamma[unsigned(base_val * aa_mask)];
83 ch = ch_center;
84 for(i = 0; i < subpixel_center_width; i++)
86 *ch++ = (value_type)val;
89 for(i = 0; i < subpixel_smoother_width; i++)
91 *ch_smoother++ =
92 m_gamma[unsigned((base_val -
93 base_val *
94 (double(i) / subpixel_smoother_width)) * aa_mask)];
97 unsigned n_smoother = profile_size() -
98 subpixel_smoother_width -
99 subpixel_center_width -
100 subpixel_size*2;
102 val = m_gamma[0];
103 for(i = 0; i < n_smoother; i++)
105 *ch_smoother++ = (value_type)val;
108 ch = ch_center;
109 for(i = 0; i < subpixel_size*2; i++)
111 *--ch = *ch_center++;