+ support multiple color stops in colorize-alpha
( TODO: add support for: <color-stop> = <color> [ <percentage> | <length> ]? )
This commit is contained in:
parent
4b713f6ed0
commit
542805e4d6
4 changed files with 29 additions and 29 deletions
|
@ -32,6 +32,7 @@
|
|||
#include <boost/variant/static_visitor.hpp>
|
||||
#include <boost/gil/gil_all.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
// agg
|
||||
#include "agg_basics.h"
|
||||
|
@ -39,7 +40,7 @@
|
|||
#include "agg_pixfmt_rgba.h"
|
||||
#include "agg_scanline_u.h"
|
||||
#include "agg_blur.h"
|
||||
|
||||
#include "agg_gradient_lut.h"
|
||||
// stl
|
||||
#include <cmath>
|
||||
|
||||
|
@ -409,18 +410,22 @@ void apply_filter(Src & src, colorize_alpha const& op)
|
|||
{
|
||||
using namespace boost::gil;
|
||||
|
||||
mapnik::color const& c0 = op.c0_;
|
||||
mapnik::color const& c1 = op.c1_;
|
||||
uint8_t reds[256];
|
||||
uint8_t greens[256];
|
||||
uint8_t blues[256];
|
||||
agg::gradient_lut<agg::color_interpolator<agg::rgba8> > grad_lut;
|
||||
grad_lut.remove_all();
|
||||
std::size_t size = op.size();
|
||||
if (size < 2) return;
|
||||
|
||||
for (unsigned a=0; a < 256;++a)
|
||||
double step = 1.0/(size-1);
|
||||
double offset = 0.0;
|
||||
BOOST_FOREACH( mapnik::color const& c, op)
|
||||
{
|
||||
reds[a] = (c0.red() + (c1.red() - c0.red()) * a) >> 8;
|
||||
greens[a] = (c0.green() + (c1.green() - c0.green()) * a) >> 8;
|
||||
blues[a] = (c0.blue() + (c1.blue() - c0.blue()) * a) >> 8;
|
||||
grad_lut.add_color(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();
|
||||
|
||||
rgba8_view_t src_view = rgba8_view(src);
|
||||
for (int y=0; y<src_view.height(); ++y)
|
||||
|
@ -434,14 +439,10 @@ void apply_filter(Src & src, colorize_alpha const& op)
|
|||
uint8_t & a = get_color(src_it[x], alpha_t());
|
||||
if ( a > 0)
|
||||
{
|
||||
|
||||
//r = (c0.red() + (c1.red() - c0.red()) * a) >> 8;
|
||||
//g = (c0.green() + (c1.green() - c0.green()) * a) >> 8;
|
||||
//b = (c0.blue() + (c1.blue() - c0.blue()) * a) >> 8;
|
||||
r = (reds[a] * a + 255) >> 8;
|
||||
g = (greens[a] * a + 255) >> 8;
|
||||
b = (blues[a] * a + 255) >> 8;
|
||||
|
||||
agg::rgba8 c = grad_lut[a];
|
||||
r = (c.r * a + 255) >> 8;
|
||||
g = (c.g * a + 255) >> 8;
|
||||
b = (c.b * a + 255) >> 8;
|
||||
#if 0
|
||||
// rainbow
|
||||
r = 0;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <boost/spirit/include/qi.hpp>
|
||||
// mapnik
|
||||
#include <mapnik/css_color_grammar.hpp>
|
||||
#include <mapnik/image_filter.hpp>
|
||||
// stl
|
||||
#include <vector>
|
||||
|
||||
|
@ -45,7 +46,7 @@ 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::color,mapnik::color>, void(ContType&), qi::ascii::space_type> colorize_alpha_filter;
|
||||
qi::rule<Iterator, qi::locals<mapnik::filter::colorize_alpha>, 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_;
|
||||
|
|
|
@ -98,17 +98,16 @@ struct hsla
|
|||
double a1;
|
||||
};
|
||||
|
||||
struct colorize_alpha
|
||||
struct colorize_alpha : std::vector<mapnik::color>
|
||||
{
|
||||
colorize_alpha() {}
|
||||
colorize_alpha(mapnik::color const& c0, mapnik::color const& c1)
|
||||
: c0_(c0),
|
||||
c1_(c1)
|
||||
{
|
||||
this->push_back(c0);
|
||||
this->push_back(c1);
|
||||
// TODO: support multiple color-stops
|
||||
// https://developer.mozilla.org/en-US/docs/CSS/linear-gradient
|
||||
}
|
||||
mapnik::color c0_;
|
||||
mapnik::color c1_;
|
||||
};
|
||||
|
||||
typedef boost::variant<filter::blur,
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/image_filter_grammar.hpp>
|
||||
#include <mapnik/image_filter.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/version.hpp>
|
||||
|
@ -110,11 +109,11 @@ image_filter_grammar<Iterator,ContType>::image_filter_grammar()
|
|||
[push_back(_r1, construct<mapnik::filter::hsla>(_a,_b,_c,_d,_e,_f,_g,_h))]
|
||||
;
|
||||
|
||||
colorize_alpha_filter = lit("colorize-alpha")
|
||||
colorize_alpha_filter = lit("colorize-alpha")[_a = construct<mapnik::filter::colorize_alpha>()]
|
||||
>> lit('(')
|
||||
>> css_color_[_a = _1] >> lit(',')
|
||||
>> css_color_[_b = _1] >> lit(')')
|
||||
[push_back(_r1,construct<mapnik::filter::colorize_alpha>(_a,_b))]
|
||||
>> css_color_[push_back(_a, _1)]
|
||||
>> +(lit(',') >> css_color_[push_back(_a, _1)])
|
||||
>> lit(')') [push_back(_r1,_a)]
|
||||
;
|
||||
|
||||
no_args = -(lit('(') >> lit(')'));
|
||||
|
|
Loading…
Reference in a new issue