13 #ifndef GIL_PACKED_PIXEL_H
14 #define GIL_PACKED_PIXEL_H
26 #include <boost/utility/enable_if.hpp>
27 #include <boost/mpl/bool.hpp>
28 #include <boost/mpl/front.hpp>
32 namespace boost {
namespace gil {
56 template <
typename BitField,
60 typename ChannelRefVec,
65 typedef Layout layout_t;
66 typedef packed_pixel value_type;
67 typedef value_type& reference;
68 typedef const value_type& const_reference;
70 BOOST_STATIC_CONSTANT(
bool, is_mutable = channel_traits<
typename mpl::front<ChannelRefVec>::type>::is_mutable);
73 explicit packed_pixel(
const BitField& bitfield) : _bitfield(bitfield) {}
76 packed_pixel(
const packed_pixel& p) : _bitfield(p._bitfield) {}
77 template <
typename P> packed_pixel(
const P& p,
typename enable_if_c<is_pixel<P>::value>::type* d=0) { check_compatible<P>(); static_copy(p,*
this); }
78 packed_pixel(
int chan0,
int chan1) : _bitfield(0) {
79 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==2));
80 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1;
82 packed_pixel(
int chan0,
int chan1,
int chan2) : _bitfield(0) {
83 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==3));
84 gil::at_c<0>(*this) = chan0;
85 gil::at_c<1>(*this) = chan1;
86 gil::at_c<2>(*this) = chan2;
88 packed_pixel(
int chan0,
int chan1,
int chan2,
int chan3) : _bitfield(0) {
89 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==4));
90 gil::at_c<0>(*this)=chan0; gil::at_c<1>(*this)=chan1; gil::at_c<2>(*this)=chan2; gil::at_c<3>(*this)=chan3;
92 packed_pixel(
int chan0,
int chan1,
int chan2,
int chan3,
int chan4) : _bitfield(0) {
93 BOOST_STATIC_ASSERT((num_channels<packed_pixel>::value==5));
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; gil::at_c<4>(*this)=chan4;
97 packed_pixel& operator=(
const packed_pixel& p) { _bitfield=p._bitfield;
return *
this; }
99 template <
typename P> packed_pixel& operator=(
const P& p) { assign(p, mpl::bool_<is_pixel<P>::value>());
return *
this; }
100 template <
typename P>
bool operator==(
const P& p)
const {
return equal(p, mpl::bool_<is_pixel<P>::value>()); }
102 template <
typename P>
bool operator!=(
const P& p)
const {
return !(*
this==p); }
105 template <
typename Pixel>
static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,packed_pixel> >(); }
106 template <
typename Pixel>
void assign(
const Pixel& p, mpl::true_) { check_compatible<Pixel>(); static_copy(p,*
this); }
107 template <
typename Pixel>
bool equal(
const Pixel& p, mpl::true_)
const { check_compatible<Pixel>();
return static_equal(*
this,p); }
110 static void check_gray() { BOOST_STATIC_ASSERT((is_same<typename Layout::color_space_t, gray_t>::value)); }
111 template <
typename Channel>
void assign(
const Channel& chan, mpl::false_) { check_gray(); gil::at_c<0>(*this)=chan; }
112 template <
typename Channel>
bool equal (
const Channel& chan, mpl::false_)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
114 packed_pixel& operator= (
int chan) { check_gray(); gil::at_c<0>(*this)=chan;
return *
this; }
115 bool operator==(
int chan)
const { check_gray();
return gil::at_c<0>(*this)==chan; }
122 template <
typename BitField,
typename ChannelRefVec,
typename Layout,
int K>
123 struct kth_element_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> :
public mpl::at_c<ChannelRefVec,K> {};
125 template <
typename BitField,
typename ChannelRefVec,
typename Layout,
int K>
126 struct kth_element_reference_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> :
public mpl::at_c<ChannelRefVec,K> {};
128 template <
typename BitField,
typename ChannelRefVec,
typename Layout,
int K>
129 struct kth_element_const_reference_type<packed_pixel<BitField,ChannelRefVec,Layout>,K> {
130 typedef typename channel_traits<typename mpl::at_c<ChannelRefVec,K>::type>::const_reference type;
133 template <
int K,
typename P,
typename C,
typename L>
inline
134 typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type
135 at_c(packed_pixel<P,C,L>& p) {
136 return typename kth_element_reference_type<packed_pixel<P,C,L>, K>::type(&p._bitfield);
139 template <
int K,
typename P,
typename C,
typename L>
inline
140 typename kth_element_const_reference_type<packed_pixel<P,C,L>, K>::type
141 at_c(
const packed_pixel<P,C,L>& p) {
142 return typename kth_element_const_reference_type<packed_pixel<P,C,L>, K>::type(&p._bitfield);
150 template <
typename BitField,
typename ChannelRefVec,
typename Layout>
151 struct is_pixel<packed_pixel<BitField,ChannelRefVec,Layout> > :
public mpl::true_{};
157 template <
typename P,
typename C,
typename Layout>
158 struct color_space_type<packed_pixel<P,C,Layout> > {
159 typedef typename Layout::color_space_t type;
162 template <
typename P,
typename C,
typename Layout>
163 struct channel_mapping_type<packed_pixel<P,C,Layout> > {
164 typedef typename Layout::channel_mapping_t type;
167 template <
typename P,
typename C,
typename Layout>
168 struct is_planar<packed_pixel<P,C,Layout> > : mpl::false_ {};
182 template <
typename P,
typename C,
typename L>
183 struct iterator_is_mutable<packed_pixel<P,C,L>*> :
public mpl::bool_<packed_pixel<P,C,L>::is_mutable> {};
184 template <
typename P,
typename C,
typename L>
185 struct iterator_is_mutable<const packed_pixel<P,C,L>*> :
public mpl::false_ {};
192 template <
typename P,
typename C,
typename L>
193 struct has_trivial_constructor<gil::packed_pixel<P,C,L> > :
public has_trivial_constructor<P> {};
pixel class and related utilities