diff --git a/include/mapnik/span_image_filter.hpp b/include/mapnik/span_image_filter.hpp index 29049beef..14ef7eb75 100644 --- a/include/mapnik/span_image_filter.hpp +++ b/include/mapnik/span_image_filter.hpp @@ -131,19 +131,27 @@ public: fg_ptr = reinterpret_cast(base_type::source().next_y()); } - fg /= total_weight; - if (fg < std::numeric_limits::min()) + if (total_weight == 0) { - span->v = std::numeric_limits::min(); - } - else if (fg > std::numeric_limits::max()) - { - span->v = std::numeric_limits::max(); + span->v = *nodata_value_; } else { - span->v = static_cast(fg); + fg /= total_weight; + if (fg < std::numeric_limits::min()) + { + span->v = std::numeric_limits::min(); + } + else if (fg > std::numeric_limits::max()) + { + span->v = std::numeric_limits::max(); + } + else + { + span->v = static_cast(fg); + } } + span->a = base_mask; ++span;