update dev300-m58
[ooovba.git] / agg / inc / agg_span_image_resample.h
blobf0112641e04c920695adb5bef17ba71fedcf8884
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 //----------------------------------------------------------------------------
15 #ifndef AGG_SPAN_IMAGE_RESAMPLE_INCLUDED
16 #define AGG_SPAN_IMAGE_RESAMPLE_INCLUDED
18 #include "agg_span_image_filter.h"
19 #include "agg_span_interpolator_linear.h"
22 namespace agg
26 //=====================================================span_image_resample
27 template<class ColorT, class Interpolator, class Allocator>
28 class span_image_resample :
29 public span_image_filter<ColorT, Interpolator, Allocator>
31 public:
32 typedef ColorT color_type;
33 typedef Interpolator interpolator_type;
34 typedef Allocator alloc_type;
35 typedef span_image_filter<color_type, interpolator_type, alloc_type> base_type;
37 //--------------------------------------------------------------------
38 span_image_resample(alloc_type& alloc) :
39 base_type(alloc),
40 m_scale_limit(20),
41 m_blur_x(image_subpixel_size),
42 m_blur_y(image_subpixel_size)
45 //--------------------------------------------------------------------
46 span_image_resample(alloc_type& alloc,
47 const rendering_buffer& src,
48 const color_type& back_color,
49 interpolator_type& inter,
50 const image_filter_lut& filter) :
51 base_type(alloc, src, back_color, inter, &filter),
52 m_scale_limit(20),
53 m_blur_x(image_subpixel_size),
54 m_blur_y(image_subpixel_size)
58 //--------------------------------------------------------------------
59 int scale_limit() const { return m_scale_limit; }
60 void scale_limit(int v) { m_scale_limit = v; }
62 //--------------------------------------------------------------------
63 double blur_x() const { return double(m_blur_x) / double(image_subpixel_size); }
64 double blur_y() const { return double(m_blur_y) / double(image_subpixel_size); }
65 void blur_x(double v) { m_blur_x = int(v * double(image_subpixel_size) + 0.5); }
66 void blur_y(double v) { m_blur_y = int(v * double(image_subpixel_size) + 0.5); }
67 void blur(double v) { m_blur_x =
68 m_blur_y = int(v * double(image_subpixel_size) + 0.5); }
70 protected:
71 int m_scale_limit;
72 int m_blur_x;
73 int m_blur_y;
83 //==============================================span_image_resample_affine
84 template<class ColorT, class Allocator>
85 class span_image_resample_affine :
86 public span_image_filter<ColorT, span_interpolator_linear<trans_affine>, Allocator>
88 public:
89 typedef ColorT color_type;
90 typedef span_interpolator_linear<trans_affine> interpolator_type;
91 typedef Allocator alloc_type;
92 typedef span_image_filter<color_type, interpolator_type, alloc_type> base_type;
94 //--------------------------------------------------------------------
95 span_image_resample_affine(alloc_type& alloc) :
96 base_type(alloc),
97 m_scale_limit(200.0),
98 m_blur_x(1.0),
99 m_blur_y(1.0)
102 //--------------------------------------------------------------------
103 span_image_resample_affine(alloc_type& alloc,
104 const rendering_buffer& src,
105 const color_type& back_color,
106 interpolator_type& inter,
107 const image_filter_lut& filter_) :
108 base_type(alloc, src, back_color, inter, &filter_),
109 m_scale_limit(200.0),
110 m_blur_x(1.0),
111 m_blur_y(1.0)
115 //--------------------------------------------------------------------
116 int scale_limit() const { return int(m_scale_limit); }
117 void scale_limit(int v) { m_scale_limit = v; }
119 //--------------------------------------------------------------------
120 double blur_x() const { return m_blur_x; }
121 double blur_y() const { return m_blur_y; }
122 void blur_x(double v) { m_blur_x = v; }
123 void blur_y(double v) { m_blur_y = v; }
124 void blur(double v) { m_blur_x = m_blur_y = v; }
127 //--------------------------------------------------------------------
128 void prepare(unsigned max_span_len)
130 base_type::prepare(max_span_len);
132 double scale_x;
133 double scale_y;
135 base_type::interpolator().transformer().scaling_abs(&scale_x, &scale_y);
137 m_rx = image_subpixel_size;
138 m_ry = image_subpixel_size;
139 m_rx_inv = image_subpixel_size;
140 m_ry_inv = image_subpixel_size;
142 scale_x *= m_blur_x;
143 scale_y *= m_blur_y;
145 if(scale_x * scale_y > m_scale_limit)
147 scale_x = scale_x * m_scale_limit / (scale_x * scale_y);
148 scale_y = scale_y * m_scale_limit / (scale_x * scale_y);
151 if(scale_x > 1.0001)
153 if(scale_x > m_scale_limit) scale_x = m_scale_limit;
154 m_rx = int( scale_x * double(image_subpixel_size) + 0.5);
155 m_rx_inv = int(1.0/scale_x * double(image_subpixel_size) + 0.5);
158 if(scale_y > 1.0001)
160 if(scale_y > m_scale_limit) scale_y = m_scale_limit;
161 m_ry = int( scale_y * double(image_subpixel_size) + 0.5);
162 m_ry_inv = int(1.0/scale_y * double(image_subpixel_size) + 0.5);
166 protected:
167 int m_rx;
168 int m_ry;
169 int m_rx_inv;
170 int m_ry_inv;
172 private:
173 double m_scale_limit;
174 double m_blur_x;
175 double m_blur_y;
180 #endif