Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:12:42

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_PLANAR_PIXEL_REFERENCE_HPP
0009 #define BOOST_GIL_PLANAR_PIXEL_REFERENCE_HPP
0010 
0011 #include <boost/gil/channel.hpp>
0012 #include <boost/gil/color_base.hpp>
0013 #include <boost/gil/concepts.hpp>
0014 #include <boost/gil/pixel.hpp>
0015 #include <boost/gil/planar_pixel_iterator.hpp>
0016 #include <boost/gil/detail/mp11.hpp>
0017 
0018 #include <type_traits>
0019 
0020 namespace boost { namespace gil {
0021 
0022 /// \defgroup ColorBaseModelPlanarRef planar_pixel_reference
0023 /// \ingroup ColorBaseModel
0024 /// \brief A homogeneous color base whose element is a channel reference. Models HomogeneousColorBaseConcept, HomogeneousPixelConcept.
0025 /// This class is used as a reference proxy to a planar pixel.
0026 
0027 /// \defgroup PixelModelPlanarRef planar_pixel_reference
0028 /// \ingroup PixelModel
0029 /// \brief A reference proxy to a planar pixel. Models HomogeneousColorBaseConcept, HomogeneousPixelConcept.
0030 
0031 /// \ingroup PixelModelPlanarRef ColorBaseModelPlanarRef PixelBasedModel
0032 /// \brief A reference proxy to a planar pixel.
0033 ///
0034 /// A reference to a planar pixel is a proxy class containing references to each of the corresponding channels.
0035 /// Models: HomogeneousColorBaseConcept, HomogeneousPixelConcept
0036 ///
0037 /// \tparam ChannelReference A channel reference, either const or mutable
0038 /// \tparam ColorSpace
0039 template <typename ChannelReference, typename ColorSpace>
0040 struct planar_pixel_reference : detail::homogeneous_color_base
0041     <
0042         ChannelReference,
0043         layout<ColorSpace>,
0044         mp11::mp_size<ColorSpace>::value
0045     >
0046 {
0047     using parent_t =detail::homogeneous_color_base
0048         <
0049             ChannelReference,
0050             layout<ColorSpace>,
0051             mp11::mp_size<ColorSpace>::value
0052         >;
0053 
0054 private:
0055     // These three are only defined for homogeneous pixels
0056     using channel_t = typename channel_traits<ChannelReference>::value_type;
0057     using channel_const_reference = typename channel_traits<ChannelReference>::const_reference;
0058 
0059 public:
0060     static constexpr bool is_mutable = channel_traits<ChannelReference>::is_mutable;
0061     using value_type = pixel<channel_t,layout<ColorSpace>>;
0062     using reference = planar_pixel_reference<ChannelReference, ColorSpace>;
0063     using const_reference = planar_pixel_reference<channel_const_reference,ColorSpace>;
0064 
0065     planar_pixel_reference(ChannelReference v0, ChannelReference v1)
0066         : parent_t(v0, v1)
0067     {}
0068 
0069     planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2)
0070         : parent_t(v0, v1, v2)
0071     {}
0072 
0073     planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3)
0074         : parent_t(v0, v1, v2, v3)
0075     {}
0076 
0077     planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4)
0078         : parent_t(v0, v1, v2, v3, v4)
0079     {}
0080 
0081     planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5)
0082         : parent_t(v0, v1, v2, v3, v4, v5)
0083     {}
0084 
0085     planar_pixel_reference(planar_pixel_reference const& p) : parent_t(p) {}
0086 
0087     // TODO: What is the purpose of returning via const reference?
0088     auto operator=(planar_pixel_reference const& p) const -> planar_pixel_reference const&
0089     {
0090         static_copy(p, *this);
0091         return *this;
0092     }
0093 
0094     template <typename Pixel>
0095     planar_pixel_reference(Pixel const& p) : parent_t(p)
0096     {
0097          check_compatible<Pixel>();
0098     }
0099 
0100     // TODO: What is the purpose of returning via const reference?
0101     template <typename Pixel>
0102     auto operator=(Pixel const& p) const -> planar_pixel_reference const&
0103     {
0104         check_compatible<Pixel>();
0105         static_copy(p, *this);
0106         return *this;
0107     }
0108 
0109     // PERFORMANCE_CHECK: Is this constructor necessary?
0110     template <typename ChannelV, typename Mapping>
0111     planar_pixel_reference(pixel<ChannelV, layout<ColorSpace, Mapping>>& p)
0112        : parent_t(p)
0113     {
0114         check_compatible<pixel<ChannelV, layout<ColorSpace, Mapping>>>();
0115     }
0116 
0117     // Construct at offset from a given location
0118     template <typename ChannelPtr>
0119     planar_pixel_reference(planar_pixel_iterator<ChannelPtr, ColorSpace> const& p, std::ptrdiff_t diff)
0120         : parent_t(p, diff)
0121     {}
0122 
0123 // This overload is necessary for a compiler implementing Core Issue 574
0124 // to prevent generation of an implicit copy assignment operator (the reason
0125 // for generating implicit copy assignment operator is that according to
0126 // Core Issue 574, a cv-qualified assignment operator is not considered
0127 // "copy assignment operator").
0128 // EDG implemented Core Issue 574 starting with EDG Version 3.8. I'm not
0129 // sure why they did it for a template member function as well.
0130 #if BOOST_WORKAROUND(__HP_aCC, >= 61700) || BOOST_WORKAROUND(__INTEL_COMPILER, >= 1000)
0131     const planar_pixel_reference& operator=(const planar_pixel_reference& p) { static_copy(p,*this); return *this; }
0132     template <typename P> const planar_pixel_reference& operator=(const P& p) { check_compatible<P>(); static_copy(p,*this); return *this; }
0133 #endif
0134 
0135     template <typename Pixel>
0136     bool operator==(Pixel const& p) const
0137     {
0138         check_compatible<Pixel>();
0139         return static_equal(*this, p);
0140     }
0141 
0142     template <typename Pixel>
0143     bool operator!=(Pixel const &p) const { return !(*this == p); }
0144 
0145     auto operator[](std::size_t i) const -> ChannelReference { return this->at_c_dynamic(i); }
0146     auto operator->() const -> planar_pixel_reference const* { return this; }
0147 
0148 private:
0149     template <typename Pixel>
0150     static void check_compatible()
0151     {
0152         gil_function_requires<PixelsCompatibleConcept<Pixel, planar_pixel_reference>>();
0153     }
0154 };
0155 
0156 /////////////////////////////
0157 //  ColorBasedConcept
0158 /////////////////////////////
0159 
0160 template <typename ChannelReference, typename ColorSpace, int K>
0161 struct kth_element_type<planar_pixel_reference<ChannelReference, ColorSpace>, K>
0162 {
0163     using type = ChannelReference;
0164 };
0165 
0166 template <typename ChannelReference, typename ColorSpace, int K>
0167 struct kth_element_reference_type
0168     <
0169         planar_pixel_reference<ChannelReference, ColorSpace>,
0170         K
0171     >
0172 {
0173     using type = ChannelReference;
0174 };
0175 
0176 template <typename ChannelReference, typename ColorSpace, int K>
0177 struct kth_element_const_reference_type
0178     <
0179         planar_pixel_reference<ChannelReference, ColorSpace>,
0180         K
0181     >
0182     : std::add_lvalue_reference<typename std::add_const<ChannelReference>::type>
0183 {
0184     //    using type = typename channel_traits<ChannelReference>::const_reference;
0185 };
0186 
0187 /////////////////////////////
0188 //  PixelConcept
0189 /////////////////////////////
0190 
0191 /// \brief Metafunction predicate that flags planar_pixel_reference as a model of PixelConcept. Required by PixelConcept
0192 /// \ingroup PixelModelPlanarRef
0193 template <typename ChannelReference, typename ColorSpace>
0194 struct is_pixel< planar_pixel_reference<ChannelReference, ColorSpace>>
0195     : std::true_type
0196 {};
0197 
0198 /////////////////////////////
0199 //  HomogeneousPixelBasedConcept
0200 /////////////////////////////
0201 
0202 /// \brief Specifies the color space type of a planar pixel reference. Required by PixelBasedConcept
0203 /// \ingroup PixelModelPlanarRef
0204 template <typename ChannelReference, typename ColorSpace>
0205 struct color_space_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
0206     using type = ColorSpace;
0207 };
0208 
0209 /// \brief Specifies the color space type of a planar pixel reference. Required by PixelBasedConcept
0210 /// \ingroup PixelModelPlanarRef
0211 template <typename ChannelReference, typename ColorSpace>
0212 struct channel_mapping_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
0213     using type = typename layout<ColorSpace>::channel_mapping_t;
0214 };
0215 
0216 /// \brief Specifies that planar_pixel_reference represents a planar construct. Required by PixelBasedConcept
0217 /// \ingroup PixelModelPlanarRef
0218 template <typename ChannelReference, typename ColorSpace>
0219 struct is_planar<planar_pixel_reference<ChannelReference, ColorSpace>>
0220     : std::true_type
0221 {};
0222 
0223 /// \brief Specifies the color space type of a planar pixel reference. Required by HomogeneousPixelBasedConcept
0224 /// \ingroup PixelModelPlanarRef
0225 template <typename ChannelReference, typename ColorSpace>
0226 struct channel_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
0227     using type = typename channel_traits<ChannelReference>::value_type;
0228 };
0229 
0230 }}  // namespace boost::gil
0231 
0232 namespace std {
0233 // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.
0234 // swap with 'left bias':
0235 // - swap between proxy and anything
0236 // - swap between value type and proxy
0237 // - swap between proxy and proxy
0238 // Having three overloads allows us to swap between different (but compatible) models of PixelConcept
0239 
0240 /// \brief  swap for planar_pixel_reference
0241 /// \ingroup PixelModelPlanarRef
0242 template <typename CR, typename CS, typename R> inline
0243 void swap(const boost::gil::planar_pixel_reference<CR,CS> x, R& y) {
0244     boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
0245 }
0246 
0247 /// \brief  swap for planar_pixel_reference
0248 /// \ingroup PixelModelPlanarRef
0249 template <typename CR, typename CS> inline
0250 void swap(typename boost::gil::planar_pixel_reference<CR,CS>::value_type& x, const boost::gil::planar_pixel_reference<CR,CS> y) {
0251     boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
0252 }
0253 
0254 /// \brief  swap for planar_pixel_reference
0255 /// \ingroup PixelModelPlanarRef
0256 template <typename CR, typename CS> inline
0257 void swap(const boost::gil::planar_pixel_reference<CR,CS> x, const boost::gil::planar_pixel_reference<CR,CS> y) {
0258     boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
0259 }
0260 
0261 }   // namespace std
0262 
0263 #endif