Merge pull request #3349 from mapycz/raster-resample-division-by-zero

Raster resample division by zero
This commit is contained in:
Artem Pavlenko 2016-03-07 14:54:44 +01:00
commit cd3e484c04

View file

@ -30,6 +30,8 @@
#include <limits>
#include <mapnik/safe_cast.hpp>
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<const value_type*>(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<const value_type*>(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<const value_type*>(base_type::source().next_y());
}
fg /= total_weight;
if (fg < std::numeric_limits<value_type>::min())
if (total_weight == 0)
{
span->v = std::numeric_limits<value_type>::min();
}
else if (fg > std::numeric_limits<value_type>::max())
{
span->v = std::numeric_limits<value_type>::max();
span->v = *nodata_value_;
}
else
{
span->v = static_cast<value_type>(fg);
span->v = safe_cast<value_type>(fg / total_weight);
}
span->a = base_mask;
++span;