followup nodata refactor - refs #2023

This commit is contained in:
Dane Springmeyer 2013-09-25 14:38:07 -07:00
parent df3a455e19
commit 7aeff3fb59

View file

@ -127,27 +127,21 @@ void raster_colorizer::colorize(raster_ptr const& raster, feature_impl const& f)
unsigned *imageData = raster->data_.getData(); unsigned *imageData = raster->data_.getData();
int len = raster->data_.width() * raster->data_.height(); int len = raster->data_.width() * raster->data_.height();
boost::optional<double> const& nodata = raster->nodata();
bool hasNoData = false;
float noDataValue = 0;
//std::map<std::string,value>::const_iterator fi = Props.find("NODATA");
if (f.has_key("NODATA"))
{
hasNoData = true;
noDataValue = static_cast<float>(f.get("NODATA").to_double());
}
for (int i=0; i<len; ++i) for (int i=0; i<len; ++i)
{ {
// the GDAL plugin reads single bands as floats // the GDAL plugin reads single bands as floats
float value = *reinterpret_cast<float *> (&imageData[i]); float value = *reinterpret_cast<float *> (&imageData[i]);
if (hasNoData && noDataValue == value) if (nodata && (std::fabs(value - *nodata) < epsilon_))
imageData[i] = color(0,0,0,0).rgba(); {
imageData[i] = 0;
}
else else
{
imageData[i] = get_color(value).rgba(); imageData[i] = get_color(value).rgba();
} }
} }
}
inline unsigned interpolate(unsigned start, unsigned end, float fraction) inline unsigned interpolate(unsigned start, unsigned end, float fraction)
{ {