8 #ifndef BOOST_GIL_UTILITIES_HPP
9 #define BOOST_GIL_UTILITIES_HPP
11 #include <boost/mpl/begin.hpp>
12 #include <boost/mpl/distance.hpp>
13 #include <boost/mpl/find.hpp>
14 #include <boost/mpl/range_c.hpp>
15 #include <boost/mpl/size.hpp>
16 #include <boost/iterator/iterator_adaptor.hpp>
17 #include <boost/iterator/iterator_facade.hpp>
18 #include <boost/static_assert.hpp>
19 #include <boost/type_traits.hpp>
28 namespace boost {
namespace gil {
37 inline std::ptrdiff_t iround(
float x)
39 return static_cast<std::ptrdiff_t
>(x + (x < 0.0f ? -0.5f : 0.5f));
42 inline std::ptrdiff_t iround(
double x)
44 return static_cast<std::ptrdiff_t
>(x + (x < 0.0 ? -0.5 : 0.5));
47 inline std::ptrdiff_t ifloor(
float x)
49 return static_cast<std::ptrdiff_t
>(std::floor(x));
52 inline std::ptrdiff_t ifloor(
double x)
54 return static_cast<std::ptrdiff_t
>(std::floor(x));
57 inline std::ptrdiff_t iceil(
float x)
59 return static_cast<std::ptrdiff_t
>(std::ceil(x));
62 inline std::ptrdiff_t iceil(
double x)
64 return static_cast<std::ptrdiff_t
>(std::ceil(x));
72 inline T align(T val, std::size_t alignment)
74 return val+(alignment - val%alignment)%alignment;
85 typename ConstReference,
92 typedef ArgType argument_type;
93 typedef ResultType result_type;
94 typedef ConstT const_t;
95 typedef Value value_type;
96 typedef Reference reference;
97 typedef ConstReference const_reference;
98 BOOST_STATIC_CONSTANT(
bool, is_mutable = IsMutable);
104 template <
typename D1,
typename D2>
107 deref_compose<typename D1::const_t, typename D2::const_t>,
108 typename D1::value_type,
109 typename D1::reference,
110 typename D1::const_reference,
111 typename D2::argument_type,
112 typename D1::result_type,
113 D1::is_mutable && D2::is_mutable
120 typedef typename D2::argument_type argument_type;
121 typedef typename D1::result_type result_type;
124 deref_compose(
const D1& x,
const D2& y) : _fn1(x), _fn2(y) {}
127 template <
typename _D1,
typename _D2>
129 : _fn1(dc._fn1), _fn2(dc._fn2)
132 result_type operator()(argument_type x)
const {
return _fn1(_fn2(x)); }
133 result_type operator()(argument_type x) {
return _fn1(_fn2(x)); }
137 template <
typename OutPtr,
typename In>
139 OutPtr gil_reinterpret_cast(In* p)
141 return static_cast<OutPtr
>(
static_cast<void*
>(p));
144 template <
typename OutPtr,
typename In> BOOST_FORCEINLINE
145 const OutPtr gil_reinterpret_cast_c(
const In* p)
147 return static_cast<const OutPtr
>(
static_cast<const void*
>(p));
156 template <
class InputIter,
class Size,
class OutputIter>
157 std::pair<InputIter, OutputIter> _copy_n(InputIter first, Size count,
158 OutputIter result, std::input_iterator_tag)
160 for ( ; count > 0; --count)
166 return std::pair<InputIter, OutputIter>(first, result);
169 template <
class RAIter,
class Size,
class OutputIter>
170 inline std::pair<RAIter, OutputIter>
171 _copy_n(RAIter first, Size count, OutputIter result, std::random_access_iterator_tag)
173 RAIter last = first + count;
174 return std::pair<RAIter, OutputIter>(last,
std::copy(first, last, result));
177 template <
class InputIter,
class Size,
class OutputIter>
178 inline std::pair<InputIter, OutputIter>
179 _copy_n(InputIter first, Size count, OutputIter result)
181 return _copy_n(first, count, result,
typename std::iterator_traits<InputIter>::iterator_category());
184 template <
class InputIter,
class Size,
class OutputIter>
185 inline std::pair<InputIter, OutputIter>
186 copy_n(InputIter first, Size count, OutputIter result)
188 return detail::_copy_n(first, count, result);
192 template <
typename T>
195 typedef T argument_type;
196 typedef T result_type;
197 const T& operator()(
const T& val)
const {
return val; }
201 template <
typename T1,
typename T2>
203 typedef T1 first_argument_type;
204 typedef T2 second_argument_type;
205 typedef T1 result_type;
206 T1 operator()(T1 f1, T2 f2)
const
213 template <
typename T>
216 typedef T argument_type;
217 typedef T result_type;
218 T operator()(T x)
const {
return ++x; }
222 template <
typename T>
225 typedef T argument_type;
226 typedef T result_type;
227 T operator()(T x)
const {
return --x; }
232 template <
typename Types,
typename T>
234 :
public mpl::distance
236 typename mpl::begin<Types>::type,
237 typename mpl::find<Types,T>::type
245 template <typename ColorSpace, typename ChannelMapping = mpl::range_c<int,0,mpl::size<ColorSpace>::value>>
248 typedef ColorSpace color_space_t;
249 typedef ChannelMapping channel_mapping_t;
253 template <
typename Value,
typename T1,
typename T2>
254 void swap_proxy(T1& left, T2& right)
262 BOOST_FORCEINLINE
bool little_endian()
264 short tester = 0x0001;
265 return *(
char*)&tester!=0;
268 BOOST_FORCEINLINE
bool big_endian()
270 return !little_endian();
plus function object whose arguments may be of different type.
Definition: utilities.hpp:202
BOOST_FORCEINLINE boost::gil::pixel< T, Cs > * copy(boost::gil::pixel< T, Cs > *first, boost::gil::pixel< T, Cs > *last, boost::gil::pixel< T, Cs > *dst)
Copy when both src and dst are interleaved and of the same type can be just memmove.
Definition: algorithm.hpp:132
Helper base class for pixel dereference adaptors.
Definition: utilities.hpp:90
operator– wrapped in a function object
Definition: utilities.hpp:223
identity taken from SGI STL.
Definition: utilities.hpp:193
operator++ wrapped in a function object
Definition: utilities.hpp:214
Represents a color space and ordering of channels in memory.
Definition: utilities.hpp:246
Composes two dereference function objects. Similar to std::unary_compose but needs to pull some typed...
Definition: utilities.hpp:105
Returns the index corresponding to the first occurrance of a given given type in. ...
Definition: utilities.hpp:233