8 #ifndef BOOST_GIL_PIXEL_HPP
9 #define BOOST_GIL_PIXEL_HPP
11 #include <boost/gil/channel.hpp>
12 #include <boost/gil/color_base.hpp>
13 #include <boost/gil/color_base_algorithm.hpp>
14 #include <boost/gil/concepts.hpp>
15 #include <boost/gil/metafunctions.hpp>
16 #include <boost/gil/utilities.hpp>
18 #include <boost/core/ignore_unused.hpp>
19 #include <boost/mpl/bool.hpp>
20 #include <boost/mpl/front.hpp>
21 #include <boost/type_traits.hpp>
22 #include <boost/utility/enable_if.hpp>
26 namespace boost {
namespace gil {
30 typedef mpl::vector1<gray_color_t> gray_t;
31 template <
typename PixelBased>
struct color_space_type;
32 template <
typename PixelBased>
struct channel_mapping_type;
33 template <
typename PixelBased>
struct channel_type;
34 template <
typename PixelBased>
struct is_planar;
36 template <
typename PixelBased>
struct color_space_type<const PixelBased> :
public color_space_type<PixelBased> {};
37 template <
typename PixelBased>
struct channel_mapping_type<const PixelBased> :
public channel_mapping_type<PixelBased> {};
38 template <
typename PixelBased>
struct channel_type<const PixelBased> :
public channel_type<PixelBased> {};
40 template <
typename PixelBased>
struct is_planar : mpl::false_ {};
41 template <
typename PixelBased>
struct is_planar<const PixelBased> :
public is_planar<PixelBased> {};
44 template <
typename T>
struct is_pixel :
public mpl::false_{};
45 template <
typename T>
struct is_pixel<const T> :
public is_pixel<T> {};
49 template <
typename PixelBased>
50 struct num_channels :
public mpl::size<typename color_space_type<PixelBased>::type> {};
92 template <
typename ChannelValue,
typename Layout>
93 struct pixel :
public detail::homogeneous_color_base<ChannelValue,Layout,mpl::size<typename Layout::color_space_t>::value> {
95 typedef ChannelValue channel_t;
96 typedef detail::homogeneous_color_base<ChannelValue,Layout,mpl::size<typename Layout::color_space_t>::value> parent_t;
98 typedef pixel value_type;
99 typedef value_type& reference;
100 typedef const value_type& const_reference;
101 BOOST_STATIC_CONSTANT(
bool, is_mutable = channel_traits<channel_t>::is_mutable);
104 explicit pixel(channel_t v) : parent_t(v) {}
105 pixel(channel_t v0, channel_t v1) : parent_t(v0,v1) {}
106 pixel(channel_t v0, channel_t v1, channel_t v2) : parent_t(v0,v1,v2) {}
107 pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3) : parent_t(v0,v1,v2,v3) {}
108 pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3, channel_t v4) : parent_t(v0,v1,v2,v3,v4) {}
109 pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3, channel_t v4, channel_t v5) : parent_t(v0,v1,v2,v3,v4,v5) {}
111 pixel(
const pixel& p) : parent_t(p) {}
112 pixel& operator=(
const pixel& p) { static_copy(p,*
this);
return *
this; }
115 template <
typename Pixel> pixel(
const Pixel& p,
typename enable_if_c<is_pixel<Pixel>::value>::type* dummy = 0) : parent_t(p) {
116 check_compatible<Pixel>();
117 boost::ignore_unused(dummy);
120 template <
typename P> pixel& operator=(
const P& p) { assign(p, mpl::bool_<is_pixel<P>::value>());
return *
this; }
121 template <
typename P>
bool operator==(
const P& p)
const {
return equal(p, mpl::bool_<is_pixel<P>::value>()); }
123 template <
typename P>
bool operator!=(
const P& p)
const {
return !(*
this==p); }
126 typename channel_traits<channel_t>::reference operator[](std::size_t i) {
return dynamic_at_c(*
this,i); }
127 typename channel_traits<channel_t>::const_reference operator[](std::size_t i)
const {
return dynamic_at_c(*
this,i); }
129 template <
typename Pixel>
void assign(
const Pixel& p, mpl::true_) { check_compatible<Pixel>(); static_copy(p,*
this); }
130 template <
typename Pixel>
bool equal(
const Pixel& p, mpl::true_)
const { check_compatible<Pixel>();
return static_equal(*
this,p); }
132 template <
typename Pixel>
void check_compatible()
const { gil_function_requires<PixelsCompatibleConcept<Pixel,pixel> >(); }
137 static void check_gray() { BOOST_STATIC_ASSERT((is_same<typename Layout::color_space_t, gray_t>::value)); }
138 template <
typename Channel>
void assign(
const Channel& chan, mpl::false_) { check_gray(); gil::at_c<0>(*this)=chan; }
139 template <
typename Channel>
bool equal (
const Channel& chan, mpl::false_)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
141 pixel& operator= (channel_t chan) { check_gray(); gil::at_c<0>(*this)=chan;
return *
this; }
142 bool operator==(channel_t chan)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
149 template <
typename ChannelValue,
typename Layout,
int K>
150 struct kth_element_type<pixel<ChannelValue,Layout>, K> {
151 typedef ChannelValue type;
154 template <
typename ChannelValue,
typename Layout,
int K>
155 struct kth_element_reference_type<pixel<ChannelValue,Layout>, K> {
156 typedef typename channel_traits<ChannelValue>::reference type;
159 template <
typename ChannelValue,
typename Layout,
int K>
160 struct kth_element_reference_type<const pixel<ChannelValue,Layout>, K> {
161 typedef typename channel_traits<ChannelValue>::const_reference type;
164 template <
typename ChannelValue,
typename Layout,
int K>
165 struct kth_element_const_reference_type<pixel<ChannelValue,Layout>, K> {
166 typedef typename channel_traits<ChannelValue>::const_reference type;
173 template <
typename ChannelValue,
typename Layout>
174 struct is_pixel<pixel<ChannelValue,Layout> > :
public mpl::true_{};
180 template <
typename ChannelValue,
typename Layout>
181 struct color_space_type<pixel<ChannelValue,Layout> > {
182 typedef typename Layout::color_space_t type;
185 template <
typename ChannelValue,
typename Layout>
186 struct channel_mapping_type<pixel<ChannelValue,Layout> > {
187 typedef typename Layout::channel_mapping_t type;
190 template <
typename ChannelValue,
typename Layout>
191 struct is_planar<pixel<ChannelValue,Layout> > :
public mpl::false_ {};
193 template <
typename ChannelValue,
typename Layout>
194 struct channel_type<pixel<ChannelValue,Layout> > {
195 typedef ChannelValue type;
201 template <
typename ChannelValue,
typename Layout>
202 struct has_trivial_constructor<gil::pixel<ChannelValue,Layout> > :
public has_trivial_constructor<ChannelValue> {};