diff options
Diffstat (limited to 'boost/gil/extension/numeric/sampler.hpp')
-rw-r--r-- | boost/gil/extension/numeric/sampler.hpp | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/boost/gil/extension/numeric/sampler.hpp b/boost/gil/extension/numeric/sampler.hpp index 494611a314..ba8fa05225 100644 --- a/boost/gil/extension/numeric/sampler.hpp +++ b/boost/gil/extension/numeric/sampler.hpp @@ -1,32 +1,21 @@ -/* - Copyright 2005-2007 Adobe Systems Incorporated - - Use, modification and distribution are subject to the Boost Software License, - Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at - http://www.boost.org/LICENSE_1_0.txt). -*/ - -/*************************************************************************************************/ - +// +// Copyright 2005-2007 Adobe Systems Incorporated +// +// Distributed under the Boost Software License, Version 1.0 +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// #ifndef BOOST_GIL_EXTENSION_NUMERIC_SAMPLER_HPP #define BOOST_GIL_EXTENSION_NUMERIC_SAMPLER_HPP -#include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp> - #include <boost/gil/extension/numeric/pixel_numeric_operations.hpp> - -//////////////////////////////////////////////////////////////////////////////////////// -/// \file -/// \brief Nearest-neighbor and bilinear image samplers. -/// NOTE: The code is for example use only. It is not optimized for performance -/// \author Lubomir Bourdev and Hailin Jin \n -/// Adobe Systems Incorporated -/// \date 2005-2007 \n -/// -//////////////////////////////////////////////////////////////////////////////////////// +#include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp> namespace boost { namespace gil { +// Nearest-neighbor and bilinear image samplers. +// NOTE: The code is for example use only. It is not optimized for performance + /////////////////////////////////////////////////////////////////////////// //// //// resample_pixels: set each pixel in the destination view as the result of a sampling function over the transformed coordinates of the source view @@ -47,9 +36,11 @@ concept SamplerConcept { struct nearest_neighbor_sampler {}; template <typename DstP, typename SrcView, typename F> -bool sample(nearest_neighbor_sampler, const SrcView& src, const point2<F>& p, DstP& result) { +bool sample(nearest_neighbor_sampler, SrcView const& src, point<F> const& p, DstP& result) +{ typename SrcView::point_t center(iround(p)); - if (center.x>=0 && center.y>=0 && center.x<src.width() && center.y<src.height()) { + if (center.x >= 0 && center.y >= 0 && center.x < src.width() && center.y < src.height()) + { result=src(center.x,center.y); return true; } @@ -96,20 +87,19 @@ struct add_dst_mul_src { }; } // namespace detail -/// \brief A sampler that sets the destination pixel as the bilinear interpolation of the four closest pixels from the source. +/// \brief A sampler that sets the destination pixel as the bilinear interpolation of the four closest pixels from the source. /// If outside the bounds, it doesn't change the destination /// \ingroup ImageAlgorithms struct bilinear_sampler {}; template <typename DstP, typename SrcView, typename F> -bool sample(bilinear_sampler, const SrcView& src, const point2<F>& p, DstP& result) +bool sample(bilinear_sampler, SrcView const& src, point<F> const& p, DstP& result) { - typedef typename SrcView::value_type SrcP; - - point2<ptrdiff_t> p0(ifloor(p.x), ifloor(p.y)); // the closest integer coordinate top left from p - point2<F> frac(p.x-p0.x, p.y-p0.y); + using SrcP = typename SrcView::value_type; + point_t p0(ifloor(p.x), ifloor(p.y)); // the closest integer coordinate top left from p + point<F> frac(p.x-p0.x, p.y-p0.y); - if (p0.x < -1 || p0.y < -1 || p0.x>=src.width() || p0.y>=src.height()) + if (p0.x < -1 || p0.y < -1 || p0.x>=src.width() || p0.y>=src.height()) { return false; } @@ -194,7 +184,6 @@ bool sample(bilinear_sampler, const SrcView& src, const point2<F>& p, DstP& resu return true; } -} // namespace gil -} // namespace boost +}} // namespace boost::gil -#endif // BOOST_GIL_EXTENSION_NUMERIC_SAMPLER_HPP +#endif |