summaryrefslogtreecommitdiff
path: root/agg/source/agg_line_profile_aa.cpp
blob: 1374475b663f768644d1ae6582ee5ca0291e3e05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
//          mcseemagg@yahoo.com
//          http://www.antigrain.com
//----------------------------------------------------------------------------

#include "agg_renderer_outline_aa.h"

namespace agg
{

    //---------------------------------------------------------------------
    void line_profile_aa::width(double w)
    {
        if(w < 0.0) w = 0.0;

        if(w < m_smoother_width) w += w;
        else                     w += m_smoother_width;

        w *= 0.5;

        w -= m_smoother_width;
        double s = m_smoother_width;
        if(w < 0.0)
        {
            s += w;
            w = 0.0;
        }
        set(w, s);
    }


    //---------------------------------------------------------------------
    line_profile_aa::value_type* line_profile_aa::profile(double w)
    {
        m_subpixel_width = int(w * subpixel_size);
        unsigned size = m_subpixel_width + subpixel_size * 6;
        if(size > m_size)
        {
            delete [] m_profile;
            m_profile = new value_type[m_size = size];
        }
        return m_profile;
    }


    //---------------------------------------------------------------------
    void line_profile_aa::set(double center_width, double _smoother_width)
    {
        double base_val = 1.0;
        if(center_width == 0.0)   center_width = 1.0 / subpixel_size;
        if(_smoother_width == 0.0) _smoother_width = 1.0 / subpixel_size;

        double _width = center_width + _smoother_width;
        if(_width < m_min_width)
        {
            double k = _width / m_min_width;
            base_val *= k;
            center_width /= k;
            _smoother_width /= k;
        }

        value_type* ch = profile(center_width + _smoother_width);

        unsigned subpixel_center_width = unsigned(center_width * subpixel_size);
        unsigned subpixel_smoother_width = unsigned(_smoother_width * subpixel_size);

        value_type* ch_center   = ch + subpixel_size*2;
        value_type* ch_smoother = ch_center + subpixel_center_width;

        unsigned i;

        unsigned val = m_gamma[unsigned(base_val * aa_mask)];
        ch = ch_center;
        for(i = 0; i < subpixel_center_width; i++)
        {
            *ch++ = (value_type)val;
        }

        for(i = 0; i < subpixel_smoother_width; i++)
        {
            *ch_smoother++ =
                m_gamma[unsigned((base_val -
                                  base_val *
                                  (double(i) / subpixel_smoother_width)) * aa_mask)];
        }

        unsigned n_smoother = profile_size() -
                              subpixel_smoother_width -
                              subpixel_center_width -
                              subpixel_size*2;

        val = m_gamma[0];
        for(i = 0; i < n_smoother; i++)
        {
            *ch_smoother++ = (value_type)val;
        }

        ch = ch_center;
        for(i = 0; i < subpixel_size*2; i++)
        {
            *--ch = *ch_center++;
        }
    }


}