Generic Image Library: bit_aligned_pixel_iterator.hpp Source File Boost , ,
bit_aligned_pixel_iterator.hpp Go to the documentation of this file. 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 #include "pixel_iterator.hpp "
00030
00031 namespace boost { namespace gil {
00032
00036
00043
00044 template <typename NonAlignedPixelReference>
00045 struct bit_aligned_pixel_iterator : public iterator_facade<bit_aligned_pixel_iterator<NonAlignedPixelReference>,
00046 typename NonAlignedPixelReference::value_type,
00047 random_access_traversal_tag,
00048 const NonAlignedPixelReference,
00049 typename NonAlignedPixelReference::bit_range_t::difference_type> {
00050 private :
00051 typedef iterator_facade<bit_aligned_pixel_iterator<NonAlignedPixelReference>,
00052 typename NonAlignedPixelReference::value_type,
00053 random_access_traversal_tag,
00054 const NonAlignedPixelReference,
00055 typename NonAlignedPixelReference::bit_range_t::difference_type> parent_t;
00056 template <typename Ref> friend struct bit_aligned_pixel_iterator ;
00057
00058 typedef typename NonAlignedPixelReference::bit_range_t bit_range_t;
00059 public :
00060 typedef typename parent_t::difference_type difference_type;
00061 typedef typename parent_t::reference reference;
00062
00063 bit_aligned_pixel_iterator () {}
00064 bit_aligned_pixel_iterator (const bit_aligned_pixel_iterator & p) : _bit_range(p._bit_range ) {}
00065 bit_aligned_pixel_iterator & operator=(const bit_aligned_pixel_iterator & p) { _bit_range=p._bit_range ; return *this ; }
00066
00067 template <typename Ref> bit_aligned_pixel_iterator (const bit_aligned_pixel_iterator<Ref> & p) : _bit_range(p._bit_range ) {}
00068
00069 bit_aligned_pixel_iterator (reference* ref) : _bit_range(ref->bit_range()) {}
00070 explicit bit_aligned_pixel_iterator (typename bit_range_t::byte_t* data, int bit_offset=0) : _bit_range(data,bit_offset) {}
00071
00074 reference operator[] (difference_type d) const { bit_aligned_pixel_iterator it=*this ; it.advance (d); return *it; }
00075
00076 reference operator->() const { return **this ; }
00077 const bit_range_t& bit_range() const { return _bit_range; }
00078 bit_range_t& bit_range() { return _bit_range; }
00079 private :
00080 bit_range_t _bit_range;
00081 BOOST_STATIC_CONSTANT(int , bit_size = NonAlignedPixelReference::bit_size);
00082
00083 friend class boost::iterator_core_access;
00084 reference dereference() const { return NonAlignedPixelReference(_bit_range); }
00085 void increment() { ++_bit_range; }
00086 void decrement() { --_bit_range; }
00087 void advance(difference_type d) { _bit_range.bit_advance(d*bit_size); }
00088
00089 difference_type distance_to(const bit_aligned_pixel_iterator& it) const { return _bit_range.bit_distance_to(it._bit_range) / bit_size; }
00090 bool equal (const bit_aligned_pixel_iterator& it) const { return _bit_range==it._bit_range; }
00091 };
00092
00093 template <typename NonAlignedPixelReference>
00094 struct const_iterator_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > {
00095 typedef bit_aligned_pixel_iterator<typename NonAlignedPixelReference::const_reference> type;
00096 };
00097
00098 template <typename NonAlignedPixelReference>
00099 struct iterator_is_mutable<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public mpl::bool_<NonAlignedPixelReference::is_mutable> {};
00100
00101 template <typename NonAlignedPixelReference>
00102 struct is_iterator_adaptor<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public mpl::false_ {};
00103
00105
00107
00108 template <typename NonAlignedPixelReference>
00109 struct color_space_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public color_space_type<NonAlignedPixelReference> {};
00110
00111 template <typename NonAlignedPixelReference>
00112 struct channel_mapping_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public channel_mapping_type<NonAlignedPixelReference> {};
00113
00114 template <typename NonAlignedPixelReference>
00115 struct is_planar<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public is_planar<NonAlignedPixelReference> {};
00116
00118
00120
00121 template <typename NonAlignedPixelReference>
00122 struct byte_to_memunit<bit_aligned_pixel_iterator<NonAlignedPixelReference> > : public mpl::int_<8> {};
00123
00124 template <typename NonAlignedPixelReference>
00125 inline std::ptrdiff_t memunit_step(const bit_aligned_pixel_iterator<NonAlignedPixelReference>&) {
00126 return NonAlignedPixelReference::bit_size;
00127 }
00128
00129 template <typename NonAlignedPixelReference>
00130 inline std::ptrdiff_t memunit_distance(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p1, const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p2) {
00131 return (p2.bit_range().current_byte() - p1.bit_range().current_byte())*8 + p2.bit_range().bit_offset() - p1.bit_range().bit_offset();
00132 }
00133
00134 template <typename NonAlignedPixelReference>
00135 inline void memunit_advance(bit_aligned_pixel_iterator<NonAlignedPixelReference>& p, std::ptrdiff_t diff) {
00136 p.bit_range().bit_advance(diff);
00137 }
00138
00139 template <typename NonAlignedPixelReference>
00140 inline bit_aligned_pixel_iterator<NonAlignedPixelReference> memunit_advanced(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p, std::ptrdiff_t diff) {
00141 bit_aligned_pixel_iterator<NonAlignedPixelReference> ret=p;
00142 memunit_advance(ret, diff);
00143 return ret;
00144 }
00145
00146 template <typename NonAlignedPixelReference> inline
00147 NonAlignedPixelReference memunit_advanced_ref(bit_aligned_pixel_iterator<NonAlignedPixelReference> it, std::ptrdiff_t diff) {
00148 return *memunit_advanced(it,diff);
00149 }
00151
00153
00154 template <typename NonAlignedPixelReference>
00155 struct dynamic_x_step_type<bit_aligned_pixel_iterator<NonAlignedPixelReference> > {
00156 typedef memory_based_step_iterator<bit_aligned_pixel_iterator<NonAlignedPixelReference> > type;
00157 };
00158
00160
00162
00163 template <typename B, typename C, typename L, bool M>
00164 struct iterator_type_from_pixel<const bit_aligned_pixel_reference<B,C,L,M>,false,false,false> {
00165 typedef bit_aligned_pixel_iterator<bit_aligned_pixel_reference<B,C,L,false> > type;
00166 };
00167
00168 template <typename B, typename C, typename L, bool M>
00169 struct iterator_type_from_pixel<const bit_aligned_pixel_reference<B,C,L,M>,false,false,true> {
00170 typedef bit_aligned_pixel_iterator<bit_aligned_pixel_reference<B,C,L,true> > type;
00171 };
00172
00173 template <typename B, typename C, typename L, bool M, bool IsPlanar, bool IsStep, bool IsMutable>
00174 struct iterator_type_from_pixel<bit_aligned_pixel_reference<B,C,L,M>,IsPlanar,IsStep,IsMutable>
00175 : public iterator_type_from_pixel<const bit_aligned_pixel_reference<B,C,L,M>,IsPlanar,IsStep,IsMutable> {};
00176
00177 } }
00178
00179 namespace std {
00180
00181
00182
00183 template <typename NonAlignedPixelReference>
00184 boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> uninitialized_copy(boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> first,
00185 boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> last,
00186 boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> dst) {
00187 return std::copy (first,last,dst);
00188 }
00189
00190 }
00191 #endif
Generated on Sat May 2 13:50:13 2009 for Generic Image Library by
1.5.6
Статья Generic Image Library: bit_aligned_pixel_iterator.hpp Source File раздела может быть полезна для разработчиков на c++ и boost.
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.
:: Главная :: ::