diff --git a/include/mapnik/span_image_filter.hpp b/include/mapnik/span_image_filter.hpp index 972558ccf..31217690e 100644 --- a/include/mapnik/span_image_filter.hpp +++ b/include/mapnik/span_image_filter.hpp @@ -30,6 +30,8 @@ #include +#include + namespace mapnik { @@ -79,16 +81,19 @@ public: { base_type::interpolator().coordinates(&x, &y); - int src_x = x >> agg::image_subpixel_shift; - int src_y = y >> agg::image_subpixel_shift; - const value_type* pix = reinterpret_cast(base_type::source().span(src_x, src_y, 0)); - if (nodata_value_ && *nodata_value_ == *pix) + if (nodata_value_) { - span->v = *nodata_value_; - span->a = base_mask; - ++span; - ++base_type::interpolator(); - continue; + int src_x = x >> agg::image_subpixel_shift; + int src_y = y >> agg::image_subpixel_shift; + const value_type* pix = reinterpret_cast(base_type::source().span(src_x, src_y, 1)); + if (*nodata_value_ == *pix) + { + span->v = *nodata_value_; + span->a = base_mask; + ++span; + ++base_type::interpolator(); + continue; + } } x += base_type::filter_dx_int() - radius_x; @@ -131,19 +136,15 @@ 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); + span->v = safe_cast(fg / total_weight); } + span->a = base_mask; ++span;