+ implement offset
``` offset = "<number> | <percentage>" ```
This commit is contained in:
parent
542805e4d6
commit
fe092ac7a2
4 changed files with 56 additions and 17 deletions
|
@ -417,12 +417,18 @@ void apply_filter(Src & src, colorize_alpha const& op)
|
|||
|
||||
double step = 1.0/(size-1);
|
||||
double offset = 0.0;
|
||||
BOOST_FOREACH( mapnik::color const& c, op)
|
||||
BOOST_FOREACH( mapnik::filter::color_stop const& stop, op)
|
||||
{
|
||||
grad_lut.add_color(offset, agg::rgba(c.red()/256.0,
|
||||
c.green()/256.0,
|
||||
c.blue()/256.0,
|
||||
c.alpha()/256.0));
|
||||
mapnik::color const& c = stop.color;
|
||||
double stop_offset = stop.offset;
|
||||
if (stop_offset == 0)
|
||||
{
|
||||
stop_offset = offset;
|
||||
}
|
||||
grad_lut.add_color(stop_offset, agg::rgba(c.red()/256.0,
|
||||
c.green()/256.0,
|
||||
c.blue()/256.0,
|
||||
c.alpha()/256.0));
|
||||
offset += step;
|
||||
}
|
||||
grad_lut.build_lut();
|
||||
|
|
|
@ -25,17 +25,40 @@
|
|||
|
||||
// boost
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/fusion/include/adapt_struct.hpp>
|
||||
// mapnik
|
||||
#include <mapnik/css_color_grammar.hpp>
|
||||
#include <mapnik/image_filter.hpp>
|
||||
// stl
|
||||
#include <vector>
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT(
|
||||
mapnik::filter::color_stop,
|
||||
(mapnik::color, color )
|
||||
(double, offset)
|
||||
)
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
|
||||
struct percent_offset_impl
|
||||
{
|
||||
template <typename T>
|
||||
struct result
|
||||
{
|
||||
typedef double type;
|
||||
};
|
||||
|
||||
double operator() (double val) const
|
||||
{
|
||||
double result = std::abs(val/100.0);
|
||||
if (result > 1.0) result = 1.0;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Iterator, typename ContType>
|
||||
struct image_filter_grammar :
|
||||
qi::grammar<Iterator, ContType(), qi::ascii::space_type>
|
||||
|
@ -46,10 +69,12 @@ struct image_filter_grammar :
|
|||
qi::rule<Iterator, qi::locals<int,int>, void(ContType&), qi::ascii::space_type> agg_blur_filter;
|
||||
qi::rule<Iterator, qi::locals<double,double,double,double,double,double,double,double>,
|
||||
void(ContType&), qi::ascii::space_type> hsla_filter;
|
||||
qi::rule<Iterator, qi::locals<mapnik::filter::colorize_alpha>, void(ContType&), qi::ascii::space_type> colorize_alpha_filter;
|
||||
qi::rule<Iterator, qi::locals<mapnik::filter::colorize_alpha, mapnik::filter::color_stop>, void(ContType&), qi::ascii::space_type> colorize_alpha_filter;
|
||||
qi::rule<Iterator, qi::ascii::space_type> no_args;
|
||||
qi::uint_parser< unsigned, 10, 1, 3 > radius_;
|
||||
css_color_grammar<Iterator> css_color_;
|
||||
qi::rule<Iterator,void(mapnik::filter::color_stop &),qi::ascii::space_type> color_stop_offset;
|
||||
phoenix::function<percent_offset_impl> percent_offset;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -98,16 +98,18 @@ struct hsla
|
|||
double a1;
|
||||
};
|
||||
|
||||
struct colorize_alpha : std::vector<mapnik::color>
|
||||
struct color_stop
|
||||
{
|
||||
color_stop() {}
|
||||
color_stop(mapnik::color const& c, double val = 0.0)
|
||||
: color(c),offset(val) {}
|
||||
mapnik::color color;
|
||||
double offset;
|
||||
};
|
||||
|
||||
struct colorize_alpha : std::vector<color_stop>
|
||||
{
|
||||
colorize_alpha() {}
|
||||
colorize_alpha(mapnik::color const& c0, mapnik::color const& c1)
|
||||
{
|
||||
this->push_back(c0);
|
||||
this->push_back(c1);
|
||||
// TODO: support multiple color-stops
|
||||
// https://developer.mozilla.org/en-US/docs/CSS/linear-gradient
|
||||
}
|
||||
};
|
||||
|
||||
typedef boost::variant<filter::blur,
|
||||
|
|
|
@ -57,7 +57,7 @@ image_filter_grammar<Iterator,ContType>::image_filter_grammar()
|
|||
using boost::spirit::ascii::string;
|
||||
using phoenix::push_back;
|
||||
using phoenix::construct;
|
||||
|
||||
using phoenix::at_c;
|
||||
#if BOOST_VERSION >= 104700
|
||||
using qi::no_skip;
|
||||
start = -(filter % no_skip[*char_(", ")])
|
||||
|
@ -111,11 +111,17 @@ image_filter_grammar<Iterator,ContType>::image_filter_grammar()
|
|||
|
||||
colorize_alpha_filter = lit("colorize-alpha")[_a = construct<mapnik::filter::colorize_alpha>()]
|
||||
>> lit('(')
|
||||
>> css_color_[push_back(_a, _1)]
|
||||
>> +(lit(',') >> css_color_[push_back(_a, _1)])
|
||||
>> (css_color_[at_c<0>(_b) = _1, at_c<1>(_b) = 0]
|
||||
>> -color_stop_offset(_b)) [push_back(_a,_b)]
|
||||
>> +(lit(',') >> css_color_[at_c<0>(_b) =_1,at_c<1>(_b) = 0]
|
||||
>> -color_stop_offset(_b))[push_back(_a,_b)]
|
||||
>> lit(')') [push_back(_r1,_a)]
|
||||
;
|
||||
|
||||
color_stop_offset = (double_ >> lit('%'))[at_c<1>(_r1) = percent_offset(_1)]
|
||||
|
|
||||
double_[at_c<1>(_r1) = _1]
|
||||
;
|
||||
no_args = -(lit('(') >> lit(')'));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue