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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "agg_rendering_buffer.h"
#include "agg_rasterizer_scanline_aa.h"
#include "agg_ellipse.h"
#include "agg_trans_affine.h"
#include "agg_conv_transform.h"
#include "agg_span_image_filter_rgb.h"
#include "agg_span_image_filter_rgba.h"
#include "agg_span_image_filter_gray.h"
#include "agg_pixfmt_rgba.h"
#include "agg_scanline_u.h"
#include "agg_renderer_scanline.h"
#include "agg_span_allocator.h"
#include "agg_span_interpolator_linear.h"
#include "agg_image_accessors.h"
#include "ctrl/agg_slider_ctrl.h"
#include "platform/agg_platform_support.h"
enum flip_y_e { flip_y = true };
#define AGG_BGR24
#include "pixel_formats.h"
class the_application : public agg::platform_support
{
agg::slider_ctrl<agg::rgba8> m_angle;
agg::slider_ctrl<agg::rgba8> m_scale;
public:
the_application(agg::pix_format_e format, bool flip_y) :
agg::platform_support(format, flip_y),
m_angle(5, 5, 300, 12, !flip_y),
m_scale(5, 5+15, 300, 12+15, !flip_y)
{
add_ctrl(m_angle);
add_ctrl(m_scale);
m_angle.label("Angle=%3.2f");
m_scale.label("Scale=%3.2f");
m_angle.range(-180.0, 180.0);
m_angle.value(0.0);
m_scale.range(0.1, 5.0);
m_scale.value(1.0);
}
virtual ~the_application()
{
}
virtual void on_draw()
{
typedef agg::renderer_base<pixfmt> renderer_base;
typedef agg::renderer_base<pixfmt_pre> renderer_base_pre;
pixfmt pixf(rbuf_window());
pixfmt_pre pixf_pre(rbuf_window());
renderer_base rb(pixf);
renderer_base_pre rb_pre(pixf_pre);
rb.clear(agg::rgba(1.0, 1.0, 1.0));
agg::trans_affine src_mtx;
src_mtx *= agg::trans_affine_translation(-initial_width()/2 - 10, -initial_height()/2 - 20 - 10);
src_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0);
src_mtx *= agg::trans_affine_scaling(m_scale.value());
src_mtx *= agg::trans_affine_translation(initial_width()/2, initial_height()/2 + 20);
src_mtx *= trans_affine_resizing();
agg::trans_affine img_mtx;
img_mtx *= agg::trans_affine_translation(-initial_width()/2 + 10, -initial_height()/2 + 20 + 10);
img_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0);
img_mtx *= agg::trans_affine_scaling(m_scale.value());
img_mtx *= agg::trans_affine_translation(initial_width()/2, initial_height()/2 + 20);
img_mtx *= trans_affine_resizing();
img_mtx.invert();
agg::span_allocator<color_type> sa;
typedef agg::span_interpolator_linear<> interpolator_type;
interpolator_type interpolator(img_mtx);
typedef agg::image_accessor_clip<pixfmt> img_source_type;
pixfmt img_pixf(rbuf_img(0));
img_source_type img_src(img_pixf, agg::rgba_pre(0, 0.4, 0, 0.5));
/*
// Version without filtering (nearest neighbor)
//------------------------------------------
typedef agg::span_image_filter_rgb_nn<img_source_type,
interpolator_type> span_gen_type;
span_gen_type sg(img_src, interpolator);
//------------------------------------------
*/
// Version with "hardcoded" bilinear filter and without
// image_accessor (direct filter, the old variant)
//------------------------------------------
typedef agg::span_image_filter_rgb_bilinear_clip<pixfmt,
interpolator_type> span_gen_type;
span_gen_type sg(img_pixf, agg::rgba_pre(0, 0.4, 0, 0.5), interpolator);
//------------------------------------------
/*
// Version with arbitrary 2x2 filter
//------------------------------------------
typedef agg::span_image_filter_rgb_2x2<img_source_type,
interpolator_type> span_gen_type;
agg::image_filter<agg::image_filter_kaiser> filter;
span_gen_type sg(img_src, interpolator, filter);
//------------------------------------------
*/
/*
// Version with arbitrary filter
//------------------------------------------
typedef agg::span_image_filter_rgb<img_source_type,
interpolator_type> span_gen_type;
agg::image_filter<agg::image_filter_spline36> filter;
span_gen_type sg(img_src, interpolator, filter);
//------------------------------------------
*/
agg::rasterizer_scanline_aa<> ras;
ras.clip_box(0, 0, width(), height());
agg::scanline_u8 sl;
double r = initial_width();
if(initial_height() - 60 < r) r = initial_height() - 60;
agg::ellipse ell(initial_width() / 2.0 + 10,
initial_height() / 2.0 + 20 + 10,
r / 2.0 + 16.0,
r / 2.0 + 16.0, 200);
agg::conv_transform<agg::ellipse> tr(ell, src_mtx);
ras.add_path(tr);
agg::render_scanlines_aa(ras, sl, rb_pre, sa, sg);
agg::render_ctrl(ras, sl, rb, m_angle);
agg::render_ctrl(ras, sl, rb, m_scale);
}
};
int agg_main(int argc, char* argv[])
{
the_application app(pix_format, flip_y);
app.caption("Image Affine Transformations with filtering");
const char* img_name = "spheres";
if(argc >= 2) img_name = argv[1];
if(!app.load_img(0, img_name))
{
char buf[256];
if(strcmp(img_name, "spheres") == 0)
{
sprintf(buf, "File not found: %s%s. Download http://www.antigrain.com/%s%s\n"
"or copy it from another directory if available.",
img_name, app.img_ext(), img_name, app.img_ext());
}
else
{
sprintf(buf, "File not found: %s%s", img_name, app.img_ext());
}
app.message(buf);
return 1;
}
if(app.init(app.rbuf_img(0).width() + 20, app.rbuf_img(0).height() + 40 + 20, agg::window_resize))
{
// Test the plain/premultiplied issue
//-------------------
//typedef agg::pixfmt_bgra32 pixfmt;
//typedef agg::renderer_base<pixfmt> renderer_base;
//pixfmt pixf(app.rbuf_img(0));
//renderer_base rb(pixf);
//for(unsigned i = 0; i < app.rbuf_img(0).height(); i += 2)
//{
// // Fully transparent
// rb.copy_hline(0, i, app.rbuf_img(0).width(), agg::rgba(0, 0, 0, 0));
// if(i + 1 < app.rbuf_img(0).height())
// {
// // Fully opaque white
// rb.copy_hline(0, i + 1, app.rbuf_img(0).width(), agg::rgba(1, 1, 1, 1));
// }
//}
return app.run();
}
return 0;
}
/*
E:\agg23\examples\image1.cpp(111) : error C2664:
'__thiscall agg::span_image_filter_gray_bilinear<struct agg::gray8,
struct agg::order_bgra,
class agg::span_interpolator_linear<class agg::trans_affine,8> >::agg::span_image_filter_gray_bilinear<struct agg::gray8,struct agg::order_bgra,class agg::span_interpolator_linear<class agg::trans_affine,8> >(class agg::span_interpolator_linear<class agg::trans_affine,8> &,const class agg::row_ptr_cache<unsigned char> &,const struct agg::gray8 &,struct agg::order_bgra &)' :
cannot convert parameter 1 from
'class agg::span_allocator<struct agg::gray8>' to
'class agg::span_interpolator_linear<class agg::trans_affine,8> &'
*/
|