Skip to content

Commit 5fa0eb8

Browse files
committed
switch channel index type in nth_channel_view to boost::gil::index_t
1 parent d7b3a7d commit 5fa0eb8

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

include/boost/gil/extension/dynamic_image/image_view_factory.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <boost/gil/dynamic_step.hpp>
1414
#include <boost/gil/image_view_factory.hpp>
1515
#include <boost/gil/point.hpp>
16+
#include <boost/gil/typedefs.hpp>
1617
#include <boost/gil/detail/mp11.hpp>
1718

1819
#include <cstddef>
@@ -137,15 +138,15 @@ struct nth_channel_view_fn
137138
{
138139
using result_type = ResultView;
139140

140-
nth_channel_view_fn(std::size_t n) : _n(n) {}
141+
nth_channel_view_fn(index_t n) : _n(n) {}
141142

142143
template <typename View>
143144
auto operator()(View const& src) const -> result_type
144145
{
145146
return result_type(nth_channel_view(src,_n));
146147
}
147148

148-
std::size_t _n;
149+
index_t _n;
149150
};
150151

151152
template <typename DstP, typename ResultView, typename CC = default_color_converter>
@@ -306,7 +307,7 @@ struct nth_channel_view_type<any_image_view<Views...>>
306307
/// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
307308
template <typename ...Views>
308309
inline
309-
auto nth_channel_view(any_image_view<Views...> const& src, std::size_t n)
310+
auto nth_channel_view(any_image_view<Views...> const& src, index_t n)
310311
-> typename nth_channel_view_type<any_image_view<Views...>>::type
311312
{
312313
using result_view_t = typename nth_channel_view_type<any_image_view<Views...>>::type;

include/boost/gil/image_view_factory.hpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <boost/gil/image_view.hpp>
1515
#include <boost/gil/metafunctions.hpp>
1616
#include <boost/gil/point.hpp>
17+
#include <boost/gil/typedefs.hpp>
1718
#include <boost/gil/detail/mp11.hpp>
1819

1920
#include <boost/assert.hpp>
@@ -338,7 +339,7 @@ namespace detail {
338339
struct __nth_channel_view_basic<View,false> {
339340
using type = typename view_type<typename channel_type<View>::type, gray_layout_t, false, true, view_is_mutable<View>::value>::type;
340341

341-
static type make(View const& src, std::size_t n) {
342+
static type make(View const& src, index_t n) {
342343
using locator_t = typename type::xy_locator;
343344
using x_iterator_t = typename type::x_iterator;
344345
using x_iterator_base_t = typename iterator_adaptor_get_base<x_iterator_t>::type;
@@ -351,7 +352,7 @@ namespace detail {
351352
template <typename View>
352353
struct __nth_channel_view_basic<View,true> {
353354
using type = typename view_type<typename channel_type<View>::type, gray_layout_t, false, false, view_is_mutable<View>::value>::type;
354-
static type make(View const& src, std::size_t n) {
355+
static type make(View const& src, index_t n) {
355356
using x_iterator_t = typename type::x_iterator;
356357
return interleaved_view(src.width(),src.height(),(x_iterator_t)&(src(0,0)[n]), src.pixels().row_size());
357358
}
@@ -375,7 +376,7 @@ namespace detail {
375376
public:
376377
using type = typename __nth_channel_view_basic<View,adjacent>::type;
377378

378-
static type make(View const& src, std::size_t n) {
379+
static type make(View const& src, index_t n) {
379380
return __nth_channel_view_basic<View,adjacent>::make(src,n);
380381
}
381382
};
@@ -403,11 +404,11 @@ namespace detail {
403404
using reference = mp11::mp_if_c<is_mutable, ref_t, value_type>;
404405
using result_type = reference;
405406

406-
nth_channel_deref_fn(std::size_t n=0) : _n(n) {}
407+
nth_channel_deref_fn(index_t n=0) : _n(n) {}
407408
template <typename P>
408409
nth_channel_deref_fn(const nth_channel_deref_fn<P>& d) : _n(d._n) {}
409410

410-
std::size_t _n; // the channel to use
411+
index_t _n; // the channel to use
411412

412413
auto operator()(argument_type srcP) const -> result_type
413414
{
@@ -421,7 +422,7 @@ namespace detail {
421422
using AD = typename View::template add_deref<deref_t>;
422423
public:
423424
using type = typename AD::type;
424-
static type make(View const& src, std::size_t n) {
425+
static type make(View const& src, index_t n) {
425426
return AD::make(src, deref_t(n));
426427
}
427428
};
@@ -440,12 +441,12 @@ struct nth_channel_view_type {
440441
using VB = detail::__nth_channel_view<View,view_is_basic<View>::value>;
441442
public:
442443
using type = typename VB::type;
443-
static type make(View const& src, std::size_t n) { return VB::make(src,n); }
444+
static type make(View const& src, index_t n) { return VB::make(src,n); }
444445
};
445446

446447
/// \ingroup ImageViewTransformationsNthChannel
447448
template <typename View>
448-
typename nth_channel_view_type<View>::type nth_channel_view(View const& src, std::size_t n) {
449+
typename nth_channel_view_type<View>::type nth_channel_view(View const& src, index_t n) {
449450
return nth_channel_view_type<View>::make(src,n);
450451
}
451452

@@ -454,11 +455,11 @@ typename nth_channel_view_type<View>::type nth_channel_view(View const& src, std
454455
/// \brief single-channel (grayscale) view of the K-th channel of a given image_view. The channel index is a template parameter
455456

456457
namespace detail {
457-
template <std::size_t K, typename View, bool AreChannelsTogether> struct __kth_channel_view_basic;
458+
template <index_t K, typename View, bool AreChannelsTogether> struct __kth_channel_view_basic;
458459

459460
// kth_channel_view when the channels are not adjacent in memory. This can happen for multi-channel interleaved images
460461
// or images with a step
461-
template <std::size_t K, typename View>
462+
template <index_t K, typename View>
462463
struct __kth_channel_view_basic<K,View,false> {
463464
private:
464465
using channel_t = typename kth_element_type<typename View::value_type,K>::type;
@@ -475,7 +476,7 @@ namespace detail {
475476
};
476477

477478
// kth_channel_view when the channels are together in memory (true for simple grayscale or planar images)
478-
template <std::size_t K, typename View>
479+
template <index_t K, typename View>
479480
struct __kth_channel_view_basic<K,View,true> {
480481
private:
481482
using channel_t = typename kth_element_type<typename View::value_type, K>::type;
@@ -487,10 +488,10 @@ namespace detail {
487488
}
488489
};
489490

490-
template <std::size_t K, typename View, bool IsBasic> struct __kth_channel_view;
491+
template <index_t K, typename View, bool IsBasic> struct __kth_channel_view;
491492

492493
// For basic (memory-based) views dispatch to __kth_channel_view_basic
493-
template <std::size_t K, typename View> struct __kth_channel_view<K,View,true>
494+
template <index_t K, typename View> struct __kth_channel_view<K,View,true>
494495
{
495496
private:
496497
using src_x_iterator = typename View::x_iterator;
@@ -515,7 +516,7 @@ namespace detail {
515516
/// 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)
516517
/// \tparam SrcP reference to PixelConcept (could be pixel value or const/non-const reference)
517518
/// Examples: pixel<T,L>, pixel<T,L>&, const pixel<T,L>&, planar_pixel_reference<T&,L>, planar_pixel_reference<const T&,L>
518-
template <std::size_t K, typename SrcP>
519+
template <index_t K, typename SrcP>
519520
struct kth_channel_deref_fn
520521
{
521522
static constexpr bool is_mutable =
@@ -544,7 +545,7 @@ namespace detail {
544545
}
545546
};
546547

547-
template <std::size_t K, typename View> struct __kth_channel_view<K,View,false> {
548+
template <index_t K, typename View> struct __kth_channel_view<K,View,false> {
548549
private:
549550
using deref_t = kth_channel_deref_fn<K,typename View::reference>;
550551
using AD = typename View::template add_deref<deref_t>;
@@ -562,7 +563,7 @@ namespace detail {
562563
/// If the channels in the source view are adjacent in memory (such as planar non-step view or single-channel view) then the
563564
/// return view is a single-channel non-step view.
564565
/// If the channels are non-adjacent (interleaved and/or step view) then the return view is a single-channel step view.
565-
template <std::size_t K, typename View>
566+
template <index_t K, typename View>
566567
struct kth_channel_view_type {
567568
private:
568569
BOOST_GIL_CLASS_REQUIRE(View, boost::gil, ImageViewConcept)
@@ -573,7 +574,7 @@ struct kth_channel_view_type {
573574
};
574575

575576
/// \ingroup ImageViewTransformationsKthChannel
576-
template <std::size_t K, typename View>
577+
template <index_t K, typename View>
577578
auto kth_channel_view(View const& src)
578579
-> typename kth_channel_view_type<K,View>::type
579580
{

include/boost/gil/typedefs.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//
22
// Copyright 2005-2007 Adobe Systems Incorporated
33
// Copyright 2018 Mateusz Loskot <[email protected]>
4+
// Copyright 2022 Dirk Stolle
45
//
56
// Use, modification and distribution are subject to the Boost Software License,
67
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -16,6 +17,7 @@
1617
#include <boost/gil/rgb.hpp>
1718
#include <boost/gil/rgba.hpp>
1819

20+
#include <cstddef>
1921
#include <cstdint>
2022
#include <memory>
2123
#if !defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
@@ -120,6 +122,9 @@ template <typename B, typename Mn, typename Mx> struct scoped_channel_value;
120122
template <typename T> struct float_point_zero;
121123
template <typename T> struct float_point_one;
122124

125+
// general-purpose index type
126+
using index_t = std::ptrdiff_t;
127+
123128
//////////////////////////////////////////////////////////////////////////////////////////
124129
/// Built-in channel models
125130
//////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)