Merge pull request #3879 from mapnik/raster-colorizer-image-size-v3.0.x

Raster colorizer: check image bounds
This commit is contained in:
Blake Thompson 2018-03-30 14:54:37 -05:00 committed by GitHub
commit ba950893af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -129,20 +129,25 @@ void raster_colorizer::colorize(image_rgba8 & out, T const& in,
{ {
using image_type = T; using image_type = T;
using pixel_type = typename image_type::pixel_type; using pixel_type = typename image_type::pixel_type;
// TODO: assuming in/out have the same width/height for now
std::uint32_t * out_data = out.data(); const std::size_t width = std::min(in.width(), out.width());
pixel_type const* in_data = in.data(); const std::size_t height = std::min(in.height(), out.height());
int len = out.width() * out.height();
for (int i=0; i<len; ++i) for (std::size_t y = 0; y < height; ++y)
{ {
pixel_type value = in_data[i]; pixel_type const * in_row = in.get_row(y);
if (nodata && (std::fabs(value - *nodata) < epsilon_)) image_rgba8::pixel_type * out_row = out.get_row(y);
for (std::size_t x = 0; x < width; ++x)
{ {
out_data[i] = 0; // rgba(0,0,0,0) pixel_type val = in_row[x];
} if (nodata && (std::fabs(val - *nodata) < epsilon_))
else {
{ out_row[x] = 0; // rgba(0,0,0,0)
out_data[i] = get_color(value); }
else
{
out_row[x] = get_color(val);
}
} }
} }
} }