Back to home page

EIC code displayed by LXR

 
 

    


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

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_CHANNEL_HPP
0009 #define BOOST_GIL_CONCEPTS_CHANNEL_HPP
0010 
0011 #include <boost/gil/concepts/basic.hpp>
0012 #include <boost/gil/concepts/concept_check.hpp>
0013 #include <boost/gil/concepts/fwd.hpp>
0014 
0015 #include <boost/concept_check.hpp>
0016 
0017 #include <utility> // std::swap
0018 #include <type_traits>
0019 
0020 #if defined(BOOST_CLANG)
0021 #pragma clang diagnostic push
0022 #pragma clang diagnostic ignored "-Wunknown-pragmas"
0023 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
0024 #endif
0025 
0026 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
0027 #pragma GCC diagnostic push
0028 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
0029 #endif
0030 
0031 namespace boost { namespace gil {
0032 
0033 // Forward declarations
0034 template <typename T>
0035 struct channel_traits;
0036 
0037 template <typename DstT, typename SrcT>
0038 auto channel_convert(SrcT const& val)
0039     -> typename channel_traits<DstT>::value_type;
0040 
0041 /// \ingroup ChannelConcept
0042 /// \brief A channel is the building block of a color.
0043 /// Color is defined as a mixture of primary colors and a channel defines
0044 /// the degree to which each primary color is used in the mixture.
0045 ///
0046 /// For example, in the RGB color space, using 8-bit unsigned channels,
0047 /// the color red is defined as [255 0 0], which means maximum of Red,
0048 /// and no Green and Blue.
0049 ///
0050 /// Built-in scalar types, such as \p int and \p float, are valid GIL channels.
0051 /// In more complex scenarios, channels may be represented as bit ranges or
0052 /// even individual bits.
0053 /// In such cases special classes are needed to represent the value and
0054 /// reference to a channel.
0055 ///
0056 /// Channels have a traits class, \p channel_traits, which defines their
0057 /// associated types as well as their operating ranges.
0058 ///
0059 /// \code
0060 /// concept ChannelConcept<typename T> : EqualityComparable<T>
0061 /// {
0062 ///     typename value_type      = T;        // use channel_traits<T>::value_type to access it
0063 ///     typename reference       = T&;       // use channel_traits<T>::reference to access it
0064 ///     typename pointer         = T*;       // use channel_traits<T>::pointer to access it
0065 ///     typename const_reference = const T&; // use channel_traits<T>::const_reference to access it
0066 ///     typename const_pointer   = const T*; // use channel_traits<T>::const_pointer to access it
0067 ///     static const bool is_mutable;        // use channel_traits<T>::is_mutable to access it
0068 ///
0069 ///     static T min_value();                // use channel_traits<T>::min_value to access it
0070 ///     static T max_value();                // use channel_traits<T>::max_value to access it
0071 /// };
0072 /// \endcode
0073 template <typename T>
0074 struct ChannelConcept
0075 {
0076     void constraints()
0077     {
0078         gil_function_requires<boost::EqualityComparableConcept<T>>();
0079 
0080         using v = typename channel_traits<T>::value_type;
0081         using r = typename channel_traits<T>::reference;
0082         using p = typename channel_traits<T>::pointer;
0083         using cr = typename channel_traits<T>::const_reference;
0084         using cp = typename channel_traits<T>::const_pointer;
0085 
0086         channel_traits<T>::min_value();
0087         channel_traits<T>::max_value();
0088     }
0089 
0090      T c;
0091 };
0092 
0093 namespace detail
0094 {
0095 
0096 /// \tparam T models ChannelConcept
0097 template <typename T>
0098 struct ChannelIsMutableConcept
0099 {
0100     void constraints()
0101     {
0102         c1 = c2;
0103         using std::swap;
0104         swap(c1, c2);
0105     }
0106     T c1;
0107     T c2;
0108 };
0109 
0110 } // namespace detail
0111 
0112 /// \brief A channel that allows for modifying its value
0113 /// \code
0114 /// concept MutableChannelConcept<ChannelConcept T> : Assignable<T>, Swappable<T> {};
0115 /// \endcode
0116 /// \ingroup ChannelConcept
0117 template <typename T>
0118 struct MutableChannelConcept
0119 {
0120     void constraints()
0121     {
0122         gil_function_requires<ChannelConcept<T>>();
0123         gil_function_requires<detail::ChannelIsMutableConcept<T>>();
0124     }
0125 };
0126 
0127 /// \brief A channel that supports default construction.
0128 /// \code
0129 /// concept ChannelValueConcept<ChannelConcept T> : Regular<T> {};
0130 /// \endcode
0131 /// \ingroup ChannelConcept
0132 template <typename T>
0133 struct ChannelValueConcept
0134 {
0135     void constraints()
0136     {
0137         gil_function_requires<ChannelConcept<T>>();
0138         gil_function_requires<Regular<T>>();
0139     }
0140 };
0141 
0142 /// \brief Predicate metafunction returning whether two channels are compatible
0143 ///
0144 /// Channels are considered compatible if their value types
0145 /// (ignoring constness and references) are the same.
0146 ///
0147 /// Example:
0148 ///
0149 /// \code
0150 /// static_assert(channels_are_compatible<uint8_t, const uint8_t&>::value, "");
0151 /// \endcode
0152 /// \ingroup ChannelAlgorithm
0153 template <typename T1, typename T2>  // Models GIL Pixel
0154 struct channels_are_compatible
0155     : std::is_same
0156         <
0157             typename channel_traits<T1>::value_type,
0158             typename channel_traits<T2>::value_type
0159         >
0160 {
0161 };
0162 
0163 /// \brief Channels are compatible if their associated value types (ignoring constness and references) are the same
0164 ///
0165 /// \code
0166 /// concept ChannelsCompatibleConcept<ChannelConcept T1, ChannelConcept T2>
0167 /// {
0168 ///     where SameType<T1::value_type, T2::value_type>;
0169 /// };
0170 /// \endcode
0171 /// \ingroup ChannelConcept
0172 template <typename Channel1, typename Channel2>
0173 struct ChannelsCompatibleConcept
0174 {
0175     void constraints()
0176     {
0177         static_assert(channels_are_compatible<Channel1, Channel2>::value, "");
0178     }
0179 };
0180 
0181 /// \brief A channel is convertible to another one if the \p channel_convert algorithm is defined for the two channels.
0182 ///
0183 /// Convertibility is non-symmetric and implies that one channel can be
0184 /// converted to another. Conversion is explicit and often lossy operation.
0185 ///
0186 /// concept ChannelConvertibleConcept<ChannelConcept SrcChannel, ChannelValueConcept DstChannel>
0187 /// {
0188 ///     DstChannel channel_convert(const SrcChannel&);
0189 /// };
0190 /// \endcode
0191 /// \ingroup ChannelConcept
0192 template <typename SrcChannel, typename DstChannel>
0193 struct ChannelConvertibleConcept
0194 {
0195     void constraints()
0196     {
0197         gil_function_requires<ChannelConcept<SrcChannel>>();
0198         gil_function_requires<MutableChannelConcept<DstChannel>>();
0199         dst = channel_convert<DstChannel, SrcChannel>(src);
0200         ignore_unused_variable_warning(dst);
0201     }
0202     SrcChannel src;
0203     DstChannel dst;
0204 };
0205 
0206 }} // namespace boost::gil
0207 
0208 #if defined(BOOST_CLANG)
0209 #pragma clang diagnostic pop
0210 #endif
0211 
0212 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
0213 #pragma GCC diagnostic pop
0214 #endif
0215 
0216 #endif