From f0109b4224f86bcefe0edf623494aa622d2f8cf1 Mon Sep 17 00:00:00 2001 From: Dirk Stolle Date: Tue, 31 May 2022 17:03:16 +0200 Subject: [PATCH] switch channel index type in nth_channel_view to boost::gil::index_t --- .../dynamic_image/image_view_factory.hpp | 7 ++-- include/boost/gil/image_view_factory.hpp | 35 ++++++++++--------- include/boost/gil/typedefs.hpp | 5 +++ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/include/boost/gil/extension/dynamic_image/image_view_factory.hpp b/include/boost/gil/extension/dynamic_image/image_view_factory.hpp index 8d883f165d..0559db202f 100644 --- a/include/boost/gil/extension/dynamic_image/image_view_factory.hpp +++ b/include/boost/gil/extension/dynamic_image/image_view_factory.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -137,7 +138,7 @@ struct nth_channel_view_fn { using result_type = ResultView; - nth_channel_view_fn(std::size_t n) : _n(n) {} + nth_channel_view_fn(index_t n) : _n(n) {} template auto operator()(View const& src) const -> result_type @@ -145,7 +146,7 @@ struct nth_channel_view_fn return result_type(nth_channel_view(src,_n)); } - std::size_t _n; + index_t _n; }; template @@ -306,7 +307,7 @@ struct nth_channel_view_type> /// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept template inline -auto nth_channel_view(any_image_view const& src, std::size_t n) +auto nth_channel_view(any_image_view const& src, index_t n) -> typename nth_channel_view_type>::type { using result_view_t = typename nth_channel_view_type>::type; diff --git a/include/boost/gil/image_view_factory.hpp b/include/boost/gil/image_view_factory.hpp index 2aedbff14c..4fe8327cf0 100644 --- a/include/boost/gil/image_view_factory.hpp +++ b/include/boost/gil/image_view_factory.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -309,7 +310,7 @@ namespace detail { struct __nth_channel_view_basic { using type = typename view_type::type, gray_layout_t, false, true, view_is_mutable::value>::type; - static type make(const View& src, std::size_t n) { + static type make(const View& src, index_t n) { using locator_t = typename type::xy_locator; using x_iterator_t = typename type::x_iterator; using x_iterator_base_t = typename iterator_adaptor_get_base::type; @@ -322,7 +323,7 @@ namespace detail { template struct __nth_channel_view_basic { using type = typename view_type::type, gray_layout_t, false, false, view_is_mutable::value>::type; - static type make(const View& src, std::size_t n) { + static type make(const View& src, index_t n) { using x_iterator_t = typename type::x_iterator; return interleaved_view(src.width(),src.height(),(x_iterator_t)&(src(0,0)[n]), src.pixels().row_size()); } @@ -346,7 +347,7 @@ namespace detail { public: using type = typename __nth_channel_view_basic::type; - static type make(const View& src, std::size_t n) { + static type make(const View& src, index_t n) { return __nth_channel_view_basic::make(src,n); } }; @@ -374,10 +375,10 @@ namespace detail { using reference = mp11::mp_if_c; using result_type = reference; - nth_channel_deref_fn(std::size_t n=0) : _n(n) {} + nth_channel_deref_fn(index_t n=0) : _n(n) {} template nth_channel_deref_fn(const nth_channel_deref_fn

& d) : _n(d._n) {} - std::size_t _n; // the channel to use + index_t _n; // the channel to use result_type operator()(argument_type srcP) const { return result_type(srcP[_n]); @@ -390,7 +391,7 @@ namespace detail { using AD = typename View::template add_deref; public: using type = typename AD::type; - static type make(const View& src, std::size_t n) { + static type make(const View& src, index_t n) { return AD::make(src, deref_t(n)); } }; @@ -409,13 +410,13 @@ struct nth_channel_view_type { using VB = detail::__nth_channel_view::value>; public: using type = typename VB::type; - static type make(const View& src, std::size_t n) { return VB::make(src,n); } + static type make(const View& src, index_t n) { return VB::make(src,n); } }; /// \ingroup ImageViewTransformationsNthChannel template -typename nth_channel_view_type::type nth_channel_view(const View& src, std::size_t n) { +typename nth_channel_view_type::type nth_channel_view(const View& src, index_t n) { return nth_channel_view_type::make(src,n); } @@ -430,11 +431,11 @@ typename nth_channel_view_type::type nth_channel_view(const View& src, std /// \brief single-channel (grayscale) view of the K-th channel of a given image_view. The channel index is a template parameter namespace detail { - template struct __kth_channel_view_basic; + template struct __kth_channel_view_basic; // kth_channel_view when the channels are not adjacent in memory. This can happen for multi-channel interleaved images // or images with a step - template + template struct __kth_channel_view_basic { private: using channel_t = typename kth_element_type::type; @@ -451,7 +452,7 @@ namespace detail { }; // kth_channel_view when the channels are together in memory (true for simple grayscale or planar images) - template + template struct __kth_channel_view_basic { private: using channel_t = typename kth_element_type::type; @@ -463,10 +464,10 @@ namespace detail { } }; - template struct __kth_channel_view; + template struct __kth_channel_view; // For basic (memory-based) views dispatch to __kth_channel_view_basic - template struct __kth_channel_view + template struct __kth_channel_view { private: using src_x_iterator = typename View::x_iterator; @@ -491,7 +492,7 @@ namespace detail { /// 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) /// \tparam SrcP reference to PixelConcept (could be pixel value or const/non-const reference) /// Examples: pixel, pixel&, const pixel&, planar_pixel_reference, planar_pixel_reference - template + template struct kth_channel_deref_fn { static constexpr bool is_mutable = @@ -519,7 +520,7 @@ namespace detail { } }; - template struct __kth_channel_view { + template struct __kth_channel_view { private: using deref_t = kth_channel_deref_fn; using AD = typename View::template add_deref; @@ -537,7 +538,7 @@ namespace detail { /// If the channels in the source view are adjacent in memory (such as planar non-step view or single-channel view) then the /// return view is a single-channel non-step view. /// If the channels are non-adjacent (interleaved and/or step view) then the return view is a single-channel step view. -template +template struct kth_channel_view_type { private: BOOST_GIL_CLASS_REQUIRE(View, boost::gil, ImageViewConcept) @@ -548,7 +549,7 @@ struct kth_channel_view_type { }; /// \ingroup ImageViewTransformationsKthChannel -template +template typename kth_channel_view_type::type kth_channel_view(const View& src) { return kth_channel_view_type::make(src); } diff --git a/include/boost/gil/typedefs.hpp b/include/boost/gil/typedefs.hpp index 4ff10d52d7..7d732525af 100644 --- a/include/boost/gil/typedefs.hpp +++ b/include/boost/gil/typedefs.hpp @@ -1,6 +1,7 @@ // // Copyright 2005-2007 Adobe Systems Incorporated // Copyright 2018 Mateusz Loskot +// Copyright 2022 Dirk Stolle // // Use, modification and distribution are subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -16,6 +17,7 @@ #include #include +#include #include #include @@ -91,6 +93,9 @@ template struct scoped_channel_value; template struct float_point_zero; template struct float_point_one; +// general-purpose index type +using index_t = std::ptrdiff_t; + ////////////////////////////////////////////////////////////////////////////////////////// /// Built-in channel models //////////////////////////////////////////////////////////////////////////////////////////