8#ifndef BOOST_GIL_UTILITIES_HPP
9#define BOOST_GIL_UTILITIES_HPP
11#include <boost/gil/detail/mp11.hpp>
13#include <boost/config.hpp>
15#if defined(BOOST_CLANG)
16#pragma clang diagnostic push
17#pragma clang diagnostic ignored "-Wconversion"
20#if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wconversion"
25#if defined(BOOST_CLANG)
26#pragma clang diagnostic pop
29#if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
30#pragma GCC diagnostic pop
41namespace boost {
namespace gil {
50inline std::ptrdiff_t iround(
float x)
52 return static_cast<std::ptrdiff_t
>(x + (x < 0.0f ? -0.5f : 0.5f));
55inline std::ptrdiff_t iround(
double x)
57 return static_cast<std::ptrdiff_t
>(x + (x < 0.0 ? -0.5 : 0.5));
60inline std::ptrdiff_t ifloor(
float x)
62 return static_cast<std::ptrdiff_t
>(std::floor(x));
65inline std::ptrdiff_t ifloor(
double x)
67 return static_cast<std::ptrdiff_t
>(std::floor(x));
70inline std::ptrdiff_t iceil(
float x)
72 return static_cast<std::ptrdiff_t
>(std::ceil(x));
75inline std::ptrdiff_t iceil(
double x)
77 return static_cast<std::ptrdiff_t
>(std::ceil(x));
85inline T align(T val, std::size_t alignment)
87 return val+(alignment - val%alignment)%alignment;
98 typename ConstReference,
105 using argument_type = ArgType;
106 using result_type = ResultType;
107 using const_t = ConstT;
108 using value_type = Value;
109 using reference = Reference;
110 using const_reference = ConstReference;
111 static constexpr bool is_mutable = IsMutable;
117template <
typename D1,
typename D2>
120 deref_compose<typename D1::const_t, typename D2::const_t>,
121 typename D1::value_type,
122 typename D1::reference,
123 typename D1::const_reference,
124 typename D2::argument_type,
125 typename D1::result_type,
126 D1::is_mutable && D2::is_mutable
133 using argument_type =
typename D2::argument_type;
134 using result_type =
typename D1::result_type;
137 deref_compose(
const D1& x,
const D2& y) : _fn1(x), _fn2(y) {}
140 template <
typename _D1,
typename _D2>
142 : _fn1(dc._fn1), _fn2(dc._fn2)
145 result_type operator()(argument_type x)
const {
return _fn1(_fn2(x)); }
146 result_type operator()(argument_type x) {
return _fn1(_fn2(x)); }
150template <
typename OutPtr,
typename In>
152auto gil_reinterpret_cast(In* p) -> OutPtr
154 return static_cast<OutPtr
>(
static_cast<void*
>(p));
157template <
typename OutPtr,
typename In>
159auto gil_reinterpret_cast_c(In
const* p) -> OutPtr
const
161 return static_cast<OutPtr const
>(
static_cast<void const*
>(p));
170template <
class InputIter,
class Size,
class OutputIter>
171auto _copy_n(InputIter first, Size count, OutputIter result, std::input_iterator_tag)
172 -> std::pair<InputIter, OutputIter>
174 for ( ; count > 0; --count)
180 return std::pair<InputIter, OutputIter>(first, result);
183template <
class RAIter,
class Size,
class OutputIter>
184inline auto _copy_n(RAIter first, Size count, OutputIter result, std::random_access_iterator_tag)
185 -> std::pair<RAIter, OutputIter>
187 RAIter last = first + count;
188 return std::pair<RAIter, OutputIter>(last, std::copy(first, last, result));
191template <
class InputIter,
class Size,
class OutputIter>
192inline auto _copy_n(InputIter first, Size count, OutputIter result)
193 -> std::pair<InputIter, OutputIter>
195 return _copy_n(first, count, result,
typename std::iterator_traits<InputIter>::iterator_category());
198template <
class InputIter,
class Size,
class OutputIter>
199inline auto copy_n(InputIter first, Size count, OutputIter result)
200 -> std::pair<InputIter, OutputIter>
202 return detail::_copy_n(first, count, result);
209 using argument_type = T;
210 using result_type = T;
211 const T& operator()(
const T& val)
const {
return val; }
215template <
typename T1,
typename T2>
217 using first_argument_type = T1;
218 using second_argument_type = T2;
219 using result_type = T1;
220 T1 operator()(T1 f1, T2 f2)
const
230 using argument_type = T;
231 using result_type = T;
232 T operator()(T x)
const {
return ++x; }
239 using argument_type = T;
240 using result_type = T;
241 T operator()(T x)
const {
return --x; }
246template <
typename Types,
typename T>
249 static_assert(mp11::mp_contains<Types, T>::value,
"T should be element of Types");
259 typename ChannelMapping = mp11::mp_iota
261 std::integral_constant<int, mp11::mp_size<ColorSpace>::value>
266 using color_space_t = ColorSpace;
267 using channel_mapping_t = ChannelMapping;
269 static_assert(mp11::mp_size<ColorSpace>::value > 0,
270 "color space should not be empty sequence");
275template <
typename Value,
typename T1,
typename T2>
276void swap_proxy(T1& left, T2& right)
284BOOST_FORCEINLINE
bool little_endian()
286 short tester = 0x0001;
287 return *(
char*)&tester!=0;
290BOOST_FORCEINLINE
bool big_endian()
292 return !little_endian();
Composes two dereference function objects. Similar to std::unary_compose but needs to pull some alias...
Definition utilities.hpp:128
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36
Helper base class for pixel dereference adaptors.
Definition utilities.hpp:104
operator– wrapped in a function object
Definition utilities.hpp:238
identity taken from SGI STL.
Definition utilities.hpp:208
operator++ wrapped in a function object
Definition utilities.hpp:229
plus function object whose arguments may be of different type.
Definition utilities.hpp:216
Returns the index corresponding to the first occurrence of a given given type in.
Definition utilities.hpp:248
Represents a color space and ordering of channels in memory.
Definition utilities.hpp:265