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>
43 struct planar_pixel_iterator
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
62 planar_pixel_iterator<ChannelPtr, ColorSpace>,
63 pixel<typename std::iterator_traits<ChannelPtr>::value_type,layout<ColorSpace>>,
64 std::random_access_iterator_tag,
65 planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference, ColorSpace>
const 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;
82 planar_pixel_iterator() : color_base_parent_t(0) {}
83 planar_pixel_iterator(
bool) {}
85 planar_pixel_iterator(
const ChannelPtr& v0,
const ChannelPtr& v1) : color_base_parent_t(v0,v1) {}
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>
91 planar_pixel_iterator(
const planar_pixel_iterator<IC1,C1>& ptr) : color_base_parent_t(ptr) {}
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 std::ptrdiff_t memunit_step(
const planar_pixel_iterator<IC,C>&) {
return sizeof(
typename std::iterator_traits<IC>::value_type); }
206 template <
typename IC,
typename C>
207 inline std::ptrdiff_t memunit_distance(
const planar_pixel_iterator<IC,C>& p1,
const planar_pixel_iterator<IC,C>& p2) {
208 return memunit_distance(gil::at_c<0>(p1),gil::at_c<0>(p2));
211 template <
typename IC>
212 struct memunit_advance_fn {
213 memunit_advance_fn(std::ptrdiff_t diff) : _diff(diff) {}
214 IC operator()(
const IC& p)
const {
return memunit_advanced(p,_diff); }
216 std::ptrdiff_t _diff;
219 template <
typename IC,
typename C>
220 inline void memunit_advance(planar_pixel_iterator<IC,C>& p, std::ptrdiff_t diff) {
221 static_transform(p, p, memunit_advance_fn<IC>(diff));
224 template <
typename IC,
typename C>
225 inline planar_pixel_iterator<IC,C> memunit_advanced(
const planar_pixel_iterator<IC,C>& p, std::ptrdiff_t diff) {
226 planar_pixel_iterator<IC,C> ret=p;
227 memunit_advance(ret, diff);
231 template <
typename ChannelPtr,
typename ColorSpace>
232 inline planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace>
233 memunit_advanced_ref(
const planar_pixel_iterator<ChannelPtr,ColorSpace>& ptr, std::ptrdiff_t diff) {
234 return planar_pixel_reference<typename std::iterator_traits<ChannelPtr>::reference,ColorSpace>(ptr, diff);
241 template <
typename IC,
typename C>
242 struct dynamic_x_step_type<planar_pixel_iterator<IC,C> > {
243 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:1029
planar_pixel_iterator(P *pix)
Definition: planar_pixel_iterator.hpp:97
reference operator[](difference_type d) const
Definition: planar_pixel_iterator.hpp:116