/* Copyright 2005-2007 Adobe Systems Incorporated Use, modification and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). See http://opensource.adobe.com/gil for most recent version including documentation. */ /*************************************************************************************************/ #ifndef GIL_CONCEPT_H #define GIL_CONCEPT_H //////////////////////////////////////////////////////////////////////////////////////// /// \file /// \brief Concept check classes for GIL concepts /// \author Lubomir Bourdev and Hailin Jin \n /// Adobe Systems Incorporated /// \date 2005-2007 \n Last updated on February 12, 2007 /// //////////////////////////////////////////////////////////////////////////////////////// #include #include "gil_config.hpp" #include #include #include #include #include #include namespace boost { namespace gil { template struct channel_traits; template struct is_pixel; template typename channel_traits::value_type channel_convert(const srcT& val); template class point2; template const T& axis_value(const point2& p); template T& axis_value( point2& p); template struct kth_element_type; template struct kth_element_reference_type; template struct kth_element_const_reference_type; template struct kth_semantic_element_reference_type; template struct kth_semantic_element_const_reference_type; template struct size; template struct element_type; template struct channel_type; template struct color_space_type; template struct channel_mapping_type; template struct is_planar; template struct num_channels; template struct const_iterator_type; template struct iterator_is_mutable; template struct is_iterator_adaptor; template struct iterator_adaptor_rebind; template struct iterator_adaptor_get_base; // forward-declare at_c namespace detail { template struct homogeneous_color_base; } template typename add_reference::type at_c( detail::homogeneous_color_base& p); template typename add_reference::type>::type at_c(const detail::homogeneous_color_base& p); #if !defined(_MSC_VER) || _MSC_VER > 1310 template struct packed_pixel; template typename kth_element_reference_type, K>::type at_c(packed_pixel& p); template typename kth_element_const_reference_type,K>::type at_c(const packed_pixel& p); template struct bit_aligned_pixel_reference; template inline typename kth_element_reference_type, K>::type at_c(const bit_aligned_pixel_reference& p); #endif // Forward-declare semantic_at_c template typename disable_if,typename kth_semantic_element_reference_type::type>::type semantic_at_c(ColorBase& p); template typename kth_semantic_element_const_reference_type::type semantic_at_c(const ColorBase& p); template struct dynamic_x_step_type; template struct dynamic_y_step_type; template struct transposed_type; namespace detail { template void initialize_it(T& x) {} } // namespace detail template struct remove_const_and_reference : public remove_const::type> {}; #ifdef BOOST_GIL_USE_CONCEPT_CHECK #define GIL_CLASS_REQUIRE(type_var, ns, concept) BOOST_CLASS_REQUIRE(type_var, ns, concept); template void gil_function_requires() { function_requires(); } #else #define GIL_CLASS_REQUIRE(T,NS,C) template void gil_function_requires() {} #endif /// \ingroup BasicConcepts /** \code auto concept DefaultConstructible { T::T(); }; \endcode */ template struct DefaultConstructible { void constraints() { function_requires >(); } }; /// \ingroup BasicConcepts /** \codeauto concept CopyConstructible { T::T(T); T::~T(); }; \endcode */ template struct CopyConstructible { void constraints() { function_requires >(); } }; /// \ingroup BasicConcepts /** \code auto concept Assignable { typename result_type; result_type operator=(T&, U); }; \endcode */ template struct Assignable { void constraints() { function_requires >(); } }; /// \ingroup BasicConcepts /** \code auto concept EqualityComparable { bool operator==(T x, T y); bool operator!=(T x, T y) { return !(x==y); } }; \endcode */ template struct EqualityComparable { void constraints() { function_requires >(); } }; /// \ingroup BasicConcepts /** \code concept SameType;// unspecified \endcode */ template struct SameType { void constraints() { BOOST_STATIC_ASSERT((boost::is_same::value_core)); } }; /// \ingroup BasicConcepts /** \code auto concept Swappable { void swap(T&,T&); }; \endcode */ template struct Swappable { void constraints() { using std::swap; swap(x,y); } T x,y; }; /// \ingroup BasicConcepts /** \code auto concept Regular : DefaultConstructible, CopyConstructible, EqualityComparable, Assignable, Swappable {}; \endcode */ template struct Regular { void constraints() { gil_function_requires< boost::DefaultConstructibleConcept >(); gil_function_requires< boost::CopyConstructibleConcept >(); gil_function_requires< boost::EqualityComparableConcept >(); // ==, != gil_function_requires< boost::AssignableConcept >(); gil_function_requires< Swappable >(); } }; /// \ingroup BasicConcepts /** \code auto concept Metafunction { typename type; }; \endcode */ template struct Metafunction { void constraints() { typedef typename T::type type; } }; //////////////////////////////////////////////////////////////////////////////////////// // // POINT CONCEPTS // //////////////////////////////////////////////////////////////////////////////////////// /// \brief N-dimensional point concept /// \ingroup PointConcept /** \code concept PointNDConcept : Regular { // the type of a coordinate along each axis template struct axis; where Metafunction; const size_t num_dimensions; // accessor/modifier of the value of each axis. template const typename axis::type& T::axis_value() const; template typename axis::type& T::axis_value(); }; \endcode */ template struct PointNDConcept { void constraints() { gil_function_requires< Regular

>(); typedef typename P::value_type value_type; static const std::size_t N=P::num_dimensions; ignore_unused_variable_warning(N); typedef typename P::template axis<0>::coord_t FT; typedef typename P::template axis::coord_t LT; FT ft=gil::axis_value<0>(point); axis_value<0>(point)=ft; LT lt=axis_value(point); axis_value(point)=lt; value_type v=point[0]; ignore_unused_variable_warning(v); point[0]=point[0]; } P point; }; /// \brief 2-dimensional point concept /// \ingroup PointConcept /** \code concept Point2DConcept : PointNDConcept { where num_dimensions == 2; where SameType::type, axis<1>::type>; typename value_type = axis<0>::type; const value_type& operator[](const T&, size_t i); value_type& operator[]( T&, size_t i); value_type x,y; }; \endcode */ template struct Point2DConcept { void constraints() { gil_function_requires< PointNDConcept

>(); BOOST_STATIC_ASSERT(P::num_dimensions == 2); point.x=point.y; point[0]=point[1]; } P point; }; //////////////////////////////////////////////////////////////////////////////////////// // // ITERATOR MUTABILITY CONCEPTS // // Taken from boost's concept_check.hpp. Isolating mutability to result in faster compile time // //////////////////////////////////////////////////////////////////////////////////////// namespace detail { template // Preconditions: TT Models boost_concepts::ForwardTraversalConcept struct ForwardIteratorIsMutableConcept { void constraints() { *i++ = *i; // require postincrement and assignment } TT i; }; template // Preconditions: TT Models boost::BidirectionalIteratorConcept struct BidirectionalIteratorIsMutableConcept { void constraints() { gil_function_requires< ForwardIteratorIsMutableConcept >(); *i-- = *i; // require postdecrement and assignment } TT i; }; template // Preconditions: TT Models boost_concepts::RandomAccessTraversalConcept struct RandomAccessIteratorIsMutableConcept { void constraints() { gil_function_requires< BidirectionalIteratorIsMutableConcept >(); typename std::iterator_traits::difference_type n=0; ignore_unused_variable_warning(n); i[n] = *i; // require element access and assignment } TT i; }; } // namespace detail //////////////////////////////////////////////////////////////////////////////////////// // // COLOR SPACE CONCEPTS // //////////////////////////////////////////////////////////////////////////////////////// /// \brief Color space type concept /// \ingroup ColorSpaceAndLayoutConcept /** \code concept ColorSpaceConcept { // An MPL Random Access Sequence, whose elements are color tags }; \endcode */ template struct ColorSpaceConcept { void constraints() { // An MPL Random Access Sequence, whose elements are color tags } }; template // Models ColorSpaceConcept struct color_spaces_are_compatible : public is_same {}; /// \brief Two color spaces are compatible if they are the same /// \ingroup ColorSpaceAndLayoutConcept /** \code concept ColorSpacesCompatibleConcept { where SameType; }; \endcode */ template struct ColorSpacesCompatibleConcept { void constraints() { BOOST_STATIC_ASSERT((color_spaces_are_compatible::value)); } }; /// \brief Channel mapping concept /// \ingroup ColorSpaceAndLayoutConcept /** \code concept ChannelMappingConcept { // An MPL Random Access Sequence, whose elements model MPLIntegralConstant representing a permutation }; \endcode */ template struct ChannelMappingConcept { void constraints() { // An MPL Random Access Sequence, whose elements model MPLIntegralConstant representing a permutation } }; //////////////////////////////////////////////////////////////////////////////////////// /// /// Channel CONCEPTS /// //////////////////////////////////////////////////////////////////////////////////////// /// \ingroup ChannelConcept /// \brief A channel is the building block of a color. Color is defined as a mixture of primary colors and a channel defines the degree to which each primary color is used in the mixture. /** For example, in the RGB color space, using 8-bit unsigned channels, the color red is defined as [255 0 0], which means maximum of Red, and no Green and Blue. Built-in scalar types, such as \p int and \p float, are valid GIL channels. In more complex scenarios, channels may be represented as bit ranges or even individual bits. In such cases special classes are needed to represent the value and reference to a channel. Channels have a traits class, \p channel_traits, which defines their associated types as well as their operating ranges. \code concept ChannelConcept : EqualityComparable { typename value_type = T; // use channel_traits::value_type to access it typename reference = T&; // use channel_traits::reference to access it typename pointer = T*; // use channel_traits::pointer to access it typename const_reference = const T&; // use channel_traits::const_reference to access it typename const_pointer = const T*; // use channel_traits::const_pointer to access it static const bool is_mutable; // use channel_traits::is_mutable to access it static T min_value(); // use channel_traits::min_value to access it static T max_value(); // use channel_traits::min_value to access it }; \endcode */ template struct ChannelConcept { void constraints() { gil_function_requires< boost::EqualityComparableConcept >(); typedef typename channel_traits::value_type v; typedef typename channel_traits::reference r; typedef typename channel_traits::pointer p; typedef typename channel_traits::const_reference cr; typedef typename channel_traits::const_pointer cp; channel_traits::min_value(); channel_traits::max_value(); } T c; }; namespace detail { // Preconditions: T models ChannelConcept template struct ChannelIsMutableConcept { void constraints() { c=c; using std::swap; swap(c,c); } T c; }; } /// \brief A channel that allows for modifying its value /// \ingroup ChannelConcept /** \code concept MutableChannelConcept : Assignable, Swappable {}; \endcode */ template struct MutableChannelConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; /// \brief A channel that supports default construction. /// \ingroup ChannelConcept /** \code concept ChannelValueConcept : Regular {}; \endcode */ template struct ChannelValueConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; /// \brief Predicate metafunction returning whether two channels are compatible /// \ingroup ChannelAlgorithm /// /// Channels are considered compatible if their value types (ignoring constness and references) are the same. /** Example: \code BOOST_STATIC_ASSERT((channels_are_compatible::value)); \endcode */ template // Models GIL Pixel struct channels_are_compatible : public is_same::value_type, typename channel_traits::value_type> {}; /// \brief Channels are compatible if their associated value types (ignoring constness and references) are the same /// \ingroup ChannelConcept /** \code concept ChannelsCompatibleConcept { where SameType; }; \endcode */ template struct ChannelsCompatibleConcept { void constraints() { BOOST_STATIC_ASSERT((channels_are_compatible::value)); } }; /// \brief A channel is convertible to another one if the \p channel_convert algorithm is defined for the two channels /// /// Convertibility is non-symmetric and implies that one channel can be converted to another. Conversion is explicit and often lossy operation. /// \ingroup ChannelConcept /** \code concept ChannelConvertibleConcept { DstChannel channel_convert(const SrcChannel&); }; \endcode */ template struct ChannelConvertibleConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); dst=channel_convert(src); ignore_unused_variable_warning(dst); } SrcChannel src; DstChannel dst; }; //////////////////////////////////////////////////////////////////////////////////////// /// /// COLOR BASE CONCEPTS /// //////////////////////////////////////////////////////////////////////////////////////// /// \ingroup ColorBaseConcept /// \brief A color base is a container of color elements (such as channels, channel references or channel pointers) /** The most common use of color base is in the implementation of a pixel, in which case the color elements are channel values. The color base concept, however, can be used in other scenarios. For example, a planar pixel has channels that are not contiguous in memory. Its reference is a proxy class that uses a color base whose elements are channel references. Its iterator uses a color base whose elements are channel iterators. A color base must have an associated layout (which consists of a color space, as well as an ordering of the channels). There are two ways to index the elements of a color base: A physical index corresponds to the way they are ordered in memory, and a semantic index corresponds to the way the elements are ordered in their color space. For example, in the RGB color space the elements are ordered as {red_t, green_t, blue_t}. For a color base with a BGR layout, the first element in physical ordering is the blue element, whereas the first semantic element is the red one. Models of \p ColorBaseConcept are required to provide the \p at_c(ColorBase) function, which allows for accessing the elements based on their physical order. GIL provides a \p semantic_at_c(ColorBase) function (described later) which can operate on any model of ColorBaseConcept and returns the corresponding semantic element. \code concept ColorBaseConcept : CopyConstructible, EqualityComparable { // a GIL layout (the color space and element permutation) typename layout_t; // The type of K-th element template struct kth_element_type; where Metafunction; // The result of at_c template struct kth_element_const_reference_type; where Metafunction; template kth_element_const_reference_type::type at_c(T); // Copy-constructible and equality comparable with other compatible color bases template where { ColorBasesCompatibleConcept } T::T(T2); template where { ColorBasesCompatibleConcept } bool operator==(const T&, const T2&); template where { ColorBasesCompatibleConcept } bool operator!=(const T&, const T2&); }; \endcode */ template struct ColorBaseConcept { void constraints() { gil_function_requires< CopyConstructible >(); gil_function_requires< EqualityComparable >(); typedef typename ColorBase::layout_t::color_space_t color_space_t; gil_function_requires >(); typedef typename ColorBase::layout_t::channel_mapping_t channel_mapping_t; // TODO: channel_mapping_t must be an MPL RandomAccessSequence static const std::size_t num_elements = size::value; typedef typename kth_element_type::type TN; typedef typename kth_element_const_reference_type::type CR; #if !defined(_MSC_VER) || _MSC_VER > 1310 CR cr=at_c(cb); ignore_unused_variable_warning(cr); #endif // functions that work for every pixel (no need to require them) semantic_at_c<0>(cb); semantic_at_c(cb); // also static_max(cb), static_min(cb), static_fill(cb,value), and all variations of static_for_each(), static_generate(), static_transform() } ColorBase cb; }; /// \ingroup ColorBaseConcept /// \brief Color base which allows for modifying its elements /** \code concept MutableColorBaseConcept : Assignable, Swappable { template struct kth_element_reference_type; where Metafunction; template kth_element_reference_type::type>::type at_c(T); template where { ColorBasesCompatibleConcept } T& operator=(T&, const T2&); }; \endcode */ template struct MutableColorBaseConcept { void constraints() { gil_function_requires< ColorBaseConcept >(); gil_function_requires< Assignable >(); gil_function_requires< Swappable >(); typedef typename kth_element_reference_type::type CR; #if !defined(_MSC_VER) || _MSC_VER > 1310 CR r=at_c<0>(cb); at_c<0>(cb)=r; #endif } ColorBase cb; }; /// \ingroup ColorBaseConcept /// \brief Color base that also has a default-constructor. Refines Regular /** \code concept ColorBaseValueConcept : MutableColorBaseConcept, Regular { }; \endcode */ template struct ColorBaseValueConcept { void constraints() { gil_function_requires< MutableColorBaseConcept >(); gil_function_requires< Regular >(); } }; /// \ingroup ColorBaseConcept /// \brief Color base whose elements all have the same type /** \code concept HomogeneousColorBaseConcept { // For all K in [0 ... size::value-1): // where SameType::type, kth_element_type::type>; kth_element_const_reference_type::type dynamic_at_c(const CB&, std::size_t n) const; }; \endcode */ template struct HomogeneousColorBaseConcept { void constraints() { gil_function_requires< ColorBaseConcept >(); static const std::size_t num_elements = size::value; typedef typename kth_element_type::type T0; typedef typename kth_element_type::type TN; BOOST_STATIC_ASSERT((is_same::value)); // better than nothing typedef typename kth_element_const_reference_type::type CRef0; CRef0 e0=dynamic_at_c(cb,0); } ColorBase cb; }; /// \ingroup ColorBaseConcept /// \brief Homogeneous color base that allows for modifying its elements /** \code concept MutableHomogeneousColorBaseConcept : HomogeneousColorBaseConcept { kth_element_reference_type::type dynamic_at_c(CB&, std::size_t n); }; \endcode */ template struct MutableHomogeneousColorBaseConcept { void constraints() { gil_function_requires< ColorBaseConcept >(); gil_function_requires< HomogeneousColorBaseConcept >(); typedef typename kth_element_reference_type::type R0; R0 x=dynamic_at_c(cb,0); dynamic_at_c(cb,0) = dynamic_at_c(cb,0); } ColorBase cb; }; /// \ingroup ColorBaseConcept /// \brief Homogeneous color base that also has a default constructor. Refines Regular. /** \code concept HomogeneousColorBaseValueConcept : MutableHomogeneousColorBaseConcept, Regular { }; \endcode */ template struct HomogeneousColorBaseValueConcept { void constraints() { gil_function_requires< MutableHomogeneousColorBaseConcept >(); gil_function_requires< Regular >(); } }; /// \ingroup ColorBaseConcept /// \brief Two color bases are compatible if they have the same color space and their elements are compatible, semantic-pairwise. /** \code concept ColorBasesCompatibleConcept { where SameType; // also, for all K in [0 ... size::value): // where Convertible::type, kth_semantic_element_type::type>; // where Convertible::type, kth_semantic_element_type::type>; }; \endcode */ template struct ColorBasesCompatibleConcept { void constraints() { BOOST_STATIC_ASSERT((is_same::value)); // typedef typename kth_semantic_element_type::type e1; // typedef typename kth_semantic_element_type::type e2; // "e1 is convertible to e2" } }; //////////////////////////////////////////////////////////////////////////////////////// /// /// PIXEL CONCEPTS /// //////////////////////////////////////////////////////////////////////////////////////// /// \brief Concept for all pixel-based GIL constructs, such as pixels, iterators, locators, views and images whose value type is a pixel /// \ingroup PixelBasedConcept /** \code concept PixelBasedConcept { typename color_space_type; where Metafunction >; where ColorSpaceConcept::type>; typename channel_mapping_type; where Metafunction >; where ChannelMappingConcept::type>; typename is_planar; where Metafunction >; where SameType::type, bool>; }; \endcode */ template struct PixelBasedConcept { void constraints() { typedef typename color_space_type

::type color_space_t; gil_function_requires >(); typedef typename channel_mapping_type

::type channel_mapping_t; gil_function_requires >(); static const bool planar = is_planar

::type::value; ignore_unused_variable_warning(planar); // This is not part of the concept, but should still work static const std::size_t nc = num_channels

::value; ignore_unused_variable_warning(nc); } }; /// \brief Concept for homogeneous pixel-based GIL constructs /// \ingroup PixelBasedConcept /** \code concept HomogeneousPixelBasedConcept { typename channel_type; where Metafunction >; where ChannelConcept::type>; }; \endcode */ template struct HomogeneousPixelBasedConcept { void constraints() { gil_function_requires >(); typedef typename channel_type

::type channel_t; gil_function_requires >(); } }; /// \brief Pixel concept - A color base whose elements are channels /// \ingroup PixelConcept /** \code concept PixelConcept : ColorBaseConcept

, PixelBasedConcept

{ where is_pixel

::type::value==true; // where for each K [0..size

::value-1]: // ChannelConcept >; typename P::value_type; where PixelValueConcept; typename P::reference; where PixelConcept; typename P::const_reference; where PixelConcept; static const bool P::is_mutable; template where { PixelConcept } P::P(P2); template where { PixelConcept } bool operator==(const P&, const P2&); template where { PixelConcept } bool operator!=(const P&, const P2&); }; \endcode */ template struct PixelConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); BOOST_STATIC_ASSERT((is_pixel

::value)); static const bool is_mutable = P::is_mutable; ignore_unused_variable_warning(is_mutable); typedef typename P::value_type value_type; // gil_function_requires >(); typedef typename P::reference reference; gil_function_requires::type> >(); typedef typename P::const_reference const_reference; gil_function_requires::type> >(); } }; /// \brief Pixel concept that allows for changing its channels /// \ingroup PixelConcept /** \code concept MutablePixelConcept : MutableColorBaseConcept

{ where is_mutable==true; }; \endcode */ template struct MutablePixelConcept { void constraints() { gil_function_requires >(); BOOST_STATIC_ASSERT(P::is_mutable); } }; /// \brief Homogeneous pixel concept /// \ingroup PixelConcept /** \code concept HomogeneousPixelConcept : HomogeneousColorBaseConcept

, HomogeneousPixelBasedConcept

{ P::template element_const_reference_type

::type operator[](P p, std::size_t i) const { return dynamic_at_c(p,i); } }; \endcode */ template struct HomogeneousPixelConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); gil_function_requires >(); p[0]; } P p; }; /// \brief Homogeneous pixel concept that allows for changing its channels /// \ingroup PixelConcept /** \code concept MutableHomogeneousPixelConcept : MutableHomogeneousColorBaseConcept

{ P::template element_reference_type

::type operator[](P p, std::size_t i) { return dynamic_at_c(p,i); } }; \endcode */ template struct MutableHomogeneousPixelConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); p[0]=p[0]; } P p; }; /// \brief Pixel concept that is a Regular type /// \ingroup PixelConcept /** \code concept PixelValueConcept : Regular

{ where SameType; }; \endcode */ template struct PixelValueConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; /// \brief Homogeneous pixel concept that is a Regular type /// \ingroup PixelConcept /** \code concept HomogeneousPixelValueConcept : Regular

{ where SameType; }; \endcode */ template struct HomogeneousPixelValueConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); BOOST_STATIC_ASSERT((is_same::value)); } }; namespace detail { template struct channels_are_pairwise_compatible : public mpl::and_, channels_are_compatible::type, typename kth_semantic_element_reference_type::type> > {}; template struct channels_are_pairwise_compatible : public mpl::true_ {}; } /// \brief Returns whether two pixels are compatible /// /// Pixels are compatible if their channels and color space types are compatible. Compatible pixels can be assigned and copy constructed from one another. /// \ingroup PixelAlgorithm template // Models GIL Pixel struct pixels_are_compatible : public mpl::and_::type, typename color_space_type::type>::type, detail::channels_are_pairwise_compatible::value-1> > {}; /// \brief Concept for pixel compatibility /// Pixels are compatible if their channels and color space types are compatible. Compatible pixels can be assigned and copy constructed from one another. /// \ingroup PixelConcept /** \code concept PixelsCompatibleConcept : ColorBasesCompatibleConcept { // where for each K [0..size::value): // ChannelsCompatibleConcept::type, kth_semantic_element_type::type>; }; \endcode */ template // precondition: P1 and P2 model PixelConcept struct PixelsCompatibleConcept { void constraints() { BOOST_STATIC_ASSERT((pixels_are_compatible::value)); } }; /// \brief Pixel convertible concept /// /// Convertibility is non-symmetric and implies that one pixel can be converted to another, approximating the color. Conversion is explicit and sometimes lossy. /// \ingroup PixelConcept /** \code template concept PixelConvertibleConcept { void color_convert(const SrcPixel&, DstPixel&); }; \endcode */ template struct PixelConvertibleConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); color_convert(src,dst); } SrcP src; DstP dst; }; //////////////////////////////////////////////////////////////////////////////////////// /// /// DEREFERENCE ADAPTOR CONCEPTS /// //////////////////////////////////////////////////////////////////////////////////////// /// \ingroup PixelDereferenceAdaptorConcept /// \brief Represents a unary function object that can be invoked upon dereferencing a pixel iterator. /// /// This can perform an arbitrary computation, such as color conversion or table lookup /** \code concept PixelDereferenceAdaptorConcept : DefaultConstructibleConcept, CopyConstructibleConcept, AssignableConcept { typename const_t; where PixelDereferenceAdaptorConcept; typename value_type; where PixelValueConcept; typename reference; // may be mutable typename const_reference; // must not be mutable static const bool D::is_mutable; where Convertible; }; \endcode */ template struct PixelDereferenceAdaptorConcept { void constraints() { gil_function_requires< boost::UnaryFunctionConcept::type, typename D::argument_type> >(); gil_function_requires< boost::DefaultConstructibleConcept >(); gil_function_requires< boost::CopyConstructibleConcept >(); gil_function_requires< boost::AssignableConcept >(); gil_function_requires::type> >(); typedef typename D::const_t const_t; gil_function_requires >(); typedef typename D::value_type value_type; gil_function_requires >(); typedef typename D::reference reference; // == PixelConcept (if you remove const and reference) typedef typename D::const_reference const_reference; // == PixelConcept (if you remove const and reference) const bool is_mutable=D::is_mutable; ignore_unused_variable_warning(is_mutable); } D d; }; template struct PixelDereferenceAdaptorArchetype : public std::unary_function { typedef PixelDereferenceAdaptorArchetype const_t; typedef typename remove_reference

::type value_type; typedef typename add_reference

::type reference; typedef reference const_reference; static const bool is_mutable=false; P operator()(P x) const { throw; } }; //////////////////////////////////////////////////////////////////////////////////////// /// /// Pixel ITERATOR CONCEPTS /// //////////////////////////////////////////////////////////////////////////////////////// /// \brief Concept for iterators, locators and views that can define a type just like the given iterator/locator/view, except it supports runtime specified step along the X navigation /// \ingroup PixelIteratorConcept /** \code concept HasDynamicXStepTypeConcept { typename dynamic_x_step_type; where Metafunction >; }; \endcode */ template struct HasDynamicXStepTypeConcept { void constraints() { typedef typename dynamic_x_step_type::type type; } }; /// \brief Concept for locators and views that can define a type just like the given locator or view, except it supports runtime specified step along the Y navigation /// \ingroup PixelLocatorConcept /** \code concept HasDynamicYStepTypeConcept { typename dynamic_y_step_type; where Metafunction >; }; \endcode */ template struct HasDynamicYStepTypeConcept { void constraints() { typedef typename dynamic_y_step_type::type type; } }; /// \brief Concept for locators and views that can define a type just like the given locator or view, except X and Y is swapped /// \ingroup PixelLocatorConcept /** \code concept HasTransposedTypeConcept { typename transposed_type; where Metafunction >; }; \endcode */ template struct HasTransposedTypeConcept { void constraints() { typedef typename transposed_type::type type; } }; /// \defgroup PixelIteratorConceptPixelIterator PixelIteratorConcept /// \ingroup PixelIteratorConcept /// \brief STL iterator over pixels /// \ingroup PixelIteratorConceptPixelIterator /// \brief An STL random access traversal iterator over a model of PixelConcept. /** GIL's iterators must also provide the following metafunctions: - \p const_iterator_type: Returns a read-only equivalent of \p Iterator - \p iterator_is_mutable: Returns whether the given iterator is read-only or mutable - \p is_iterator_adaptor: Returns whether the given iterator is an adaptor over another iterator. See IteratorAdaptorConcept for additional requirements of adaptors. \code concept PixelIteratorConcept : boost_concepts::RandomAccessTraversalConcept, PixelBasedConcept { where PixelValueConcept; typename const_iterator_type::type; where PixelIteratorConcept::type>; static const bool iterator_is_mutable::type::value; static const bool is_iterator_adaptor::type::value; // is it an iterator adaptor }; \endcode */ template struct PixelIteratorConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); typedef typename std::iterator_traits::value_type value_type; gil_function_requires >(); typedef typename const_iterator_type::type const_t; static const bool is_mut = iterator_is_mutable::type::value; ignore_unused_variable_warning(is_mut); const_t const_it(it); ignore_unused_variable_warning(const_it); // immutable iterator must be constructible from (possibly mutable) iterator check_base(typename is_iterator_adaptor::type()); } void check_base(mpl::false_) {} void check_base(mpl::true_) { typedef typename iterator_adaptor_get_base::type base_t; gil_function_requires >(); } Iterator it; }; namespace detail { template // Preconditions: Iterator Models PixelIteratorConcept struct PixelIteratorIsMutableConcept { void constraints() { gil_function_requires >(); typedef typename remove_reference::reference>::type ref; typedef typename element_type::type channel_t; gil_function_requires >(); } }; } /// \brief Pixel iterator that allows for changing its pixel /// \ingroup PixelIteratorConceptPixelIterator /** \code concept MutablePixelIteratorConcept : MutableRandomAccessIteratorConcept {}; \endcode */ template struct MutablePixelIteratorConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; namespace detail { // Iterators that can be used as the base of memory_based_step_iterator require some additional functions template // Preconditions: Iterator Models boost_concepts::RandomAccessTraversalConcept struct RandomAccessIteratorIsMemoryBasedConcept { void constraints() { std::ptrdiff_t bs=memunit_step(it); ignore_unused_variable_warning(bs); it=memunit_advanced(it,3); std::ptrdiff_t bd=memunit_distance(it,it); ignore_unused_variable_warning(bd); memunit_advance(it,3); // for performace you may also provide a customized implementation of memunit_advanced_ref } Iterator it; }; } /// \defgroup PixelIteratorConceptStepIterator StepIteratorConcept /// \ingroup PixelIteratorConcept /// \brief Iterator that advances by a specified step /// \brief Concept of a random-access iterator that can be advanced in memory units (bytes or bits) /// \ingroup PixelIteratorConceptStepIterator /** \code concept MemoryBasedIteratorConcept { typename byte_to_memunit; where metafunction >; std::ptrdiff_t memunit_step(const Iterator&); std::ptrdiff_t memunit_distance(const Iterator& , const Iterator&); void memunit_advance(Iterator&, std::ptrdiff_t diff); Iterator memunit_advanced(const Iterator& p, std::ptrdiff_t diff) { Iterator tmp; memunit_advance(tmp,diff); return tmp; } Iterator::reference memunit_advanced_ref(const Iterator& p, std::ptrdiff_t diff) { return *memunit_advanced(p,diff); } }; \endcode */ template struct MemoryBasedIteratorConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; /// \brief Step iterator concept /// /// Step iterators are iterators that have a set_step method /// \ingroup PixelIteratorConceptStepIterator /** \code concept StepIteratorConcept { template void Iterator::set_step(D step); }; \endcode */ template struct StepIteratorConcept { void constraints() { gil_function_requires >(); it.set_step(0); } Iterator it; }; /// \brief Step iterator that allows for modifying its current value /// /// \ingroup PixelIteratorConceptStepIterator /** \code concept MutableStepIteratorConcept : StepIteratorConcept {}; \endcode */ template struct MutableStepIteratorConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; /// \defgroup PixelIteratorConceptIteratorAdaptor IteratorAdaptorConcept /// \ingroup PixelIteratorConcept /// \brief Adaptor over another iterator /// \ingroup PixelIteratorConceptIteratorAdaptor /// \brief Iterator adaptor is a forward iterator adapting another forward iterator. /** In addition to GIL iterator requirements, GIL iterator adaptors must provide the following metafunctions: - \p is_iterator_adaptor: Returns \p mpl::true_ - \p iterator_adaptor_get_base: Returns the base iterator type - \p iterator_adaptor_rebind: Replaces the base iterator with the new one The adaptee can be obtained from the iterator via the "base()" method. \code concept IteratorAdaptorConcept { where SameType::type, mpl::true_>; typename iterator_adaptor_get_base; where Metafunction >; where boost_concepts::ForwardTraversalConcept::type>; typename another_iterator; typename iterator_adaptor_rebind::type; where boost_concepts::ForwardTraversalConcept; where IteratorAdaptorConcept::type>; const iterator_adaptor_get_base::type& Iterator::base() const; }; \endcode */ template struct IteratorAdaptorConcept { void constraints() { gil_function_requires >(); typedef typename iterator_adaptor_get_base::type base_t; gil_function_requires >(); BOOST_STATIC_ASSERT(is_iterator_adaptor::value); typedef typename iterator_adaptor_rebind::type rebind_t; base_t base=it.base(); ignore_unused_variable_warning(base); } Iterator it; }; /// \brief Iterator adaptor that is mutable /// \ingroup PixelIteratorConceptIteratorAdaptor /** \code concept MutableIteratorAdaptorConcept : IteratorAdaptorConcept {}; \endcode */ template struct MutableIteratorAdaptorConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; //////////////////////////////////////////////////////////////////////////////////////// /// /// LOCATOR CONCEPTS /// //////////////////////////////////////////////////////////////////////////////////////// /// \defgroup LocatorNDConcept RandomAccessNDLocatorConcept /// \ingroup PixelLocatorConcept /// \brief N-dimensional locator /// \defgroup Locator2DConcept RandomAccess2DLocatorConcept /// \ingroup PixelLocatorConcept /// \brief 2-dimensional locator /// \defgroup PixelLocator2DConcept PixelLocatorConcept /// \ingroup PixelLocatorConcept /// \brief 2-dimensional locator over pixel data /// \ingroup LocatorNDConcept /// \brief N-dimensional locator over immutable values /** \code concept RandomAccessNDLocatorConcept { typename value_type; // value over which the locator navigates typename reference; // result of dereferencing typename difference_type; where PointNDConcept; // return value of operator-. typename const_t; // same as Loc, but operating over immutable values typename cached_location_t; // type to store relative location (for efficient repeated access) typename point_t = difference_type; static const size_t num_dimensions; // dimensionality of the locator where num_dimensions = point_t::num_dimensions; // The difference_type and iterator type along each dimension. The iterators may only differ in // difference_type. Their value_type must be the same as Loc::value_type template struct axis { typename coord_t = point_t::axis::coord_t; typename iterator; where RandomAccessTraversalConcept; // iterator along D-th axis. where iterator::value_type == value_type; }; // Defines the type of a locator similar to this type, except it invokes Deref upon dereferencing template struct add_deref { typename type; where RandomAccessNDLocatorConcept; static type make(const Loc& loc, const Deref& deref); }; Loc& operator+=(Loc&, const difference_type&); Loc& operator-=(Loc&, const difference_type&); Loc operator+(const Loc&, const difference_type&); Loc operator-(const Loc&, const difference_type&); reference operator*(const Loc&); reference operator[](const Loc&, const difference_type&); // Storing relative location for faster repeated access and accessing it cached_location_t Loc::cache_location(const difference_type&) const; reference operator[](const Loc&,const cached_location_t&); // Accessing iterators along a given dimension at the current location or at a given offset template axis::iterator& Loc::axis_iterator(); template axis::iterator const& Loc::axis_iterator() const; template axis::iterator Loc::axis_iterator(const difference_type&) const; }; \endcode */ template struct RandomAccessNDLocatorConcept { void constraints() { gil_function_requires< Regular >(); typedef typename Loc::value_type value_type; typedef typename Loc::reference reference; // result of dereferencing typedef typename Loc::difference_type difference_type; // result of operator-(pixel_locator, pixel_locator) typedef typename Loc::cached_location_t cached_location_t; // type used to store relative location (to allow for more efficient repeated access) typedef typename Loc::const_t const_t; // same as this type, but over const values typedef typename Loc::point_t point_t; // same as difference_type static const std::size_t N=Loc::num_dimensions; ignore_unused_variable_warning(N); typedef typename Loc::template axis<0>::iterator first_it_type; typedef typename Loc::template axis::iterator last_it_type; gil_function_requires >(); gil_function_requires >(); // point_t must be an N-dimensional point, each dimension of which must have the same type as difference_type of the corresponding iterator gil_function_requires >(); BOOST_STATIC_ASSERT(point_t::num_dimensions==N); BOOST_STATIC_ASSERT((is_same::difference_type, typename point_t::template axis<0>::coord_t>::value)); BOOST_STATIC_ASSERT((is_same::difference_type, typename point_t::template axis::coord_t>::value)); difference_type d; loc+=d; loc-=d; loc=loc+d; loc=loc-d; reference r1=loc[d]; ignore_unused_variable_warning(r1); reference r2=*loc; ignore_unused_variable_warning(r2); cached_location_t cl=loc.cache_location(d); ignore_unused_variable_warning(cl); reference r3=loc[d]; ignore_unused_variable_warning(r3); first_it_type fi=loc.template axis_iterator<0>(); fi=loc.template axis_iterator<0>(d); last_it_type li=loc.template axis_iterator(); li=loc.template axis_iterator(d); typedef PixelDereferenceAdaptorArchetype deref_t; typedef typename Loc::template add_deref::type dtype; //gil_function_requires >(); // infinite recursion } Loc loc; }; /// \ingroup Locator2DConcept /// \brief 2-dimensional locator over immutable values /** \code concept RandomAccess2DLocatorConcept { where num_dimensions==2; where Point2DConcept; typename x_iterator = axis<0>::iterator; typename y_iterator = axis<1>::iterator; typename x_coord_t = axis<0>::coord_t; typename y_coord_t = axis<1>::coord_t; // Only available to locators that have dynamic step in Y //Loc::Loc(const Loc& loc, y_coord_t); // Only available to locators that have dynamic step in X and Y //Loc::Loc(const Loc& loc, x_coord_t, y_coord_t, bool transposed=false); x_iterator& Loc::x(); x_iterator const& Loc::x() const; y_iterator& Loc::y(); y_iterator const& Loc::y() const; x_iterator Loc::x_at(const difference_type&) const; y_iterator Loc::y_at(const difference_type&) const; Loc Loc::xy_at(const difference_type&) const; // x/y versions of all methods that can take difference type x_iterator Loc::x_at(x_coord_t, y_coord_t) const; y_iterator Loc::y_at(x_coord_t, y_coord_t) const; Loc Loc::xy_at(x_coord_t, y_coord_t) const; reference operator()(const Loc&, x_coord_t, y_coord_t); cached_location_t Loc::cache_location(x_coord_t, y_coord_t) const; bool Loc::is_1d_traversable(x_coord_t width) const; y_coord_t Loc::y_distance_to(const Loc& loc2, x_coord_t x_diff) const; }; \endcode */ template struct RandomAccess2DLocatorConcept { void constraints() { gil_function_requires >(); BOOST_STATIC_ASSERT(Loc::num_dimensions==2); typedef typename dynamic_x_step_type::type dynamic_x_step_t; typedef typename dynamic_y_step_type::type dynamic_y_step_t; typedef typename transposed_type::type transposed_t; typedef typename Loc::cached_location_t cached_location_t; gil_function_requires >(); typedef typename Loc::x_iterator x_iterator; typedef typename Loc::y_iterator y_iterator; typedef typename Loc::x_coord_t x_coord_t; typedef typename Loc::y_coord_t y_coord_t; x_coord_t xd=0; ignore_unused_variable_warning(xd); y_coord_t yd=0; ignore_unused_variable_warning(yd); typename Loc::difference_type d; typename Loc::reference r=loc(xd,yd); ignore_unused_variable_warning(r); dynamic_x_step_t loc2(dynamic_x_step_t(), yd); dynamic_x_step_t loc3(dynamic_x_step_t(), xd, yd); typedef typename dynamic_y_step_type::type>::type dynamic_xy_step_transposed_t; dynamic_xy_step_transposed_t loc4(loc, xd,yd,true); bool is_contiguous=loc.is_1d_traversable(xd); ignore_unused_variable_warning(is_contiguous); loc.y_distance_to(loc, xd); loc=loc.xy_at(d); loc=loc.xy_at(xd,yd); x_iterator xit=loc.x_at(d); xit=loc.x_at(xd,yd); xit=loc.x(); y_iterator yit=loc.y_at(d); yit=loc.y_at(xd,yd); yit=loc.y(); cached_location_t cl=loc.cache_location(xd,yd); ignore_unused_variable_warning(cl); } Loc loc; }; /// \ingroup PixelLocator2DConcept /// \brief GIL's 2-dimensional locator over immutable GIL pixels /** \code concept PixelLocatorConcept { where PixelValueConcept; where PixelIteratorConcept; where PixelIteratorConcept; where x_coord_t == y_coord_t; typename coord_t = x_coord_t; }; \endcode */ template struct PixelLocatorConcept { void constraints() { gil_function_requires< RandomAccess2DLocatorConcept >(); gil_function_requires< PixelIteratorConcept >(); gil_function_requires< PixelIteratorConcept >(); typedef typename Loc::coord_t coord_t; BOOST_STATIC_ASSERT((is_same::value)); } Loc loc; }; namespace detail { template // preconditions: Loc Models RandomAccessNDLocatorConcept struct RandomAccessNDLocatorIsMutableConcept { void constraints() { gil_function_requires::iterator> >(); gil_function_requires::iterator> >(); typename Loc::difference_type d; initialize_it(d); typename Loc::value_type v;initialize_it(v); typename Loc::cached_location_t cl=loc.cache_location(d); *loc=v; loc[d]=v; loc[cl]=v; } Loc loc; }; template // preconditions: Loc Models RandomAccess2DLocatorConcept struct RandomAccess2DLocatorIsMutableConcept { void constraints() { gil_function_requires >(); typename Loc::x_coord_t xd=0; ignore_unused_variable_warning(xd); typename Loc::y_coord_t yd=0; ignore_unused_variable_warning(yd); typename Loc::value_type v; initialize_it(v); loc(xd,yd)=v; } Loc loc; }; } /// \ingroup LocatorNDConcept /// \brief N-dimensional locator over mutable pixels /** \code concept MutableRandomAccessNDLocatorConcept { where Mutable; }; \endcode */ template struct MutableRandomAccessNDLocatorConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; /// \ingroup Locator2DConcept /// \brief 2-dimensional locator over mutable pixels /** \code concept MutableRandomAccess2DLocatorConcept : MutableRandomAccessNDLocatorConcept {}; \endcode */ template struct MutableRandomAccess2DLocatorConcept { void constraints() { gil_function_requires< RandomAccess2DLocatorConcept >(); gil_function_requires >(); } }; /// \ingroup PixelLocator2DConcept /// \brief GIL's 2-dimensional locator over mutable GIL pixels /** \code concept MutablePixelLocatorConcept : MutableRandomAccess2DLocatorConcept {}; \endcode */ template struct MutablePixelLocatorConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; //////////////////////////////////////////////////////////////////////////////////////// /// /// IMAGE VIEW CONCEPTS /// //////////////////////////////////////////////////////////////////////////////////////// /// \defgroup ImageViewNDConcept ImageViewNDLocatorConcept /// \ingroup ImageViewConcept /// \brief N-dimensional range /// \defgroup ImageView2DConcept ImageView2DConcept /// \ingroup ImageViewConcept /// \brief 2-dimensional range /// \defgroup PixelImageViewConcept ImageViewConcept /// \ingroup ImageViewConcept /// \brief 2-dimensional range over pixel data /// \ingroup ImageViewNDConcept /// \brief N-dimensional view over immutable values /** \code concept RandomAccessNDImageViewConcept { typename value_type; typename reference; // result of dereferencing typename difference_type; // result of operator-(iterator,iterator) (1-dimensional!) typename const_t; where RandomAccessNDImageViewConcept; // same as View, but over immutable values typename point_t; where PointNDConcept; // N-dimensional point typename locator; where RandomAccessNDLocatorConcept; // N-dimensional locator. typename iterator; where RandomAccessTraversalConcept; // 1-dimensional iterator over all values typename reverse_iterator; where RandomAccessTraversalConcept; typename size_type; // the return value of size() // Equivalent to RandomAccessNDLocatorConcept::axis template struct axis { typename coord_t = point_t::axis::coord_t; typename iterator; where RandomAccessTraversalConcept; // iterator along D-th axis. where SameType; where SameType; }; // Defines the type of a view similar to this type, except it invokes Deref upon dereferencing template struct add_deref { typename type; where RandomAccessNDImageViewConcept; static type make(const View& v, const Deref& deref); }; static const size_t num_dimensions = point_t::num_dimensions; // Create from a locator at the top-left corner and dimensions View::View(const locator&, const point_type&); size_type View::size() const; // total number of elements reference operator[](View, const difference_type&) const; // 1-dimensional reference iterator View::begin() const; iterator View::end() const; reverse_iterator View::rbegin() const; reverse_iterator View::rend() const; iterator View::at(const point_t&); point_t View::dimensions() const; // number of elements along each dimension bool View::is_1d_traversable() const; // can an iterator over the first dimension visit each value? I.e. are there gaps between values? // iterator along a given dimension starting at a given point template View::axis::iterator View::axis_iterator(const point_t&) const; reference operator()(View,const point_t&) const; }; \endcode */ template struct RandomAccessNDImageViewConcept { void constraints() { gil_function_requires< Regular >(); typedef typename View::value_type value_type; typedef typename View::reference reference; // result of dereferencing typedef typename View::difference_type difference_type; // result of operator-(1d_iterator,1d_iterator) typedef typename View::const_t const_t; // same as this type, but over const values typedef typename View::point_t point_t; // N-dimensional point typedef typename View::locator locator; // N-dimensional locator typedef typename View::iterator iterator; typedef typename View::reverse_iterator reverse_iterator; typedef typename View::size_type size_type; static const std::size_t N=View::num_dimensions; gil_function_requires >(); gil_function_requires >(); gil_function_requires >(); typedef typename View::template axis<0>::iterator first_it_type; typedef typename View::template axis::iterator last_it_type; gil_function_requires >(); gil_function_requires >(); // BOOST_STATIC_ASSERT((typename std::iterator_traits::difference_type, typename point_t::template axis<0>::coord_t>::value)); // BOOST_STATIC_ASSERT((typename std::iterator_traits< last_it_type>::difference_type, typename point_t::template axis::coord_t>::value)); // point_t must be an N-dimensional point, each dimension of which must have the same type as difference_type of the corresponding iterator gil_function_requires >(); BOOST_STATIC_ASSERT(point_t::num_dimensions==N); BOOST_STATIC_ASSERT((is_same::difference_type, typename point_t::template axis<0>::coord_t>::value)); BOOST_STATIC_ASSERT((is_same::difference_type, typename point_t::template axis::coord_t>::value)); point_t p; locator lc; iterator it; reverse_iterator rit; difference_type d; detail::initialize_it(d); ignore_unused_variable_warning(d); View(p,lc); // view must be constructible from a locator and a point p=view.dimensions(); lc=view.pixels(); size_type sz=view.size(); ignore_unused_variable_warning(sz); bool is_contiguous=view.is_1d_traversable(); ignore_unused_variable_warning(is_contiguous); it=view.begin(); it=view.end(); rit=view.rbegin(); rit=view.rend(); reference r1=view[d]; ignore_unused_variable_warning(r1); // 1D access reference r2=view(p); ignore_unused_variable_warning(r2); // 2D access // get 1-D iterator of any dimension at a given pixel location first_it_type fi=view.template axis_iterator<0>(p); ignore_unused_variable_warning(fi); last_it_type li=view.template axis_iterator(p); ignore_unused_variable_warning(li); typedef PixelDereferenceAdaptorArchetype deref_t; typedef typename View::template add_deref::type dtype; } View view; }; /// \ingroup ImageView2DConcept /// \brief 2-dimensional view over immutable values /** \code concept RandomAccess2DImageViewConcept { where num_dimensions==2; typename x_iterator = axis<0>::iterator; typename y_iterator = axis<1>::iterator; typename x_coord_t = axis<0>::coord_t; typename y_coord_t = axis<1>::coord_t; typename xy_locator = locator; x_coord_t View::width() const; y_coord_t View::height() const; // X-navigation x_iterator View::x_at(const point_t&) const; x_iterator View::row_begin(y_coord_t) const; x_iterator View::row_end (y_coord_t) const; // Y-navigation y_iterator View::y_at(const point_t&) const; y_iterator View::col_begin(x_coord_t) const; y_iterator View::col_end (x_coord_t) const; // navigating in 2D xy_locator View::xy_at(const point_t&) const; // (x,y) versions of all methods taking point_t View::View(x_coord_t,y_coord_t,const locator&); iterator View::at(x_coord_t,y_coord_t) const; reference operator()(View,x_coord_t,y_coord_t) const; xy_locator View::xy_at(x_coord_t,y_coord_t) const; x_iterator View::x_at(x_coord_t,y_coord_t) const; y_iterator View::y_at(x_coord_t,y_coord_t) const; }; \endcode */ template struct RandomAccess2DImageViewConcept { void constraints() { gil_function_requires >(); BOOST_STATIC_ASSERT(View::num_dimensions==2); // TODO: This executes the requirements for RandomAccessNDLocatorConcept again. Fix it to improve compile time gil_function_requires >(); typedef typename dynamic_x_step_type::type dynamic_x_step_t; typedef typename dynamic_y_step_type::type dynamic_y_step_t; typedef typename transposed_type::type transposed_t; typedef typename View::x_iterator x_iterator; typedef typename View::y_iterator y_iterator; typedef typename View::x_coord_t x_coord_t; typedef typename View::y_coord_t y_coord_t; typedef typename View::xy_locator xy_locator; x_coord_t xd=0; ignore_unused_variable_warning(xd); y_coord_t yd=0; ignore_unused_variable_warning(yd); x_iterator xit; y_iterator yit; typename View::point_t d; View(xd,yd,xy_locator()); // constructible with width, height, 2d_locator xy_locator lc=view.xy_at(xd,yd); lc=view.xy_at(d); typename View::reference r=view(xd,yd); ignore_unused_variable_warning(r); xd=view.width(); yd=view.height(); xit=view.x_at(d); xit=view.x_at(xd,yd); xit=view.row_begin(xd); xit=view.row_end(xd); yit=view.y_at(d); yit=view.y_at(xd,yd); yit=view.col_begin(xd); yit=view.col_end(xd); } View view; }; /// \ingroup PixelImageViewConcept /// \brief GIL's 2-dimensional view over immutable GIL pixels /** \code concept ImageViewConcept { where PixelValueConcept; where PixelIteratorConcept; where PixelIteratorConcept; where x_coord_t == y_coord_t; typename coord_t = x_coord_t; std::size_t View::num_channels() const; }; \endcode */ template struct ImageViewConcept { void constraints() { gil_function_requires >(); // TODO: This executes the requirements for RandomAccess2DLocatorConcept again. Fix it to improve compile time gil_function_requires >(); BOOST_STATIC_ASSERT((is_same::value)); typedef typename View::coord_t coord_t; // 1D difference type (same for all dimensions) std::size_t num_chan = view.num_channels(); ignore_unused_variable_warning(num_chan); } View view; }; namespace detail { template // Preconditions: View Models RandomAccessNDImageViewConcept struct RandomAccessNDImageViewIsMutableConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); gil_function_requires >(); gil_function_requires::iterator> >(); gil_function_requires::iterator> >(); typename View::difference_type diff; initialize_it(diff); ignore_unused_variable_warning(diff); typename View::point_t pt; typename View::value_type v; initialize_it(v); view[diff]=v; view(pt)=v; } View view; }; template // preconditions: View Models RandomAccessNDImageViewConcept struct RandomAccess2DImageViewIsMutableConcept { void constraints() { gil_function_requires >(); typename View::x_coord_t xd=0; ignore_unused_variable_warning(xd); typename View::y_coord_t yd=0; ignore_unused_variable_warning(yd); typename View::value_type v; initialize_it(v); view(xd,yd)=v; } View view; }; template // preconditions: View Models ImageViewConcept struct PixelImageViewIsMutableConcept { void constraints() { gil_function_requires >(); } }; } /// \ingroup ImageViewNDConcept /// \brief N-dimensional view over mutable values /** \code concept MutableRandomAccessNDImageViewConcept { where Mutable; }; \endcode */ template struct MutableRandomAccessNDImageViewConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; /// \ingroup ImageView2DConcept /// \brief 2-dimensional view over mutable values /** \code concept MutableRandomAccess2DImageViewConcept : MutableRandomAccessNDImageViewConcept {}; \endcode */ template struct MutableRandomAccess2DImageViewConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; /// \ingroup PixelImageViewConcept /// \brief GIL's 2-dimensional view over mutable GIL pixels /** \code concept MutableImageViewConcept : MutableRandomAccess2DImageViewConcept {}; \endcode */ template struct MutableImageViewConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); } }; /// \brief Returns whether two views are compatible /// /// Views are compatible if their pixels are compatible. Compatible views can be assigned and copy constructed from one another. template // Model ImageViewConcept struct views_are_compatible : public pixels_are_compatible {}; /// \brief Views are compatible if they have the same color spaces and compatible channel values. Constness and layout are not important for compatibility /// \ingroup ImageViewConcept /** \code concept ViewsCompatibleConcept { where PixelsCompatibleConcept; }; \endcode */ template struct ViewsCompatibleConcept { void constraints() { BOOST_STATIC_ASSERT((views_are_compatible::value)); } }; //////////////////////////////////////////////////////////////////////////////////////// /// /// IMAGE CONCEPTS /// //////////////////////////////////////////////////////////////////////////////////////// /// \ingroup ImageConcept /// \brief N-dimensional container of values /** \code concept RandomAccessNDImageConcept : Regular { typename view_t; where MutableRandomAccessNDImageViewConcept; typename const_view_t = view_t::const_t; typename point_t = view_t::point_t; typename value_type = view_t::value_type; typename allocator_type; Img::Img(point_t dims, std::size_t alignment=1); Img::Img(point_t dims, value_type fill_value, std::size_t alignment); void Img::recreate(point_t new_dims, std::size_t alignment=1); void Img::recreate(point_t new_dims, value_type fill_value, std::size_t alignment); const point_t& Img::dimensions() const; const const_view_t& const_view(const Img&); const view_t& view(Img&); }; \endcode */ template struct RandomAccessNDImageConcept { void constraints() { gil_function_requires >(); typedef typename Img::view_t view_t; gil_function_requires >(); typedef typename Img::const_view_t const_view_t; typedef typename Img::value_type pixel_t; typedef typename Img::point_t point_t; gil_function_requires >(); const_view_t cv = const_view(img); ignore_unused_variable_warning(cv); view_t v = view(img); ignore_unused_variable_warning(v); pixel_t fill_value; point_t pt=img.dimensions(); Img im1(pt); Img im2(pt,1); Img im3(pt,fill_value,1); img.recreate(pt); img.recreate(pt,1); img.recreate(pt,fill_value,1); } Img img; }; /// \ingroup ImageConcept /// \brief 2-dimensional container of values /** \code concept RandomAccess2DImageConcept { typename x_coord_t = const_view_t::x_coord_t; typename y_coord_t = const_view_t::y_coord_t; Img::Img(x_coord_t width, y_coord_t height, std::size_t alignment=1); Img::Img(x_coord_t width, y_coord_t height, value_type fill_value, std::size_t alignment); x_coord_t Img::width() const; y_coord_t Img::height() const; void Img::recreate(x_coord_t width, y_coord_t height, std::size_t alignment=1); void Img::recreate(x_coord_t width, y_coord_t height, value_type fill_value, std::size_t alignment); }; \endcode */ template struct RandomAccess2DImageConcept { void constraints() { gil_function_requires >(); typedef typename Img::x_coord_t x_coord_t; typedef typename Img::y_coord_t y_coord_t; typedef typename Img::value_type value_t; gil_function_requires >(); x_coord_t w=img.width(); y_coord_t h=img.height(); value_t fill_value; Img im1(w,h); Img im2(w,h,1); Img im3(w,h,fill_value,1); img.recreate(w,h); img.recreate(w,h,1); img.recreate(w,h,fill_value,1); } Img img; }; /// \ingroup ImageConcept /// \brief 2-dimensional image whose value type models PixelValueConcept /** \code concept ImageConcept { where MutableImageViewConcept; typename coord_t = view_t::coord_t; }; \endcode */ template struct ImageConcept { void constraints() { gil_function_requires >(); gil_function_requires >(); typedef typename Img::coord_t coord_t; BOOST_STATIC_ASSERT(num_channels::value == mpl::size::type>::value); BOOST_STATIC_ASSERT((is_same::value)); BOOST_STATIC_ASSERT((is_same::value)); } Img img; }; } } // namespace boost::gil #endif