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://stlab.adobe.com/gil for most recent version including documentation. Chris@16: */ Chris@16: Chris@16: /*************************************************************************************************/ Chris@16: Chris@16: #ifndef GIL_PLANAR_REF_H Chris@16: #define GIL_PLANAR_REF_H Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file Chris@16: /// \brief planar pixel reference class Chris@16: /// \author Lubomir Bourdev and Hailin Jin \n Chris@16: /// Adobe Systems Incorporated Chris@16: /// \date 2005-2007 \n Last updated on September 28, 2006 Chris@16: /// Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #include Chris@16: #include "gil_config.hpp" Chris@16: #include "gil_concept.hpp" Chris@16: #include "color_base.hpp" Chris@16: #include "channel.hpp" Chris@16: #include "pixel.hpp" Chris@16: #include "planar_pixel_iterator.hpp" Chris@16: Chris@16: namespace boost { namespace gil { Chris@16: Chris@16: /// \defgroup ColorBaseModelPlanarRef planar_pixel_reference Chris@16: /// \ingroup ColorBaseModel Chris@16: /// \brief A homogeneous color base whose element is a channel reference. Models HomogeneousColorBaseConcept, HomogeneousPixelConcept. Chris@16: /// This class is used as a reference proxy to a planar pixel. Chris@16: Chris@16: /// \defgroup PixelModelPlanarRef planar_pixel_reference Chris@16: /// \ingroup PixelModel Chris@16: /// \brief A reference proxy to a planar pixel. Models HomogeneousColorBaseConcept, HomogeneousPixelConcept. Chris@16: Chris@16: Chris@16: /// \ingroup PixelModelPlanarRef ColorBaseModelPlanarRef PixelBasedModel Chris@16: /// \brief A reference proxy to a planar pixel. Models: HomogeneousColorBaseConcept, HomogeneousPixelConcept Chris@16: /// Chris@16: /// A reference to a planar pixel is a proxy class containing references to each of the corresponding channels. Chris@16: /// Chris@16: template // ChannelReference is a channel reference (const or mutable) Chris@16: struct planar_pixel_reference Chris@16: : public detail::homogeneous_color_base,mpl::size::value> { Chris@16: typedef detail::homogeneous_color_base,mpl::size::value> parent_t; Chris@16: private: Chris@16: // These three are only defined for homogeneous pixels Chris@16: typedef typename channel_traits::value_type channel_t; Chris@16: typedef typename channel_traits::const_reference channel_const_reference; Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT(bool, is_mutable = channel_traits::is_mutable); Chris@16: typedef pixel > value_type; Chris@16: typedef planar_pixel_reference reference; Chris@16: typedef planar_pixel_reference const_reference; Chris@16: Chris@16: planar_pixel_reference(ChannelReference v0, ChannelReference v1) : parent_t(v0,v1) {} Chris@16: planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2) : parent_t(v0,v1,v2) {} Chris@16: planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3) : parent_t(v0,v1,v2,v3) {} Chris@16: planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4) : parent_t(v0,v1,v2,v3,v4) {} Chris@16: planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5) : parent_t(v0,v1,v2,v3,v4,v5) {} Chris@16: Chris@16: template planar_pixel_reference(const P& p) : parent_t(p) { check_compatible

();} Chris@16: Chris@16: // PERFORMANCE_CHECK: Is this constructor necessary? Chris@16: template Chris@16: planar_pixel_reference(pixel >& p) : parent_t(p) { check_compatible > >();} Chris@16: Chris@16: // Construct at offset from a given location Chris@16: template planar_pixel_reference(const planar_pixel_iterator& p, std::ptrdiff_t diff) : parent_t(p,diff) {} Chris@16: Chris@16: const planar_pixel_reference& operator=(const planar_pixel_reference& p) const { static_copy(p,*this); return *this; } Chris@16: template const planar_pixel_reference& operator=(const P& p) const { check_compatible

(); static_copy(p,*this); return *this; } Chris@16: Chris@16: // This overload is necessary for a compiler implementing Core Issue 574 Chris@16: // to prevent generation of an implicit copy assignment operator (the reason Chris@16: // for generating implicit copy assignment operator is that according to Chris@16: // Core Issue 574, a cv-qualified assignment operator is not considered Chris@16: // "copy assignment operator"). Chris@16: // EDG implemented Core Issue 574 starting with EDG Version 3.8. I'm not Chris@16: // sure why they did it for a template member function as well. Chris@16: #if BOOST_WORKAROUND(__HP_aCC, >= 61700) || BOOST_WORKAROUND(__INTEL_COMPILER, >= 1000) Chris@16: const planar_pixel_reference& operator=(const planar_pixel_reference& p) { static_copy(p,*this); return *this; } Chris@16: template const planar_pixel_reference& operator=(const P& p) { check_compatible

(); static_copy(p,*this); return *this; } Chris@16: #endif Chris@16: Chris@16: template bool operator==(const P& p) const { check_compatible

(); return static_equal(*this,p); } Chris@16: template bool operator!=(const P& p) const { return !(*this==p); } Chris@16: Chris@16: ChannelReference operator[](std::size_t i) const { return this->at_c_dynamic(i); } Chris@16: Chris@16: const planar_pixel_reference* operator->() const { return this; } Chris@16: private: Chris@16: template static void check_compatible() { gil_function_requires >(); } Chris@16: }; Chris@16: Chris@16: ///////////////////////////// Chris@16: // ColorBasedConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: template Chris@16: struct kth_element_type, K> { Chris@16: typedef ChannelReference type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct kth_element_reference_type, K> { Chris@16: typedef ChannelReference type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct kth_element_const_reference_type, K> Chris@16: : public add_reference::type> Chris@16: { Chris@16: // typedef typename channel_traits::const_reference type; Chris@16: }; Chris@16: Chris@16: ///////////////////////////// Chris@16: // PixelConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: /// \brief Metafunction predicate that flags planar_pixel_reference as a model of PixelConcept. Required by PixelConcept Chris@16: /// \ingroup PixelModelPlanarRef Chris@16: template Chris@16: struct is_pixel< planar_pixel_reference > : public mpl::true_{}; Chris@16: Chris@16: ///////////////////////////// Chris@16: // HomogeneousPixelBasedConcept Chris@16: ///////////////////////////// Chris@16: Chris@16: /// \brief Specifies the color space type of a planar pixel reference. Required by PixelBasedConcept Chris@16: /// \ingroup PixelModelPlanarRef Chris@16: template Chris@16: struct color_space_type > { Chris@16: typedef ColorSpace type; Chris@16: }; Chris@16: Chris@16: /// \brief Specifies the color space type of a planar pixel reference. Required by PixelBasedConcept Chris@16: /// \ingroup PixelModelPlanarRef Chris@16: template Chris@16: struct channel_mapping_type > { Chris@16: typedef typename layout::channel_mapping_t type; Chris@16: }; Chris@16: Chris@16: /// \brief Specifies that planar_pixel_reference represents a planar construct. Required by PixelBasedConcept Chris@16: /// \ingroup PixelModelPlanarRef Chris@16: template Chris@16: struct is_planar > : mpl::true_ {}; Chris@16: Chris@16: /// \brief Specifies the color space type of a planar pixel reference. Required by HomogeneousPixelBasedConcept Chris@16: /// \ingroup PixelModelPlanarRef Chris@16: template Chris@16: struct channel_type > { Chris@16: typedef typename channel_traits::value_type type; Chris@16: }; Chris@16: Chris@16: } } // namespace boost::gil Chris@16: Chris@16: namespace std { Chris@16: // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified. Chris@16: // swap with 'left bias': Chris@16: // - swap between proxy and anything Chris@16: // - swap between value type and proxy Chris@16: // - swap between proxy and proxy Chris@16: // Having three overloads allows us to swap between different (but compatible) models of PixelConcept Chris@16: Chris@16: /// \brief swap for planar_pixel_reference Chris@16: /// \ingroup PixelModelPlanarRef Chris@16: template inline Chris@16: void swap(const boost::gil::planar_pixel_reference x, R& y) { Chris@16: boost::gil::swap_proxy::value_type>(x,y); Chris@16: } Chris@16: Chris@16: Chris@16: /// \brief swap for planar_pixel_reference Chris@16: /// \ingroup PixelModelPlanarRef Chris@16: template inline Chris@16: void swap(typename boost::gil::planar_pixel_reference::value_type& x, const boost::gil::planar_pixel_reference y) { Chris@16: boost::gil::swap_proxy::value_type>(x,y); Chris@16: } Chris@16: Chris@16: Chris@16: /// \brief swap for planar_pixel_reference Chris@16: /// \ingroup PixelModelPlanarRef Chris@16: template inline Chris@16: void swap(const boost::gil::planar_pixel_reference x, const boost::gil::planar_pixel_reference y) { Chris@16: boost::gil::swap_proxy::value_type>(x,y); Chris@16: } Chris@16: } // namespace std Chris@16: Chris@16: #endif