diff --git a/bindings/python/mapnik_raster_symbolizer.cpp b/bindings/python/mapnik_raster_symbolizer.cpp index 69e0acca8..54f66a554 100644 --- a/bindings/python/mapnik_raster_symbolizer.cpp +++ b/bindings/python/mapnik_raster_symbolizer.cpp @@ -28,6 +28,18 @@ #include #include +namespace { + +// https://github.com/mapnik/mapnik/issues/1367 +PyObject* get_premultiplied_impl(mapnik::raster_symbolizer & sym) +{ + boost::optional premultiplied = sym.premultiplied(); + if (premultiplied) + return ::PyBool_FromLong(*premultiplied); + Py_RETURN_NONE; +} + +} using mapnik::raster_symbolizer; void export_raster_symbolizer() @@ -119,5 +131,17 @@ void export_raster_symbolizer() ">>> r = RasterSymbolizer()\n" ">>> r.mesh_size = 32\n" ) + .add_property("premultiplied", + &get_premultiplied_impl, + &raster_symbolizer::set_premultiplied, + "Get/Set premultiplied status of the source image.\n" + "Can be used to override what the source data reports (when in error)\n" + "\n" + "Usage:\n" + "\n" + ">>> from mapnik import RasterSymbolizer\n" + ">>> r = RasterSymbolizer()\n" + ">>> r.premultiplied = False\n" + ) ; } diff --git a/include/mapnik/raster_symbolizer.hpp b/include/mapnik/raster_symbolizer.hpp index 58ea11ab9..454c0f663 100644 --- a/include/mapnik/raster_symbolizer.hpp +++ b/include/mapnik/raster_symbolizer.hpp @@ -52,6 +52,8 @@ struct MAPNIK_DECL raster_symbolizer : public symbolizer_base double calculate_filter_factor() const; unsigned get_mesh_size() const; void set_mesh_size(unsigned mesh_size); + boost::optional premultiplied() const; + void set_premultiplied(bool premultiplied); private: std::string mode_; @@ -60,6 +62,7 @@ private: raster_colorizer_ptr colorizer_; double filter_factor_; unsigned mesh_size_; + boost::optional premultiplied_; }; } diff --git a/src/load_map.cpp b/src/load_map.cpp index 47418ea09..06d78e94a 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -1490,6 +1490,9 @@ void map_parser::parse_raster_symbolizer(rule & rule, xml_node const & sym) optional mesh_size = sym.get_opt_attr("mesh-size"); if (mesh_size) raster_sym.set_mesh_size(*mesh_size); + // premultiplied status of image + optional premultiplied = sym.get_opt_attr("premultiplied"); + if (premultiplied) raster_sym.set_premultiplied(*premultiplied); xml_node::const_iterator cssIter = sym.begin(); xml_node::const_iterator endCss = sym.end(); diff --git a/src/raster_symbolizer.cpp b/src/raster_symbolizer.cpp index 6b3b981ef..b70657ea4 100644 --- a/src/raster_symbolizer.cpp +++ b/src/raster_symbolizer.cpp @@ -177,6 +177,15 @@ void raster_symbolizer::set_mesh_size(unsigned mesh_size) mesh_size_=mesh_size; } +void raster_symbolizer::set_premultiplied(bool premultiplied) +{ + premultiplied_=premultiplied; +} + +boost::optional raster_symbolizer::premultiplied() const +{ + return premultiplied_; +} } diff --git a/src/save_map.cpp b/src/save_map.cpp index 7b90ce29b..55996e471 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -180,10 +180,18 @@ public: set_attr( sym_node, "mesh-size", sym.get_mesh_size() ); } - if (sym.get_colorizer()) { + if (sym.get_colorizer()) + { serialize_raster_colorizer(sym_node, sym.get_colorizer(), explicit_defaults_); } + + boost::optional premultiplied = sym.premultiplied(); + if (premultiplied) + { + set_attr( sym_node, "premultiplied", *sym.premultiplied()); + } + serialize_symbolizer_base(sym_node, sym); }