00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef GIL_BIT_ALIGNED_PIXEL_ITERATOR_HPP
00014 #define GIL_BIT_ALIGNED_PIXEL_ITERATOR_HPP
00015
00024
00025 #include <functional>
00026 #include <boost/iterator/iterator_facade.hpp>
00027 #include "gil_config.hpp"
00028 #include "bit_aligned_pixel_reference.hpp"
00029
00030 namespace boost { namespace gil {
00031
00035
00042
00043 template <typename NonAlignedPixelReference>
00044 struct bit_aligned_pixel_iterator : public iterator_facade<bit_aligned_pixel_iterator<NonAlignedPixelReference>,
00045 typename NonAlignedPixelReference::value_type,
00046 random_access_traversal_tag,
00047 const NonAlignedPixelReference,
00048 typename NonAlignedPixelReference::bit_range_t::difference_type> {
00049 private:
00050 typedef iterator_facade<bit_aligned_pixel_iterator<NonAlignedPixelReference>,
00051 typename NonAlignedPixelReference::value_type,
00052 random_access_traversal_tag,
00053 const NonAlignedPixelReference,
00054 typename NonAlignedPixelReference::bit_range_t::difference_type> parent_t;
00055 template <typename Ref> friend struct bit_aligned_pixel_iterator;
00056
00057 typedef typename NonAlignedPixelReference::bit_range_t bit_range_t;
00058 public:
00059 typedef typename parent_t::difference_type difference_type;
00060 typedef typename parent_t::reference reference;
00061
00062 bit_aligned_pixel_iterator() {}
00063 bit_aligned_pixel_iterator(const bit_aligned_pixel_iterator& p) : _bit_range(p._bit_range) {}
00064 bit_aligned_pixel_iterator& operator=(const bit_aligned_pixel_iterator& p) { _bit_range=p._bit_range; return *this; }
00065
00066 template <typename Ref> bit_aligned_pixel_iterator(const bit_aligned_pixel_iterator<Ref>& p) : _bit_range(p._bit_range) {}
00067
00068 bit_aligned_pixel_iterator(reference* ref) : _bit_range(ref->bit_range()) {}
00069 explicit bit_aligned_pixel_iterator(typename bit_range_t::byte_t* data, int bit_offset=0) : _bit_range(data,bit_offset) {}
00070
00073 reference operator[](difference_type d) const { bit_aligned_pixel_iterator it=*this; it.advance(d); return *it; }
00074
00075 reference operator->() const { return **this; }
00076 const bit_range_t& bit_range() const { return _bit_range; }
00077 bit_range_t& bit_range() { return _bit_range; }
00078 private:
00079 bit_range_t _bit_range;
00080 BOOST_STATIC_CONSTANT(int, bit_size = NonAlignedPixelReference::bit_size);
00081
00082 friend class boost::iterator_core_access;
00083 reference dereference() const { return NonAlignedPixelReference(_bit_range); }
00084 void increment() { ++_bit_range; }
00085 void decrement() { --_bit_range; }
00086 void advance(difference_type d) { _bit_range.bit_advance(d*bit_size); }
00087
00088 difference_type distance_to(const bit_aligned_pixel_iterator& it) const { return _bit_range.bit_distance_to(it._bit_range) / bit_size; }
00089 bool equal(const bit_aligned_pixel_iterator& it) const { return _bit_range==it._bit_range; }
00090 };
00091
00092 template <typename NonAlignedPixelReference>
00093 struct const_iterator_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > {
00094 typedef bit_aligned_pixel_iterator<typename NonAlignedPixelReference::const_reference> type;
00095 };
00096
00097 template <typename NonAlignedPixelReference>
00098 struct iterator_is_mutable<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public mpl::bool_<NonAlignedPixelReference::is_mutable> {};
00099
00100 template <typename NonAlignedPixelReference>
00101 struct is_iterator_adaptor<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public mpl::false_ {};
00102
00104
00106
00107 template <typename NonAlignedPixelReference>
00108 struct color_space_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public color_space_type<NonAlignedPixelReference> {};
00109
00110 template <typename NonAlignedPixelReference>
00111 struct channel_mapping_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public channel_mapping_type<NonAlignedPixelReference> {};
00112
00113 template <typename NonAlignedPixelReference>
00114 struct is_planar<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public is_planar<NonAlignedPixelReference> {};
00115
00117
00119
00120 template <typename NonAlignedPixelReference>
00121 struct byte_to_memunit<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public mpl::int_<8> {};
00122
00123 template <typename NonAlignedPixelReference>
00124 inline std::ptrdiff_t memunit_step(const bit_aligned_pixel_iterator<NonAlignedPixelReference>&) {
00125 return NonAlignedPixelReference::bit_size;
00126 }
00127
00128 template <typename NonAlignedPixelReference>
00129 inline std::ptrdiff_t memunit_distance(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p1, const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p2) {
00130 return (p2.bit_range().current_byte() - p1.bit_range().current_byte())*8 + p2.bit_range().bit_offset() - p1.bit_range().bit_offset();
00131 }
00132
00133 template <typename NonAlignedPixelReference>
00134 inline void memunit_advance(bit_aligned_pixel_iterator<NonAlignedPixelReference>& p, std::ptrdiff_t diff) {
00135 p.bit_range().bit_advance(diff);
00136 }
00137
00138 template <typename NonAlignedPixelReference>
00139 inline bit_aligned_pixel_iterator<NonAlignedPixelReference> memunit_advanced(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p, std::ptrdiff_t diff) {
00140 bit_aligned_pixel_iterator<NonAlignedPixelReference> ret=p;
00141 memunit_advance(ret, diff);
00142 return ret;
00143 }
00144
00145 template <typename NonAlignedPixelReference> inline
00146 NonAlignedPixelReference memunit_advanced_ref(bit_aligned_pixel_iterator<NonAlignedPixelReference> it, std::ptrdiff_t diff) {
00147 return *memunit_advanced(it,diff);
00148 }
00150
00152
00153 template <typename NonAlignedPixelReference>
00154 struct dynamic_x_step_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > {
00155 typedef memory_based_step_iterator<bit_aligned_pixel_iterator<NonAlignedPixelReference> > type;
00156 };
00157
00159
00161
00162 template <typename C, typename L, bool M>
00163 struct iterator_type_from_pixel<const bit_aligned_pixel_reference<C,L,M>,false,false,false> {
00164 typedef bit_aligned_pixel_iterator<bit_aligned_pixel_reference<C,L,false> > type;
00165 };
00166
00167 template <typename C, typename L, bool M>
00168 struct iterator_type_from_pixel<const bit_aligned_pixel_reference<C,L,M>,false,false,true> {
00169 typedef bit_aligned_pixel_iterator<bit_aligned_pixel_reference<C,L,true> > type;
00170 };
00171
00172 template <typename C, typename L, bool M, bool IsPlanar, bool IsStep, bool IsMutable>
00173 struct iterator_type_from_pixel<bit_aligned_pixel_reference<C,L,M>,IsPlanar,IsStep,IsMutable>
00174 : public iterator_type_from_pixel<const bit_aligned_pixel_reference<C,L,M>,IsPlanar,IsStep,IsMutable> {};
00175
00176 } }
00177
00178 namespace std {
00179
00180
00181
00182 template <typename NonAlignedPixelReference>
00183 boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> uninitialized_copy(boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> first,
00184 boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> last,
00185 boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> dst) {
00186 return std::copy(first,last,dst);
00187 }
00188
00189 }
00190 #endif