8 #ifndef BOOST_GIL_PACKED_PIXEL_HPP 9 #define BOOST_GIL_PACKED_PIXEL_HPP 11 #include <boost/gil/pixel.hpp> 12 #include <boost/gil/detail/mp11.hpp> 15 #include <type_traits> 17 namespace boost {
namespace gil {
48 template <
typename BitField,
typename ChannelRefs,
typename Layout>
51 BitField _bitfield{0};
53 using layout_t = Layout;
54 using value_type = packed_pixel<BitField, ChannelRefs, Layout>;
55 using reference = value_type&;
56 using const_reference = value_type
const&;
58 static constexpr
bool is_mutable =
59 channel_traits<mp11::mp_front<ChannelRefs>>::is_mutable;
61 packed_pixel() =
default;
62 explicit packed_pixel(
const BitField& bitfield) : _bitfield(bitfield) {}
65 packed_pixel(
const packed_pixel& p) : _bitfield(p._bitfield) {}
67 template <
typename Pixel>
68 packed_pixel(Pixel
const& p,
69 typename std::enable_if<is_pixel<Pixel>::value>::type* =
nullptr)
71 check_compatible<Pixel>();
72 static_copy(p, *
this);
75 packed_pixel(
int chan0,
int chan1)
78 static_assert(num_channels<packed_pixel>::value == 2,
"");
79 gil::at_c<0>(*
this) = chan0;
80 gil::at_c<1>(*
this) = chan1;
83 packed_pixel(
int chan0,
int chan1,
int chan2)
86 static_assert(num_channels<packed_pixel>::value == 3,
"");
87 gil::at_c<0>(*
this) = chan0;
88 gil::at_c<1>(*
this) = chan1;
89 gil::at_c<2>(*
this) = chan2;
92 packed_pixel(
int chan0,
int chan1,
int chan2,
int chan3)
95 static_assert(num_channels<packed_pixel>::value == 4,
"");
96 gil::at_c<0>(*
this) = chan0;
97 gil::at_c<1>(*
this) = chan1;
98 gil::at_c<2>(*
this) = chan2;
99 gil::at_c<3>(*
this) = chan3;
102 packed_pixel(
int chan0,
int chan1,
int chan2,
int chan3,
int chan4)
105 static_assert(num_channels<packed_pixel>::value == 5,
"");
106 gil::at_c<0>(*
this) = chan0;
107 gil::at_c<1>(*
this) = chan1;
108 gil::at_c<2>(*
this) = chan2;
109 gil::at_c<3>(*
this) = chan3;
110 gil::at_c<4>(*
this) = chan4;
113 auto operator=(packed_pixel
const& p) -> packed_pixel&
115 _bitfield = p._bitfield;
119 template <
typename Pixel>
120 auto operator=(Pixel
const& p) -> packed_pixel&
122 assign(p, is_pixel<Pixel>());
126 template <
typename Pixel>
127 bool operator==(Pixel
const& p)
const 129 return equal(p, is_pixel<Pixel>());
132 template <
typename Pixel>
133 bool operator!=(Pixel
const& p)
const {
return !(*
this==p); }
136 template <
typename Pixel>
137 static void check_compatible()
139 gil_function_requires<PixelsCompatibleConcept<Pixel, packed_pixel>>();
142 template <
typename Pixel>
143 void assign(Pixel
const& p, std::true_type)
145 check_compatible<Pixel>();
146 static_copy(p, *
this);
149 template <
typename Pixel>
150 bool equal(Pixel
const& p, std::true_type)
const 152 check_compatible<Pixel>();
153 return static_equal(*
this, p);
157 static void check_gray()
159 static_assert(std::is_same<typename Layout::color_space_t, gray_t>::value,
"");
162 template <
typename Channel>
163 void assign(Channel
const& channel, std::false_type)
166 gil::at_c<0>(*
this) = channel;
169 template <
typename Channel>
170 bool equal (Channel
const& channel, std::false_type)
const 173 return gil::at_c<0>(*
this) == channel;
177 auto operator=(
int channel) -> packed_pixel&
180 gil::at_c<0>(*
this) = channel;
184 bool operator==(
int channel)
const 187 return gil::at_c<0>(*
this) == channel;
195 template <
typename BitField,
typename ChannelRefs,
typename Layout,
int K>
196 struct kth_element_type<packed_pixel<BitField, ChannelRefs, Layout>, K>
198 using type =
typename channel_traits<mp11::mp_at_c<ChannelRefs, K>>::value_type;
201 template <
typename BitField,
typename ChannelRefs,
typename Layout,
int K>
202 struct kth_element_reference_type<packed_pixel<BitField, ChannelRefs, Layout>, K>
204 using type =
typename channel_traits<mp11::mp_at_c<ChannelRefs, K>>::reference;
207 template <
typename BitField,
typename ChannelRefs,
typename Layout,
int K>
208 struct kth_element_const_reference_type<packed_pixel<BitField, ChannelRefs, Layout>, K>
210 using type =
typename channel_traits<mp11::mp_at_c<ChannelRefs, K>>::const_reference;
213 template <
int K,
typename P,
typename C,
typename L>
215 auto at_c(packed_pixel<P, C, L>& p)
216 ->
typename kth_element_reference_type<packed_pixel<P, C, L>, K>::type
218 return typename kth_element_reference_type
220 packed_pixel<P, C, L>,
222 >::type{&p._bitfield};
225 template <
int K,
typename P,
typename C,
typename L>
227 auto at_c(
const packed_pixel<P, C, L>& p)
228 ->
typename kth_element_const_reference_type<packed_pixel<P, C, L>, K>::type
230 return typename kth_element_const_reference_type
232 packed_pixel<P, C, L>,
233 K>::type{&p._bitfield};
242 template <
typename BitField,
typename ChannelRefs,
typename Layout>
243 struct is_pixel<packed_pixel<BitField, ChannelRefs, Layout>> : std::true_type {};
249 template <
typename P,
typename C,
typename Layout>
250 struct color_space_type<packed_pixel<P, C, Layout>>
252 using type =
typename Layout::color_space_t;
255 template <
typename P,
typename C,
typename Layout>
256 struct channel_mapping_type<packed_pixel<P, C, Layout>>
258 using type =
typename Layout::channel_mapping_t;
261 template <
typename P,
typename C,
typename Layout>
262 struct is_planar<packed_pixel<P, C, Layout>> : std::false_type {};
275 template <
typename P,
typename C,
typename L>
276 struct iterator_is_mutable<packed_pixel<P, C, L>*>
277 : std::integral_constant<bool, packed_pixel<P, C, L>::is_mutable>
280 template <
typename P,
typename C,
typename L>
281 struct iterator_is_mutable<const packed_pixel<P, C, L>*> : std::false_type {};
auto at_c(detail::homogeneous_color_base< E, L, N > &p) -> typename std::add_lvalue_reference< E >::type
Provides mutable access to the K-th element, in physical order.
Definition: color_base.hpp:597