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> 24 #include <type_traits> 26 namespace boost {
namespace gil {
30 using gray_t = mpl::vector1<gray_color_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 using channel_t = ChannelValue;
96 using parent_t = detail::homogeneous_color_base<ChannelValue,Layout,mpl::size<typename Layout::color_space_t>::value>;
98 using value_type = pixel<ChannelValue, Layout>;
99 using reference = value_type&;
100 using const_reference = value_type
const&;
101 static constexpr
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>
116 pixel(Pixel
const& p,
117 typename std::enable_if<is_pixel<Pixel>::value>::type* =
nullptr)
120 check_compatible<Pixel>();
123 template <
typename P> pixel& operator=(
const P& p) { assign(p, mpl::bool_<is_pixel<P>::value>());
return *
this; }
124 template <
typename P>
bool operator==(
const P& p)
const {
return equal(p, mpl::bool_<is_pixel<P>::value>()); }
126 template <
typename P>
bool operator!=(
const P& p)
const {
return !(*
this==p); }
129 typename channel_traits<channel_t>::reference operator[](std::size_t i) {
return dynamic_at_c(*
this,i); }
130 typename channel_traits<channel_t>::const_reference operator[](std::size_t i)
const {
return dynamic_at_c(*
this,i); }
132 template <
typename Pixel>
void assign(
const Pixel& p, mpl::true_) { check_compatible<Pixel>(); static_copy(p,*
this); }
133 template <
typename Pixel>
bool equal(
const Pixel& p, mpl::true_)
const { check_compatible<Pixel>();
return static_equal(*
this,p); }
135 template <
typename Pixel>
void check_compatible()
const { gil_function_requires<PixelsCompatibleConcept<Pixel,pixel> >(); }
140 static void check_gray()
142 static_assert(is_same<typename Layout::color_space_t, gray_t>::value,
"");
144 template <
typename Channel>
void assign(
const Channel& chan, mpl::false_) { check_gray(); gil::at_c<0>(*this)=chan; }
145 template <
typename Channel>
bool equal (
const Channel& chan, mpl::false_)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
147 pixel& operator= (channel_t chan) { check_gray(); gil::at_c<0>(*this)=chan;
return *
this; }
148 bool operator==(channel_t chan)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
155 template <
typename ChannelValue,
typename Layout,
int K>
156 struct kth_element_type<pixel<ChannelValue,Layout>, K> {
157 using type = ChannelValue;
160 template <
typename ChannelValue,
typename Layout,
int K>
161 struct kth_element_reference_type<pixel<ChannelValue,Layout>, K> {
162 using type =
typename channel_traits<ChannelValue>::reference;
165 template <
typename ChannelValue,
typename Layout,
int K>
166 struct kth_element_reference_type<const pixel<ChannelValue,Layout>, K> {
167 using type =
typename channel_traits<ChannelValue>::const_reference;
170 template <
typename ChannelValue,
typename Layout,
int K>
171 struct kth_element_const_reference_type<pixel<ChannelValue,Layout>, K> {
172 using type =
typename channel_traits<ChannelValue>::const_reference;
179 template <
typename ChannelValue,
typename Layout>
180 struct is_pixel<pixel<ChannelValue,Layout> > :
public mpl::true_{};
186 template <
typename ChannelValue,
typename Layout>
187 struct color_space_type<pixel<ChannelValue,Layout> > {
188 using type =
typename Layout::color_space_t;
191 template <
typename ChannelValue,
typename Layout>
192 struct channel_mapping_type<pixel<ChannelValue,Layout> > {
193 using type =
typename Layout::channel_mapping_t;
196 template <
typename ChannelValue,
typename Layout>
197 struct is_planar<pixel<ChannelValue,Layout> > :
public mpl::false_ {};
199 template <
typename ChannelValue,
typename Layout>
200 struct channel_type<pixel<ChannelValue,Layout> > {
201 using type = ChannelValue;
207 template <
typename ChannelValue,
typename Layout>
208 struct has_trivial_constructor<gil::pixel<ChannelValue,Layout> > :
public has_trivial_constructor<ChannelValue> {};
Definition: algorithm.hpp:30
BOOST_FORCEINLINE bool equal(boost::gil::iterator_from_2d< Loc1 > first, boost::gil::iterator_from_2d< Loc1 > last, boost::gil::iterator_from_2d< Loc2 > first2)
std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d
Definition: algorithm.hpp:929