Skip to content

Commit 6121765

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 36a45e3 commit 6121765

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>
@@ -304,7 +305,7 @@ struct nth_channel_view_type<any_image_view<Views...>>
304305
/// \tparam Views Models Boost.MP11-compatible list of models of ImageViewConcept
305306
template <typename ...Views>
306307
inline
307-
auto nth_channel_view(const any_image_view<Views...>& src, int n)
308+
auto nth_channel_view(const any_image_view<Views...>& src, std::size_t n)
308309
-> typename nth_channel_view_type<any_image_view<Views...>>::type
309310
{
310311
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
@@ -309,7 +309,7 @@ namespace detail {
309309
struct __nth_channel_view_basic<View,false> {
310310
using type = typename view_type<typename channel_type<View>::type, gray_layout_t, false, true, view_is_mutable<View>::value>::type;
311311

312-
static type make(const View& src, int n) {
312+
static type make(const View& src, std::size_t n) {
313313
using locator_t = typename type::xy_locator;
314314
using x_iterator_t = typename type::x_iterator;
315315
using x_iterator_base_t = typename iterator_adaptor_get_base<x_iterator_t>::type;
@@ -322,7 +322,7 @@ namespace detail {
322322
template <typename View>
323323
struct __nth_channel_view_basic<View,true> {
324324
using type = typename view_type<typename channel_type<View>::type, gray_layout_t, false, false, view_is_mutable<View>::value>::type;
325-
static type make(const View& src, int n) {
325+
static type make(const View& src, std::size_t n) {
326326
using x_iterator_t = typename type::x_iterator;
327327
return interleaved_view(src.width(),src.height(),(x_iterator_t)&(src(0,0)[n]), src.pixels().row_size());
328328
}
@@ -346,7 +346,7 @@ namespace detail {
346346
public:
347347
using type = typename __nth_channel_view_basic<View,adjacent>::type;
348348

349-
static type make(const View& src, int n) {
349+
static type make(const View& src, std::size_t n) {
350350
return __nth_channel_view_basic<View,adjacent>::make(src,n);
351351
}
352352
};
@@ -374,10 +374,10 @@ namespace detail {
374374
using reference = mp11::mp_if_c<is_mutable, ref_t, value_type>;
375375
using result_type = reference;
376376

377-
nth_channel_deref_fn(int n=0) : _n(n) {}
377+
nth_channel_deref_fn(std::size_t n=0) : _n(n) {}
378378
template <typename P> nth_channel_deref_fn(const nth_channel_deref_fn<P>& d) : _n(d._n) {}
379379

380-
int _n; // the channel to use
380+
std::size_t _n; // the channel to use
381381

382382
result_type operator()(argument_type srcP) const {
383383
return result_type(srcP[_n]);
@@ -390,7 +390,7 @@ namespace detail {
390390
using AD = typename View::template add_deref<deref_t>;
391391
public:
392392
using type = typename AD::type;
393-
static type make(const View& src, int n) {
393+
static type make(const View& src, std::size_t n) {
394394
return AD::make(src, deref_t(n));
395395
}
396396
};
@@ -409,13 +409,13 @@ struct nth_channel_view_type {
409409
using VB = detail::__nth_channel_view<View,view_is_basic<View>::value>;
410410
public:
411411
using type = typename VB::type;
412-
static type make(const View& src, int n) { return VB::make(src,n); }
412+
static type make(const View& src, std::size_t n) { return VB::make(src,n); }
413413
};
414414

415415

416416
/// \ingroup ImageViewTransformationsNthChannel
417417
template <typename View>
418-
typename nth_channel_view_type<View>::type nth_channel_view(const View& src, int n) {
418+
typename nth_channel_view_type<View>::type nth_channel_view(const View& src, std::size_t n) {
419419
return nth_channel_view_type<View>::make(src,n);
420420
}
421421

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

432432
namespace detail {
433-
template <int K, typename View, bool AreChannelsTogether> struct __kth_channel_view_basic;
433+
template <std::size_t K, typename View, bool AreChannelsTogether> struct __kth_channel_view_basic;
434434

435435
// kth_channel_view when the channels are not adjacent in memory. This can happen for multi-channel interleaved images
436436
// or images with a step
437-
template <int K, typename View>
437+
template <std::size_t K, typename View>
438438
struct __kth_channel_view_basic<K,View,false> {
439439
private:
440440
using channel_t = typename kth_element_type<typename View::value_type,K>::type;
@@ -451,7 +451,7 @@ namespace detail {
451451
};
452452

453453
// kth_channel_view when the channels are together in memory (true for simple grayscale or planar images)
454-
template <int K, typename View>
454+
template <std::size_t K, typename View>
455455
struct __kth_channel_view_basic<K,View,true> {
456456
private:
457457
using channel_t = typename kth_element_type<typename View::value_type, K>::type;
@@ -463,10 +463,10 @@ namespace detail {
463463
}
464464
};
465465

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

468468
// For basic (memory-based) views dispatch to __kth_channel_view_basic
469-
template <int K, typename View> struct __kth_channel_view<K,View,true>
469+
template <std::size_t K, typename View> struct __kth_channel_view<K,View,true>
470470
{
471471
private:
472472
using src_x_iterator = typename View::x_iterator;
@@ -491,7 +491,7 @@ namespace detail {
491491
/// 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)
492492
/// \tparam SrcP reference to PixelConcept (could be pixel value or const/non-const reference)
493493
/// Examples: pixel<T,L>, pixel<T,L>&, const pixel<T,L>&, planar_pixel_reference<T&,L>, planar_pixel_reference<const T&,L>
494-
template <int K, typename SrcP>
494+
template <std::size_t K, typename SrcP>
495495
struct kth_channel_deref_fn
496496
{
497497
static constexpr bool is_mutable =
@@ -519,7 +519,7 @@ namespace detail {
519519
}
520520
};
521521

522-
template <int K, typename View> struct __kth_channel_view<K,View,false> {
522+
template <std::size_t K, typename View> struct __kth_channel_view<K,View,false> {
523523
private:
524524
using deref_t = kth_channel_deref_fn<K,typename View::reference>;
525525
using AD = typename View::template add_deref<deref_t>;
@@ -537,7 +537,7 @@ namespace detail {
537537
/// If the channels in the source view are adjacent in memory (such as planar non-step view or single-channel view) then the
538538
/// return view is a single-channel non-step view.
539539
/// If the channels are non-adjacent (interleaved and/or step view) then the return view is a single-channel step view.
540-
template <int K, typename View>
540+
template <std::size_t K, typename View>
541541
struct kth_channel_view_type {
542542
private:
543543
BOOST_GIL_CLASS_REQUIRE(View, boost::gil, ImageViewConcept)
@@ -548,7 +548,7 @@ struct kth_channel_view_type {
548548
};
549549

550550
/// \ingroup ImageViewTransformationsKthChannel
551-
template <int K, typename View>
551+
template <std::size_t K, typename View>
552552
typename kth_channel_view_type<K,View>::type kth_channel_view(const View& src) {
553553
return kth_channel_view_type<K,View>::make(src);
554554
}

0 commit comments

Comments
 (0)