Skip to content

Commit d2d5c37

Browse files
committed
use std::size_t as channel index type in nth_channel_view
This unifies the channel index type in nth_channel_view and image_view::num_channels - the latter one already uses std::size_t. Fixes #373.
1 parent 2c3ee86 commit d2d5c37

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-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
@@ -15,6 +15,7 @@
1515
#include <boost/gil/point.hpp>
1616
#include <boost/gil/detail/mp11.hpp>
1717

18+
#include <cstddef>
1819
#include <cstdint>
1920

2021
namespace boost { namespace gil {
@@ -136,15 +137,15 @@ struct nth_channel_view_fn
136137
{
137138
using result_type = ResultView;
138139

139-
nth_channel_view_fn(int n) : _n(n) {}
140+
nth_channel_view_fn(std::size_t n) : _n(n) {}
140141

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

147-
int _n;
148+
std::size_t _n;
148149
};
149150

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

include/boost/gil/image_view_factory.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ namespace detail {
338338
struct __nth_channel_view_basic<View,false> {
339339
using type = typename view_type<typename channel_type<View>::type, gray_layout_t, false, true, view_is_mutable<View>::value>::type;
340340

341-
static type make(View const& src, int n) {
341+
static type make(View const& src, std::size_t n) {
342342
using locator_t = typename type::xy_locator;
343343
using x_iterator_t = typename type::x_iterator;
344344
using x_iterator_base_t = typename iterator_adaptor_get_base<x_iterator_t>::type;
@@ -351,7 +351,7 @@ namespace detail {
351351
template <typename View>
352352
struct __nth_channel_view_basic<View,true> {
353353
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, int n) {
354+
static type make(View const& src, std::size_t n) {
355355
using x_iterator_t = typename type::x_iterator;
356356
return interleaved_view(src.width(),src.height(),(x_iterator_t)&(src(0,0)[n]), src.pixels().row_size());
357357
}
@@ -375,7 +375,7 @@ namespace detail {
375375
public:
376376
using type = typename __nth_channel_view_basic<View,adjacent>::type;
377377

378-
static type make(View const& src, int n) {
378+
static type make(View const& src, std::size_t n) {
379379
return __nth_channel_view_basic<View,adjacent>::make(src,n);
380380
}
381381
};
@@ -403,11 +403,11 @@ namespace detail {
403403
using reference = mp11::mp_if_c<is_mutable, ref_t, value_type>;
404404
using result_type = reference;
405405

406-
nth_channel_deref_fn(int n=0) : _n(n) {}
406+
nth_channel_deref_fn(std::size_t n=0) : _n(n) {}
407407
template <typename P>
408408
nth_channel_deref_fn(const nth_channel_deref_fn<P>& d) : _n(d._n) {}
409409

410-
int _n; // the channel to use
410+
std::size_t _n; // the channel to use
411411

412412
auto operator()(argument_type srcP) const -> result_type
413413
{
@@ -421,7 +421,7 @@ namespace detail {
421421
using AD = typename View::template add_deref<deref_t>;
422422
public:
423423
using type = typename AD::type;
424-
static type make(View const& src, int n) {
424+
static type make(View const& src, std::size_t n) {
425425
return AD::make(src, deref_t(n));
426426
}
427427
};
@@ -440,12 +440,12 @@ struct nth_channel_view_type {
440440
using VB = detail::__nth_channel_view<View,view_is_basic<View>::value>;
441441
public:
442442
using type = typename VB::type;
443-
static type make(View const& src, int n) { return VB::make(src,n); }
443+
static type make(View const& src, std::size_t n) { return VB::make(src,n); }
444444
};
445445

446446
/// \ingroup ImageViewTransformationsNthChannel
447447
template <typename View>
448-
typename nth_channel_view_type<View>::type nth_channel_view(View const& src, int n) {
448+
typename nth_channel_view_type<View>::type nth_channel_view(View const& src, std::size_t n) {
449449
return nth_channel_view_type<View>::make(src,n);
450450
}
451451

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

456456
namespace detail {
457-
template <int K, typename View, bool AreChannelsTogether> struct __kth_channel_view_basic;
457+
template <std::size_t K, typename View, bool AreChannelsTogether> struct __kth_channel_view_basic;
458458

459459
// kth_channel_view when the channels are not adjacent in memory. This can happen for multi-channel interleaved images
460460
// or images with a step
461-
template <int K, typename View>
461+
template <std::size_t K, typename View>
462462
struct __kth_channel_view_basic<K,View,false> {
463463
private:
464464
using channel_t = typename kth_element_type<typename View::value_type,K>::type;
@@ -475,7 +475,7 @@ namespace detail {
475475
};
476476

477477
// kth_channel_view when the channels are together in memory (true for simple grayscale or planar images)
478-
template <int K, typename View>
478+
template <std::size_t K, typename View>
479479
struct __kth_channel_view_basic<K,View,true> {
480480
private:
481481
using channel_t = typename kth_element_type<typename View::value_type, K>::type;
@@ -487,10 +487,10 @@ namespace detail {
487487
}
488488
};
489489

490-
template <int K, typename View, bool IsBasic> struct __kth_channel_view;
490+
template <std::size_t K, typename View, bool IsBasic> struct __kth_channel_view;
491491

492492
// For basic (memory-based) views dispatch to __kth_channel_view_basic
493-
template <int K, typename View> struct __kth_channel_view<K,View,true>
493+
template <std::size_t K, typename View> struct __kth_channel_view<K,View,true>
494494
{
495495
private:
496496
using src_x_iterator = typename View::x_iterator;
@@ -515,7 +515,7 @@ namespace detail {
515515
/// 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)
516516
/// \tparam SrcP reference to PixelConcept (could be pixel value or const/non-const reference)
517517
/// Examples: pixel<T,L>, pixel<T,L>&, const pixel<T,L>&, planar_pixel_reference<T&,L>, planar_pixel_reference<const T&,L>
518-
template <int K, typename SrcP>
518+
template <std::size_t K, typename SrcP>
519519
struct kth_channel_deref_fn
520520
{
521521
static constexpr bool is_mutable =
@@ -544,7 +544,7 @@ namespace detail {
544544
}
545545
};
546546

547-
template <int K, typename View> struct __kth_channel_view<K,View,false> {
547+
template <std::size_t K, typename View> struct __kth_channel_view<K,View,false> {
548548
private:
549549
using deref_t = kth_channel_deref_fn<K,typename View::reference>;
550550
using AD = typename View::template add_deref<deref_t>;
@@ -562,7 +562,7 @@ namespace detail {
562562
/// If the channels in the source view are adjacent in memory (such as planar non-step view or single-channel view) then the
563563
/// return view is a single-channel non-step view.
564564
/// If the channels are non-adjacent (interleaved and/or step view) then the return view is a single-channel step view.
565-
template <int K, typename View>
565+
template <std::size_t K, typename View>
566566
struct kth_channel_view_type {
567567
private:
568568
BOOST_GIL_CLASS_REQUIRE(View, boost::gil, ImageViewConcept)
@@ -573,7 +573,7 @@ struct kth_channel_view_type {
573573
};
574574

575575
/// \ingroup ImageViewTransformationsKthChannel
576-
template <int K, typename View>
576+
template <std::size_t K, typename View>
577577
auto kth_channel_view(View const& src)
578578
-> typename kth_channel_view_type<K,View>::type
579579
{

0 commit comments

Comments
 (0)