13 #ifndef GIL_PACKED_PIXEL_H
14 #define GIL_PACKED_PIXEL_H
26 #include <boost/core/ignore_unused.hpp>
27 #include <boost/utility/enable_if.hpp>
28 #include <boost/mpl/bool.hpp>
29 #include <boost/mpl/front.hpp>
33 namespace boost {
namespace gil {
57 template <
typename BitField,
61 typename ChannelRefVec,
66 typedef Layout layout_t;
67 typedef packed_pixel value_type;
68 typedef value_type& reference;
69 typedef const value_type& const_reference;
71 BOOST_STATIC_CONSTANT(
bool, is_mutable = channel_traits<
typename mpl::front<ChannelRefVec>::type>::is_mutable);
74 explicit packed_pixel(
const BitField& bitfield) : _bitfield(bitfield) {}
77 packed_pixel(
const packed_pixel& p) : _bitfield(p._bitfield) {}
78 template <
typename P> packed_pixel(
const P& p,
typename enable_if_c<is_pixel<P>::value>::type* d=0) {
79 check_compatible<P>(); static_copy(p,*
this);
80 boost::ignore_unused(d);
82 packed_pixel(
int chan0,
int chan1) : _bitfield(0) {
83 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==2));
84 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1;
86 packed_pixel(
int chan0,
int chan1,
int chan2) : _bitfield(0) {
87 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==3));
88 gil::at_c<0>(*this) = chan0;
89 gil::at_c<1>(*this) = chan1;
90 gil::at_c<2>(*this) = chan2;
92 packed_pixel(
int chan0,
int chan1,
int chan2,
int chan3) : _bitfield(0) {
93 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==4));
94 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1; gil::at_c<2>(*this)=chan2; gil::at_c<3>(*this)=chan3;
96 packed_pixel(
int chan0,
int chan1,
int chan2,
int chan3,
int chan4) : _bitfield(0) {
97 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==5));
98 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;
101 packed_pixel& operator=(
const packed_pixel& p) { _bitfield=p._bitfield;
return *
this; }
103 template <
typename P> packed_pixel& operator=(
const P& p) { assign(p, mpl::bool_<is_pixel<P>::value>());
return *
this; }
104 template <
typename P>
bool operator==(
const P& p)
const {
return equal(p, mpl::bool_<is_pixel<P>::value>()); }
106 template <
typename P>
bool operator!=(
const P& p)
const {
return !(*
this==p); }
109 template <
typename Pixel>
static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,packed_pixel> >(); }
110 template <
typename Pixel>
void assign(
const Pixel& p, mpl::true_) { check_compatible<Pixel>(); static_copy(p,*
this); }
111 template <
typename Pixel>
bool equal(
const Pixel& p, mpl::true_)
const { check_compatible<Pixel>();
return static_equal(*
this,p); }
114 static void check_gray() { BOOST_STATIC_ASSERT((is_same<typename Layout::color_space_t, gray_t>::value)); }
115 template <
typename Channel>
void assign(
const Channel& chan, mpl::false_) { check_gray(); gil::at_c<0>(*this)=chan; }
116 template <
typename Channel>
bool equal (
const Channel& chan, mpl::false_)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
118 packed_pixel& operator= (
int chan) { check_gray(); gil::at_c<0>(*this)=chan;
return *
this; }
119 bool operator==(
int chan)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
126 template <
typename BitField,
typename ChannelRefVec,
typename Layout,
int K>
127 struct kth_element_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> :
public mpl::at_c<ChannelRefVec,K> {};
129 template <
typename BitField,
typename ChannelRefVec,
typename Layout,
int K>
130 struct kth_element_reference_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> :
public mpl::at_c<ChannelRefVec,K> {};
132 template <
typename BitField,
typename ChannelRefVec,
typename Layout,
int K>
133 struct kth_element_const_reference_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> {
134 typedef typename channel_traits<typename mpl::at_c<ChannelRefVec,K>::type>::const_reference type;
137 template <
int K,
typename P,
typename C,
typename L>
inline
138 typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type
139 at_c(packed_pixel<P,C,L>& p) {
140 return typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type(&p._bitfield);
143 template <
int K,
typename P,
typename C,
typename L>
inline
144 typename kth_element_const_reference_type<packed_pixel<P,C,L>, K>::type
145 at_c(
const packed_pixel<P,C,L>& p) {
146 return typename kth_element_const_reference_type<packed_pixel<P,C,L>, K>::type(&p._bitfield);
154 template <
typename BitField,
typename ChannelRefVec,
typename Layout>
155 struct is_pixel<packed_pixel<BitField,ChannelRefVec,Layout> > :
public mpl::true_{};
161 template <
typename P,
typename C,
typename Layout>
162 struct color_space_type<packed_pixel<P,C,Layout> > {
163 typedef typename Layout::color_space_t type;
166 template <
typename P,
typename C,
typename Layout>
167 struct channel_mapping_type<packed_pixel<P,C,Layout> > {
168 typedef typename Layout::channel_mapping_t type;
171 template <
typename P,
typename C,
typename Layout>
172 struct is_planar<packed_pixel<P,C,Layout> > : mpl::false_ {};
186 template <
typename P,
typename C,
typename L>
187 struct iterator_is_mutable<packed_pixel<P,C,L>*> :
public mpl::bool_<packed_pixel<P,C,L>::is_mutable> {};
188 template <
typename P,
typename C,
typename L>
189 struct iterator_is_mutable<const packed_pixel<P,C,L>*> :
public mpl::false_ {};
196 template <
typename P,
typename C,
typename L>
197 struct has_trivial_constructor<gil::packed_pixel<P,C,L> > :
public has_trivial_constructor<P> {};
pixel class and related utilities