Chris@16: /* Chris@16: Copyright 2005-2007 Adobe Systems Incorporated Chris@16: Chris@16: Use, modification and distribution are subject to the Boost Software License, Chris@16: Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt). Chris@16: Chris@16: See http://opensource.adobe.com/gil for most recent version including documentation. Chris@16: */ Chris@16: Chris@16: /*************************************************************************************************/ Chris@16: Chris@16: #ifndef GIL_IMAGE_VIEW_FACTORY_HPP Chris@16: #define GIL_IMAGE_VIEW_FACTORY_HPP Chris@16: Chris@16: /*! Chris@16: /// \file Chris@16: /// \brief Methods for constructing image views from raw data or other image views Chris@16: /// \author Lubomir Bourdev and Hailin Jin \n Chris@16: /// Adobe Systems Incorporated Chris@16: /// \date 2005-2007 \n Last updated on March 9, 2007 Chris@16: /// Methods for creating shallow image views from raw pixel data or from other image views - Chris@16: /// flipping horizontally or vertically, axis-aligned rotation, a subimage, subsampled Chris@16: /// or n-th channel image view. Derived image views are shallow copies and are fast to construct. Chris@16: */ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include "gil_config.hpp" Chris@16: #include "metafunctions.hpp" Chris@16: #include "gray.hpp" Chris@16: #include "color_convert.hpp" Chris@16: Chris@16: /// \defgroup ImageViewConstructors Image View From Raw Data Chris@16: /// \ingroup ImageViewAlgorithm Chris@16: /// \brief Methods for constructing image views from raw data and for getting raw data from views Chris@16: Chris@16: /// \defgroup ImageViewTransformations Image View Transformations Chris@16: /// \ingroup ImageViewAlgorithm Chris@16: /// \brief Methods for constructing one image view from another Chris@16: Chris@16: namespace boost { namespace gil { Chris@16: struct default_color_converter; Chris@16: Chris@16: template struct dynamic_x_step_type; Chris@16: template struct dynamic_y_step_type; Chris@16: template struct transposed_type; Chris@16: Chris@16: /// \brief Returns the type of a view that has a dynamic step along both X and Y Chris@16: /// \ingroup ImageViewTransformations Chris@16: template Chris@16: struct dynamic_xy_step_type : public dynamic_y_step_type::type> {}; Chris@16: Chris@16: /// \brief Returns the type of a transposed view that has a dynamic step along both X and Y Chris@16: /// \ingroup ImageViewTransformations Chris@16: template Chris@16: struct dynamic_xy_step_transposed_type : public dynamic_xy_step_type::type> {}; Chris@16: Chris@16: Chris@16: /// \ingroup ImageViewConstructors Chris@16: /// \brief Constructing image views from raw interleaved pixel data Chris@16: template Chris@16: typename type_from_x_iterator::view_t Chris@16: interleaved_view(std::size_t width, std::size_t height, Chris@16: Iterator pixels, std::ptrdiff_t rowsize_in_bytes) { Chris@16: typedef typename type_from_x_iterator::view_t RView; Chris@16: return RView(width, height, typename RView::locator(pixels, rowsize_in_bytes)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewConstructors Chris@16: /// \brief Constructing image views from raw interleaved pixel data Chris@16: template Chris@16: typename type_from_x_iterator::view_t Chris@16: interleaved_view(point2 dim, Chris@16: Iterator pixels, std::ptrdiff_t rowsize_in_bytes) { Chris@16: typedef typename type_from_x_iterator::view_t RView; Chris@16: return RView(dim, typename RView::locator(pixels, rowsize_in_bytes)); Chris@16: } Chris@16: Chris@16: ///////////////////////////// Chris@16: // interleaved_view_get_raw_data, planar_view_get_raw_data - return pointers to the raw data (the channels) of a basic homogeneous view. Chris@16: ///////////////////////////// Chris@16: Chris@16: namespace detail { Chris@16: template struct channel_pointer_type_impl; Chris@16: Chris@16: template struct channel_pointer_type_impl { Chris@16: typedef typename channel_type::type* type; Chris@16: }; Chris@16: template struct channel_pointer_type_impl { Chris@16: typedef const typename channel_type::type* type; Chris@16: }; Chris@16: Chris@16: template struct channel_pointer_type Chris@16: : public channel_pointer_type_impl::value> {}; Chris@16: } // namespace detail Chris@16: Chris@16: /// \ingroup ImageViewConstructors Chris@16: /// \brief Returns C pointer to the the channels of an interleaved homogeneous view. Chris@16: template Chris@16: typename detail::channel_pointer_type::type interleaved_view_get_raw_data(const HomogeneousView& view) { Chris@16: BOOST_STATIC_ASSERT((!is_planar::value && view_is_basic::value)); Chris@16: BOOST_STATIC_ASSERT((boost::is_pointer::value)); Chris@16: Chris@16: return &gil::at_c<0>(view(0,0)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewConstructors Chris@16: /// \brief Returns C pointer to the the channels of a given color plane of a planar homogeneous view. Chris@16: template Chris@16: typename detail::channel_pointer_type::type planar_view_get_raw_data(const HomogeneousView& view, int plane_index) { Chris@16: BOOST_STATIC_ASSERT((is_planar::value && view_is_basic::value)); Chris@16: return dynamic_at_c(view.row_begin(0),plane_index); Chris@16: } Chris@16: Chris@16: Chris@16: /// \defgroup ImageViewTransformationsColorConvert color_converted_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief Color converted view of another view Chris@16: Chris@16: /// \ingroup ImageViewTransformationsColorConvert PixelDereferenceAdaptorModel Chris@16: /// \brief Function object that given a source pixel, returns it converted to a given color space and channel depth. Models: PixelDereferenceAdaptorConcept Chris@16: /// Chris@16: /// Useful in constructing a color converted view over a given image view Chris@16: template // const_reference to the source pixel and destination pixel value Chris@16: class color_convert_deref_fn : public deref_base, DstP, DstP, const DstP&, SrcConstRefP, DstP, false> { Chris@16: private: Chris@16: CC _cc; // color-converter Chris@16: public: Chris@16: color_convert_deref_fn() {} Chris@16: color_convert_deref_fn(CC cc_in) : _cc(cc_in) {} Chris@16: Chris@16: DstP operator()(SrcConstRefP srcP) const { Chris@16: DstP dstP; Chris@16: _cc(srcP,dstP); Chris@16: return dstP; Chris@16: } Chris@16: }; Chris@16: Chris@16: namespace detail { Chris@16: // Add color converter upon dereferencing Chris@16: template Chris@16: struct _color_converted_view_type { Chris@16: private: Chris@16: typedef color_convert_deref_fn deref_t; Chris@16: typedef typename SrcView::template add_deref add_ref_t; Chris@16: public: Chris@16: typedef typename add_ref_t::type type; Chris@16: static type make(const SrcView& sv,CC cc) {return add_ref_t::make(sv,deref_t(cc));} Chris@16: }; Chris@16: Chris@16: // If the Src view has the same pixel type as the target, there is no need for color conversion Chris@16: template Chris@16: struct _color_converted_view_type { Chris@16: typedef SrcView type; Chris@16: static type make(const SrcView& sv,CC) {return sv;} Chris@16: }; Chris@16: } // namespace detail Chris@16: Chris@16: Chris@16: /// \brief Returns the type of a view that does color conversion upon dereferencing its pixels Chris@16: /// \ingroup ImageViewTransformationsColorConvert Chris@16: template Chris@16: struct color_converted_view_type : public detail::_color_converted_view_type { Chris@16: GIL_CLASS_REQUIRE(DstP, boost::gil, MutablePixelConcept)//why does it have to be mutable??? Chris@16: }; Chris@16: Chris@16: Chris@16: /// \ingroup ImageViewTransformationsColorConvert Chris@16: /// \brief view of a different color space with a user defined color-converter Chris@16: template Chris@16: inline typename color_converted_view_type::type color_converted_view(const View& src,CC cc) { Chris@16: return color_converted_view_type::make(src,cc); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewTransformationsColorConvert Chris@16: /// \brief overload of generic color_converted_view with the default color-converter Chris@16: template Chris@16: inline typename color_converted_view_type::type Chris@16: color_converted_view(const View& src) { Chris@16: return color_converted_view(src,default_color_converter()); Chris@16: } Chris@16: Chris@16: /// \defgroup ImageViewTransformationsFlipUD flipped_up_down_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief view of a view flipped up-to-down Chris@16: Chris@16: /// \ingroup ImageViewTransformationsFlipUD Chris@16: template Chris@16: inline typename dynamic_y_step_type::type flipped_up_down_view(const View& src) { Chris@16: typedef typename dynamic_y_step_type::type RView; Chris@16: return RView(src.dimensions(),typename RView::xy_locator(src.xy_at(0,src.height()-1),-1)); Chris@16: } Chris@16: Chris@16: /// \defgroup ImageViewTransformationsFlipLR flipped_left_right_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief view of a view flipped left-to-right Chris@16: Chris@16: /// \ingroup ImageViewTransformationsFlipLR Chris@16: template Chris@16: inline typename dynamic_x_step_type::type flipped_left_right_view(const View& src) { Chris@16: typedef typename dynamic_x_step_type::type RView; Chris@16: return RView(src.dimensions(),typename RView::xy_locator(src.xy_at(src.width()-1,0),-1,1)); Chris@16: } Chris@16: Chris@16: /// \defgroup ImageViewTransformationsTransposed transposed_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief view of a view transposed Chris@16: Chris@16: /// \ingroup ImageViewTransformationsTransposed Chris@16: template Chris@16: inline typename dynamic_xy_step_transposed_type::type transposed_view(const View& src) { Chris@16: typedef typename dynamic_xy_step_transposed_type::type RView; Chris@16: return RView(src.height(),src.width(),typename RView::xy_locator(src.xy_at(0,0),1,1,true)); Chris@16: } Chris@16: Chris@16: /// \defgroup ImageViewTransformations90CW rotated90cw_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief view of a view rotated 90 degrees clockwise Chris@16: Chris@16: /// \ingroup ImageViewTransformations90CW Chris@16: template Chris@16: inline typename dynamic_xy_step_transposed_type::type rotated90cw_view(const View& src) { Chris@16: typedef typename dynamic_xy_step_transposed_type::type RView; Chris@16: return RView(src.height(),src.width(),typename RView::xy_locator(src.xy_at(0,src.height()-1),-1,1,true)); Chris@16: } Chris@16: Chris@16: /// \defgroup ImageViewTransformations90CCW rotated90ccw_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief view of a view rotated 90 degrees counter-clockwise Chris@16: Chris@16: /// \ingroup ImageViewTransformations90CCW Chris@16: template Chris@16: inline typename dynamic_xy_step_transposed_type::type rotated90ccw_view(const View& src) { Chris@16: typedef typename dynamic_xy_step_transposed_type::type RView; Chris@16: return RView(src.height(),src.width(),typename RView::xy_locator(src.xy_at(src.width()-1,0),1,-1,true)); Chris@16: } Chris@16: Chris@16: /// \defgroup ImageViewTransformations180 rotated180_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief view of a view rotated 180 degrees Chris@16: Chris@16: /// \ingroup ImageViewTransformations180 Chris@16: template Chris@16: inline typename dynamic_xy_step_type::type rotated180_view(const View& src) { Chris@16: typedef typename dynamic_xy_step_type::type RView; Chris@16: return RView(src.dimensions(),typename RView::xy_locator(src.xy_at(src.width()-1,src.height()-1),-1,-1)); Chris@16: } Chris@16: Chris@16: /// \defgroup ImageViewTransformationsSubimage subimage_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief view of an axis-aligned rectangular area within an image_view Chris@16: Chris@16: /// \ingroup ImageViewTransformationsSubimage Chris@16: template Chris@16: inline View subimage_view(const View& src, const typename View::point_t& topleft, const typename View::point_t& dimensions) { Chris@16: return View(dimensions,src.xy_at(topleft)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewTransformationsSubimage Chris@16: template Chris@16: inline View subimage_view(const View& src, int xMin, int yMin, int width, int height) { Chris@16: return View(width,height,src.xy_at(xMin,yMin)); Chris@16: } Chris@16: Chris@16: /// \defgroup ImageViewTransformationsSubsampled subsampled_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief view of a subsampled version of an image_view, stepping over a number of channels in X and number of rows in Y Chris@16: Chris@16: /// \ingroup ImageViewTransformationsSubsampled Chris@16: template Chris@16: inline typename dynamic_xy_step_type::type subsampled_view(const View& src, typename View::coord_t xStep, typename View::coord_t yStep) { Chris@16: assert(xStep>0 && yStep>0); Chris@16: typedef typename dynamic_xy_step_type::type RView; Chris@16: return RView((src.width()+(xStep-1))/xStep,(src.height()+(yStep-1))/yStep, Chris@16: typename RView::xy_locator(src.xy_at(0,0),xStep,yStep)); Chris@16: } Chris@16: Chris@16: /// \ingroup ImageViewTransformationsSubsampled Chris@16: template Chris@16: inline typename dynamic_xy_step_type::type subsampled_view(const View& src, const typename View::point_t& step) { Chris@16: return subsampled_view(src,step.x,step.y); Chris@16: } Chris@16: Chris@16: /// \defgroup ImageViewTransformationsNthChannel nth_channel_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief single-channel (grayscale) view of the N-th channel of a given image_view Chris@16: Chris@16: namespace detail { Chris@16: template struct __nth_channel_view_basic; Chris@16: Chris@16: // nth_channel_view when the channels are not adjacent in memory. This can happen for multi-channel interleaved images Chris@16: // or images with a step Chris@16: template Chris@16: struct __nth_channel_view_basic { Chris@16: typedef typename view_type::type, gray_layout_t, false, true, view_is_mutable::value>::type type; Chris@16: Chris@16: static type make(const View& src, int n) { Chris@16: typedef typename type::xy_locator locator_t; Chris@16: typedef typename type::x_iterator x_iterator_t; Chris@16: typedef typename iterator_adaptor_get_base::type x_iterator_base_t; Chris@16: x_iterator_t sit(x_iterator_base_t(&(src(0,0)[n])),src.pixels().pixel_size()); Chris@16: return type(src.dimensions(),locator_t(sit, src.pixels().row_size())); Chris@16: } Chris@16: }; Chris@16: Chris@16: // nth_channel_view when the channels are together in memory (true for simple grayscale or planar images) Chris@16: template Chris@16: struct __nth_channel_view_basic { Chris@16: typedef typename view_type::type, gray_layout_t, false, false, view_is_mutable::value>::type type; Chris@16: static type make(const View& src, int n) { Chris@16: typedef typename type::x_iterator x_iterator_t; Chris@16: return interleaved_view(src.width(),src.height(),(x_iterator_t)&(src(0,0)[n]), src.pixels().row_size()); Chris@16: } Chris@16: }; Chris@16: Chris@16: template struct __nth_channel_view; Chris@16: Chris@16: // For basic (memory-based) views dispatch to __nth_channel_view_basic Chris@16: template struct __nth_channel_view { Chris@16: private: Chris@16: typedef typename View::x_iterator src_x_iterator; Chris@16: Chris@16: // Determines whether the channels of a given pixel iterator are adjacent in memory. Chris@16: // Planar and grayscale iterators have channels adjacent in memory, whereas multi-channel interleaved and iterators with non-fundamental step do not. Chris@16: BOOST_STATIC_CONSTANT(bool, adjacent= Chris@16: !iterator_is_step::value && Chris@16: (is_planar::value || Chris@16: num_channels::value==1)); Chris@16: public: Chris@16: typedef typename __nth_channel_view_basic::type type; Chris@16: Chris@16: static type make(const View& src, int n) { Chris@16: return __nth_channel_view_basic::make(src,n); Chris@16: } Chris@16: }; Chris@16: Chris@16: /// \brief Function object that returns a grayscale reference of the N-th channel of a given reference. Models: PixelDereferenceAdaptorConcept. Chris@16: /// \ingroup PixelDereferenceAdaptorModel Chris@16: /// Chris@16: /// If the input is a pixel value or constant reference, the function object is immutable. Otherwise it is mutable (and returns non-const reference to the n-th channel) Chris@16: template // SrcP is a reference to PixelConcept (could be pixel value or const/non-const reference) Chris@16: // Examples: pixel, pixel&, const pixel&, planar_pixel_reference, planar_pixel_reference Chris@16: struct nth_channel_deref_fn { Chris@16: BOOST_STATIC_CONSTANT(bool, is_mutable=pixel_is_reference::value && pixel_reference_is_mutable::value); Chris@16: private: Chris@16: typedef typename remove_reference::type src_pixel_t; Chris@16: typedef typename channel_type::type channel_t; Chris@16: typedef typename src_pixel_t::const_reference const_ref_t; Chris@16: typedef typename pixel_reference_type::type ref_t; Chris@16: public: Chris@16: typedef nth_channel_deref_fn const_t; Chris@16: typedef typename pixel_value_type::type value_type; Chris@16: typedef typename pixel_reference_type::type const_reference; Chris@16: typedef SrcP argument_type; Chris@16: typedef typename mpl::if_c::type reference; Chris@16: typedef reference result_type; Chris@16: Chris@16: nth_channel_deref_fn(int n=0) : _n(n) {} Chris@16: template nth_channel_deref_fn(const nth_channel_deref_fn

& d) : _n(d._n) {} Chris@16: Chris@16: int _n; // the channel to use Chris@16: Chris@16: result_type operator()(argument_type srcP) const { Chris@16: return result_type(srcP[_n]); Chris@16: } Chris@16: }; Chris@16: Chris@16: template struct __nth_channel_view { Chris@16: private: Chris@16: typedef nth_channel_deref_fn deref_t; Chris@16: typedef typename View::template add_deref AD; Chris@16: public: Chris@16: typedef typename AD::type type; Chris@16: static type make(const View& src, int n) { Chris@16: return AD::make(src, deref_t(n)); Chris@16: } Chris@16: }; Chris@16: } // namespace detail Chris@16: Chris@16: /// \brief Given a source image view type View, returns the type of an image view over a single channel of View Chris@16: /// \ingroup ImageViewTransformationsNthChannel Chris@16: /// Chris@16: /// If the channels in the source view are adjacent in memory (such as planar non-step view or single-channel view) then the Chris@16: /// return view is a single-channel non-step view. Chris@16: /// If the channels are non-adjacent (interleaved and/or step view) then the return view is a single-channel step view. Chris@16: template Chris@16: struct nth_channel_view_type { Chris@16: private: Chris@16: GIL_CLASS_REQUIRE(View, boost::gil, ImageViewConcept) Chris@16: typedef detail::__nth_channel_view::value> VB; Chris@16: public: Chris@16: typedef typename VB::type type; Chris@16: static type make(const View& src, int n) { return VB::make(src,n); } Chris@16: }; Chris@16: Chris@16: Chris@16: /// \ingroup ImageViewTransformationsNthChannel Chris@16: template Chris@16: typename nth_channel_view_type::type nth_channel_view(const View& src, int n) { Chris@16: return nth_channel_view_type::make(src,n); Chris@16: } Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: /// \defgroup ImageViewTransformationsKthChannel kth_channel_view Chris@16: /// \ingroup ImageViewTransformations Chris@16: /// \brief single-channel (grayscale) view of the K-th channel of a given image_view. The channel index is a template parameter Chris@16: Chris@16: namespace detail { Chris@16: template struct __kth_channel_view_basic; Chris@16: Chris@16: // kth_channel_view when the channels are not adjacent in memory. This can happen for multi-channel interleaved images Chris@16: // or images with a step Chris@16: template Chris@16: struct __kth_channel_view_basic { Chris@16: private: Chris@16: typedef typename kth_element_type::type channel_t; Chris@16: public: Chris@16: typedef typename view_type::value>::type type; Chris@16: Chris@16: static type make(const View& src) { Chris@16: typedef typename type::xy_locator locator_t; Chris@16: typedef typename type::x_iterator x_iterator_t; Chris@16: typedef typename iterator_adaptor_get_base::type x_iterator_base_t; Chris@16: x_iterator_t sit(x_iterator_base_t(&gil::at_c(src(0,0))),src.pixels().pixel_size()); Chris@16: return type(src.dimensions(),locator_t(sit, src.pixels().row_size())); Chris@16: } Chris@16: }; Chris@16: Chris@16: // kth_channel_view when the channels are together in memory (true for simple grayscale or planar images) Chris@16: template Chris@16: struct __kth_channel_view_basic { Chris@16: private: Chris@16: typedef typename kth_element_type::type channel_t; Chris@16: public: Chris@16: typedef typename view_type::value>::type type; Chris@16: static type make(const View& src) { Chris@16: typedef typename type::x_iterator x_iterator_t; Chris@16: return interleaved_view(src.width(),src.height(),(x_iterator_t)&gil::at_c(src(0,0)), src.pixels().row_size()); Chris@16: } Chris@16: }; Chris@16: Chris@16: template struct __kth_channel_view; Chris@16: Chris@16: // For basic (memory-based) views dispatch to __kth_channel_view_basic Chris@16: template struct __kth_channel_view { Chris@16: private: Chris@16: typedef typename View::x_iterator src_x_iterator; Chris@16: Chris@16: // Determines whether the channels of a given pixel iterator are adjacent in memory. Chris@16: // Planar and grayscale iterators have channels adjacent in memory, whereas multi-channel interleaved and iterators with non-fundamental step do not. Chris@16: BOOST_STATIC_CONSTANT(bool, adjacent= Chris@16: !iterator_is_step::value && Chris@16: (is_planar::value || Chris@16: num_channels::value==1)); Chris@16: public: Chris@16: typedef typename __kth_channel_view_basic::type type; Chris@16: Chris@16: static type make(const View& src) { Chris@16: return __kth_channel_view_basic::make(src); Chris@16: } Chris@16: }; Chris@16: Chris@16: /// \brief Function object that returns a grayscale reference of the K-th channel (specified as a template parameter) of a given reference. Models: PixelDereferenceAdaptorConcept. Chris@16: /// \ingroup PixelDereferenceAdaptorModel Chris@16: /// Chris@16: /// If the input is a pixel value or constant reference, the function object is immutable. Otherwise it is mutable (and returns non-const reference to the k-th channel) Chris@16: template // SrcP is a reference to PixelConcept (could be pixel value or const/non-const reference) Chris@16: // Examples: pixel, pixel&, const pixel&, planar_pixel_reference, planar_pixel_reference Chris@16: struct kth_channel_deref_fn { Chris@16: BOOST_STATIC_CONSTANT(bool, is_mutable=pixel_is_reference::value && pixel_reference_is_mutable::value); Chris@16: private: Chris@16: typedef typename remove_reference::type src_pixel_t; Chris@16: typedef typename kth_element_type::type channel_t; Chris@16: typedef typename src_pixel_t::const_reference const_ref_t; Chris@16: typedef typename pixel_reference_type::type ref_t; Chris@16: public: Chris@16: typedef kth_channel_deref_fn const_t; Chris@16: typedef typename pixel_value_type::type value_type; Chris@16: typedef typename pixel_reference_type::type const_reference; Chris@16: typedef SrcP argument_type; Chris@16: typedef typename mpl::if_c::type reference; Chris@16: typedef reference result_type; Chris@16: Chris@16: kth_channel_deref_fn() {} Chris@16: template kth_channel_deref_fn(const kth_channel_deref_fn&) {} Chris@16: Chris@16: result_type operator()(argument_type srcP) const { Chris@16: return result_type(gil::at_c(srcP)); Chris@16: } Chris@16: }; Chris@16: Chris@16: template struct __kth_channel_view { Chris@16: private: Chris@16: typedef kth_channel_deref_fn deref_t; Chris@16: typedef typename View::template add_deref AD; Chris@16: public: Chris@16: typedef typename AD::type type; Chris@16: static type make(const View& src) { Chris@16: return AD::make(src, deref_t()); Chris@16: } Chris@16: }; Chris@16: } // namespace detail Chris@16: Chris@16: /// \brief Given a source image view type View, returns the type of an image view over a given channel of View. Chris@16: /// \ingroup ImageViewTransformationsKthChannel Chris@16: /// Chris@16: /// If the channels in the source view are adjacent in memory (such as planar non-step view or single-channel view) then the Chris@16: /// return view is a single-channel non-step view. Chris@16: /// If the channels are non-adjacent (interleaved and/or step view) then the return view is a single-channel step view. Chris@16: template Chris@16: struct kth_channel_view_type { Chris@16: private: Chris@16: GIL_CLASS_REQUIRE(View, boost::gil, ImageViewConcept) Chris@16: typedef detail::__kth_channel_view::value> VB; Chris@16: public: Chris@16: typedef typename VB::type type; Chris@16: static type make(const View& src) { return VB::make(src); } Chris@16: }; Chris@16: Chris@16: /// \ingroup ImageViewTransformationsKthChannel Chris@16: template Chris@16: typename kth_channel_view_type::type kth_channel_view(const View& src) { Chris@16: return kth_channel_view_type::make(src); Chris@16: } Chris@16: Chris@16: } } // namespace boost::gil Chris@16: Chris@16: #endif