diff --git a/bindings/python/mapnik_map.cpp b/bindings/python/mapnik_map.cpp index 37c4a50d8..cc580d17c 100644 --- a/bindings/python/mapnik_map.cpp +++ b/bindings/python/mapnik_map.cpp @@ -412,6 +412,22 @@ void export_map() ">>> m.background_image = '/path/to/image.png'\n" ) + .add_property("background_image_comp_op",&Map::background_image_comp_op, + &Map::set_background_image_comp_op, + "The background image compositing operation.\n" + "\n" + "Usage:\n" + ">>> m.background_image_comp_op = mapnik.CompositeOp.src_over\n" + ) + + .add_property("background_image_opacity",&Map::background_image_opacity, + &Map::set_background_image_opacity, + "The background image opacity.\n" + "\n" + "Usage:\n" + ">>> m.background_image_opacity = 1.0\n" + ) + .add_property("base", make_function(&Map::base_path,return_value_policy()), &Map::set_base_path, diff --git a/include/mapnik/map.hpp b/include/mapnik/map.hpp index fcf121832..850313cc4 100644 --- a/include/mapnik/map.hpp +++ b/include/mapnik/map.hpp @@ -25,15 +25,17 @@ // mapnik #include +#include #include #include #include // for featureset_ptr #include #include #include +#include // boost -#include +#include namespace mapnik { @@ -76,6 +78,8 @@ private: int buffer_size_; boost::optional background_; boost::optional background_image_; + composite_mode_e background_image_comp_op_; + float background_image_opacity_; std::map styles_; std::map fontsets_; std::vector layers_; @@ -286,10 +290,30 @@ public: */ boost::optional const& background_image() const; + /*! \brief Set the compositing operation uses to blend the background image into the background color. + * @param comp_op compositing operation. + */ + void set_background_image_comp_op(composite_mode_e comp_op); + + /*! \brief Get the map background image compositing operation + * @return Background image compositing operation as composite_mode_e + * object + */ + composite_mode_e background_image_comp_op() const; + + /*! \brief Set the map background image opacity. + * @param opacity Background image opacity. + */ + void set_background_image_opacity(float opacity); + + /*! \brief Get the map background image opacity + * @return opacity value as float + */ + float background_image_opacity() const; + /*! \brief Set buffer size * @param buffer_size Buffer size in pixels. */ - void set_buffer_size(int buffer_size); /*! \brief Get the map buffer size diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index ce9f9dbc8..3e9f58fd3 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -30,7 +30,7 @@ #include // boost -#include +#include // stl #include diff --git a/src/agg/agg_renderer.cpp b/src/agg/agg_renderer.cpp index 9f2b2e272..8bfd79c4a 100644 --- a/src/agg/agg_renderer.cpp +++ b/src/agg/agg_renderer.cpp @@ -162,13 +162,13 @@ void agg_renderer::setup(Map const &m) if ( w > 0 && h > 0) { // repeat background-image both vertically and horizontally - unsigned x_steps = unsigned(std::ceil(width_/double(w))); - unsigned y_steps = unsigned(std::ceil(height_/double(h))); + unsigned x_steps = static_cast(std::ceil(width_/double(w))); + unsigned y_steps = static_cast(std::ceil(height_/double(h))); for (unsigned x=0;x > max_extent = map_in.maximum_extent(); if (max_extent) diff --git a/src/load_map.cpp b/src/load_map.cpp index ef7a3b0ac..36de527d2 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -199,6 +199,26 @@ void map_parser::parse_map(Map & map, xml_node const& pt, std::string const& bas map.set_background_image(ensure_relative_to_xml(image_filename)); } + optional comp_op_name = map_node.get_opt_attr("background-image-comp-op"); + if (comp_op_name) + { + optional comp_op = comp_op_from_string(*comp_op_name); + if (comp_op) + { + map.set_background_image_comp_op(*comp_op); + } + else + { + throw config_error("failed to parse background-image-comp-op: '" + *comp_op_name + "'"); + } + } + + optional opacity = map_node.get_opt_attr("background-image-opacity"); + if (opacity) + { + map.set_background_image_opacity(*opacity); + } + std::string srs = map_node.get_attr("srs", map.srs()); try { diff --git a/src/map.cpp b/src/map.cpp index 618300159..3b6b4fcfa 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -67,6 +67,8 @@ Map::Map() height_(400), srs_(MAPNIK_LONGLAT_PROJ), buffer_size_(0), + background_image_comp_op_(src_over), + background_image_opacity_(1.0), aspectFixMode_(GROW_BBOX), base_path_("") {} @@ -75,6 +77,8 @@ Map::Map(int width,int height, std::string const& srs) height_(height), srs_(srs), buffer_size_(0), + background_image_comp_op_(src_over), + background_image_opacity_(1.0), aspectFixMode_(GROW_BBOX), base_path_("") {} @@ -85,6 +89,8 @@ Map::Map(Map const& rhs) buffer_size_(rhs.buffer_size_), background_(rhs.background_), background_image_(rhs.background_image_), + background_image_comp_op_(rhs.background_image_comp_op_), + background_image_opacity_(rhs.background_image_opacity_), styles_(rhs.styles_), fontsets_(rhs.fontsets_), layers_(rhs.layers_), @@ -105,6 +111,8 @@ Map& Map::operator=(Map const& rhs) buffer_size_ = rhs.buffer_size_; background_=rhs.background_; background_image_=rhs.background_image_; + background_image_comp_op_=rhs.background_image_comp_op_; + background_image_opacity_=rhs.background_image_opacity_; styles_=rhs.styles_; fontsets_ = rhs.fontsets_; layers_=rhs.layers_; @@ -320,6 +328,26 @@ void Map::set_background_image(std::string const& image_filename) background_image_ = image_filename; } +composite_mode_e Map::background_image_comp_op() const +{ + return background_image_comp_op_; +} + +void Map::set_background_image_comp_op(composite_mode_e comp_op) +{ + background_image_comp_op_ = comp_op; +} + +float Map::background_image_opacity() const +{ + return background_image_opacity_; +} + +void Map::set_background_image_opacity(float opacity) +{ + background_image_opacity_ = opacity; +} + void Map::set_maximum_extent(box2d const& box) { maximum_extent_.reset(box); diff --git a/src/save_map.cpp b/src/save_map.cpp index 9db228f98..1c0c2af64 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -831,6 +831,19 @@ void serialize_map(ptree & pt, Map const & map, bool explicit_defaults) set_attr( map_node, "background-image", *image_filename ); } + composite_mode_e comp_op = map.background_image_comp_op(); + if (comp_op != src_over || explicit_defaults) + { + set_attr(map_node, "background-image-comp-op", *comp_op_to_string(comp_op)); + } + + double opacity = map.background_image_opacity(); + if (opacity != 1.0 || explicit_defaults) + { + set_attr(map_node, "background-image-opacity", opacity); + } + + int buffer_size = map.buffer_size(); if ( buffer_size || explicit_defaults) { diff --git a/tests/python_tests/object_test.py b/tests/python_tests/object_test.py index d123c3c92..922c8e5e8 100644 --- a/tests/python_tests/object_test.py +++ b/tests/python_tests/object_test.py @@ -336,6 +336,9 @@ def test_map_init(): eq_(m.srs, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs') eq_(m.base, '') eq_(m.maximum_extent, None) + eq_(m.background_image, None) + eq_(m.background_image_comp_op, mapnik.CompositeOp.src_over) + eq_(m.background_image_opacity, 1.0) m = mapnik.Map(256, 256, '+proj=latlong') eq_(m.srs, '+proj=latlong') diff --git a/tests/visual_tests/data/pattern.png b/tests/visual_tests/data/pattern.png new file mode 100644 index 000000000..b1d977a0e Binary files /dev/null and b/tests/visual_tests/data/pattern.png differ diff --git a/tests/visual_tests/grids/map-background-image-compositing-512-512-1.0-grid-reference.json b/tests/visual_tests/grids/map-background-image-compositing-512-512-1.0-grid-reference.json new file mode 100644 index 000000000..fb6e6350f --- /dev/null +++ b/tests/visual_tests/grids/map-background-image-compositing-512-512-1.0-grid-reference.json @@ -0,0 +1,137 @@ +{ + "keys": [ + "", + "1" + ], + "data": {}, + "grid": [ + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " !!!!!!!! ", + " !!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ", + " !!!!!!!!!!!!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!!!!!!!!! ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " " + ] +} \ No newline at end of file diff --git a/tests/visual_tests/images/map-background-image-compositing-512-512-1.0-agg-reference.png b/tests/visual_tests/images/map-background-image-compositing-512-512-1.0-agg-reference.png new file mode 100644 index 000000000..1778b2e83 Binary files /dev/null and b/tests/visual_tests/images/map-background-image-compositing-512-512-1.0-agg-reference.png differ diff --git a/tests/visual_tests/images/map-background-image-compositing-512-512-1.0-cairo-reference.png b/tests/visual_tests/images/map-background-image-compositing-512-512-1.0-cairo-reference.png new file mode 100644 index 000000000..0553c7450 Binary files /dev/null and b/tests/visual_tests/images/map-background-image-compositing-512-512-1.0-cairo-reference.png differ diff --git a/tests/visual_tests/images/map-background-image-compositing-512-512-2.0-agg-reference.png b/tests/visual_tests/images/map-background-image-compositing-512-512-2.0-agg-reference.png new file mode 100644 index 000000000..02b41e6b9 Binary files /dev/null and b/tests/visual_tests/images/map-background-image-compositing-512-512-2.0-agg-reference.png differ diff --git a/tests/visual_tests/images/map-background-image-compositing-512-512-2.0-cairo-reference.png b/tests/visual_tests/images/map-background-image-compositing-512-512-2.0-cairo-reference.png new file mode 100644 index 000000000..6be8ee3d5 Binary files /dev/null and b/tests/visual_tests/images/map-background-image-compositing-512-512-2.0-cairo-reference.png differ diff --git a/tests/visual_tests/styles/map-background-image-compositing.xml b/tests/visual_tests/styles/map-background-image-compositing.xml new file mode 100644 index 000000000..9bedf747b --- /dev/null +++ b/tests/visual_tests/styles/map-background-image-compositing.xml @@ -0,0 +1,54 @@ + + + + + + ellipse + + csv + +x,y +2.5,2.5 + + + + + + + + + + frame + + csv + +x,y +0,0 +5,0 +0,5 +5,5 + + + + + \ No newline at end of file diff --git a/tests/visual_tests/test.py b/tests/visual_tests/test.py index 5a12cff9f..dbe938e9f 100755 --- a/tests/visual_tests/test.py +++ b/tests/visual_tests/test.py @@ -169,7 +169,8 @@ files = { 'style-level-compositing-tiled-1,0':{'sizes':[(512,512)],'bbox':merc_z1_bboxes['1,0']}, 'style-level-compositing-tiled-0,1':{'sizes':[(512,512)],'bbox':merc_z1_bboxes['0,1']}, 'style-level-compositing-tiled-1,1':{'sizes':[(512,512)],'bbox':merc_z1_bboxes['1,1']}, - 'marker-path-expression':{} + 'marker-path-expression':{}, + 'map-background-image-compositing':{'sizes':[(512,512)]} } class Reporting: