Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:55

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_CONCEPTS_PIXEL_HPP
0009 #define BOOST_GIL_CONCEPTS_PIXEL_HPP
0010 
0011 #include <boost/gil/concepts/basic.hpp>
0012 #include <boost/gil/concepts/channel.hpp>
0013 #include <boost/gil/concepts/color.hpp>
0014 #include <boost/gil/concepts/color_base.hpp>
0015 #include <boost/gil/concepts/concept_check.hpp>
0016 #include <boost/gil/concepts/fwd.hpp>
0017 #include <boost/gil/concepts/pixel_based.hpp>
0018 #include <boost/gil/concepts/detail/type_traits.hpp>
0019 #include <boost/gil/detail/mp11.hpp>
0020 
0021 #include <cstddef>
0022 #include <type_traits>
0023 
0024 #if defined(BOOST_CLANG)
0025 #pragma clang diagnostic push
0026 #pragma clang diagnostic ignored "-Wunknown-pragmas"
0027 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
0028 #endif
0029 
0030 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
0031 #pragma GCC diagnostic push
0032 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
0033 #endif
0034 
0035 namespace boost { namespace gil {
0036 
0037 /// \brief Pixel concept - A color base whose elements are channels
0038 /// \ingroup PixelConcept
0039 /// \code
0040 /// concept PixelConcept<typename P> : ColorBaseConcept<P>, PixelBasedConcept<P>
0041 /// {
0042 ///     where is_pixel<P>::value == true;
0043 ///     // where for each K [0..size<P>::value - 1]:
0044 ///     //      ChannelConcept<kth_element_type<P, K>>;
0045 ///
0046 ///     typename P::value_type;
0047 ///         where PixelValueConcept<value_type>;
0048 ///     typename P::reference;
0049 ///         where PixelConcept<reference>;
0050 ///     typename P::const_reference;
0051 ///         where PixelConcept<const_reference>;
0052 ///     static const bool P::is_mutable;
0053 ///
0054 ///     template <PixelConcept P2> where { PixelConcept<P, P2> }
0055 ///         P::P(P2);
0056 ///     template <PixelConcept P2> where { PixelConcept<P, P2> }
0057 ///         bool operator==(const P&, const P2&);
0058 ///     template <PixelConcept P2> where { PixelConcept<P, P2> }
0059 ///         bool operator!=(const P&, const P2&);
0060 /// };
0061 /// \endcode
0062 template <typename P>
0063 struct PixelConcept
0064 {
0065     void constraints()
0066     {
0067         gil_function_requires<ColorBaseConcept<P>>();
0068         gil_function_requires<PixelBasedConcept<P>>();
0069 
0070         static_assert(is_pixel<P>::value, "");
0071         static const bool is_mutable = P::is_mutable;
0072         ignore_unused_variable_warning(is_mutable);
0073 
0074         using value_type = typename P::value_type;
0075         // TODO: Is the cyclic dependency intentional? --mloskot
0076         // gil_function_requires<PixelValueConcept<value_type>>();
0077 
0078         using reference = typename P::reference;
0079         gil_function_requires<PixelConcept
0080             <
0081                 typename detail::remove_const_and_reference<reference>::type
0082             >>();
0083 
0084         using const_reference = typename P::const_reference;
0085         gil_function_requires<PixelConcept
0086             <
0087                 typename detail::remove_const_and_reference<const_reference>::type
0088             >>();
0089     }
0090 };
0091 
0092 /// \brief Pixel concept that allows for changing its channels
0093 /// \ingroup PixelConcept
0094 /// \code
0095 /// concept MutablePixelConcept<PixelConcept P> : MutableColorBaseConcept<P>
0096 /// {
0097 ///     where is_mutable==true;
0098 /// };
0099 /// \endcode
0100 template <typename P>
0101 struct MutablePixelConcept
0102 {
0103     void constraints()
0104     {
0105         gil_function_requires<PixelConcept<P>>();
0106         static_assert(P::is_mutable, "");
0107     }
0108 };
0109 
0110 /// \brief Homogeneous pixel concept
0111 /// \ingroup PixelConcept
0112 /// \code
0113 /// concept HomogeneousPixelConcept<PixelConcept P>
0114 ///     : HomogeneousColorBaseConcept<P>, HomogeneousPixelBasedConcept<P>
0115 /// {
0116 ///     P::template element_const_reference_type<P>::type operator[](P p, std::size_t i) const
0117 ///     {
0118 ///         return dynamic_at_c(p,i);
0119 /// }
0120 /// };
0121 /// \endcode
0122 template <typename P>
0123 struct HomogeneousPixelConcept
0124 {
0125     void constraints()
0126     {
0127         gil_function_requires<PixelConcept<P>>();
0128         gil_function_requires<HomogeneousColorBaseConcept<P>>();
0129         gil_function_requires<HomogeneousPixelBasedConcept<P>>();
0130         p[0];
0131     }
0132     P p;
0133 };
0134 
0135 /// \brief Homogeneous pixel concept that allows for changing its channels
0136 /// \ingroup PixelConcept
0137 /// \code
0138 /// concept MutableHomogeneousPixelConcept<HomogeneousPixelConcept P>
0139 ///     : MutableHomogeneousColorBaseConcept<P>
0140 /// {
0141 ///     P::template element_reference_type<P>::type operator[](P p, std::size_t i)
0142 ///     {
0143 ///         return dynamic_at_c(p, i);
0144 ///     }
0145 /// };
0146 /// \endcode
0147 template <typename P>
0148 struct MutableHomogeneousPixelConcept
0149 {
0150     void constraints()
0151     {
0152         gil_function_requires<HomogeneousPixelConcept<P>>();
0153         gil_function_requires<MutableHomogeneousColorBaseConcept<P>>();
0154         p[0] = v;
0155         v = p[0];
0156     }
0157     typename P::template element_type<P>::type v;
0158     P p;
0159 };
0160 
0161 /// \brief Pixel concept that is a Regular type
0162 /// \ingroup PixelConcept
0163 /// \code
0164 /// concept PixelValueConcept<PixelConcept P> : Regular<P>
0165 /// {
0166 ///     where SameType<value_type,P>;
0167 /// };
0168 /// \endcode
0169 template <typename P>
0170 struct PixelValueConcept
0171 {
0172     void constraints()
0173     {
0174         gil_function_requires<PixelConcept<P>>();
0175         gil_function_requires<Regular<P>>();
0176     }
0177 };
0178 
0179 /// \brief Homogeneous pixel concept that is a Regular type
0180 /// \ingroup PixelConcept
0181 /// \code
0182 /// concept HomogeneousPixelValueConcept<HomogeneousPixelConcept P> : Regular<P>
0183 /// {
0184 ///     where SameType<value_type,P>;
0185 /// };
0186 /// \endcode
0187 template <typename P>
0188 struct HomogeneousPixelValueConcept
0189 {
0190     void constraints()
0191     {
0192         gil_function_requires<HomogeneousPixelConcept<P>>();
0193         gil_function_requires<Regular<P>>();
0194         static_assert(std::is_same<P, typename P::value_type>::value, "");
0195     }
0196 };
0197 
0198 namespace detail {
0199 
0200 template <typename P1, typename P2, int K>
0201 struct channels_are_pairwise_compatible
0202     : mp11::mp_and
0203     <
0204         channels_are_pairwise_compatible<P1, P2, K - 1>,
0205         channels_are_compatible
0206         <
0207             typename kth_semantic_element_reference_type<P1, K>::type,
0208             typename kth_semantic_element_reference_type<P2, K>::type
0209         >
0210     >
0211 {
0212 };
0213 
0214 template <typename P1, typename P2>
0215 struct channels_are_pairwise_compatible<P1, P2, -1> : std::true_type {};
0216 
0217 } // namespace detail
0218 
0219 /// \ingroup PixelAlgorithm
0220 /// \brief Returns whether two pixels are compatible
0221 /// Pixels are compatible if their channels and color space types are compatible.
0222 /// Compatible pixels can be assigned and copy constructed from one another.
0223 /// \tparam P1 Models PixelConcept
0224 /// \tparam P2 Models PixelConcept
0225 template <typename P1, typename P2>
0226 struct pixels_are_compatible
0227     : mp11::mp_and
0228         <
0229             typename color_spaces_are_compatible
0230             <
0231                 typename color_space_type<P1>::type,
0232                 typename color_space_type<P2>::type
0233             >::type,
0234             detail::channels_are_pairwise_compatible
0235             <
0236                 P1, P2, num_channels<P1>::value - 1
0237             >
0238         >
0239 {
0240 };
0241 
0242 /// \ingroup PixelConcept
0243 /// \brief  Concept for pixel compatibility
0244 /// Pixels are compatible if their channels and color space types are compatible.
0245 /// Compatible pixels can be assigned and copy constructed from one another.
0246 /// \tparam P1 Models PixelConcept
0247 /// \tparam P2 Models PixelConcept
0248 /// \code
0249 /// concept PixelsCompatibleConcept<PixelConcept P1, PixelConcept P2>
0250 ///     : ColorBasesCompatibleConcept<P1,P2> {
0251 ///     // where for each K [0..size<P1>::value):
0252 ///     //    ChannelsCompatibleConcept<kth_semantic_element_type<P1,K>::type, kth_semantic_element_type<P2,K>::type>;
0253 /// };
0254 /// \endcode
0255 template <typename P1, typename P2>
0256 struct PixelsCompatibleConcept
0257 {
0258     void constraints()
0259     {
0260         static_assert(pixels_are_compatible<P1, P2>::value, "");
0261     }
0262 };
0263 
0264 /// \ingroup PixelConcept
0265 /// \brief Pixel convertible concept
0266 /// Convertibility is non-symmetric and implies that one pixel
0267 /// can be converted to another, approximating the color.
0268 /// Conversion is explicit and sometimes lossy.
0269 /// \code
0270 /// template <PixelConcept SrcPixel, MutablePixelConcept DstPixel>
0271 /// concept PixelConvertibleConcept
0272 /// {
0273 ///     void color_convert(const SrcPixel&, DstPixel&);
0274 /// };
0275 /// \endcode
0276 template <typename SrcP, typename DstP>
0277 struct PixelConvertibleConcept
0278 {
0279     void constraints()
0280     {
0281         gil_function_requires<PixelConcept<SrcP>>();
0282         gil_function_requires<MutablePixelConcept<DstP>>();
0283         color_convert(src, dst);
0284     }
0285     SrcP src;
0286     DstP dst;
0287 };
0288 
0289 }} // namespace boost::gil
0290 
0291 #if defined(BOOST_CLANG)
0292 #pragma clang diagnostic pop
0293 #endif
0294 
0295 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
0296 #pragma GCC diagnostic pop
0297 #endif
0298 
0299 #endif