Generic Image Library: planar_pixel_reference.hpp Source File

Modules | Alphabetical List | Class List | Directories | File List | GIL Home Page # planar_pixel_reference.hpp Go to the documentation of this file.
    00001 /*
    00002     Copyright 2005-2007 Adobe Systems Incorporated
    00003
    00004     Use, modification and distribution are subject to the Boost Software License,
    00005     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    00006     http://www.boost.org/LICENSE_1_0.txt).
    00007
    00008     See http://stlab.adobe.com/gil for most recent version including documentation.
    00009 */
    00010
    00011 /*************************************************************************************************/
    00012
    00013 #ifndef GIL_PLANAR_REF_H
    00014 #define GIL_PLANAR_REF_H
    00015
    00024
    00025 #include <boost/mpl/range_c.hpp>
    00026 #include "gil_config.hpp"
    00027 #include "gil_concept.hpp"
    00028 #include "color_base.hpp"
    00029 #include "channel.hpp"
    00030 #include "pixel.hpp"
    00031 #include "planar_pixel_iterator.hpp"
    00032
    00033 namespace boost { namespace gil {
    00034
    00039
    00043
    00044
    00050 template <typename ChannelReference, typename ColorSpace>        // ChannelReference is a channel reference (const or mutable)
    00051 struct planar_pixel_reference
    00052    : public detail::homogeneous_color_base<ChannelReference,layout<ColorSpace>,mpl::size<ColorSpace>::value> {
    00053     typedef detail::homogeneous_color_base<ChannelReference,layout<ColorSpace>,mpl::size<ColorSpace>::value> parent_t;
    00054 private:
    00055     // These three are only defined for homogeneous pixels
    00056     typedef typename channel_traits<ChannelReference>::value_type      channel_t;
    00057     typedef typename channel_traits<ChannelReference>::const_reference channel_const_reference;
    00058 public:
    00059     BOOST_STATIC_CONSTANT(bool, is_mutable = channel_traits<ChannelReference>::is_mutable);
    00060     typedef pixel<channel_t,layout<ColorSpace> >                       value_type;
    00061     typedef planar_pixel_reference                                     reference;
    00062     typedef planar_pixel_reference<channel_const_reference,ColorSpace> const_reference;
    00063
    00064     planar_pixel_reference(ChannelReference v0, ChannelReference v1) : parent_t(v0,v1) {}
    00065     planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2) : parent_t(v0,v1,v2) {}
    00066     planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3) : parent_t(v0,v1,v2,v3) {}
    00067     planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4) : parent_t(v0,v1,v2,v3,v4) {}
    00068     planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5) : parent_t(v0,v1,v2,v3,v4,v5) {}
    00069
    00070     template <typename P>                         planar_pixel_reference(const P& p)        : parent_t(p) { check_compatible<P>();}
    00071
    00072     // PERFORMANCE_CHECK: Is this constructor necessary?
    00073     template <typename ChannelV, typename Mapping>
    00074     planar_pixel_reference(pixel<ChannelV,layout<ColorSpace,Mapping> >& p)   : parent_t(p) { check_compatible<pixel<ChannelV,layout<ColorSpace,Mapping> > >();}
    00075
    00076     // Construct at offset from a given location
    00077     template <typename ChannelPtr> planar_pixel_reference(const planar_pixel_iterator<ChannelPtr,ColorSpace>& p, std::ptrdiff_t diff) : parent_t(p,diff) {}
    00078
    00079     const planar_pixel_reference&                             operator=(const planar_pixel_reference& p)  const { static_copy(p,*this); return *this; }
    00080     template <typename P> const planar_pixel_reference&       operator=(const P& p)           const { check_compatible<P>(); static_copy(p,*this); return *this; }
    00081
    00082 // This overload is necessary for a compiler implementing Core Issue 574
    00083 // to prevent generation of an implicit copy assignment operator (the reason
    00084 // for generating implicit copy assignment operator is that according to
    00085 // Core Issue 574, a cv-qualified assignment operator is not considered
    00086 // "copy assignment operator").
    00087 // EDG implemented Core Issue 574 starting with EDG Version 3.8. I'm not
    00088 // sure why they did it for a template member function as well.
    00089 #if BOOST_WORKAROUND(__HP_aCC, >= 61700) || BOOST_WORKAROUND(__INTEL_COMPILER, >= 1000)
    00090     const planar_pixel_reference& operator=(const planar_pixel_reference& p) { static_copy(p,*this); return *this; }
    00091     template <typename P> const planar_pixel_reference& operator=(const P& p) { check_compatible<P>(); static_copy(p,*this); return *this; }
    00092 #endif
    00093
    00094     template <typename P> bool                    operator==(const P& p)    const { check_compatible<P>(); return static_equal(*this,p); }
    00095     template <typename P> bool                    operator!=(const P& p)    const { return !(*this==p); }
    00096
    00097     ChannelReference                              operator[](std::size_t i) const { return this->at_c_dynamic(i); }
    00098
    00099     const planar_pixel_reference*     operator->()              const { return this; }
    00100 private:
    00101     template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,planar_pixel_reference> >(); }
    00102 };
    00103
    00105 //  ColorBasedConcept
    00107
    00108 template <typename ChannelReference, typename ColorSpace, int K>
    00109 struct kth_element_type<planar_pixel_reference<ChannelReference,ColorSpace>, K> {
    00110     typedef ChannelReference type;
    00111 };
    00112
    00113 template <typename ChannelReference, typename ColorSpace, int K>
    00114 struct kth_element_reference_type<planar_pixel_reference<ChannelReference,ColorSpace>, K> {
    00115     typedef ChannelReference type;
    00116 };
    00117
    00118 template <typename ChannelReference, typename ColorSpace, int K>
    00119 struct kth_element_const_reference_type<planar_pixel_reference<ChannelReference,ColorSpace>, K>
    00120     : public add_reference<typename add_const<ChannelReference>::type>
    00121 {
    00122 //    typedef typename channel_traits<ChannelReference>::const_reference type;
    00123 };
    00124
    00126 //  PixelConcept
    00128
    00131 template <typename ChannelReference, typename ColorSpace>
    00132 struct is_pixel< planar_pixel_reference<ChannelReference,ColorSpace> > : public mpl::true_{};
    00133
    00135 //  HomogeneousPixelBasedConcept
    00137
    00140 template <typename ChannelReference, typename ColorSpace>
    00141 struct color_space_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
    00142     typedef ColorSpace type;
    00143 };
    00144
    00147 template <typename ChannelReference, typename ColorSpace>
    00148 struct channel_mapping_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
    00149     typedef typename layout<ColorSpace>::channel_mapping_t type;
    00150 };
    00151
    00154 template <typename ChannelReference, typename ColorSpace>
    00155 struct is_planar<planar_pixel_reference<ChannelReference,ColorSpace> > : mpl::true_ {};
    00156
    00159 template <typename ChannelReference, typename ColorSpace>
    00160 struct channel_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
    00161     typedef typename channel_traits<ChannelReference>::value_type type;
    00162 };
    00163
    00164 } }  // namespace boost::gil
    00165
    00166 namespace std {
    00167 // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.
    00168 // swap with 'left bias':
    00169 // - swap between proxy and anything
    00170 // - swap between value type and proxy
    00171 // - swap between proxy and proxy
    00172 // Having three overloads allows us to swap between different (but compatible) models of PixelConcept
    00173
    00176 template <typename CR, typename CS, typename R> inline
    00177 void swap(const boost::gil::planar_pixel_reference<CR,CS> x, R& y) {
    00178     boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
    00179 }
    00180
    00181
    00184 template <typename CR, typename CS> inline
    00185 void swap(typename boost::gil::planar_pixel_reference<CR,CS>::value_type& x, const boost::gil::planar_pixel_reference<CR,CS> y) {
    00186     boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
    00187 }
    00188
    00189
    00192 template <typename CR, typename CS> inline
    00193 void swap(const boost::gil::planar_pixel_reference<CR,CS> x, const boost::gil::planar_pixel_reference<CR,CS> y) {
    00194     boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
    00195 }
    00196 }   // namespace std
    00197
    00198 #endif