+ make comp_op boost::optional<>

+ use plain pixf when style_level_compositing=true
This commit is contained in:
Artem Pavlenko 2012-04-23 15:41:18 +01:00
parent 377f851a69
commit a4cdc7a1c0
9 changed files with 70 additions and 63 deletions

View file

@ -95,7 +95,7 @@ void set_join_caps(Stroke const& stroke_, PathType & stroke)
template <typename PixelFormat>
struct renderer_ : private boost::noncopyable
struct renderer_scanline_solid : private boost::noncopyable
{
typedef PixelFormat pixfmt_type;
typedef typename pixfmt_type::color_type color_type;
@ -104,7 +104,7 @@ struct renderer_ : private boost::noncopyable
typedef agg::renderer_scanline_aa_solid<ren_base> renderer;
typedef agg::scanline_u8 scanline_type;
renderer_()
renderer_scanline_solid()
: renb_(),
ren_(renb_)
{}
@ -124,19 +124,14 @@ struct renderer_ : private boost::noncopyable
void render(Rasterizer & ras)
{
agg::render_scanlines(ras, sl_, ren_);
sl_. reset_spans();
sl_.reset_spans();
}
scanline_type sl_;
ren_base renb_;
renderer ren_;
};
struct aa_renderer : renderer_<agg::pixfmt_rgba32>
{
typedef agg::pixfmt_rgba32 pixel_format_type;
};
}
#endif //MAPNIK_AGG_HELPERS_HPP

View file

@ -48,7 +48,6 @@ namespace mapnik {
class marker;
struct rasterizer;
struct aa_renderer;
template <typename T>
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T> >,
@ -122,7 +121,7 @@ private:
buffer_type & pixmap_;
boost::shared_ptr<buffer_type> internal_buffer_;
mutable buffer_type * current_buffer_;
mutable bool style_level_compositing_;
unsigned width_;
unsigned height_;
double scale_factor_;
@ -132,11 +131,7 @@ private:
boost::shared_ptr<label_collision_detector4> detector_;
boost::scoped_ptr<rasterizer> ras_ptr;
box2d<double> query_extent_;
void setup(Map const &m);
void set_current_buffer(bool per_layer = false);
};
}

View file

@ -29,6 +29,8 @@
#include <mapnik/enumeration.hpp>
#include <mapnik/image_filter.hpp>
// boost
#include <boost/optional.hpp>
// stl
#include <vector>
@ -54,7 +56,7 @@ private:
// image_filters
std::vector<filter::filter_type> filters_;
// comp-op
composite_mode_e comp_op_;
boost::optional<composite_mode_e> comp_op_;
// The rule_ptrs vectors are only valid for the scale_denom_validity_.
double scale_denom_validity_;
rule_ptrs if_rules_;
@ -84,7 +86,7 @@ public:
std::vector<filter::filter_type> & image_filters();
// compositing
void set_comp_op(composite_mode_e comp_op);
composite_mode_e comp_op() const;
boost::optional<composite_mode_e> comp_op() const;
~feature_type_style() {}

View file

@ -31,6 +31,7 @@
// boost
#include <boost/array.hpp>
#include <boost/optional.hpp>
namespace mapnik
{
@ -46,8 +47,7 @@ public:
: properties_(),
properties_complete_(),
writer_name_(),
writer_ptr_(),
comp_op_(clear)
writer_ptr_()
{
affine_transform_[0] = 1.0;
affine_transform_[1] = 0.0;
@ -96,7 +96,7 @@ public:
std::string const& get_metawriter_name() const { return writer_name_; }
void set_comp_op(composite_mode_e comp_op);
composite_mode_e comp_op() const;
boost::optional<composite_mode_e> comp_op() const;
void set_transform(transform_type const& );
transform_type const& get_transform() const;
std::string get_transform_string() const;
@ -105,7 +105,7 @@ private:
metawriter_properties properties_complete_;
std::string writer_name_;
metawriter_ptr writer_ptr_;
composite_mode_e comp_op_;
boost::optional<composite_mode_e> comp_op_;
transform_type affine_transform_;
};

View file

@ -89,6 +89,7 @@ agg_renderer<T>::agg_renderer(Map const& m, T & pixmap, double scale_factor, uns
pixmap_(pixmap),
internal_buffer_(),
current_buffer_(&pixmap),
style_level_compositing_(false),
width_(pixmap_.width()),
height_(pixmap_.height()),
scale_factor_(scale_factor),
@ -108,6 +109,7 @@ agg_renderer<T>::agg_renderer(Map const& m, T & pixmap, boost::shared_ptr<label_
pixmap_(pixmap),
internal_buffer_(),
current_buffer_(&pixmap),
style_level_compositing_(false),
width_(pixmap_.width()),
height_(pixmap_.height()),
scale_factor_(scale_factor),
@ -172,7 +174,7 @@ template <typename T>
void agg_renderer<T>::end_map_processing(Map const& )
{
agg::rendering_buffer buf(current_buffer_->raw_data(),width_,height_, width_ * 4);
aa_renderer::pixel_format_type pixf(buf);
agg::pixfmt_rgba32 pixf(buf);
pixf.demultiply();
#ifdef MAPNIK_DEBUG
std::clog << "end map processing\n";
@ -211,12 +213,15 @@ void agg_renderer<T>::start_style_processing(feature_type_style const& st)
#ifdef MAPNIK_DEBUG
std::clog << "start style processing\n";
#endif
if (st.comp_op() != clear || st.image_filters().size() > 0)
if (st.comp_op()) style_level_compositing_ = true;
else style_level_compositing_ = false;
if (style_level_compositing_ || st.image_filters().size() > 0)
{
if (!internal_buffer_)
internal_buffer_ = boost::make_shared<buffer_type>(pixmap_.width(),pixmap_.height());
internal_buffer_ = boost::make_shared<buffer_type>(pixmap_.width(),pixmap_.height());
else
internal_buffer_->set_background(color(0,0,0,0)); // transparent
internal_buffer_->set_background(color(0,0,0,0)); // fill with transparent colour
current_buffer_ = internal_buffer_.get();
}
else
@ -228,10 +233,10 @@ void agg_renderer<T>::start_style_processing(feature_type_style const& st)
template <typename T>
void agg_renderer<T>::end_style_processing(feature_type_style const& st)
{
bool blend = false;
bool blend_from = false;
if (st.image_filters().size() > 0)
{
blend = true;
blend_from = true;
mapnik::filter::filter_visitor<image_32> visitor(*current_buffer_);
BOOST_FOREACH(mapnik::filter::filter_type filter_tag, st.image_filters())
{
@ -239,11 +244,11 @@ void agg_renderer<T>::end_style_processing(feature_type_style const& st)
}
}
if (st.comp_op() != clear) // compositing FIXME: add 'none' to comp-op enum
if (st.comp_op())
{
composite(pixmap_.data(),current_buffer_->data(), st.comp_op(),false,false);
composite(pixmap_.data(),current_buffer_->data(), *st.comp_op(),false,false);
}
else if (blend)
else if (blend_from)
{
agg::rendering_buffer in(current_buffer_->raw_data(), current_buffer_->width(),
current_buffer_->height(), current_buffer_->width() * 4);
@ -251,10 +256,9 @@ void agg_renderer<T>::end_style_processing(feature_type_style const& st)
agg::rendering_buffer out(pixmap_.raw_data(), pixmap_.width(),
pixmap_.height(), pixmap_.width() * 4);
agg::pixfmt_rgba32 pixf_in(in);
agg::pixfmt_rgba32 pixf_out(out);
agg::renderer_base<agg::pixfmt_rgba32> ren(pixf_out);
ren.blend_from(pixf_in,0,0,0,255);
agg::pixfmt_rgba32_plain pixf_in(in);
agg::pixfmt_rgba32_plain pixf_out(out);
pixf_out.blend_from(pixf_in,0,0,0,0,0,255);
}
#ifdef MAPNIK_DEBUG
std::clog << "end style processing\n";

View file

@ -62,8 +62,7 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
agg::rendering_buffer buf(current_buffer_->raw_data(),width_,height_, width_ * 4);
//agg::pixfmt_rgba32 pixf(buf);
aa_renderer::pixel_format_type pixf(buf);
box2d<double> ext = query_extent_ * 1.1;
if (sym.get_rasterizer() == RASTERIZER_FAST)
@ -103,9 +102,6 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
{
ras_ptr->reset();
set_gamma_method(stroke_, ras_ptr);
aa_renderer ren;
ren.attach(pixf);
//metawriter_with_properties writer = sym.get_metawriter();
typedef boost::mpl::vector<clip_line_tag,transform_tag, affine_transform_tag, smooth_tag, dash_tag, stroke_tag> conv_types;
vertex_converter<box2d<double>,rasterizer,line_symbolizer, proj_transform, CoordTransform,conv_types>
@ -129,16 +125,8 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
agg::rendering_buffer buf(current_buffer_->raw_data(),width_,height_, width_ * 4);
if (sym.comp_op() == clear)
if (sym.comp_op())
{
aa_renderer::pixfmt_type pixf(buf);
aa_renderer ren;
ren.attach(pixf);
ren.color(agg::rgba8(r, g, b, int(a * stroke_.get_opacity())));
ren.render(*ras_ptr);
}
else
{
typedef agg::rgba8 color_type;
typedef agg::order_rgba order_type;
typedef agg::pixel32_type pixel_type;
@ -147,13 +135,29 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
typedef agg::renderer_base<pixfmt_comp_type> renderer_base;
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_type;
pixfmt_comp_type pixf(buf);
pixf.comp_op(static_cast<agg::comp_op_e>(sym.comp_op()));
pixf.comp_op(static_cast<agg::comp_op_e>(*sym.comp_op()));
renderer_base renb(pixf);
renderer_type ren(renb);
ren.color(agg::rgba8(r, g, b, int(a * stroke_.get_opacity())));
agg::scanline_u8 sl;
agg::render_scanlines(*ras_ptr, sl, ren);
}
else if (style_level_compositing_)
{
agg::pixfmt_rgba32_plain pixf(buf);
renderer_scanline_solid<agg::pixfmt_rgba32_plain> ren;
ren.attach(pixf);
ren.color(agg::rgba8(r, g, b, int(a * stroke_.get_opacity())));
ren.render(*ras_ptr);
}
else
{
agg::pixfmt_rgba32 pixf(buf);
renderer_scanline_solid<agg::pixfmt_rgba32> ren;
ren.attach(pixf);
ren.color(agg::rgba8(r, g, b, int(a * stroke_.get_opacity())));
ren.render(*ras_ptr);
}
}
}

View file

@ -75,16 +75,8 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
unsigned b=fill.blue();
unsigned a=fill.alpha();
if (sym.comp_op() == clear)
if (sym.comp_op())
{
aa_renderer::pixfmt_type pixf(buf);
aa_renderer ren;
ren.attach(pixf);
ren.color(agg::rgba8(r, g, b, int(a * sym.get_opacity())));
ren.render(*ras_ptr);
}
else
{
typedef agg::rgba8 color_type;
typedef agg::order_rgba order_type;
typedef agg::pixel32_type pixel_type;
@ -93,14 +85,30 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
typedef agg::renderer_base<pixfmt_comp_type> renderer_base;
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_type;
pixfmt_comp_type pixf(buf);
pixf.comp_op(static_cast<agg::comp_op_e>(sym.comp_op()));
pixf.comp_op(static_cast<agg::comp_op_e>(*sym.comp_op()));
renderer_base renb(pixf);
renderer_type ren(renb);
ren.color(agg::rgba8(r, g, b, int(a * sym.get_opacity())));
agg::scanline_u8 sl;
agg::render_scanlines(*ras_ptr, sl, ren);
}
else if (style_level_compositing_)
{
// use plain pixel format
agg::pixfmt_rgba32_plain pixf(buf);
renderer_scanline_solid<agg::pixfmt_rgba32_plain> ren;
ren.attach(pixf);
ren.color(agg::rgba8(r, g, b, int(a * sym.get_opacity())));
ren.render(*ras_ptr);
}
else
{
agg::pixfmt_rgba32 pixf(buf);
renderer_scanline_solid<agg::pixfmt_rgba32> ren;
ren.attach(pixf);
ren.color(agg::rgba8(r, g, b, int(a * sym.get_opacity())));
ren.render(*ras_ptr);
}
}
template void agg_renderer<image_32>::process(polygon_symbolizer const&,

View file

@ -37,7 +37,6 @@ IMPLEMENT_ENUM( filter_mode_e, filter_mode_strings )
feature_type_style::feature_type_style()
: filter_mode_(FILTER_ALL),
filters_(),
comp_op_(clear),
scale_denom_validity_(-1)
{}
@ -109,7 +108,7 @@ void feature_type_style::set_comp_op(composite_mode_e comp_op)
comp_op_ = comp_op;
}
composite_mode_e feature_type_style::comp_op() const
boost::optional<composite_mode_e> feature_type_style::comp_op() const
{
return comp_op_;
}

View file

@ -75,7 +75,7 @@ void symbolizer_base::set_comp_op(composite_mode_e comp_op)
comp_op_ = comp_op;
}
composite_mode_e symbolizer_base::comp_op() const
boost::optional<composite_mode_e> symbolizer_base::comp_op() const
{
return comp_op_;
}