raster scaling: check for division by zero

This commit is contained in:
Jiri Drbalek 2016-03-04 15:13:55 +00:00 committed by artemp
parent 53c643092c
commit 93a34cc68d

View file

@ -131,19 +131,27 @@ 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);
fg /= total_weight;
if (fg < std::numeric_limits<value_type>::min())
{
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();
}
else
{
span->v = static_cast<value_type>(fg);
}
}
span->a = base_mask;
++span;