summaryrefslogtreecommitdiff
path: root/agg/inc/agg_span_image_resample.h
blob: f4dfd57455d7ca575c02fb9aa16007b17f097987 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//----------------------------------------------------------------------------
// 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
//----------------------------------------------------------------------------
#ifndef AGG_SPAN_IMAGE_RESAMPLE_INCLUDED
#define AGG_SPAN_IMAGE_RESAMPLE_INCLUDED

#include "agg_span_image_filter.h"
#include "agg_span_interpolator_linear.h"


namespace agg
{


    //=====================================================span_image_resample
    template<class ColorT, class Interpolator, class Allocator>
    class span_image_resample :
    public span_image_filter<ColorT, Interpolator, Allocator>
    {
    public:
        typedef ColorT color_type;
        typedef Interpolator interpolator_type;
        typedef Allocator alloc_type;
        typedef span_image_filter<color_type, interpolator_type, alloc_type> base_type;

        //--------------------------------------------------------------------
        span_image_resample(alloc_type& alloc) :
            base_type(alloc),
            m_scale_limit(20),
            m_blur_x(image_subpixel_size),
            m_blur_y(image_subpixel_size)
        {}

        //--------------------------------------------------------------------
        span_image_resample(alloc_type& alloc,
                            const rendering_buffer& src,
                            const color_type& back_color,
                            interpolator_type& inter,
                            const image_filter_lut& filter) :
            base_type(alloc, src, back_color, inter, &filter),
            m_scale_limit(20),
            m_blur_x(image_subpixel_size),
            m_blur_y(image_subpixel_size)
        {}


        //--------------------------------------------------------------------
        int  scale_limit() const { return m_scale_limit; }
        void scale_limit(int v)  { m_scale_limit = v; }

        //--------------------------------------------------------------------
        double blur_x() const { return double(m_blur_x) / double(image_subpixel_size); }
        double blur_y() const { return double(m_blur_y) / double(image_subpixel_size); }
        void blur_x(double v) { m_blur_x = int(v * double(image_subpixel_size) + 0.5); }
        void blur_y(double v) { m_blur_y = int(v * double(image_subpixel_size) + 0.5); }
        void blur(double v)   { m_blur_x =
                                m_blur_y = int(v * double(image_subpixel_size) + 0.5); }

    protected:
        int m_scale_limit;
        int m_blur_x;
        int m_blur_y;
    };








    //==============================================span_image_resample_affine
    template<class ColorT, class Allocator>
    class span_image_resample_affine :
    public span_image_filter<ColorT, span_interpolator_linear<trans_affine>, Allocator>
    {
    public:
        typedef ColorT color_type;
        typedef span_interpolator_linear<trans_affine> interpolator_type;
        typedef Allocator alloc_type;
        typedef span_image_filter<color_type, interpolator_type, alloc_type> base_type;

        //--------------------------------------------------------------------
        span_image_resample_affine(alloc_type& alloc) :
            base_type(alloc),
            m_scale_limit(200.0),
            m_blur_x(1.0),
            m_blur_y(1.0)
        {}

        //--------------------------------------------------------------------
        span_image_resample_affine(alloc_type& alloc,
                                   const rendering_buffer& src,
                                   const color_type& back_color,
                                   interpolator_type& inter,
                                   const image_filter_lut& filter_) :
            base_type(alloc, src, back_color, inter, &filter_),
            m_scale_limit(200.0),
            m_blur_x(1.0),
            m_blur_y(1.0)
        {}


        //--------------------------------------------------------------------
        int  scale_limit() const { return int(m_scale_limit); }
        void scale_limit(int v)  { m_scale_limit = v; }

        //--------------------------------------------------------------------
        double blur_x() const { return m_blur_x; }
        double blur_y() const { return m_blur_y; }
        void blur_x(double v) { m_blur_x = v; }
        void blur_y(double v) { m_blur_y = v; }
        void blur(double v) { m_blur_x = m_blur_y = v; }


        //--------------------------------------------------------------------
        void prepare(unsigned max_span_len)
        {
            base_type::prepare(max_span_len);

            double scale_x;
            double scale_y;

            base_type::interpolator().transformer().scaling_abs(&scale_x, &scale_y);

            m_rx     = image_subpixel_size;
            m_ry     = image_subpixel_size;
            m_rx_inv = image_subpixel_size;
            m_ry_inv = image_subpixel_size;

            scale_x *= m_blur_x;
            scale_y *= m_blur_y;

            if(scale_x * scale_y > m_scale_limit)
            {
                scale_x = scale_x * m_scale_limit / (scale_x * scale_y);
                scale_y = scale_y * m_scale_limit / (scale_x * scale_y);
            }

            if(scale_x > 1.0001)
            {
                if(scale_x > m_scale_limit) scale_x = m_scale_limit;
                m_rx     = int(    scale_x * double(image_subpixel_size) + 0.5);
                m_rx_inv = int(1.0/scale_x * double(image_subpixel_size) + 0.5);
            }

            if(scale_y > 1.0001)
            {
                if(scale_y > m_scale_limit) scale_y = m_scale_limit;
                m_ry     = int(    scale_y * double(image_subpixel_size) + 0.5);
                m_ry_inv = int(1.0/scale_y * double(image_subpixel_size) + 0.5);
            }
        }

    protected:
        int m_rx;
        int m_ry;
        int m_rx_inv;
        int m_ry_inv;

    private:
        double m_scale_limit;
        double m_blur_x;
        double m_blur_y;
    };

}

#endif