fix handling of premultiplied pixels during rendering

This commit is contained in:
Dane Springmeyer 2015-01-14 21:04:05 -08:00
parent 1f25bae0f4
commit 364fb4961b
4 changed files with 8 additions and 11 deletions

View file

@ -25,6 +25,7 @@
// mapnik
#include <mapnik/image_data.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/svg/svg_storage.hpp>
#include <mapnik/svg/svg_path_attributes.hpp>
#include <mapnik/svg/svg_path_adapter.hpp>
@ -56,7 +57,7 @@ public:
marker()
{
// create default OGC 4x4 black pixel
bitmap_data_ = boost::optional<mapnik::image_ptr>(std::make_shared<image_data_rgba8>(4,4));
bitmap_data_ = boost::optional<mapnik::image_ptr>(std::make_shared<image_data_rgba8>(4,4,true,true));
(*bitmap_data_)->set(0xff000000);
}

View file

@ -72,7 +72,7 @@ struct image_data_dispatcher
void operator() (image_data_null const& data_in) const {} //no-op
void operator() (image_data_rgba8 const& data_in) const
{
image_data_rgba8 data_out(width_, height_);
image_data_rgba8 data_out(width_, height_, true, true);
scale_image_agg(data_out, data_in, method_, scale_x_, scale_y_, 0.0, 0.0, filter_factor_);
composite_(data_out, comp_op_, opacity_, start_x_, start_y_);
}
@ -86,6 +86,7 @@ struct image_data_dispatcher
image_data_rgba8 dst(width_, height_);
raster_colorizer_ptr colorizer = get<raster_colorizer_ptr>(sym_, keys::colorizer);
if (colorizer) colorizer->colorize(dst, data_out, nodata_, feature_);
premultiply_alpha(dst);
composite_(dst, comp_op_, opacity_, start_x_, start_y_);
}
private:
@ -138,7 +139,7 @@ struct image_data_warp_dispatcher
void operator() (image_data_rgba8 const& data_in) const
{
image_data_rgba8 data_out(width_, height_);
image_data_rgba8 data_out(width_, height_, true, true);
warp_image(data_out, data_in, prj_trans_, target_ext_, source_ext_, offset_x_, offset_y_, mesh_size_, scaling_method_, filter_factor_);
composite_(data_out, comp_op_, opacity_, start_x_, start_y_);
}
@ -153,6 +154,7 @@ struct image_data_warp_dispatcher
image_data_rgba8 dst(width_, height_);
raster_colorizer_ptr colorizer = get<raster_colorizer_ptr>(sym_, keys::colorizer);
if (colorizer) colorizer->colorize(dst, data_out, nodata_, feature_);
premultiply_alpha(dst);
composite_(dst, comp_op_, opacity_, start_x_, start_y_);
}
private:

View file

@ -111,6 +111,7 @@ agg_renderer<T0,T1>::agg_renderer(Map const& m, T0 & pixmap, std::shared_ptr<T1>
template <typename T0, typename T1>
void agg_renderer<T0,T1>::setup(Map const &m)
{
mapnik::set_premultiplied_alpha(pixmap_.data(), true);
boost::optional<color> const& bg = m.background();
if (bg)
{
@ -145,8 +146,6 @@ void agg_renderer<T0,T1>::setup(Map const &m)
{
for (unsigned y=0;y<y_steps;++y)
{
premultiply_alpha(*bg_image);
premultiply_alpha(pixmap_.data());
composite(pixmap_.data(),*bg_image, m.background_image_comp_op(), m.background_image_opacity(), x*w, y*h);
}
}
@ -255,6 +254,7 @@ void agg_renderer<T0,T1>::start_style_processing(feature_type_style const& st)
ras_ptr->clip_box(0,0,common_.width_,common_.height_);
}
current_buffer_ = internal_buffer_.get();
set_premultiplied_alpha(current_buffer_->data(),true);
}
else
{
@ -279,8 +279,6 @@ void agg_renderer<T0,T1>::end_style_processing(feature_type_style const& st)
util::apply_visitor(visitor, filter_tag);
}
}
mapnik::premultiply_alpha(pixmap_.data());
mapnik::premultiply_alpha(current_buffer_->data());
if (st.comp_op())
{
composite(pixmap_.data(), current_buffer_->data(),
@ -374,8 +372,6 @@ void agg_renderer<T0,T1>::render_marker(pixel_position const& pos,
{
double cx = 0.5 * width;
double cy = 0.5 * height;
mapnik::premultiply_alpha(current_buffer_->data());
mapnik::premultiply_alpha(**marker.get_bitmap_data());
composite(current_buffer_->data(), **marker.get_bitmap_data(),
comp_op, opacity,
std::floor(pos.x - cx + .5),

View file

@ -54,8 +54,6 @@ void agg_renderer<T0,T1>::process(raster_symbolizer const& sym,
sym, feature, prj_trans, common_,
[&](image_data_rgba8 & target, composite_mode_e comp_op, double opacity,
int start_x, int start_y) {
premultiply_alpha(target);
premultiply_alpha(current_buffer_->data());
composite(current_buffer_->data(), target,
comp_op, opacity, start_x, start_y);
}