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;
58 static constexpr
bool is_mutable =
59 channel_traits<mp11::mp_front<ChannelRefs>>::is_mutable;
62 explicit packed_pixel(
const BitField& bitfield) : _bitfield(bitfield) {}
64 template <
typename Pixel>
66 typename std::enable_if<is_pixel<Pixel>::value>::type* =
nullptr)
68 check_compatible<Pixel>();
69 static_copy(p, *
this);
76 gil::at_c<0>(*
this) = chan0;
77 gil::at_c<1>(*
this) = chan1;
84 gil::at_c<0>(*
this) = chan0;
85 gil::at_c<1>(*
this) = chan1;
86 gil::at_c<2>(*
this) = chan2;
93 gil::at_c<0>(*
this) = chan0;
94 gil::at_c<1>(*
this) = chan1;
95 gil::at_c<2>(*
this) = chan2;
96 gil::at_c<3>(*
this) = chan3;
99 packed_pixel(
int chan0,
int chan1,
int chan2,
int chan3,
int chan4)
103 gil::at_c<0>(*
this) = chan0;
104 gil::at_c<1>(*
this) = chan1;
105 gil::at_c<2>(*
this) = chan2;
106 gil::at_c<3>(*
this) = chan3;
107 gil::at_c<4>(*
this) = chan4;
110 template <
typename Pixel>
113 assign(p, is_pixel<Pixel>());
117 template <
typename Pixel>
118 bool operator==(Pixel
const& p)
const
120 return equal(p, is_pixel<Pixel>());
123 template <
typename Pixel>
124 bool operator!=(Pixel
const& p)
const {
return !(*
this==p); }
127 template <
typename Pixel>
128 static void check_compatible()
130 gil_function_requires<PixelsCompatibleConcept<Pixel, packed_pixel>>();
133 template <
typename Pixel>
134 void assign(Pixel
const& p, std::true_type)
136 check_compatible<Pixel>();
137 static_copy(p, *
this);
140 template <
typename Pixel>
141 bool equal(Pixel
const& p, std::true_type)
const
143 check_compatible<Pixel>();
144 return static_equal(*
this, p);
148 static void check_gray()
150 static_assert(std::is_same<typename Layout::color_space_t, gray_t>::value,
"");
153 template <
typename Channel>
154 void assign(Channel
const& channel, std::false_type)
157 gil::at_c<0>(*
this) = channel;
160 template <
typename Channel>
161 bool equal (Channel
const& channel, std::false_type)
const
164 return gil::at_c<0>(*
this) == channel;
171 gil::at_c<0>(*
this) = channel;
175 bool operator==(
int channel)
const
178 return gil::at_c<0>(*
this) == channel;
186 template <
typename BitField,
typename ChannelRefs,
typename Layout,
int K>
187 struct kth_element_type<
packed_pixel<BitField, ChannelRefs, Layout>, K>
189 using type =
typename channel_traits<mp11::mp_at_c<ChannelRefs, K>>::value_type;
192 template <
typename BitField,
typename ChannelRefs,
typename Layout,
int K>
193 struct kth_element_reference_type<packed_pixel<BitField, ChannelRefs, Layout>, K>
195 using type =
typename channel_traits<mp11::mp_at_c<ChannelRefs, K>>::reference;
198 template <
typename BitField,
typename ChannelRefs,
typename Layout,
int K>
199 struct kth_element_const_reference_type<packed_pixel<BitField, ChannelRefs, Layout>, K>
201 using type =
typename channel_traits<mp11::mp_at_c<ChannelRefs, K>>::const_reference;
204 template <
int K,
typename P,
typename C,
typename L>
206 auto at_c(packed_pixel<P, C, L>& p)
207 ->
typename kth_element_reference_type<packed_pixel<P, C, L>, K>::type
209 return typename kth_element_reference_type
211 packed_pixel<P, C, L>,
213 >::type{&p._bitfield};
216 template <
int K,
typename P,
typename C,
typename L>
218 auto at_c(
const packed_pixel<P, C, L>& p)
219 ->
typename kth_element_const_reference_type<packed_pixel<P, C, L>, K>::type
221 return typename kth_element_const_reference_type
223 packed_pixel<P, C, L>,
224 K>::type{&p._bitfield};
233 template <
typename BitField,
typename ChannelRefs,
typename Layout>
234 struct is_pixel<packed_pixel<BitField, ChannelRefs, Layout>> : std::true_type {};
240 template <
typename P,
typename C,
typename Layout>
241 struct color_space_type<packed_pixel<P, C, Layout>>
243 using type =
typename Layout::color_space_t;
246 template <
typename P,
typename C,
typename Layout>
247 struct channel_mapping_type<packed_pixel<P, C, Layout>>
249 using type =
typename Layout::channel_mapping_t;
252 template <
typename P,
typename C,
typename Layout>
253 struct is_planar<packed_pixel<P, C, Layout>> : std::false_type {};
266 template <
typename P,
typename C,
typename L>
267 struct iterator_is_mutable<packed_pixel<P, C, L>*>
268 : std::integral_constant<bool, packed_pixel<P, C, L>::is_mutable>
271 template <
typename P,
typename C,
typename L>
272 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:632
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
Returns the number of channels of a pixel-based GIL construct.
Definition: pixel.hpp:54
Heterogeneous pixel value whose channel references can be constructed from the pixel bitfield and the...
Definition: packed_pixel.hpp:50