Merge branch 'fix-raster-scaling' of https://github.com/mapycz/mapnik into mapycz-fix-raster-scaling

This commit is contained in:
artemp 2015-06-11 10:28:41 +01:00
commit e32465368b
3 changed files with 36 additions and 28 deletions

View file

@ -53,7 +53,8 @@ struct image_dispatcher
double scale_x, double scale_y, double scale_x, double scale_y,
scaling_method_e method, double filter_factor, scaling_method_e method, double filter_factor,
double opacity, composite_mode_e comp_op, double opacity, composite_mode_e comp_op,
raster_symbolizer const& sym, feature_impl const& feature, F & composite, boost::optional<double> const& nodata) raster_symbolizer const& sym, feature_impl const& feature,
F & composite, boost::optional<double> const& nodata, bool scale)
: start_x_(start_x), : start_x_(start_x),
start_y_(start_y), start_y_(start_y),
width_(width), width_(width),
@ -67,25 +68,40 @@ struct image_dispatcher
sym_(sym), sym_(sym),
feature_(feature), feature_(feature),
composite_(composite), composite_(composite),
nodata_(nodata) {} nodata_(nodata),
scale_(scale) {}
void operator() (image_null const& data_in) const {} //no-op void operator() (image_null const& data_in) const {} //no-op
void operator() (image_rgba8 const& data_in) const void operator() (image_rgba8 const& data_in) const
{
if (scale_)
{ {
image_rgba8 data_out(width_, height_, true, true); image_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_); 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_); composite_(data_out, comp_op_, opacity_, start_x_, start_y_);
} }
else
{
composite_(data_in, comp_op_, opacity_, start_x_, start_y_);
}
}
template <typename T> template <typename T>
void operator() (T const& data_in) const void operator() (T const& data_in) const
{ {
using image_type = T; using image_type = T;
image_type data_out(width_, height_);
scale_image_agg(data_out, data_in, method_, scale_x_, scale_y_, 0.0, 0.0, filter_factor_);
image_rgba8 dst(width_, height_); image_rgba8 dst(width_, height_);
raster_colorizer_ptr colorizer = get<raster_colorizer_ptr>(sym_, keys::colorizer); raster_colorizer_ptr colorizer = get<raster_colorizer_ptr>(sym_, keys::colorizer);
if (scale_)
{
image_type data_out(width_, height_);
scale_image_agg(data_out, data_in, method_, scale_x_, scale_y_, 0.0, 0.0, filter_factor_);
if (colorizer) colorizer->colorize(dst, data_out, nodata_, feature_); if (colorizer) colorizer->colorize(dst, data_out, nodata_, feature_);
}
else
{
if (colorizer) colorizer->colorize(dst, data_in, nodata_, feature_);
}
premultiply_alpha(dst); premultiply_alpha(dst);
composite_(dst, comp_op_, opacity_, start_x_, start_y_); composite_(dst, comp_op_, opacity_, start_x_, start_y_);
} }
@ -104,6 +120,7 @@ private:
feature_impl const& feature_; feature_impl const& feature_;
composite_function & composite_; composite_function & composite_;
boost::optional<double> const& nodata_; boost::optional<double> const& nodata_;
bool scale_;
}; };
template <typename F> template <typename F>
@ -231,28 +248,19 @@ void render_raster_symbolizer(raster_symbolizer const& sym,
double image_ratio_x = ext.width() / source->data_.width(); double image_ratio_x = ext.width() / source->data_.width();
double image_ratio_y = ext.height() / source->data_.height(); double image_ratio_y = ext.height() / source->data_.height();
double eps = 1e-5; double eps = 1e-5;
if ( (std::fabs(image_ratio_x - 1.0) <= eps) && bool scale = (std::fabs(image_ratio_x - 1.0) > eps) ||
(std::fabs(image_ratio_y - 1.0) <= eps) && (std::fabs(image_ratio_y - 1.0) > eps) ||
(std::abs(start_x) <= eps) && (std::abs(start_x) > eps) ||
(std::abs(start_y) <= eps) ) (std::abs(start_y) > eps);
{
if (source->data_.is<image_rgba8>())
{
composite(util::get<image_rgba8>(source->data_), comp_op, opacity, start_x, start_y);
}
}
else
{
detail::image_dispatcher<F> dispatcher(start_x, start_y, raster_width, raster_height, detail::image_dispatcher<F> dispatcher(start_x, start_y, raster_width, raster_height,
image_ratio_x, image_ratio_y, image_ratio_x, image_ratio_y,
scaling_method, source->get_filter_factor(), scaling_method, source->get_filter_factor(),
opacity, comp_op, sym, feature, composite, source->nodata()); opacity, comp_op, sym, feature, composite, source->nodata(), scale);
util::apply_visitor(dispatcher, source->data_); util::apply_visitor(dispatcher, source->data_);
} }
} }
} }
} }
}
} // namespace mapnik } // namespace mapnik

View file

@ -51,7 +51,7 @@ void agg_renderer<T0,T1>::process(raster_symbolizer const& sym,
{ {
render_raster_symbolizer( render_raster_symbolizer(
sym, feature, prj_trans, common_, sym, feature, prj_trans, common_,
[&](image_rgba8 & target, composite_mode_e comp_op, double opacity, [&](image_rgba8 const & target, composite_mode_e comp_op, double opacity,
int start_x, int start_y) { int start_x, int start_y) {
composite(*current_buffer_, target, composite(*current_buffer_, target,
comp_op, opacity, start_x, start_y); comp_op, opacity, start_x, start_y);

View file

@ -43,7 +43,7 @@ void cairo_renderer<T>::process(raster_symbolizer const& sym,
cairo_save_restore guard(context_); cairo_save_restore guard(context_);
render_raster_symbolizer( render_raster_symbolizer(
sym, feature, prj_trans, common_, sym, feature, prj_trans, common_,
[&](image_rgba8 &target, composite_mode_e comp_op, double opacity, [&](image_rgba8 const & target, composite_mode_e comp_op, double opacity,
int start_x, int start_y) { int start_x, int start_y) {
context_.set_operator(comp_op); context_.set_operator(comp_op);
context_.add_image(start_x, start_y, target, opacity); context_.add_image(start_x, start_y, target, opacity);