Chris@16: /* Chris@16: Copyright 2005-2007 Adobe Systems Incorporated Chris@16: Chris@16: Use, modification and distribution are subject to the Boost Software License, Chris@16: Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt). Chris@16: Chris@16: See http://opensource.adobe.com/gil for most recent version including documentation. Chris@16: */ Chris@16: Chris@16: /*************************************************************************************************/ Chris@16: Chris@16: #ifndef GIL_PIXEL_ITERATOR_H Chris@16: #define GIL_PIXEL_ITERATOR_H Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file Chris@16: /// \brief pixel iterator support Chris@16: /// \author Lubomir Bourdev and Hailin Jin \n Chris@16: /// Adobe Systems Incorporated Chris@16: /// \date 2005-2007 \n May 16, 2006 Chris@16: /// Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include "gil_config.hpp" Chris@16: #include "gil_concept.hpp" Chris@16: #include "utilities.hpp" Chris@16: #include "pixel.hpp" Chris@16: Chris@16: namespace boost { namespace gil { Chris@16: Chris@16: //forwarded declaration (as this file is included in step_iterator.hpp) Chris@16: template Chris@16: class memory_based_step_iterator; Chris@16: Chris@16: template struct dynamic_x_step_type; Chris@16: Chris@16: /// \brief metafunction predicate determining whether the given iterator is a plain one or an adaptor over another iterator. Chris@16: /// Examples of adaptors are the step iterator and the dereference iterator adaptor. Chris@16: template Chris@16: struct is_iterator_adaptor : public mpl::false_{}; Chris@16: Chris@16: /// \brief returns the base iterator for a given iterator adaptor. Provide an specialization when introducing new iterator adaptors Chris@16: template Chris@16: struct iterator_adaptor_get_base; Chris@16: Chris@16: /// \brief Changes the base iterator of an iterator adaptor. Provide an specialization when introducing new iterator adaptors Chris@16: template Chris@16: struct iterator_adaptor_rebind; Chris@16: Chris@16: /// \brief Returns the type of an iterator just like the input iterator, except operating over immutable values Chris@16: template Chris@16: struct const_iterator_type; Chris@16: Chris@16: // The default implementation when the iterator is a C pointer is to use the standard constness semantics Chris@16: template struct const_iterator_type< T*> { typedef const T* type; }; Chris@16: template struct const_iterator_type { typedef const T* type; }; Chris@16: Chris@16: /// \brief Metafunction predicate returning whether the given iterator allows for changing its values Chris@16: /// \ingroup GILIsMutable Chris@16: template Chris@16: struct iterator_is_mutable{}; Chris@16: Chris@16: // The default implementation when the iterator is a C pointer is to use the standard constness semantics Chris@16: template struct iterator_is_mutable< T*> : public mpl::true_{}; Chris@16: template struct iterator_is_mutable : public mpl::false_{}; Chris@16: Chris@16: /// \defgroup PixelIteratorModelInterleavedPtr C pointer to a pixel Chris@16: /// \ingroup PixelIteratorModel Chris@16: /// \brief Iterators over interleaved pixels. Chris@16: /// A C pointer to a model of PixelValueConcept is used as an iterator over interleaved pixels. Models PixelIteratorConcept, HomogeneousPixelBasedConcept, HasDynamicXStepTypeConcept, MemoryBasedIteratorConcept Chris@16: Chris@16: Chris@16: Chris@16: ///////////////////////////// Chris@16: // HasDynamicXStepTypeConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: /// \ingroup PixelIteratorModelInterleavedPtr Chris@16: template Chris@16: struct dynamic_x_step_type { Chris@16: typedef memory_based_step_iterator type; Chris@16: }; Chris@16: Chris@16: /// \ingroup PixelIteratorModelInterleavedPtr Chris@16: template Chris@16: struct dynamic_x_step_type { Chris@16: typedef memory_based_step_iterator type; Chris@16: }; Chris@16: Chris@16: Chris@16: ///////////////////////////// Chris@16: // PixelBasedConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: template struct color_space_type< Pixel*> : public color_space_type {}; Chris@16: template struct color_space_type : public color_space_type {}; Chris@16: Chris@16: template struct channel_mapping_type< Pixel*> : public channel_mapping_type {}; Chris@16: template struct channel_mapping_type : public channel_mapping_type {}; Chris@16: Chris@16: template struct is_planar< Pixel*> : public is_planar {}; Chris@16: template struct is_planar : public is_planar {}; Chris@16: Chris@16: ///////////////////////////// Chris@16: // HomogeneousPixelBasedConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: template struct channel_type : public channel_type {}; Chris@16: template struct channel_type : public channel_type {}; Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: /// Chris@16: /// Support for pixel iterator movement measured in memory units (bytes or bits) as opposed to pixel type. \n Chris@16: /// Necessary to handle image row alignment and channel plane alignment. Chris@16: /// Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: ///////////////////////////// Chris@16: // MemoryBasedIteratorConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: template Chris@16: struct byte_to_memunit : public mpl::int_<1> {}; Chris@16: Chris@16: template Chris@16: inline std::ptrdiff_t memunit_step(const P*) { return sizeof(P); } Chris@16: Chris@16: template Chris@16: inline std::ptrdiff_t memunit_distance(const P* p1, const P* p2) { Chris@16: return (gil_reinterpret_cast_c(p2)-gil_reinterpret_cast_c(p1)); Chris@16: } Chris@16: Chris@16: template Chris@16: inline void memunit_advance(P* &p, std::ptrdiff_t diff) { Chris@16: p=(P*)((unsigned char*)(p)+diff); Chris@16: } Chris@16: Chris@16: template Chris@16: inline P* memunit_advanced(const P* p, std::ptrdiff_t diff) { Chris@16: return (P*)((char*)(p)+diff); Chris@16: } Chris@16: Chris@16: // memunit_advanced_ref Chris@16: // (shortcut to advancing a pointer by a given number of memunits and taking the reference in case the compiler is not smart enough) Chris@16: Chris@16: template Chris@16: inline P& memunit_advanced_ref(P* p, std::ptrdiff_t diff) { Chris@16: return *memunit_advanced(p,diff); Chris@16: } Chris@16: Chris@16: } } // namespace boost::gil Chris@16: Chris@16: #endif