8 #ifndef BOOST_GIL_PACKED_PIXEL_HPP 9 #define BOOST_GIL_PACKED_PIXEL_HPP 11 #include <boost/gil/pixel.hpp> 13 #include <boost/core/ignore_unused.hpp> 14 #include <boost/mpl/bool.hpp> 15 #include <boost/mpl/front.hpp> 18 #include <type_traits> 20 namespace boost {
namespace gil {
48 template <
typename BitField,
49 typename ChannelRefVec,
55 using layout_t = Layout;
56 using value_type = packed_pixel<BitField, ChannelRefVec, Layout>;
57 using reference = value_type&;
58 using const_reference = value_type
const&;
60 static constexpr
bool is_mutable =
61 channel_traits<typename mpl::front<ChannelRefVec>::type>::is_mutable;
64 explicit packed_pixel(
const BitField& bitfield) : _bitfield(bitfield) {}
67 packed_pixel(
const packed_pixel& p) : _bitfield(p._bitfield) {}
70 packed_pixel(P
const& p,
71 typename std::enable_if<is_pixel<P>::value>::type* =
nullptr)
73 check_compatible<P>();
74 static_copy(p, *
this);
77 packed_pixel(
int chan0,
int chan1) : _bitfield(0) {
78 static_assert(num_channels<packed_pixel>::value == 2,
"");
79 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1;
81 packed_pixel(
int chan0,
int chan1,
int chan2) : _bitfield(0) {
82 static_assert(num_channels<packed_pixel>::value == 3,
"");
83 gil::at_c<0>(*this) = chan0;
84 gil::at_c<1>(*this) = chan1;
85 gil::at_c<2>(*this) = chan2;
87 packed_pixel(
int chan0,
int chan1,
int chan2,
int chan3) : _bitfield(0) {
88 static_assert(num_channels<packed_pixel>::value == 4,
"");
89 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1; gil::at_c<2>(*this)=chan2; gil::at_c<3>(*this)=chan3;
91 packed_pixel(
int chan0,
int chan1,
int chan2,
int chan3,
int chan4) : _bitfield(0) {
92 static_assert(num_channels<packed_pixel>::value == 5,
"");
93 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1; gil::at_c<2>(*this)=chan2; gil::at_c<3>(*this)=chan3; gil::at_c<4>(*this)=chan4;
96 packed_pixel& operator=(
const packed_pixel& p) { _bitfield=p._bitfield;
return *
this; }
98 template <
typename P> packed_pixel& operator=(
const P& p) { assign(p, mpl::bool_<is_pixel<P>::value>());
return *
this; }
99 template <
typename P>
bool operator==(
const P& p)
const {
return equal(p, mpl::bool_<is_pixel<P>::value>()); }
101 template <
typename P>
bool operator!=(
const P& p)
const {
return !(*
this==p); }
104 template <
typename Pixel>
static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,packed_pixel> >(); }
105 template <
typename Pixel>
void assign(
const Pixel& p, mpl::true_) { check_compatible<Pixel>(); static_copy(p,*
this); }
106 template <
typename Pixel>
bool equal(
const Pixel& p, mpl::true_)
const { check_compatible<Pixel>();
return static_equal(*
this,p); }
109 static void check_gray()
111 static_assert(is_same<typename Layout::color_space_t, gray_t>::value,
"");
113 template <
typename Channel>
void assign(
const Channel& chan, mpl::false_) { check_gray(); gil::at_c<0>(*this)=chan; }
114 template <
typename Channel>
bool equal (
const Channel& chan, mpl::false_)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
116 packed_pixel& operator= (
int chan) { check_gray(); gil::at_c<0>(*this)=chan;
return *
this; }
117 bool operator==(
int chan)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
124 template <
typename BitField,
typename ChannelRefVec,
typename Layout,
int K>
125 struct kth_element_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> :
public mpl::at_c<ChannelRefVec,K> {};
127 template <
typename BitField,
typename ChannelRefVec,
typename Layout,
int K>
128 struct kth_element_reference_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> :
public mpl::at_c<ChannelRefVec,K> {};
130 template <
typename BitField,
typename ChannelRefVec,
typename Layout,
int K>
131 struct kth_element_const_reference_type<packed_pixel<BitField,ChannelRefVec,Layout>,K>
133 using type =
typename channel_traits<typename mpl::at_c<ChannelRefVec,K>::type>::const_reference;
136 template <
int K,
typename P,
typename C,
typename L>
inline 137 typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type
138 at_c(packed_pixel<P,C,L>& p) {
139 return typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type(&p._bitfield);
142 template <
int K,
typename P,
typename C,
typename L>
inline 143 typename kth_element_const_reference_type<packed_pixel<P,C,L>, K>::type
144 at_c(
const packed_pixel<P,C,L>& p) {
145 return typename kth_element_const_reference_type<packed_pixel<P,C,L>, K>::type(&p._bitfield);
153 template <
typename BitField,
typename ChannelRefVec,
typename Layout>
154 struct is_pixel<packed_pixel<BitField,ChannelRefVec,Layout> > :
public mpl::true_{};
160 template <
typename P,
typename C,
typename Layout>
161 struct color_space_type<packed_pixel<P,C,Layout> > {
162 using type =
typename Layout::color_space_t;
165 template <
typename P,
typename C,
typename Layout>
166 struct channel_mapping_type<packed_pixel<P,C,Layout> > {
167 using type =
typename Layout::channel_mapping_t;
170 template <
typename P,
typename C,
typename Layout>
171 struct is_planar<packed_pixel<P,C,Layout> > : mpl::false_ {};
185 template <
typename P,
typename C,
typename L>
186 struct iterator_is_mutable<packed_pixel<P,C,L>*> :
public mpl::bool_<packed_pixel<P,C,L>::is_mutable> {};
187 template <
typename P,
typename C,
typename L>
188 struct iterator_is_mutable<const packed_pixel<P,C,L>*> :
public mpl::false_ {};
195 template <
typename P,
typename C,
typename L>
196 struct has_trivial_constructor<gil::packed_pixel<P,C,L> > :
public has_trivial_constructor<P> {};
Definition: algorithm.hpp:30
add_reference< E >::type at_c(detail::homogeneous_color_base< E, L, N > &p)
Provides mutable access to the K-th element, in physical order.
Definition: color_base.hpp:387