From 44c02a10c59aaa71895034154ee5a90f2d9b2373 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 14 Mar 2013 17:05:06 -0700 Subject: [PATCH] reduce overhead of flexible agg gamma setting per symbolizer - closes #1174 --- src/agg/agg_renderer.cpp | 22 +++++++++++++++---- src/agg/process_building_symbolizer.cpp | 7 +++++- src/agg/process_line_symbolizer.cpp | 7 +++++- src/agg/process_markers_symbolizer.cpp | 7 +++++- .../process_polygon_pattern_symbolizer.cpp | 8 +++++-- src/agg/process_polygon_symbolizer.cpp | 8 +++++-- 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/agg/agg_renderer.cpp b/src/agg/agg_renderer.cpp index a0d016f62..cf774eafd 100644 --- a/src/agg/agg_renderer.cpp +++ b/src/agg/agg_renderer.cpp @@ -79,7 +79,10 @@ agg_renderer::agg_renderer(Map const& m, T & pixmap, double scale_factor, uns font_engine_(), font_manager_(font_engine_), detector_(boost::make_shared(box2d(-m.buffer_size(), -m.buffer_size(), m.width() + m.buffer_size() ,m.height() + m.buffer_size()))), - ras_ptr(new rasterizer) + ras_ptr(new rasterizer), + query_extent_(), + gamma_method_(GAMMA_POWER), + gamma_(1.0) { setup(m); } @@ -98,7 +101,10 @@ agg_renderer::agg_renderer(Map const& m, request const& req, T & pixmap, doub font_engine_(), font_manager_(font_engine_), detector_(boost::make_shared(box2d(-req.buffer_size(), -req.buffer_size(), req.width() + req.buffer_size() ,req.height() + req.buffer_size()))), - ras_ptr(new rasterizer) + ras_ptr(new rasterizer), + query_extent_(), + gamma_method_(GAMMA_POWER), + gamma_(1.0) { setup(m); } @@ -118,7 +124,10 @@ agg_renderer::agg_renderer(Map const& m, T & pixmap, boost::shared_ptr::render_marker(pixel_position const& pos, typedef agg::pod_bvector svg_attribute_type; ras_ptr->reset(); - ras_ptr->gamma(agg::gamma_power()); + if (gamma_method_ != GAMMA_POWER || gamma_ != 1.0) + { + ras_ptr->gamma(agg::gamma_power()); + gamma_method_ = GAMMA_POWER; + gamma_ = 1.0; + } agg::scanline_u8 sl; agg::rendering_buffer buf(current_buffer_->raw_data(), width_, height_, width_ * 4); pixfmt_comp_type pixf(buf); diff --git a/src/agg/process_building_symbolizer.cpp b/src/agg/process_building_symbolizer.cpp index 5addaac02..ecb91b3aa 100644 --- a/src/agg/process_building_symbolizer.cpp +++ b/src/agg/process_building_symbolizer.cpp @@ -70,7 +70,12 @@ void agg_renderer::process(building_symbolizer const& sym, agg::scanline_u8 sl; ras_ptr->reset(); - ras_ptr->gamma(agg::gamma_power()); + if (gamma_method_ != GAMMA_POWER || gamma_ != 1.0) + { + ras_ptr->gamma(agg::gamma_power()); + gamma_method_ = GAMMA_POWER; + gamma_ = 1.0; + } double height = 0.0; expression_ptr height_expr = sym.height(); diff --git a/src/agg/process_line_symbolizer.cpp b/src/agg/process_line_symbolizer.cpp index 8138ff098..76cac96dc 100644 --- a/src/agg/process_line_symbolizer.cpp +++ b/src/agg/process_line_symbolizer.cpp @@ -66,7 +66,12 @@ void agg_renderer::process(line_symbolizer const& sym, unsigned a=col.alpha(); ras_ptr->reset(); - set_gamma_method(stroke_, ras_ptr); + if (stroke_.get_gamma() != gamma_ || stroke_.get_gamma_method() != gamma_method_) + { + set_gamma_method(stroke_, ras_ptr); + gamma_method_ = stroke_.get_gamma_method(); + gamma_ = stroke_.get_gamma(); + } agg::rendering_buffer buf(current_buffer_->raw_data(),width_,height_, width_ * 4); diff --git a/src/agg/process_markers_symbolizer.cpp b/src/agg/process_markers_symbolizer.cpp index 95399857a..66913a1b5 100644 --- a/src/agg/process_markers_symbolizer.cpp +++ b/src/agg/process_markers_symbolizer.cpp @@ -83,7 +83,12 @@ void agg_renderer::process(markers_symbolizer const& sym, if (mark && *mark) { ras_ptr->reset(); - ras_ptr->gamma(agg::gamma_power()); + if (gamma_method_ != GAMMA_POWER || gamma_ != 1.0) + { + ras_ptr->gamma(agg::gamma_power()); + gamma_method_ = GAMMA_POWER; + gamma_ = 1.0; + } agg::trans_affine geom_tr; evaluate_transform(geom_tr, feature, sym.get_transform()); agg::trans_affine tr = agg::trans_affine_scaling(scale_factor_); diff --git a/src/agg/process_polygon_pattern_symbolizer.cpp b/src/agg/process_polygon_pattern_symbolizer.cpp index 5297ae3b8..da43f91b3 100644 --- a/src/agg/process_polygon_pattern_symbolizer.cpp +++ b/src/agg/process_polygon_pattern_symbolizer.cpp @@ -61,8 +61,12 @@ void agg_renderer::process(polygon_pattern_symbolizer const& sym, agg::rendering_buffer buf(current_buffer_->raw_data(), width_, height_, width_ * 4); ras_ptr->reset(); - set_gamma_method(sym,ras_ptr); - + if (sym.get_gamma() != gamma_ || sym.get_gamma_method() != gamma_method_) + { + set_gamma_method(sym, ras_ptr); + gamma_method_ = sym.get_gamma_method(); + gamma_ = sym.get_gamma(); + } std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature); boost::optional marker; if ( !filename.empty() ) diff --git a/src/agg/process_polygon_symbolizer.cpp b/src/agg/process_polygon_symbolizer.cpp index 107da8066..febd2a514 100644 --- a/src/agg/process_polygon_symbolizer.cpp +++ b/src/agg/process_polygon_symbolizer.cpp @@ -48,8 +48,12 @@ void agg_renderer::process(polygon_symbolizer const& sym, { ras_ptr->reset(); - set_gamma_method(sym,ras_ptr); - + if (sym.get_gamma() != gamma_ || sym.get_gamma_method() != gamma_method_) + { + set_gamma_method(sym, ras_ptr); + gamma_method_ = sym.get_gamma_method(); + gamma_ = sym.get_gamma(); + } agg::trans_affine tr; evaluate_transform(tr, feature, sym.get_transform());