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_COLOR_BASE_HPP
0009 #define BOOST_GIL_CONCEPTS_COLOR_BASE_HPP
0010 
0011 #include <boost/gil/concepts/basic.hpp>
0012 #include <boost/gil/concepts/color.hpp>
0013 #include <boost/gil/concepts/concept_check.hpp>
0014 #include <boost/gil/concepts/fwd.hpp>
0015 
0016 #include <boost/core/ignore_unused.hpp>
0017 #include <type_traits>
0018 
0019 #if defined(BOOST_CLANG)
0020 #pragma clang diagnostic push
0021 #pragma clang diagnostic ignored "-Wunknown-pragmas"
0022 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
0023 #endif
0024 
0025 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
0026 #pragma GCC diagnostic push
0027 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
0028 #endif
0029 
0030 namespace boost { namespace gil {
0031 
0032 // Forward declarations of at_c
0033 namespace detail {
0034 
0035 template <typename Element, typename Layout, int K>
0036 struct homogeneous_color_base;
0037 
0038 } // namespace detail
0039 
0040 template <int K, typename E, typename L, int N>
0041 auto at_c(detail::homogeneous_color_base<E, L, N>& p)
0042     -> typename std::add_lvalue_reference<E>::type;
0043 
0044 template <int K, typename E, typename L, int N>
0045 auto at_c(detail::homogeneous_color_base<E, L, N> const& p)
0046     -> typename std::add_lvalue_reference<typename std::add_const<E>::type>::type;
0047 
0048 template <typename P, typename C, typename L>
0049 struct packed_pixel;
0050 
0051 template <int K, typename P, typename C, typename L>
0052 auto at_c(packed_pixel<P, C, L>& p)
0053     -> typename kth_element_reference_type<packed_pixel<P, C, L>, K>::type;
0054 
0055 template <int K, typename P, typename C, typename L>
0056 auto at_c(packed_pixel<P, C, L> const& p)
0057     -> typename kth_element_const_reference_type<packed_pixel<P, C, L>, K>::type;
0058 
0059 template <typename B, typename C, typename L, bool M>
0060 struct bit_aligned_pixel_reference;
0061 
0062 template <int K, typename B, typename C, typename L, bool M>
0063 inline auto at_c(bit_aligned_pixel_reference<B, C, L, M> const& p)
0064     -> typename kth_element_reference_type
0065         <
0066             bit_aligned_pixel_reference<B, C, L, M>,
0067             K
0068         >::type;
0069 
0070 // Forward declarations of semantic_at_c
0071 template <int K, typename ColorBase>
0072 auto semantic_at_c(ColorBase& p)
0073     -> typename std::enable_if
0074         <
0075             !std::is_const<ColorBase>::value,
0076             typename kth_semantic_element_reference_type<ColorBase, K>::type
0077         >::type;
0078 
0079 template <int K, typename ColorBase>
0080 auto semantic_at_c(ColorBase const& p)
0081     -> typename kth_semantic_element_const_reference_type<ColorBase, K>::type;
0082 
0083 /// \ingroup ColorBaseConcept
0084 /// \brief A color base is a container of color elements (such as channels, channel references or channel pointers).
0085 ///
0086 /// The most common use of color base is in the implementation of a pixel,
0087 /// in which case the color elements are channel values. The color base concept,
0088 /// however, can be used in other scenarios. For example, a planar pixel has
0089 /// channels that are not contiguous in memory. Its reference is a proxy class
0090 /// that uses a color base whose elements are channel references. Its iterator
0091 /// uses a color base whose elements are channel iterators.
0092 ///
0093 /// A color base must have an associated layout (which consists of a color space,
0094 /// as well as an ordering of the channels).
0095 /// There are two ways to index the elements of a color base: A physical index
0096 /// corresponds to the way they are ordered in memory, and a semantic index
0097 /// corresponds to the way the elements are ordered in their color space.
0098 /// For example, in the RGB color space the elements are ordered as
0099 /// {red_t, green_t, blue_t}. For a color base with a BGR layout, the first element
0100 /// in physical ordering is the blue element, whereas the first semantic element
0101 /// is the red one.
0102 /// Models of \p ColorBaseConcept are required to provide the \p at_c<K>(ColorBase)
0103 /// function, which allows for accessing the elements based on their physical order.
0104 /// GIL provides a \p semantic_at_c<K>(ColorBase) function (described later)
0105 /// which can operate on any model of ColorBaseConcept and returns the corresponding
0106 /// semantic element.
0107 ///
0108 /// \code
0109 /// concept ColorBaseConcept<typename T> : CopyConstructible<T>, EqualityComparable<T>
0110 /// {
0111 ///     // a GIL layout (the color space and element permutation)
0112 ///     typename layout_t;
0113 ///
0114 ///     // The type of K-th element
0115 ///     template <int K>
0116 ///     struct kth_element_type;
0117 ///         where Metafunction<kth_element_type>;
0118 ///
0119 ///     // The result of at_c
0120 ///     template <int K>
0121 ///     struct kth_element_const_reference_type;
0122 ///         where Metafunction<kth_element_const_reference_type>;
0123 ///
0124 ///     template <int K>
0125 ///     kth_element_const_reference_type<T,K>::type at_c(T);
0126 ///
0127 ///     // Copy-constructible and equality comparable with other compatible color bases
0128 ///     template <ColorBaseConcept T2> where { ColorBasesCompatibleConcept<T,T2> }
0129 ///         T::T(T2);
0130 ///     template <ColorBaseConcept T2> where { ColorBasesCompatibleConcept<T,T2> }
0131 ///         bool operator==(const T&, const T2&);
0132 ///     template <ColorBaseConcept T2> where { ColorBasesCompatibleConcept<T,T2> }
0133 ///         bool operator!=(const T&, const T2&);
0134 /// };
0135 /// \endcode
0136 template <typename ColorBase>
0137 struct ColorBaseConcept
0138 {
0139     void constraints()
0140     {
0141         gil_function_requires<CopyConstructible<ColorBase>>();
0142         gil_function_requires<EqualityComparable<ColorBase>>();
0143 
0144         using color_space_t = typename ColorBase::layout_t::color_space_t;
0145         gil_function_requires<ColorSpaceConcept<color_space_t>>();
0146 
0147         using channel_mapping_t = typename ColorBase::layout_t::channel_mapping_t;
0148         // TODO: channel_mapping_t must be an Boost.MP11-compatible random access sequence
0149 
0150         static const int num_elements = size<ColorBase>::value;
0151 
0152         using TN = typename kth_element_type<ColorBase, num_elements - 1>::type;
0153         using RN = typename kth_element_const_reference_type<ColorBase, num_elements - 1>::type;
0154 
0155         RN r = gil::at_c<num_elements - 1>(cb);
0156         boost::ignore_unused(r);
0157 
0158         // functions that work for every pixel (no need to require them)
0159         semantic_at_c<0>(cb);
0160         semantic_at_c<num_elements-1>(cb);
0161         // also static_max(cb), static_min(cb), static_fill(cb,value),
0162         // and all variations of static_for_each(), static_generate(), static_transform()
0163     }
0164     ColorBase cb;
0165 };
0166 
0167 /// \ingroup ColorBaseConcept
0168 /// \brief Color base which allows for modifying its elements
0169 /// \code
0170 /// concept MutableColorBaseConcept<ColorBaseConcept T> : Assignable<T>, Swappable<T>
0171 /// {
0172 ///     template <int K>
0173 ///     struct kth_element_reference_type; where Metafunction<kth_element_reference_type>;
0174 ///
0175 ///     template <int K>
0176 ///     kth_element_reference_type<kth_element_type<T,K>::type>::type at_c(T);
0177 ///
0178 ///     template <ColorBaseConcept T2> where { ColorBasesCompatibleConcept<T,T2> }
0179 ///         T& operator=(T&, const T2&);
0180 /// };
0181 /// \endcode
0182 template <typename ColorBase>
0183 struct MutableColorBaseConcept
0184 {
0185     void constraints()
0186     {
0187         gil_function_requires<ColorBaseConcept<ColorBase>>();
0188         gil_function_requires<Assignable<ColorBase>>();
0189         gil_function_requires<Swappable<ColorBase>>();
0190 
0191         using R0 = typename kth_element_reference_type<ColorBase, 0>::type;
0192 
0193         R0 r = gil::at_c<0>(cb);
0194         gil::at_c<0>(cb) = r;
0195     }
0196     ColorBase cb;
0197 };
0198 
0199 /// \ingroup ColorBaseConcept
0200 /// \brief Color base that also has a default-constructor. Refines Regular
0201 /// \code
0202 /// concept ColorBaseValueConcept<typename T> : MutableColorBaseConcept<T>, Regular<T>
0203 /// {
0204 /// };
0205 /// \endcode
0206 template <typename ColorBase>
0207 struct ColorBaseValueConcept
0208 {
0209     void constraints()
0210     {
0211         gil_function_requires<MutableColorBaseConcept<ColorBase>>();
0212         gil_function_requires<Regular<ColorBase>>();
0213     }
0214 };
0215 
0216 /// \ingroup ColorBaseConcept
0217 /// \brief Color base whose elements all have the same type
0218 /// \code
0219 /// concept HomogeneousColorBaseConcept<ColorBaseConcept CB>
0220 /// {
0221 ///     // For all K in [0 ... size<C1>::value-1):
0222 ///     //     where SameType<kth_element_type<CB,K>::type, kth_element_type<CB,K+1>::type>;
0223 ///     kth_element_const_reference_type<CB,0>::type dynamic_at_c(CB const&, std::size_t n) const;
0224 /// };
0225 /// \endcode
0226 template <typename ColorBase>
0227 struct HomogeneousColorBaseConcept
0228 {
0229     void constraints()
0230     {
0231         gil_function_requires<ColorBaseConcept<ColorBase>>();
0232 
0233         static const int num_elements = size<ColorBase>::value;
0234 
0235         using T0 = typename kth_element_type<ColorBase, 0>::type;
0236         using TN = typename kth_element_type<ColorBase, num_elements - 1>::type;
0237 
0238         static_assert(std::is_same<T0, TN>::value, "");   // better than nothing
0239 
0240         using R0 = typename kth_element_const_reference_type<ColorBase, 0>::type;
0241         R0 r = dynamic_at_c(cb, 0);
0242         boost::ignore_unused(r);
0243     }
0244     ColorBase cb;
0245 };
0246 
0247 /// \ingroup ColorBaseConcept
0248 /// \brief Homogeneous color base that allows for modifying its elements
0249 /// \code
0250 /// concept MutableHomogeneousColorBaseConcept<ColorBaseConcept CB>
0251 ///     : HomogeneousColorBaseConcept<CB>
0252 /// {
0253 ///     kth_element_reference_type<CB, 0>::type dynamic_at_c(CB&, std::size_t n);
0254 /// };
0255 /// \endcode
0256 template <typename ColorBase>
0257 struct MutableHomogeneousColorBaseConcept
0258 {
0259     void constraints()
0260     {
0261         gil_function_requires<ColorBaseConcept<ColorBase>>();
0262         gil_function_requires<HomogeneousColorBaseConcept<ColorBase>>();
0263         using R0 = typename kth_element_reference_type<ColorBase, 0>::type;
0264         R0 r = dynamic_at_c(cb, 0);
0265         boost::ignore_unused(r);
0266         dynamic_at_c(cb, 0) = dynamic_at_c(cb, 0);
0267     }
0268     ColorBase cb;
0269 };
0270 
0271 /// \ingroup ColorBaseConcept
0272 /// \brief Homogeneous color base that also has a default constructor.
0273 /// Refines Regular.
0274 ///
0275 /// \code
0276 /// concept HomogeneousColorBaseValueConcept<typename T>
0277 ///     : MutableHomogeneousColorBaseConcept<T>, Regular<T>
0278 /// {
0279 /// };
0280 /// \endcode
0281 template <typename ColorBase>
0282 struct HomogeneousColorBaseValueConcept
0283 {
0284     void constraints()
0285     {
0286         gil_function_requires<MutableHomogeneousColorBaseConcept<ColorBase>>();
0287         gil_function_requires<Regular<ColorBase>>();
0288     }
0289 };
0290 
0291 /// \ingroup ColorBaseConcept
0292 /// \brief Two color bases are compatible if they have the same color space and their elements are compatible, semantic-pairwise.
0293 /// \code
0294 /// concept ColorBasesCompatibleConcept<ColorBaseConcept C1, ColorBaseConcept C2>
0295 /// {
0296 ///     where SameType<C1::layout_t::color_space_t, C2::layout_t::color_space_t>;
0297 ///     // also, for all K in [0 ... size<C1>::value):
0298 ///     //     where Convertible<kth_semantic_element_type<C1,K>::type, kth_semantic_element_type<C2,K>::type>;
0299 ///     //     where Convertible<kth_semantic_element_type<C2,K>::type, kth_semantic_element_type<C1,K>::type>;
0300 /// };
0301 /// \endcode
0302 template <typename ColorBase1, typename ColorBase2>
0303 struct ColorBasesCompatibleConcept
0304 {
0305     void constraints()
0306     {
0307         static_assert(std::is_same
0308             <
0309                 typename ColorBase1::layout_t::color_space_t,
0310                 typename ColorBase2::layout_t::color_space_t
0311             >::value, "");
0312 
0313 //        using e1 = typename kth_semantic_element_type<ColorBase1,0>::type;
0314 //        using e2 = typename kth_semantic_element_type<ColorBase2,0>::type;
0315 //        "e1 is convertible to e2"
0316     }
0317 };
0318 
0319 }} // namespace boost::gil
0320 
0321 #if defined(BOOST_CLANG)
0322 #pragma clang diagnostic pop
0323 #endif
0324 
0325 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
0326 #pragma GCC diagnostic pop
0327 #endif
0328 
0329 #endif