Raster colorizer: check image bounds
This commit is contained in:
parent
e128d75366
commit
a93dd6b17d
1 changed files with 17 additions and 12 deletions
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue