optimize raster rendering when not resizing

This commit is contained in:
Dane Springmeyer 2014-05-15 23:38:47 -07:00
parent 03bb19dc3a
commit aaae8b1cba
3 changed files with 43 additions and 26 deletions

View file

@ -23,6 +23,9 @@
#ifndef MAPNIK_RENDERER_COMMON_PROCESS_RASTER_SYMBOLIZER_HPP
#define MAPNIK_RENDERER_COMMON_PROCESS_RASTER_SYMBOLIZER_HPP
// mapnik
#include <mapnik/warp.hpp>
// agg
#include "agg_rendering_buffer.h"
#include "agg_pixfmt_rgba.h"
@ -55,10 +58,8 @@ void render_raster_symbolizer(raster_symbolizer const &sym,
int raster_height = end_y - start_y;
if (raster_width > 0 && raster_height > 0)
{
raster target(target_ext, raster_width, raster_height, source->get_filter_factor());
scaling_method_e scaling_method = get<scaling_method_e>(sym, keys::scaling, feature, common.vars_, SCALING_NEAR);
composite_mode_e comp_op = get<composite_mode_e>(sym, keys::comp_op, feature, common.vars_, src_over);
double opacity = get<double>(sym,keys::opacity,feature, common.vars_, 1.0);
bool premultiply_source = !source->premultiplied_alpha_;
auto is_premultiplied = get_optional<bool>(sym, keys::premultiplied, feature, common.vars_);
@ -80,6 +81,7 @@ void render_raster_symbolizer(raster_symbolizer const &sym,
{
double offset_x = ext.minx() - start_x;
double offset_y = ext.miny() - start_y;
raster target(target_ext, raster_width, raster_height, source->get_filter_factor());
unsigned mesh_size = static_cast<unsigned>(get<value_integer>(sym,keys::mesh_size,feature, common.vars_, 16));
reproject_and_scale_raster(target,
*source,
@ -88,9 +90,23 @@ void render_raster_symbolizer(raster_symbolizer const &sym,
offset_y,
mesh_size,
scaling_method);
composite(target.data_, comp_op, opacity, start_x, start_y);
}
else
{
double image_ratio_x = ext.width() / source->data_.width();
double image_ratio_y = ext.height() / source->data_.height();
double eps = 1e-5;
if ( (std::fabs(image_ratio_x - 1) <= eps) &&
(std::fabs(image_ratio_y - 1) <= eps) &&
(std::fabs(start_x) <= eps) &&
(std::fabs(start_y) <= eps) )
{
composite(source->data_, comp_op, opacity, start_x, start_y);
}
else
{
raster target(target_ext, raster_width, raster_height, source->get_filter_factor());
if (scaling_method == SCALING_BILINEAR8)
{
scale_image_bilinear8<image_data_32>(target.data_,
@ -111,8 +127,9 @@ void render_raster_symbolizer(raster_symbolizer const &sym,
0.0,
source->get_filter_factor());
}
composite(target.data_, comp_op, opacity, start_x, start_y);
}
}
composite(target, comp_op, opacity, start_x, start_y);
}
}
}

View file

@ -33,7 +33,6 @@
#include <mapnik/image_util.hpp>
#include <mapnik/raster.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/warp.hpp>
#include <mapnik/config.hpp>
#include <mapnik/renderer_common/process_raster_symbolizer.hpp>
@ -53,11 +52,12 @@ void agg_renderer<T0,T1>::process(raster_symbolizer const& sym,
{
render_raster_symbolizer(
sym, feature, prj_trans, common_,
[&](raster &target, composite_mode_e comp_op, double opacity,
[&](image_data_32 & target, composite_mode_e comp_op, double opacity,
int start_x, int start_y) {
composite(current_buffer_->data(), target.data_,
composite(current_buffer_->data(), target,
comp_op, opacity, start_x, start_y, false);
});
}
);
}
template void agg_renderer<image_32>::process(raster_symbolizer const&,

View file

@ -761,14 +761,14 @@ void cairo_renderer_base::process(raster_symbolizer const& sym,
proj_transform const& prj_trans)
{
cairo_save_restore guard(context_);
render_raster_symbolizer(
sym, feature, prj_trans, common_,
[&](raster &target, composite_mode_e comp_op, double opacity,
[&](image_data_32 &target, composite_mode_e comp_op, double opacity,
int start_x, int start_y) {
context_.set_operator(comp_op);
context_.add_image(start_x, start_y, target.data_, opacity);
});
context_.add_image(start_x, start_y, target, opacity);
}
);
}
namespace detail {