Compare commits
11 commits
master
...
layer-opac
Author | SHA1 | Date | |
---|---|---|---|
|
dc5b9202ac | ||
|
7be976d691 | ||
|
947e24730b | ||
|
4c4d265f08 | ||
|
4fec802492 | ||
|
624de4dcf4 | ||
|
299fedaaa6 | ||
|
5d3ee5787e | ||
|
b75ae3a16f | ||
|
2003df01a1 | ||
|
79f8433329 |
5 changed files with 69 additions and 7 deletions
|
@ -159,8 +159,11 @@ protected:
|
|||
private:
|
||||
buffer_type & pixmap_;
|
||||
std::shared_ptr<buffer_type> internal_buffer_;
|
||||
std::shared_ptr<buffer_type> internal_buffer2_;
|
||||
mutable buffer_type * current_layer_buffer_;
|
||||
mutable buffer_type * current_buffer_;
|
||||
mutable bool style_level_compositing_;
|
||||
mutable bool layer_level_opacity_;
|
||||
const std::unique_ptr<rasterizer> ras_ptr;
|
||||
gamma_method_enum gamma_method_;
|
||||
double gamma_;
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
layer(layer && l);
|
||||
layer& operator=(layer rhs);
|
||||
bool operator==(layer const& other) const;
|
||||
~layer();
|
||||
|
||||
/*!
|
||||
* @brief Set the name of the layer.
|
||||
|
@ -203,7 +204,8 @@ public:
|
|||
void set_buffer_size(int size);
|
||||
boost::optional<int> const& buffer_size() const;
|
||||
void reset_buffer_size();
|
||||
~layer();
|
||||
void set_opacity(float opacity);
|
||||
float get_opacity() const;
|
||||
private:
|
||||
std::string name_;
|
||||
std::string srs_;
|
||||
|
@ -218,6 +220,7 @@ private:
|
|||
datasource_ptr ds_;
|
||||
boost::optional<int> buffer_size_;
|
||||
boost::optional<box2d<double> > maximum_extent_;
|
||||
float opacity_;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -67,8 +67,11 @@ agg_renderer<T0,T1>::agg_renderer(Map const& m, T0 & pixmap, double scale_factor
|
|||
: feature_style_processor<agg_renderer>(m, scale_factor),
|
||||
pixmap_(pixmap),
|
||||
internal_buffer_(),
|
||||
internal_buffer2_(),
|
||||
current_layer_buffer_(&pixmap),
|
||||
current_buffer_(&pixmap),
|
||||
style_level_compositing_(false),
|
||||
layer_level_opacity_(false),
|
||||
ras_ptr(new rasterizer),
|
||||
gamma_method_(GAMMA_POWER),
|
||||
gamma_(1.0),
|
||||
|
@ -82,8 +85,11 @@ agg_renderer<T0,T1>::agg_renderer(Map const& m, request const& req, attributes c
|
|||
: feature_style_processor<agg_renderer>(m, scale_factor),
|
||||
pixmap_(pixmap),
|
||||
internal_buffer_(),
|
||||
internal_buffer2_(),
|
||||
current_layer_buffer_(&pixmap),
|
||||
current_buffer_(&pixmap),
|
||||
style_level_compositing_(false),
|
||||
layer_level_opacity_(false),
|
||||
ras_ptr(new rasterizer),
|
||||
gamma_method_(GAMMA_POWER),
|
||||
gamma_(1.0),
|
||||
|
@ -98,8 +104,11 @@ agg_renderer<T0,T1>::agg_renderer(Map const& m, T0 & pixmap, std::shared_ptr<T1>
|
|||
: feature_style_processor<agg_renderer>(m, scale_factor),
|
||||
pixmap_(pixmap),
|
||||
internal_buffer_(),
|
||||
internal_buffer2_(),
|
||||
current_layer_buffer_(&pixmap),
|
||||
current_buffer_(&pixmap),
|
||||
style_level_compositing_(false),
|
||||
layer_level_opacity_(false),
|
||||
ras_ptr(new rasterizer),
|
||||
gamma_method_(GAMMA_POWER),
|
||||
gamma_(1.0),
|
||||
|
@ -192,11 +201,36 @@ void agg_renderer<T0,T1>::start_layer_processing(layer const& lay, box2d<double>
|
|||
{
|
||||
common_.query_extent_.clip(*maximum_extent);
|
||||
}
|
||||
|
||||
// layer opacity
|
||||
if (lay.get_opacity() < 1.0f)
|
||||
{
|
||||
layer_level_opacity_ = true;
|
||||
if (!internal_buffer2_)
|
||||
{
|
||||
internal_buffer2_ = std::make_shared<buffer_type>(pixmap_.width(),pixmap_.height());
|
||||
}
|
||||
else
|
||||
{
|
||||
internal_buffer2_->set_background(color(0,0,0,0)); // fill with transparent colour
|
||||
}
|
||||
current_layer_buffer_ = internal_buffer2_.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
layer_level_opacity_ = false;
|
||||
current_layer_buffer_ = &pixmap_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template <typename T0, typename T1>
|
||||
void agg_renderer<T0,T1>::end_layer_processing(layer const&)
|
||||
void agg_renderer<T0,T1>::end_layer_processing(layer const& lay)
|
||||
{
|
||||
if (layer_level_opacity_)
|
||||
{
|
||||
composite(pixmap_.data(), current_layer_buffer_->data(), src_over, lay.get_opacity(), 0, 0, false);
|
||||
}
|
||||
MAPNIK_LOG_DEBUG(agg_renderer) << "agg_renderer: End layer processing";
|
||||
}
|
||||
|
||||
|
@ -261,7 +295,7 @@ void agg_renderer<T0,T1>::start_style_processing(feature_type_style const& st)
|
|||
{
|
||||
common_.t_.set_offset(0);
|
||||
ras_ptr->clip_box(0,0,common_.width_,common_.height_);
|
||||
current_buffer_ = &pixmap_;
|
||||
current_buffer_ = current_layer_buffer_;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@ layer::layer(std::string const& name, std::string const& srs)
|
|||
styles_(),
|
||||
ds_(),
|
||||
buffer_size_(),
|
||||
maximum_extent_() {}
|
||||
maximum_extent_()
|
||||
opacity_(1.0f) {}
|
||||
|
||||
layer::layer(layer const& rhs)
|
||||
: name_(rhs.name_),
|
||||
|
@ -59,7 +60,8 @@ layer::layer(layer const& rhs)
|
|||
styles_(rhs.styles_),
|
||||
ds_(rhs.ds_),
|
||||
buffer_size_(rhs.buffer_size_),
|
||||
maximum_extent_(rhs.maximum_extent_) {}
|
||||
maximum_extent_(rhs.maximum_extent_),
|
||||
opacity_(rhs.opacity_) {}
|
||||
|
||||
layer::layer(layer && rhs)
|
||||
: name_(std::move(rhs.name_)),
|
||||
|
@ -74,7 +76,8 @@ layer::layer(layer && rhs)
|
|||
styles_(std::move(rhs.styles_)),
|
||||
ds_(std::move(rhs.ds_)),
|
||||
buffer_size_(std::move(rhs.buffer_size_)),
|
||||
maximum_extent_(std::move(rhs.maximum_extent_)) {}
|
||||
maximum_extent_(std::move(rhs.maximum_extent_)),
|
||||
opacity_(std::move(rhs.opacity_)) {}
|
||||
|
||||
layer& layer::operator=(layer rhs)
|
||||
{
|
||||
|
@ -92,6 +95,7 @@ layer& layer::operator=(layer rhs)
|
|||
std::swap(this->ds_, rhs.ds_);
|
||||
std::swap(this->buffer_size_, rhs.buffer_size_);
|
||||
std::swap(this->maximum_extent_, rhs.maximum_extent_);
|
||||
std::swap(this->opacity_, rhs.opacity_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -109,7 +113,8 @@ bool layer::operator==(layer const& rhs) const
|
|||
(styles_ == rhs.styles_) &&
|
||||
((ds_ && rhs.ds_) ? *ds_ == *rhs.ds_ : ds_ == rhs.ds_) &&
|
||||
(buffer_size_ == rhs.buffer_size_) &&
|
||||
(maximum_extent_ == rhs.maximum_extent_);
|
||||
(maximum_extent_ == rhs.maximum_extent_) &&
|
||||
(opacity_ == rhs.opacity_);
|
||||
}
|
||||
|
||||
layer::~layer() {}
|
||||
|
@ -270,4 +275,15 @@ std::string const& layer::group_by() const
|
|||
return group_by_;
|
||||
}
|
||||
|
||||
void layer::set_opacity(float opacity)
|
||||
{
|
||||
opacity_ = opacity;
|
||||
}
|
||||
|
||||
float layer::get_opacity() const
|
||||
{
|
||||
return opacity_;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -656,6 +656,12 @@ void map_parser::parse_layer(Map & map, xml_node const& node)
|
|||
}
|
||||
}
|
||||
|
||||
optional<float> opacity = node.get_opt_attr<float>("opacity");
|
||||
if (opacity)
|
||||
{
|
||||
lyr.set_opacity(* opacity);
|
||||
}
|
||||
|
||||
for (auto const& child: node)
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in a new issue