+ refactor gamma setting logic to avoid code duplication

( agg_helpers.hpp )
This commit is contained in:
Artem Pavlenko 2012-03-14 15:42:22 +00:00
parent 87b22c29b2
commit 108b99725c
4 changed files with 76 additions and 65 deletions

View file

@ -0,0 +1,57 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_AGG_HELPERS_HPP
#define MAPNIK_AGG_HELPERS_HPP
#include "agg_gamma_functions.h"
namespace mapnik {
template <typename T0, typename T1>
void set_gamma_method(T0 const& obj, T1 & ras_ptr)
{
switch (obj.get_gamma_method())
{
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(obj.get_gamma()));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, obj.get_gamma()));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(obj.get_gamma()));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(obj.get_gamma()));
break;
default:
ras_ptr->gamma(agg::gamma_power(obj.get_gamma()));
}
}
}
#endif //MAPNIK_AGG_HELPERS_HPP

View file

@ -23,6 +23,7 @@
// mapnik
#include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_helpers.hpp>
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/line_symbolizer.hpp>
@ -71,7 +72,6 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
agg::line_profile_aa profile;
//agg::line_profile_aa profile(stroke_.get_width() * scale_factor_, agg::gamma_none());
profile.width(stroke_.get_width() * scale_factor_);
ren_base base_ren(pixf);
renderer_type ren(base_ren, profile);
@ -102,26 +102,10 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
ren_base renb(pixf);
renderer ren(renb);
ras_ptr->reset();
switch (stroke_.get_gamma_method())
{
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(stroke_.get_gamma()));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, stroke_.get_gamma()));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(stroke_.get_gamma()));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(stroke_.get_gamma()));
break;
default:
ras_ptr->gamma(agg::gamma_power(stroke_.get_gamma()));
}
set_gamma_method(stroke_, ras_ptr);
//metawriter_with_properties writer = sym.get_metawriter();
for (unsigned i=0;i<feature->num_geometries();++i)
@ -129,12 +113,13 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
geometry_type & geom = feature->get_geometry(i);
if (geom.num_points() > 1)
{
clipped_geometry_type clipped(geom);
clipped.clip_box(ext.minx(),ext.miny(),ext.maxx(),ext.maxy());
path_type path(t_,clipped,prj_trans);
if (stroke_.has_dash())
{
clipped_geometry_type clipped(geom);
clipped.clip_box(ext.minx(),ext.miny(),ext.maxx(),ext.maxy());
path_type path(t_,clipped,prj_trans);
agg::conv_dash<path_type> dash(path);
dash_array const& d = stroke_.get_dash_array();
dash_array::const_iterator itr = d.begin();
@ -172,6 +157,10 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
}
else
{
clipped_geometry_type clipped(geom);
clipped.clip_box(ext.minx(),ext.miny(),ext.maxx(),ext.maxy());
path_type path(t_,clipped,prj_trans);
agg::conv_stroke<path_type> stroke(path);
line_join_e join=stroke_.get_line_join();
if ( join == MITER_JOIN)

View file

@ -23,6 +23,7 @@
// mapnik
#include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_helpers.hpp>
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
@ -72,27 +73,8 @@ void agg_renderer<T>::process(polygon_pattern_symbolizer const& sym,
agg::scanline_u8 sl;
ras_ptr->reset();
switch (sym.get_gamma_method())
{
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(sym.get_gamma()));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, sym.get_gamma()));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(sym.get_gamma()));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(sym.get_gamma()));
break;
default:
ras_ptr->gamma(agg::gamma_power(sym.get_gamma()));
}
set_gamma_method(sym,ras_ptr);
std::string filename = path_processor_type::evaluate( *sym.get_filename(), *feature);
boost::optional<mapnik::marker_ptr> marker;
if ( !filename.empty() )

View file

@ -23,6 +23,7 @@
// mapnik
#include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_helpers.hpp>
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/polygon_symbolizer.hpp>
@ -65,27 +66,9 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
renderer ren(renb);
ras_ptr->reset();
switch (sym.get_gamma_method())
{
case GAMMA_POWER:
ras_ptr->gamma(agg::gamma_power(sym.get_gamma()));
break;
case GAMMA_LINEAR:
ras_ptr->gamma(agg::gamma_linear(0.0, sym.get_gamma()));
break;
case GAMMA_NONE:
ras_ptr->gamma(agg::gamma_none());
break;
case GAMMA_THRESHOLD:
ras_ptr->gamma(agg::gamma_threshold(sym.get_gamma()));
break;
case GAMMA_MULTIPLY:
ras_ptr->gamma(agg::gamma_multiply(sym.get_gamma()));
break;
default:
ras_ptr->gamma(agg::gamma_power(sym.get_gamma()));
}
set_gamma_method(sym,ras_ptr);
//metawriter_with_properties writer = sym.get_metawriter();
for (unsigned i=0;i<feature->num_geometries();++i)
{