8 #ifndef BOOST_GIL_PLANAR_PIXEL_ITERATOR_HPP
9 #define BOOST_GIL_PLANAR_PIXEL_ITERATOR_HPP
11 #include <boost/gil/pixel.hpp>
12 #include <boost/gil/step_iterator.hpp>
13 #include <boost/gil/detail/mp11.hpp>
15 #include <boost/iterator/iterator_facade.hpp>
18 #include <type_traits>
20 namespace boost {
namespace gil {
23 template <
typename ChannelReference,
typename ColorSpace>
24 struct planar_pixel_reference;
42 template <
typename ChannelPtr,
typename ColorSpace>
47 planar_pixel_iterator<ChannelPtr, ColorSpace>,
48 pixel<typename std::iterator_traits<ChannelPtr>::value_type,layout<ColorSpace>>,
49 std::random_access_iterator_tag,
50 planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference, ColorSpace> const
52 detail::homogeneous_color_base
56 mp11::mp_size<ColorSpace>::value
60 using parent_t = iterator_facade
64 std::random_access_iterator_tag,
68 using color_base_parent_t = detail::homogeneous_color_base
72 mp11::mp_size<ColorSpace>::value
75 using channel_t =
typename std::iterator_traits<ChannelPtr>::value_type;
78 using value_type =
typename parent_t::value_type;
79 using reference =
typename parent_t::reference;
80 using difference_type =
typename parent_t::difference_type;
86 planar_pixel_iterator(
const ChannelPtr& v0,
const ChannelPtr& v1,
const ChannelPtr& v2) : color_base_parent_t(v0,v1,v2) {}
87 planar_pixel_iterator(
const ChannelPtr& v0,
const ChannelPtr& v1,
const ChannelPtr& v2,
const ChannelPtr& v3) : color_base_parent_t(v0,v1,v2,v3) {}
88 planar_pixel_iterator(
const ChannelPtr& v0,
const ChannelPtr& v1,
const ChannelPtr& v2,
const ChannelPtr& v3,
const ChannelPtr& v4) : color_base_parent_t(v0,v1,v2,v3,v4) {}
90 template <
typename IC1,
typename C1>
98 function_requires<PixelsCompatibleConcept<P,value_type> >();
101 struct address_of {
template <
typename T> T* operator()(T& t) {
return &t; } };
102 template <
typename P>
103 planar_pixel_iterator& operator=(P* pix) {
104 function_requires<PixelsCompatibleConcept<P,value_type> >();
105 static_transform(*pix,*
this, address_of());
116 reference
operator[](difference_type d)
const {
return memunit_advanced_ref(*
this,d*
sizeof(channel_t));}
118 reference operator->()
const {
return **
this; }
121 bool operator< (
const planar_pixel_iterator& ptr)
const {
return gil::at_c<0>(*
this)< gil::at_c<0>(ptr); }
122 bool operator!=(
const planar_pixel_iterator& ptr)
const {
return gil::at_c<0>(*
this)!=gil::at_c<0>(ptr); }
124 friend class boost::iterator_core_access;
126 void increment() { static_transform(*
this,*
this,detail::inc<ChannelPtr>()); }
127 void decrement() { static_transform(*
this,*
this,detail::dec<ChannelPtr>()); }
128 void advance(std::ptrdiff_t d){ static_transform(*
this,*
this,std::bind(detail::plus_asymmetric<ChannelPtr,std::ptrdiff_t>(),std::placeholders::_1,d)); }
129 reference dereference()
const {
return this->
template deref<reference>(); }
131 std::ptrdiff_t distance_to(
const planar_pixel_iterator& it)
const {
return gil::at_c<0>(it)-gil::at_c<0>(*
this); }
132 bool equal(
const planar_pixel_iterator& it)
const {
return gil::at_c<0>(*
this)==gil::at_c<0>(it); }
136 template <
typename I>
137 struct channel_iterator_is_mutable : std::true_type {};
139 template <
typename I>
140 struct channel_iterator_is_mutable<I const*> : std::false_type {};
144 template <
typename IC,
typename C>
145 struct const_iterator_type<planar_pixel_iterator<IC,C> > {
147 using channel_t =
typename std::iterator_traits<IC>::value_type;
149 using type = planar_pixel_iterator<typename channel_traits<channel_t>::const_pointer,C>;
153 template <
typename IC,
typename C>
154 struct iterator_is_mutable<planar_pixel_iterator<IC,C> > :
public detail::channel_iterator_is_mutable<IC> {};
160 template <
typename IC,
typename C,
int K>
161 struct kth_element_type<planar_pixel_iterator<IC, C>, K>
166 template <
typename IC,
typename C,
int K>
167 struct kth_element_reference_type<planar_pixel_iterator<IC, C>, K>
168 : std::add_lvalue_reference<IC> {};
170 template <
typename IC,
typename C,
int K>
171 struct kth_element_const_reference_type<planar_pixel_iterator<IC, C>, K>
172 : std::add_lvalue_reference<typename std::add_const<IC>::type>
179 template <
typename IC,
typename C>
180 struct color_space_type<planar_pixel_iterator<IC,C>>
185 template <
typename IC,
typename C>
186 struct channel_mapping_type<planar_pixel_iterator<IC, C>>
187 : channel_mapping_type<typename planar_pixel_iterator<IC,C>::value_type>
190 template <
typename IC,
typename C>
191 struct is_planar<planar_pixel_iterator<IC, C>> : std::true_type {};
193 template <
typename IC,
typename C>
194 struct channel_type<planar_pixel_iterator<IC, C>>
196 using type =
typename std::iterator_traits<IC>::value_type;
203 template <
typename IC,
typename C>
204 inline auto memunit_step(planar_pixel_iterator<IC,C>
const&)
207 return sizeof(
typename std::iterator_traits<IC>::value_type);
210 template <
typename IC,
typename C>
211 inline auto memunit_distance(planar_pixel_iterator<IC,C>
const& p1, planar_pixel_iterator<IC,C>
const& p2)
214 return memunit_distance(gil::at_c<0>(p1),gil::at_c<0>(p2));
217 template <
typename IC>
218 struct memunit_advance_fn {
219 memunit_advance_fn(std::ptrdiff_t diff) : _diff(diff) {}
220 IC operator()(
const IC& p)
const {
return memunit_advanced(p,_diff); }
222 std::ptrdiff_t _diff;
225 template <
typename IC,
typename C>
226 inline void memunit_advance(planar_pixel_iterator<IC,C>& p, std::ptrdiff_t diff) {
227 static_transform(p, p, memunit_advance_fn<IC>(diff));
230 template <
typename IC,
typename C>
231 inline auto memunit_advanced(planar_pixel_iterator<IC,C>
const& p, std::ptrdiff_t diff)
232 -> planar_pixel_iterator<IC,C>
234 planar_pixel_iterator<IC,C> ret=p;
235 memunit_advance(ret, diff);
239 template <
typename ChannelPtr,
typename ColorSpace>
240 inline auto memunit_advanced_ref(planar_pixel_iterator<ChannelPtr,ColorSpace>
const& ptr, std::ptrdiff_t diff)
241 -> planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace>
243 return planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace>(ptr, diff);
250 template <
typename IC,
typename C>
251 struct dynamic_x_step_type<planar_pixel_iterator<IC,C> > {
252 using type = memory_based_step_iterator<planar_pixel_iterator<IC,C>>;
BOOST_FORCEINLINE bool equal(boost::gil::iterator_from_2d< Loc1 > first, boost::gil::iterator_from_2d< Loc1 > last, boost::gil::iterator_from_2d< Loc2 > first2)
std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d
Definition: algorithm.hpp:1087
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
Represents a color space and ordering of channels in memory.
Definition: utilities.hpp:268
Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept,...
Definition: pixel.hpp:106
An iterator over planar pixels. Models HomogeneousColorBaseConcept, PixelIteratorConcept,...
Definition: planar_pixel_iterator.hpp:58
reference operator[](difference_type d) const
Definition: planar_pixel_iterator.hpp:116
planar_pixel_iterator(P *pix)
Definition: planar_pixel_iterator.hpp:97
A reference proxy to a planar pixel.
Definition: planar_pixel_reference.hpp:46