Adding gamma-method to polygon symbolizer
This commit is contained in:
parent
88af05fadc
commit
c007a608ff
7 changed files with 120 additions and 7 deletions
|
@ -22,8 +22,10 @@
|
|||
//$Id$
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include "mapnik_enumeration.hpp"
|
||||
#include <mapnik/polygon_symbolizer.hpp>
|
||||
|
||||
using namespace mapnik;
|
||||
using mapnik::polygon_symbolizer;
|
||||
using mapnik::color;
|
||||
|
||||
|
@ -38,17 +40,17 @@ struct polygon_symbolizer_pickle_suite : boost::python::pickle_suite
|
|||
static boost::python::tuple
|
||||
getstate(const polygon_symbolizer& p)
|
||||
{
|
||||
return boost::python::make_tuple(p.get_opacity(),p.get_gamma());
|
||||
return boost::python::make_tuple(p.get_opacity(),p.get_gamma(),p.get_gamma_method());
|
||||
}
|
||||
|
||||
static void
|
||||
setstate (polygon_symbolizer& p, boost::python::tuple state)
|
||||
{
|
||||
using namespace boost::python;
|
||||
if (len(state) != 2)
|
||||
if (len(state) != 3)
|
||||
{
|
||||
PyErr_SetObject(PyExc_ValueError,
|
||||
("expected 2-item tuple in call to __setstate__; got %s"
|
||||
("expected 3-item tuple in call to __setstate__; got %s"
|
||||
% state).ptr()
|
||||
);
|
||||
throw_error_already_set();
|
||||
|
@ -56,6 +58,7 @@ struct polygon_symbolizer_pickle_suite : boost::python::pickle_suite
|
|||
|
||||
p.set_opacity(extract<float>(state[0]));
|
||||
p.set_gamma(extract<float>(state[1]));
|
||||
p.set_gamma_method(extract<gamma_method_e>(state[2]));
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -64,6 +67,14 @@ void export_polygon_symbolizer()
|
|||
{
|
||||
using namespace boost::python;
|
||||
|
||||
enumeration_<gamma_method_e>("gamma_method")
|
||||
.value("POWER", GAMMA_POWER)
|
||||
.value("LINEAR", GAMMA_LINEAR)
|
||||
.value("NONE", GAMMA_NONE)
|
||||
.value("THRESHOLD", GAMMA_THRESHOLD)
|
||||
.value("MULTIPLY", GAMMA_MULTIPLY)
|
||||
;
|
||||
|
||||
class_<polygon_symbolizer>("PolygonSymbolizer",
|
||||
init<>("Default PolygonSymbolizer - solid fill grey"))
|
||||
.def(init<color const&>("TODO"))
|
||||
|
@ -78,6 +89,10 @@ void export_polygon_symbolizer()
|
|||
.add_property("gamma",
|
||||
&polygon_symbolizer::get_gamma,
|
||||
&polygon_symbolizer::set_gamma)
|
||||
.add_property("gamma_method",
|
||||
&polygon_symbolizer::get_gamma_method,
|
||||
&polygon_symbolizer::set_gamma_method,
|
||||
"Set/get the gamma correction method of the polygon")
|
||||
;
|
||||
|
||||
}
|
||||
|
|
|
@ -27,22 +27,40 @@
|
|||
#include <mapnik/color.hpp>
|
||||
#include <mapnik/symbolizer.hpp>
|
||||
#include <mapnik/filter_factory.hpp>
|
||||
#include <mapnik/enumeration.hpp>
|
||||
|
||||
// stl
|
||||
#include <string>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
enum gamma_method_enum {
|
||||
GAMMA_POWER, //agg::gamma_power
|
||||
GAMMA_LINEAR, //agg::gamma_linear
|
||||
GAMMA_NONE, //agg::gamma_none
|
||||
GAMMA_THRESHOLD, //agg::gamma_threshold
|
||||
GAMMA_MULTIPLY, //agg::gamma_multiply
|
||||
gamma_method_enum_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( gamma_method_e, gamma_method_enum );
|
||||
|
||||
struct MAPNIK_DECL polygon_symbolizer : public symbolizer_base
|
||||
{
|
||||
explicit polygon_symbolizer()
|
||||
: symbolizer_base(),
|
||||
fill_(color(128,128,128)),
|
||||
opacity_(1.0),
|
||||
gamma_(1.0) {}
|
||||
gamma_(1.0),
|
||||
gamma_method_(GAMMA_POWER) {}
|
||||
|
||||
polygon_symbolizer(color const& fill)
|
||||
: symbolizer_base(),
|
||||
fill_(fill),
|
||||
opacity_(1.0),
|
||||
gamma_(1.0) {}
|
||||
gamma_(1.0),
|
||||
gamma_method_(GAMMA_POWER) {}
|
||||
|
||||
color const& get_fill() const
|
||||
{
|
||||
|
@ -68,11 +86,20 @@ struct MAPNIK_DECL polygon_symbolizer : public symbolizer_base
|
|||
{
|
||||
return gamma_;
|
||||
}
|
||||
void set_gamma_method(gamma_method_e gamma_method)
|
||||
{
|
||||
gamma_method_ = gamma_method;
|
||||
}
|
||||
gamma_method_e get_gamma_method() const
|
||||
{
|
||||
return gamma_method_;
|
||||
}
|
||||
|
||||
private:
|
||||
color fill_;
|
||||
double opacity_;
|
||||
double gamma_;
|
||||
gamma_method_e gamma_method_;
|
||||
};
|
||||
|
||||
struct MAPNIK_DECL building_symbolizer : public symbolizer_base
|
||||
|
|
|
@ -62,7 +62,26 @@ void agg_renderer<T>::process(polygon_symbolizer const& sym,
|
|||
renderer ren(renb);
|
||||
|
||||
ras_ptr->reset();
|
||||
ras_ptr->gamma(agg::gamma_power(sym.get_gamma()));
|
||||
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()));
|
||||
}
|
||||
|
||||
metawriter_with_properties writer = sym.get_metawriter();
|
||||
for (unsigned i=0;i<feature.num_geometries();++i)
|
||||
{
|
||||
|
|
|
@ -128,6 +128,7 @@ source = Split(
|
|||
png_reader.cpp
|
||||
point_symbolizer.cpp
|
||||
polygon_pattern_symbolizer.cpp
|
||||
polygon_symbolizer.cpp
|
||||
save_map.cpp
|
||||
shield_symbolizer.cpp
|
||||
text_symbolizer.cpp
|
||||
|
|
|
@ -1883,7 +1883,7 @@ void map_parser::parse_line_symbolizer( rule & rule, ptree const & sym )
|
|||
|
||||
void map_parser::parse_polygon_symbolizer( rule & rule, ptree const & sym )
|
||||
{
|
||||
ensure_attrs(sym, "PolygonSymbolizer", "fill,fill-opacity,gamma,meta-writer,meta-output");
|
||||
ensure_attrs(sym, "PolygonSymbolizer", "fill,fill-opacity,gamma,gamma-method,meta-writer,meta-output");
|
||||
try
|
||||
{
|
||||
polygon_symbolizer poly_sym;
|
||||
|
@ -1896,6 +1896,9 @@ void map_parser::parse_polygon_symbolizer( rule & rule, ptree const & sym )
|
|||
// gamma
|
||||
optional<double> gamma = get_opt_attr<double>(sym, "gamma");
|
||||
if (gamma) poly_sym.set_gamma(*gamma);
|
||||
// gamma method
|
||||
gamma_method_e gamma_method = get_attr<gamma_method_e>(sym, "gamma-method", GAMMA_POWER);
|
||||
poly_sym.set_gamma_method(gamma_method);
|
||||
|
||||
parse_metawriter_in_symbolizer(poly_sym, sym);
|
||||
rule.append(poly_sym);
|
||||
|
|
44
src/polygon_symbolizer.cpp
Normal file
44
src/polygon_symbolizer.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
// mapnik
|
||||
#include <mapnik/polygon_symbolizer.hpp>
|
||||
#include <mapnik/enumeration.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
static const char * gamma_method_strings[] = {
|
||||
"power", //agg::gamma_power
|
||||
"linear", //agg::gamma_linear
|
||||
"none", //agg::gamma_none
|
||||
"threshold", //agg::gamma_threshold
|
||||
"multiply", //agg::gamma_multiply",
|
||||
""
|
||||
};
|
||||
|
||||
|
||||
IMPLEMENT_ENUM( gamma_method_e, gamma_method_strings )
|
||||
|
||||
}
|
||||
|
|
@ -118,6 +118,10 @@ public:
|
|||
{
|
||||
set_attr( sym_node, "gamma", sym.get_gamma() );
|
||||
}
|
||||
if ( sym.get_gamma_method() != dfl.get_gamma_method() || explicit_defaults_ )
|
||||
{
|
||||
set_attr( sym_node, "gamma-method", sym.get_gamma_method() );
|
||||
}
|
||||
add_metawriter_attributes(sym_node, sym);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue