25 #include <boost/core/ignore_unused.hpp>
26 #include <boost/utility/enable_if.hpp>
27 #include <boost/mpl/bool.hpp>
28 #include <boost/mpl/front.hpp>
29 #include <boost/type_traits.hpp>
38 namespace boost {
namespace gil {
42 typedef mpl::vector1<gray_color_t> gray_t;
43 template <
typename PixelBased>
struct color_space_type;
44 template <
typename PixelBased>
struct channel_mapping_type;
45 template <
typename PixelBased>
struct channel_type;
46 template <
typename PixelBased>
struct is_planar;
48 template <
typename PixelBased>
struct color_space_type<const PixelBased> :
public color_space_type<PixelBased> {};
49 template <
typename PixelBased>
struct channel_mapping_type<const PixelBased> :
public channel_mapping_type<PixelBased> {};
50 template <
typename PixelBased>
struct channel_type<const PixelBased> :
public channel_type<PixelBased> {};
52 template <
typename PixelBased>
struct is_planar : mpl::false_ {};
53 template <
typename PixelBased>
struct is_planar<const PixelBased> :
public is_planar<PixelBased> {};
56 template <
typename T>
struct is_pixel :
public mpl::false_{};
57 template <
typename T>
struct is_pixel<const T> :
public is_pixel<T> {};
61 template <
typename PixelBased>
62 struct num_channels :
public mpl::size<typename color_space_type<PixelBased>::type> {};
104 template <
typename ChannelValue,
typename Layout>
105 struct pixel :
public detail::homogeneous_color_base<ChannelValue,Layout,mpl::size<typename Layout::color_space_t>::value> {
107 typedef ChannelValue channel_t;
108 typedef detail::homogeneous_color_base<ChannelValue,Layout,mpl::size<typename Layout::color_space_t>::value> parent_t;
110 typedef pixel value_type;
111 typedef value_type& reference;
112 typedef const value_type& const_reference;
113 BOOST_STATIC_CONSTANT(
bool, is_mutable = channel_traits<channel_t>::is_mutable);
116 explicit pixel(channel_t v) : parent_t(v) {}
117 pixel(channel_t v0, channel_t v1) : parent_t(v0,v1) {}
118 pixel(channel_t v0, channel_t v1, channel_t v2) : parent_t(v0,v1,v2) {}
119 pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3) : parent_t(v0,v1,v2,v3) {}
120 pixel(channel_t v0, channel_t v1, channel_t v2, channel_t v3, channel_t v4) : parent_t(v0,v1,v2,v3,v4) {}
121 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) {}
123 pixel(
const pixel& p) : parent_t(p) {}
124 pixel& operator=(
const pixel& p) { static_copy(p,*
this);
return *
this; }
127 template <
typename Pixel> pixel(
const Pixel& p,
typename enable_if_c<is_pixel<Pixel>::value>::type* dummy = 0) : parent_t(p) {
128 check_compatible<Pixel>();
129 boost::ignore_unused(dummy);
132 template <
typename P> pixel& operator=(
const P& p) { assign(p, mpl::bool_<is_pixel<P>::value>());
return *
this; }
133 template <
typename P>
bool operator==(
const P& p)
const {
return equal(p, mpl::bool_<is_pixel<P>::value>()); }
135 template <
typename P>
bool operator!=(
const P& p)
const {
return !(*
this==p); }
138 typename channel_traits<channel_t>::reference operator[](std::size_t i) {
return dynamic_at_c(*
this,i); }
139 typename channel_traits<channel_t>::const_reference operator[](std::size_t i)
const {
return dynamic_at_c(*
this,i); }
141 template <
typename Pixel>
void assign(
const Pixel& p, mpl::true_) { check_compatible<Pixel>(); static_copy(p,*
this); }
142 template <
typename Pixel>
bool equal(
const Pixel& p, mpl::true_)
const { check_compatible<Pixel>();
return static_equal(*
this,p); }
144 template <
typename Pixel>
void check_compatible()
const { gil_function_requires<PixelsCompatibleConcept<Pixel,pixel> >(); }
149 static void check_gray() { BOOST_STATIC_ASSERT((is_same<typename Layout::color_space_t, gray_t>::value)); }
150 template <
typename Channel>
void assign(
const Channel& chan, mpl::false_) { check_gray(); gil::at_c<0>(*this)=chan; }
151 template <
typename Channel>
bool equal (
const Channel& chan, mpl::false_)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
153 pixel& operator= (channel_t chan) { check_gray(); gil::at_c<0>(*this)=chan;
return *
this; }
154 bool operator==(channel_t chan)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
161 template <
typename ChannelValue,
typename Layout,
int K>
162 struct kth_element_type<pixel<ChannelValue,Layout>, K> {
163 typedef ChannelValue type;
166 template <
typename ChannelValue,
typename Layout,
int K>
167 struct kth_element_reference_type<pixel<ChannelValue,Layout>, K> {
168 typedef typename channel_traits<ChannelValue>::reference type;
171 template <
typename ChannelValue,
typename Layout,
int K>
172 struct kth_element_reference_type<const pixel<ChannelValue,Layout>, K> {
173 typedef typename channel_traits<ChannelValue>::const_reference type;
176 template <
typename ChannelValue,
typename Layout,
int K>
177 struct kth_element_const_reference_type<pixel<ChannelValue,Layout>, K> {
178 typedef typename channel_traits<ChannelValue>::const_reference type;
185 template <
typename ChannelValue,
typename Layout>
186 struct is_pixel<pixel<ChannelValue,Layout> > :
public mpl::true_{};
192 template <
typename ChannelValue,
typename Layout>
193 struct color_space_type<pixel<ChannelValue,Layout> > {
194 typedef typename Layout::color_space_t type;
197 template <
typename ChannelValue,
typename Layout>
198 struct channel_mapping_type<pixel<ChannelValue,Layout> > {
199 typedef typename Layout::channel_mapping_t type;
202 template <
typename ChannelValue,
typename Layout>
203 struct is_planar<pixel<ChannelValue,Layout> > :
public mpl::false_ {};
205 template <
typename ChannelValue,
typename Layout>
206 struct channel_type<pixel<ChannelValue,Layout> > {
207 typedef ChannelValue type;
213 template <
typename ChannelValue,
typename Layout>
214 struct has_trivial_constructor<gil::pixel<ChannelValue,Layout> > :
public has_trivial_constructor<ChannelValue> {};
Concept check classes for GIL concepts.
pixel class and related utilities
Various utilities not specific to the image library. Some are non-standard STL extensions or generic ...