00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <math.h>
00004 #include "agg_rendering_buffer.h"
00005 #include "agg_rasterizer_scanline_aa.h"
00006 #include "agg_ellipse.h"
00007 #include "agg_trans_affine.h"
00008 #include "agg_conv_transform.h"
00009 #include "agg_span_image_filter_rgb.h"
00010 #include "agg_span_image_filter_rgba.h"
00011 #include "agg_span_image_filter_gray.h"
00012 #include "agg_pixfmt_rgba.h"
00013 #include "agg_scanline_u.h"
00014 #include "agg_renderer_scanline.h"
00015 #include "agg_span_allocator.h"
00016 #include "agg_span_interpolator_linear.h"
00017 #include "agg_image_accessors.h"
00018 #include "ctrl/agg_slider_ctrl.h"
00019 #include "platform/agg_platform_support.h"
00020
00021 enum flip_y_e { flip_y = true };
00022
00023 #define AGG_BGR24
00024 #include "pixel_formats.h"
00025
00026
00027 class the_application : public agg::platform_support
00028 {
00029 agg::slider_ctrl<agg::rgba8> m_angle;
00030 agg::slider_ctrl<agg::rgba8> m_scale;
00031
00032 public:
00033 the_application(agg::pix_format_e format, bool flip_y) :
00034 agg::platform_support(format, flip_y),
00035 m_angle(5, 5, 300, 12, !flip_y),
00036 m_scale(5, 5+15, 300, 12+15, !flip_y)
00037 {
00038 add_ctrl(m_angle);
00039 add_ctrl(m_scale);
00040 m_angle.label("Angle=%3.2f");
00041 m_scale.label("Scale=%3.2f");
00042 m_angle.range(-180.0, 180.0);
00043 m_angle.value(0.0);
00044 m_scale.range(0.1, 5.0);
00045 m_scale.value(1.0);
00046 }
00047
00048 virtual ~the_application()
00049 {
00050 }
00051
00052 virtual void on_draw()
00053 {
00054 typedef agg::renderer_base<pixfmt> renderer_base;
00055 typedef agg::renderer_base<pixfmt_pre> renderer_base_pre;
00056
00057 pixfmt pixf(rbuf_window());
00058 pixfmt_pre pixf_pre(rbuf_window());
00059 renderer_base rb(pixf);
00060 renderer_base_pre rb_pre(pixf_pre);
00061
00062 rb.clear(agg::rgba(1.0, 1.0, 1.0));
00063
00064 agg::trans_affine src_mtx;
00065 src_mtx *= agg::trans_affine_translation(-initial_width()/2 - 10, -initial_height()/2 - 20 - 10);
00066 src_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0);
00067 src_mtx *= agg::trans_affine_scaling(m_scale.value());
00068 src_mtx *= agg::trans_affine_translation(initial_width()/2, initial_height()/2 + 20);
00069 src_mtx *= trans_affine_resizing();
00070
00071 agg::trans_affine img_mtx;
00072 img_mtx *= agg::trans_affine_translation(-initial_width()/2 + 10, -initial_height()/2 + 20 + 10);
00073 img_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0);
00074 img_mtx *= agg::trans_affine_scaling(m_scale.value());
00075 img_mtx *= agg::trans_affine_translation(initial_width()/2, initial_height()/2 + 20);
00076 img_mtx *= trans_affine_resizing();
00077 img_mtx.invert();
00078
00079 agg::span_allocator<color_type> sa;
00080
00081 typedef agg::span_interpolator_linear<> interpolator_type;
00082 interpolator_type interpolator(img_mtx);
00083
00084 typedef agg::image_accessor_clip<pixfmt> img_source_type;
00085
00086 pixfmt img_pixf(rbuf_img(0));
00087 img_source_type img_src(img_pixf, agg::rgba_pre(0, 0.4, 0, 0.5));
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 typedef agg::span_image_filter_rgb_bilinear_clip<pixfmt,
00102 interpolator_type> span_gen_type;
00103 span_gen_type sg(img_pixf, agg::rgba_pre(0, 0.4, 0, 0.5), interpolator);
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 agg::rasterizer_scanline_aa<> ras;
00126 ras.clip_box(0, 0, width(), height());
00127 agg::scanline_u8 sl;
00128 double r = initial_width();
00129 if(initial_height() - 60 < r) r = initial_height() - 60;
00130 agg::ellipse ell(initial_width() / 2.0 + 10,
00131 initial_height() / 2.0 + 20 + 10,
00132 r / 2.0 + 16.0,
00133 r / 2.0 + 16.0, 200);
00134
00135
00136 agg::conv_transform<agg::ellipse> tr(ell, src_mtx);
00137
00138 ras.add_path(tr);
00139 agg::render_scanlines_aa(ras, sl, rb_pre, sa, sg);
00140
00141 agg::render_ctrl(ras, sl, rb, m_angle);
00142 agg::render_ctrl(ras, sl, rb, m_scale);
00143 }
00144
00145 };
00146
00147
00148
00149
00150
00151 int agg_main(int argc, char* argv[])
00152 {
00153 the_application app(pix_format, flip_y);
00154 app.caption("Image Affine Transformations with filtering");
00155
00156 const char* img_name = "spheres";
00157 if(argc >= 2) img_name = argv[1];
00158 if(!app.load_img(0, img_name))
00159 {
00160 char buf[256];
00161 if(strcmp(img_name, "spheres") == 0)
00162 {
00163 sprintf(buf, "File not found: %s%s. Download http://www.antigrain.com/%s%s\n"
00164 "or copy it from another directory if available.",
00165 img_name, app.img_ext(), img_name, app.img_ext());
00166 }
00167 else
00168 {
00169 sprintf(buf, "File not found: %s%s", img_name, app.img_ext());
00170 }
00171 app.message(buf);
00172 return 1;
00173 }
00174
00175 if(app.init(app.rbuf_img(0).width() + 20, app.rbuf_img(0).height() + 40 + 20, agg::window_resize))
00176 {
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 return app.run();
00196 }
00197 return 0;
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213