9 #ifndef BOOST_GIL_PIXEL_HPP    10 #define BOOST_GIL_PIXEL_HPP    12 #include <boost/gil/channel.hpp>    13 #include <boost/gil/color_base.hpp>    14 #include <boost/gil/color_base_algorithm.hpp>    15 #include <boost/gil/concepts.hpp>    16 #include <boost/gil/metafunctions.hpp>    17 #include <boost/gil/utilities.hpp>    18 #include <boost/gil/detail/mp11.hpp>    21 #include <type_traits>    23 namespace boost { 
namespace gil {
    27 using gray_t = mp11::mp_list<gray_color_t>;
    28 template <
typename PixelBased> 
struct color_space_type;
    29 template <
typename PixelBased> 
struct channel_mapping_type;
    30 template <
typename PixelBased> 
struct channel_type;
    31 template <
typename PixelBased> 
struct is_planar;
    33 template <
typename PixelBased>
    34 struct color_space_type<PixelBased const> : color_space_type<PixelBased> {};
    36 template <
typename PixelBased>
    37 struct channel_mapping_type<PixelBased const> : channel_mapping_type<PixelBased> {};
    39 template <
typename PixelBased>
    40 struct channel_type<PixelBased const> : channel_type<PixelBased> {};
    42 template <
typename PixelBased>
    43 struct is_planar : std::false_type {};
    45 template <
typename PixelBased>
    46 struct is_planar<PixelBased const> : is_planar<PixelBased> {};
    48 template <
typename T> 
struct is_pixel : std::false_type {};
    49 template <
typename T> 
struct is_pixel<T const> : is_pixel<T> {};
    53 template <
typename PixelBased>
    54 struct num_channels : mp11::mp_size<typename color_space_type<PixelBased>::type>::type {};
    98 template <
typename ChannelValue, 
typename Layout>
   100     detail::homogeneous_color_base
   104         mp11::mp_size<typename Layout::color_space_t>::value
   108     using channel_t = ChannelValue;
   109     using parent_t = detail::homogeneous_color_base
   113             mp11::mp_size<typename Layout::color_space_t>::value
   116     using value_type = pixel<ChannelValue, Layout>;
   117     using reference = value_type&;
   118     using const_reference = value_type 
const&;
   119     static constexpr 
bool is_mutable = channel_traits<channel_t>::is_mutable;
   122     explicit pixel(channel_t v) : parent_t(v) {}  
   123     pixel(channel_t v0, channel_t v1) : parent_t(v0, v1) {}
   124     pixel(channel_t v0, channel_t v1, channel_t v2) : parent_t(v0, v1, v2) {}
   126     pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3)
   127         : parent_t(v0, v1, v2, v3)
   130     pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3, channel_t v4)
   131         : parent_t(v0, v1, v2, v3, v4)
   134     pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3, channel_t v4, channel_t v5)
   135         : parent_t(v0, v1, v2, v3, v4, v5)
   138     pixel(
const pixel& p) : parent_t(p) {}
   140     pixel& operator=(pixel 
const& p)
   142         static_copy(p,*
this);
   147     template <
typename Pixel>
   148     pixel(Pixel 
const& p,
   149         typename std::enable_if<is_pixel<Pixel>::value>::type*  = 
nullptr)
   152         check_compatible<Pixel>();
   155     template <
typename Pixel>
   156     pixel& operator=(Pixel 
const& p)
   158         assign(p, is_pixel<Pixel>());
   162     template <
typename Pixel>
   163     bool operator==(Pixel 
const& p)
 const { 
return equal(p, is_pixel<Pixel>()); }
   165     template <
typename Pixel>
   166     bool operator!=(Pixel 
const& p)
 const { 
return !(*
this == p); }
   169     auto operator[](std::size_t index)
   170         -> 
typename channel_traits<channel_t>::reference
   172         return dynamic_at_c(*
this, index);
   175     auto operator[](std::size_t index) 
const   176         -> 
typename channel_traits<channel_t>::const_reference
   178         return dynamic_at_c(*
this, index);
   182     template <
typename Pixel>
   183     void assign(Pixel 
const& p, std::true_type)
   185         check_compatible<Pixel>();
   186         static_copy(p, *
this);
   189     template <
typename Pixel>
   190     bool equal(Pixel 
const& p, std::true_type)
 const   192         check_compatible<Pixel>();
   193         return static_equal(*
this, p);
   196     template <
typename Pixel>
   197     void check_compatible()
 const   199         gil_function_requires<PixelsCompatibleConcept<Pixel, pixel>>();
   205     static void check_gray()
   207         static_assert(std::is_same<typename Layout::color_space_t, gray_t>::value, 
"");
   210     template <
typename Channel>
   211     void assign(Channel 
const& channel, std::false_type)
   214         gil::at_c<0>(*
this) = channel;
   217     template <
typename Channel>
   218     bool equal (Channel 
const& channel, std::false_type)
 const   221         return gil::at_c<0>(*
this) == channel;
   225     pixel& operator= (channel_t channel)
   228         gil::at_c<0>(*
this) = channel;
   232     bool operator==(channel_t channel)
 const   235         return gil::at_c<0>(*
this) == channel;
   243 template <
typename ChannelValue, 
typename Layout, 
int K>
   244 struct kth_element_type<pixel<ChannelValue,Layout>, K>
   246     using type = ChannelValue;
   249 template <
typename ChannelValue, 
typename Layout, 
int K>
   250 struct kth_element_reference_type<pixel<ChannelValue,Layout>, K>
   252     using type = 
typename channel_traits<ChannelValue>::reference;
   255 template <
typename ChannelValue, 
typename Layout, 
int K>
   256 struct kth_element_reference_type<const pixel<ChannelValue,Layout>, K>
   258     using type = 
typename channel_traits<ChannelValue>::const_reference;
   261 template <
typename ChannelValue, 
typename Layout, 
int K>
   262 struct kth_element_const_reference_type<pixel<ChannelValue,Layout>, K>
   264     using type = 
typename channel_traits<ChannelValue>::const_reference;
   271 template <
typename ChannelValue, 
typename Layout>
   272 struct is_pixel<pixel<ChannelValue,Layout>> : std::true_type {};
   278 template <
typename ChannelValue, 
typename Layout>
   279 struct color_space_type<pixel<ChannelValue, Layout>>
   281     using type = 
typename Layout::color_space_t;
   284 template <
typename ChannelValue, 
typename Layout>
   285 struct channel_mapping_type<pixel<ChannelValue, Layout>>
   287     using type = 
typename Layout::channel_mapping_t;
   290 template <
typename ChannelValue, 
typename Layout>
   291 struct is_planar<pixel<ChannelValue, Layout>> : std::false_type {};
   293 template <
typename ChannelValue, 
typename Layout>
   294 struct channel_type<pixel<ChannelValue, Layout>>
   296     using type = ChannelValue;