From e23fdb276f9181dc94430acb5caf35701751c8f3 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Wed, 2 May 2012 17:22:54 +0100 Subject: [PATCH] + pass scale_factor to vertex_converter --- include/mapnik/vertex_converters.hpp | 15 +++++--- src/agg/process_line_pattern_symbolizer.cpp | 2 +- src/agg/process_line_symbolizer.cpp | 2 +- .../process_polygon_pattern_symbolizer.cpp | 38 +++++++++++++++---- src/agg/process_polygon_symbolizer.cpp | 2 +- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/include/mapnik/vertex_converters.hpp b/include/mapnik/vertex_converters.hpp index 6d7332db0..dd9773d7a 100644 --- a/include/mapnik/vertex_converters.hpp +++ b/include/mapnik/vertex_converters.hpp @@ -121,7 +121,7 @@ struct converter_traits static void setup(geometry_type & geom, Args & args) { typename boost::mpl::at >::type sym = boost::fusion::at_c<2>(args); - double scale_factor = 1.0; //FIXME + double scale_factor = boost::fusion::at_c<5>(args); stroke const& stroke_ = sym.get_stroke(); dash_array const& d = stroke_.get_dash_array(); dash_array::const_iterator itr = d.begin(); @@ -312,15 +312,18 @@ struct vertex_converter : private boost::noncopyable rasterizer_type&, symbolizer_type const&, trans_type const&, - proj_trans_type const& + proj_trans_type const&, + double //scale-factor > args_type; - + vertex_converter(bbox_type const& b, rasterizer_type & ras, - symbolizer_type const& sym, trans_type & tr, proj_trans_type const& prj_trans) + symbolizer_type const& sym, trans_type & tr, + proj_trans_type const& prj_trans, + double scale_factor) : disp_(args_type(boost::cref(b),boost::ref(ras), boost::cref(sym),boost::cref(tr), - boost::cref(prj_trans))) {} - + boost::cref(prj_trans),scale_factor)) {} + template void apply(Geometry & geom) { diff --git a/src/agg/process_line_pattern_symbolizer.cpp b/src/agg/process_line_pattern_symbolizer.cpp index 06a92a288..aae9a687a 100644 --- a/src/agg/process_line_pattern_symbolizer.cpp +++ b/src/agg/process_line_pattern_symbolizer.cpp @@ -88,7 +88,7 @@ void agg_renderer::process(line_pattern_symbolizer const& sym, typedef boost::mpl::vector conv_types; vertex_converter,rasterizer_type,line_pattern_symbolizer, proj_transform, CoordTransform, conv_types> - converter(ext,ras,sym,t_,prj_trans); + converter(ext,ras,sym,t_,prj_trans,scale_factor_); if (sym.clip()) converter.set(); //optional clip (default: true) converter.set(); //always transform diff --git a/src/agg/process_line_symbolizer.cpp b/src/agg/process_line_symbolizer.cpp index 35544182f..7f03c3d1a 100644 --- a/src/agg/process_line_symbolizer.cpp +++ b/src/agg/process_line_symbolizer.cpp @@ -105,7 +105,7 @@ void agg_renderer::process(line_symbolizer const& sym, //metawriter_with_properties writer = sym.get_metawriter(); typedef boost::mpl::vector conv_types; vertex_converter,rasterizer,line_symbolizer, proj_transform, CoordTransform,conv_types> - converter(ext,*ras_ptr,sym,t_,prj_trans); + converter(ext,*ras_ptr,sym,t_,prj_trans,scale_factor_); if (sym.clip()) converter.set(); // optional clip (default: true) converter.set(); // always transform diff --git a/src/agg/process_polygon_pattern_symbolizer.cpp b/src/agg/process_polygon_pattern_symbolizer.cpp index 6ce0a104c..5fc8f8236 100644 --- a/src/agg/process_polygon_pattern_symbolizer.cpp +++ b/src/agg/process_polygon_pattern_symbolizer.cpp @@ -46,6 +46,30 @@ namespace mapnik { +template +struct multiplier +{ + typedef typename ColorT::value_type value_type; + typedef typename ColorT::calc_type calc_type; + + void operator() (value_type * p) const + { + calc_type a = p[Order::A]; + if(a < ColorT::base_mask) + { + if(a == 0) + { + p[Order::R] = p[Order::G] = p[Order::B] = 0; + return; + } + p[Order::R] = value_type((p[Order::R] * a + ColorT::base_mask) >> ColorT::base_shift); + p[Order::G] = value_type((p[Order::G] * a + ColorT::base_mask) >> ColorT::base_shift); + p[Order::B] = value_type((p[Order::B] * a + ColorT::base_mask) >> ColorT::base_shift); + } + } +}; + + template void agg_renderer::process(polygon_pattern_symbolizer const& sym, mapnik::feature_ptr const& feature, @@ -53,8 +77,7 @@ void agg_renderer::process(polygon_pattern_symbolizer const& sym, { typedef agg::conv_clip_polygon clipped_geometry_type; typedef coord_transform2 path_type; - - + agg::rendering_buffer buf(current_buffer_->raw_data(), width_, height_, width_ * 4); agg::pixfmt_rgba32_plain pixf(buf); @@ -82,9 +105,8 @@ void agg_renderer::process(polygon_pattern_symbolizer const& sym, return; } - boost::optional pat = (*marker)->get_bitmap_data(); - + if (!pat) return; typedef agg::wrap_mode_repeat wrap_x_type; @@ -106,7 +128,9 @@ void agg_renderer::process(polygon_pattern_symbolizer const& sym, agg::row_accessor pattern_rbuf((agg::int8u*)(*pat)->getBytes(),w,h,w*4); agg::span_allocator sa; rendering_buffer pixf_pattern(pattern_rbuf); - pixf_pattern.premultiply(); + + pixf_pattern.for_each_pixel(multiplier()); + img_source_type img_src(pixf_pattern); unsigned num_geometries = feature->num_geometries(); @@ -133,11 +157,11 @@ void agg_renderer::process(polygon_pattern_symbolizer const& sym, renderer_type rp(renb,sa, sg); //metawriter_with_properties writer = sym.get_metawriter(); - + box2d inflated_extent = query_extent_ * 1.1; typedef boost::mpl::vector conv_types; vertex_converter,rasterizer,polygon_pattern_symbolizer, proj_transform, CoordTransform,conv_types> - converter(inflated_extent,*ras_ptr,sym,t_,prj_trans); + converter(inflated_extent,*ras_ptr,sym,t_,prj_trans, scale_factor_); if (sym.clip()) converter.set(); //optional clip (default: true) converter.set(); //always transform diff --git a/src/agg/process_polygon_symbolizer.cpp b/src/agg/process_polygon_symbolizer.cpp index bf1f98eac..bc96e0f3c 100644 --- a/src/agg/process_polygon_symbolizer.cpp +++ b/src/agg/process_polygon_symbolizer.cpp @@ -51,7 +51,7 @@ void agg_renderer::process(polygon_symbolizer const& sym, typedef boost::mpl::vector conv_types; vertex_converter,rasterizer,polygon_symbolizer, proj_transform, CoordTransform,conv_types> - converter(inflated_extent,*ras_ptr,sym,t_,prj_trans); + converter(inflated_extent,*ras_ptr,sym,t_,prj_trans,scale_factor_); if (sym.clip()) converter.set(); //optional clip (default: true) converter.set(); //always transform