Merge branch 'master' into mapycz-fix-raster-scaling
This commit is contained in:
commit
eabe5b50e6
5 changed files with 64 additions and 88 deletions
49
include/mapnik/pixel_cast.hpp
Normal file
49
include/mapnik/pixel_cast.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_PIXEL_CAST_HPP
|
||||
#define MAPNIK_PIXEL_CAST_HPP
|
||||
|
||||
#include <boost/numeric/conversion/bounds.hpp>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
template <typename T, typename S>
|
||||
inline T pixel_cast(S s)
|
||||
{
|
||||
using namespace boost::numeric;
|
||||
if (s > bounds<T>::highest() )
|
||||
{
|
||||
return bounds<T>::highest();
|
||||
}
|
||||
else if (s < bounds<T>::lowest())
|
||||
{
|
||||
return bounds<T>::lowest();
|
||||
}
|
||||
else return static_cast<T>(s);
|
||||
}
|
||||
|
||||
} // ns mapnik
|
||||
|
||||
|
||||
|
||||
#endif // MAPNIK_PIXEL_CAST_HPP
|
|
@ -25,11 +25,11 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/view_transform.hpp>
|
||||
|
||||
#include <mapnik/pixel_cast.hpp>
|
||||
// boost
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
@ -46,8 +46,8 @@ struct view_strategy
|
|||
double x = boost::geometry::get<0>(p1);
|
||||
double y = boost::geometry::get<1>(p1);
|
||||
tr_.forward(&x,&y);
|
||||
boost::geometry::set<0>(p2, boost::numeric_cast<coordinate_type>(x));
|
||||
boost::geometry::set<1>(p2, boost::numeric_cast<coordinate_type>(y));
|
||||
boost::geometry::set<0>(p2, pixel_cast<coordinate_type>(x));
|
||||
boost::geometry::set<1>(p2, pixel_cast<coordinate_type>(y));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,13 +24,7 @@
|
|||
#include <mapnik/image_copy.hpp>
|
||||
#include <mapnik/image.hpp>
|
||||
#include <mapnik/image_any.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
|
||||
using boost::numeric_cast;
|
||||
using boost::numeric::positive_overflow;
|
||||
using boost::numeric::negative_overflow;
|
||||
#include <mapnik/pixel_cast.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
@ -61,18 +55,7 @@ struct visitor_image_copy
|
|||
{
|
||||
for (unsigned x = 0; x < dst.width(); ++x)
|
||||
{
|
||||
try
|
||||
{
|
||||
dst(x,y) = numeric_cast<dst_type>(src(x,y));
|
||||
}
|
||||
catch(negative_overflow&)
|
||||
{
|
||||
dst(x,y) = std::numeric_limits<dst_type>::min();
|
||||
}
|
||||
catch(positive_overflow&)
|
||||
{
|
||||
dst(x,y) = std::numeric_limits<dst_type>::max();
|
||||
}
|
||||
dst(x,y) = pixel_cast<dst_type>(src(x,y));
|
||||
}
|
||||
}
|
||||
return T0(std::move(dst));
|
||||
|
@ -119,20 +102,9 @@ struct visitor_image_copy_so
|
|||
{
|
||||
for (unsigned x = 0; x < dst.width(); ++x)
|
||||
{
|
||||
double scaled_src_val = (numeric_cast<double>(src(x,y)) * src_scaling) + src_offset;
|
||||
double scaled_src_val = (pixel_cast<double>(src(x,y)) * src_scaling) + src_offset;
|
||||
double dst_val = (scaled_src_val - offset_) / scaling_;
|
||||
try
|
||||
{
|
||||
dst(x,y) = numeric_cast<dst_type>(dst_val);
|
||||
}
|
||||
catch(negative_overflow&)
|
||||
{
|
||||
dst(x,y) = std::numeric_limits<dst_type>::min();
|
||||
}
|
||||
catch(positive_overflow&)
|
||||
{
|
||||
dst(x,y) = std::numeric_limits<dst_type>::max();
|
||||
}
|
||||
dst(x,y) = pixel_cast<dst_type>(dst_val);
|
||||
}
|
||||
}
|
||||
return T0(std::move(dst));
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <mapnik/box2d.hpp>
|
||||
#include <mapnik/util/variant.hpp>
|
||||
#include <mapnik/debug.hpp>
|
||||
#include <mapnik/pixel_cast.hpp>
|
||||
#ifdef SSE_MATH
|
||||
#include <mapnik/sse.hpp>
|
||||
|
||||
|
@ -51,16 +52,9 @@
|
|||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
// boost
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
using boost::numeric_cast;
|
||||
using boost::numeric::positive_overflow;
|
||||
using boost::numeric::negative_overflow;
|
||||
|
||||
template <typename T>
|
||||
MAPNIK_DECL std::string save_to_string(T const& image,
|
||||
std::string const& type,
|
||||
|
@ -936,20 +930,7 @@ struct visitor_fill
|
|||
void operator() (T2 & data) const
|
||||
{
|
||||
using pixel_type = typename T2::pixel_type;
|
||||
pixel_type val;
|
||||
try
|
||||
{
|
||||
val = numeric_cast<pixel_type>(val_);
|
||||
}
|
||||
catch(negative_overflow&)
|
||||
{
|
||||
val = std::numeric_limits<pixel_type>::min();
|
||||
}
|
||||
catch(positive_overflow&)
|
||||
{
|
||||
val = std::numeric_limits<pixel_type>::max();
|
||||
}
|
||||
data.set(val);
|
||||
data.set(pixel_cast<pixel_type>(val_));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -1392,22 +1373,9 @@ struct visitor_set_pixel
|
|||
void operator() (T2 & data) const
|
||||
{
|
||||
using pixel_type = typename T2::pixel_type;
|
||||
pixel_type val;
|
||||
try
|
||||
{
|
||||
val = numeric_cast<pixel_type>(val_);
|
||||
}
|
||||
catch(negative_overflow&)
|
||||
{
|
||||
val = std::numeric_limits<pixel_type>::min();
|
||||
}
|
||||
catch(positive_overflow&)
|
||||
{
|
||||
val = std::numeric_limits<pixel_type>::max();
|
||||
}
|
||||
if (check_bounds(data, x_, y_))
|
||||
{
|
||||
data(x_, y_) = val;
|
||||
data(x_, y_) = pixel_cast<pixel_type>(val_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1699,20 +1667,7 @@ struct visitor_get_pixel
|
|||
using pixel_type = T1;
|
||||
if (check_bounds(data, x_, y_))
|
||||
{
|
||||
T1 val;
|
||||
try
|
||||
{
|
||||
val = numeric_cast<T1>(data(x_,y_));
|
||||
}
|
||||
catch(negative_overflow&)
|
||||
{
|
||||
val = std::numeric_limits<T1>::min();
|
||||
}
|
||||
catch(positive_overflow&)
|
||||
{
|
||||
val = std::numeric_limits<T1>::max();
|
||||
}
|
||||
return val;
|
||||
return pixel_cast<T1>(data(x_, y_));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include <mapnik/geometry_transform.hpp>
|
||||
#include <mapnik/geometry_to_path.hpp>
|
||||
#include <mapnik/util/geometry_to_ds_type.hpp>
|
||||
|
||||
#include <mapnik/pixel_cast.hpp>
|
||||
// boost
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
|
||||
|
@ -59,8 +59,8 @@ struct coord_transformer
|
|||
calc_type z = 0.0;
|
||||
if (!prj_trans_.backward(x, y, z)) return false;
|
||||
tr_.forward(&x,&y);
|
||||
boost::geometry::set<0>(p2, boost::numeric_cast<coordinate_type>(x));
|
||||
boost::geometry::set<1>(p2, boost::numeric_cast<coordinate_type>(y));
|
||||
boost::geometry::set<0>(p2, pixel_cast<coordinate_type>(x));
|
||||
boost::geometry::set<1>(p2, pixel_cast<coordinate_type>(y));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue