use safe_cast for narrowing double->typename span_gen_type::value_type cast (#3856) (thanks @talaj!)

This commit is contained in:
Artem Pavlenko 2018-02-14 16:46:24 +01:00
parent 533c6d6e5b
commit 17a98767b4
2 changed files with 6 additions and 4 deletions

View file

@ -24,6 +24,7 @@
#include <mapnik/image.hpp>
#include <mapnik/image_scaling.hpp>
#include <mapnik/image_scaling_traits.hpp>
#include <mapnik/safe_cast.hpp>
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
@ -99,7 +100,7 @@ boost::optional<std::string> scaling_method_to_string(scaling_method_e scaling_m
template <typename T>
void scale_image_agg(T & target, T const& source, scaling_method_e scaling_method,
double image_ratio_x, double image_ratio_y, double x_off_f, double y_off_f,
double filter_factor, boost::optional<double> const & nodata_value)
double filter_factor, boost::optional<double> const& nodata_value)
{
// "the image filters should work namely in the premultiplied color space"
// http://old.nabble.com/Re:--AGG--Basic-image-transformations-p1110665.html
@ -160,7 +161,7 @@ void scale_image_agg(T & target, T const& source, scaling_method_e scaling_metho
boost::optional<typename span_gen_type::value_type> nodata;
if (nodata_value)
{
nodata = nodata_value;
nodata.emplace(safe_cast<typename span_gen_type::value_type>(*nodata_value));
}
span_gen_type sg(img_src, interpolator, filter, nodata);
agg::render_scanlines_aa(ras, sl, rb_dst_pre, sa, sg);
@ -168,7 +169,7 @@ void scale_image_agg(T & target, T const& source, scaling_method_e scaling_metho
}
template MAPNIK_DECL void scale_image_agg(image_rgba8 &, image_rgba8 const&, scaling_method_e,
double, double , double, double , double, boost::optional<double> const &);
double, double , double, double , double, boost::optional<double> const &);
template MAPNIK_DECL void scale_image_agg(image_gray8 &, image_gray8 const&, scaling_method_e,
double, double , double, double , double, boost::optional<double> const &);

View file

@ -30,6 +30,7 @@
#include <mapnik/view_transform.hpp>
#include <mapnik/raster.hpp>
#include <mapnik/proj_transform.hpp>
#include <mapnik/safe_cast.hpp>
#pragma GCC diagnostic push
#include <mapnik/warning_ignore_agg.hpp>
@ -153,7 +154,7 @@ MAPNIK_DECL void warp_image (T & target, T const& source, proj_transform const&
boost::optional<typename span_gen_type::value_type> nodata;
if (nodata_value)
{
nodata = nodata_value;
nodata = safe_cast<typename span_gen_type::value_type>(*nodata_value);
}
span_gen_type sg(ia, interpolator, filter, nodata);
agg::render_scanlines_bin(rasterizer, scanline, rb, sa, sg);