Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/gil/pixel_iterator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // Copyright 2005-2007 Adobe Systems Incorporated
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 #ifndef BOOST_GIL_PIXEL_ITERATOR_HPP
0009 #define BOOST_GIL_PIXEL_ITERATOR_HPP
0010 
0011 #include <boost/gil/concepts.hpp>
0012 #include <boost/gil/dynamic_step.hpp>
0013 #include <boost/gil/utilities.hpp>
0014 #include <boost/gil/pixel.hpp>
0015 
0016 #include <iterator>
0017 #include <type_traits>
0018 
0019 namespace boost { namespace gil {
0020 
0021 //forwarded declaration (as this file is included in step_iterator.hpp)
0022 template <typename Iterator>
0023 class memory_based_step_iterator;
0024 
0025 /// \brief metafunction predicate determining whether the given iterator is a plain one or an adaptor over another iterator.
0026 /// Examples of adaptors are the step iterator and the dereference iterator adaptor.
0027 template <typename It>
0028 struct is_iterator_adaptor : public std::false_type {};
0029 
0030 /// \brief returns the base iterator for a given iterator adaptor. Provide an specialization when introducing new iterator adaptors
0031 template <typename It>
0032 struct iterator_adaptor_get_base;
0033 
0034 /// \brief Changes the base iterator of an iterator adaptor. Provide an specialization when introducing new iterator adaptors
0035 template <typename It, typename NewBaseIt>
0036 struct iterator_adaptor_rebind;
0037 
0038 /// \brief Returns the type of an iterator just like the input iterator, except operating over immutable values
0039 template <typename It>
0040 struct const_iterator_type;
0041 
0042 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
0043 template <typename T> struct const_iterator_type<T*>       { using type = T const*; };
0044 template <typename T> struct const_iterator_type<T const*> { using type = T const*; };
0045 
0046 /// \brief Metafunction predicate returning whether the given iterator allows for changing its values
0047 /// \ingroup GILIsMutable
0048 template <typename It>
0049 struct iterator_is_mutable{};
0050 
0051 // The default implementation when the iterator is a C pointer is to use the standard constness semantics
0052 template <typename T>
0053 struct iterator_is_mutable<T*> : std::true_type {};
0054 
0055 template <typename T>
0056 struct iterator_is_mutable<T const*> : std::false_type {};
0057 
0058 /// \defgroup PixelIteratorModelInterleavedPtr C pointer to a pixel
0059 /// \ingroup PixelIteratorModel
0060 /// \brief Iterators over interleaved pixels.
0061 /// A C pointer to a model of PixelValueConcept is used as an iterator over interleaved pixels. Models PixelIteratorConcept, HomogeneousPixelBasedConcept, HasDynamicXStepTypeConcept, MemoryBasedIteratorConcept
0062 
0063 
0064 
0065 /////////////////////////////
0066 //  HasDynamicXStepTypeConcept
0067 /////////////////////////////
0068 
0069 /// \ingroup PixelIteratorModelInterleavedPtr
0070 template <typename Pixel>
0071 struct dynamic_x_step_type<Pixel*> {
0072     using type = memory_based_step_iterator<Pixel *>;
0073 };
0074 
0075 /// \ingroup PixelIteratorModelInterleavedPtr
0076 template <typename Pixel>
0077 struct dynamic_x_step_type<const Pixel*> {
0078     using type = memory_based_step_iterator<const Pixel *>;
0079 };
0080 
0081 
0082 /////////////////////////////
0083 //  PixelBasedConcept
0084 /////////////////////////////
0085 
0086 template <typename Pixel>
0087 struct color_space_type<Pixel*> : color_space_type<Pixel> {};
0088 
0089 template <typename Pixel>
0090 struct color_space_type<Pixel const*> : color_space_type<Pixel> {};
0091 
0092 template <typename Pixel>
0093 struct channel_mapping_type<Pixel*> : channel_mapping_type<Pixel> {};
0094 
0095 template <typename Pixel>
0096 struct channel_mapping_type<Pixel const*> : channel_mapping_type<Pixel> {};
0097 
0098 template <typename Pixel>
0099 struct is_planar<Pixel*> : is_planar<Pixel> {};
0100 
0101 template <typename Pixel>
0102 struct is_planar<Pixel const*> : is_planar<Pixel> {};
0103 
0104 /////////////////////////////
0105 //  HomogeneousPixelBasedConcept
0106 /////////////////////////////
0107 
0108 template <typename Pixel>
0109 struct channel_type<Pixel*> : channel_type<Pixel> {};
0110 
0111 template <typename Pixel>
0112 struct channel_type<Pixel const*> : channel_type<Pixel> {};
0113 
0114 ////////////////////////////////////////////////////////////////////////////////////////
0115 /// Support for pixel iterator movement measured in memory units (bytes or bits) as opposed to pixel type.
0116 /// Necessary to handle image row alignment and channel plane alignment.
0117 ////////////////////////////////////////////////////////////////////////////////////////
0118 
0119 /////////////////////////////
0120 //  MemoryBasedIteratorConcept
0121 /////////////////////////////
0122 
0123 template <typename T>
0124 struct byte_to_memunit : std::integral_constant<int, 1> {};
0125 
0126 template <typename P>
0127 inline std::ptrdiff_t memunit_step(P const*) { return sizeof(P); }
0128 
0129 template <typename P>
0130 inline std::ptrdiff_t memunit_distance(P const* p1, P const* p2)
0131 {
0132     return (
0133         gil_reinterpret_cast_c<unsigned char const*>(p2) -
0134         gil_reinterpret_cast_c<unsigned char const*>(p1));
0135 }
0136 
0137 template <typename P>
0138 inline void memunit_advance(P* &p, std::ptrdiff_t diff)
0139 {
0140     p = (P*)((unsigned char*)(p)+diff);
0141 }
0142 
0143 template <typename P>
0144 inline P* memunit_advanced(const P* p, std::ptrdiff_t diff)
0145 {
0146     return (P*)((char*)(p)+diff);
0147 }
0148 
0149 //  memunit_advanced_ref
0150 //  (shortcut to advancing a pointer by a given number of memunits and taking the reference in case the compiler is not smart enough)
0151 
0152 template <typename P>
0153 inline P& memunit_advanced_ref(P* p, std::ptrdiff_t diff) {
0154     return *memunit_advanced(p,diff);
0155 }
0156 
0157 } }  // namespace boost::gil
0158 
0159 #endif