2 // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
3 // Copyright 2005-2007 Adobe Systems Incorporated
5 // Distributed under the Boost Software License, Version 1.0
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
9 #include <boost/gil/channel.hpp>
10 #include <boost/gil/color_base_algorithm.hpp>
11 #include <boost/gil/concepts/pixel.hpp>
12 #include <boost/gil/pixel.hpp>
13 #include <boost/gil/planar_pixel_reference.hpp>
14 #include <boost/gil/promote_integral.hpp>
15 #include <boost/gil/typedefs.hpp>
17 #include <boost/core/typeinfo.hpp>
18 #include <boost/mp11.hpp>
19 #include <boost/mp11/mpl.hpp> // for compatibility with Boost.Test
23 #include <type_traits>
25 namespace boost { namespace gil {
29 struct print_color_base
32 std::size_t element_index_{0};
33 print_color_base(std::ostream& os) : os_(os) {}
35 template <typename Element>
36 void operator()(Element& c)
38 typename gil::promote_integral<Element>::type const v(c);
39 if (element_index_ > 0) os_ << ", ";
40 os_ << "v" << element_index_ << "=" << v;
47 // Pixel has to implement operator<< to be printable for BOOST_TEST()
48 template <typename ChannelValue, typename Layout>
49 std::ostream& operator<<(std::ostream& os, pixel<ChannelValue, Layout> const& p)
52 << "Channel=" << boost::core::demangled_name(typeid(ChannelValue))
53 << ", Layout=" << boost::core::demangled_name(typeid(Layout))
56 gil::static_for_each(p, detail::print_color_base{os});
57 os << ")" << std::endl;
61 namespace test { namespace fixture {
63 template <typename Pixel, int Tag = 0>
71 pixel_value() = default;
72 explicit pixel_value(pixel_t const& pixel)
73 : pixel_(pixel) // test copy constructor
75 type temp_pixel; // test default constructor
76 boost::function_requires<PixelValueConcept<pixel_t> >();
80 // Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp
81 // The core suffix indicates `Pixel` is GIL core pixel type.
82 template <typename Pixel, int Tag = 0>
83 using value_core = pixel_value<Pixel, Tag>;
85 template <typename PixelRef, int Tag = 0>
86 struct pixel_reference
89 typename std::remove_reference<PixelRef>::type,
94 std::is_reference<PixelRef>::value ||
95 gil::is_planar<PixelRef>::value, // poor-man test for specialization of planar_pixel_reference
96 "PixelRef must be reference or gil::planar_pixel_reference");
98 using type = PixelRef;
99 using pixel_t = typename std::remove_reference<PixelRef>::type;
100 using parent_t = pixel_value<typename pixel_t::value_type, Tag>;
101 using value_t = typename pixel_t::value_type;
102 type pixel_{}; // reference
104 pixel_reference() : parent_t{}, pixel_(parent_t::pixel_) {}
105 explicit pixel_reference(value_t const& pixel) : parent_t(pixel), pixel_(parent_t::pixel_)
107 boost::function_requires<PixelConcept<pixel_t>>();
111 // Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp
112 // The core suffix indicates `Pixel` is GIL core pixel type.
113 template <typename Pixel, int Tag = 0>
114 using reference_core = pixel_reference<Pixel, Tag>;
116 // Metafunction to yield nested type of a representative pixel type
117 template <typename PixelValueOrReference>
118 using nested_type = typename PixelValueOrReference::type;
120 // Metafunction to yield nested type of a representative pixel_t type
121 template <typename PixelValueOrReference>
122 using nested_pixel_type = typename PixelValueOrReference::pixel_t;
124 // Subset of pixel models that covers all color spaces, channel depths,
125 // reference/value, planar/interleaved, const/mutable.
126 // Operations like color conversion will be invoked on pairs of those.
127 using representative_pixel_types= ::boost::mp11::mp_list
129 value_core<gil::gray8_pixel_t>,
130 reference_core<gil::gray16_pixel_t&>,
131 value_core<gil::bgr8_pixel_t>,
132 reference_core<gil::rgb8_planar_ref_t>,
133 value_core<gil::argb32_pixel_t>,
134 reference_core<gil::cmyk32f_pixel_t&>,
135 reference_core<gil::abgr16c_ref_t>, // immutable reference
136 reference_core<gil::rgb32fc_planar_ref_t>
139 // List of all core pixel types (i.e. without cv-qualifiers)
140 using pixel_types = ::boost::mp11::mp_list
145 gil::gray16s_pixel_t,
147 gil::gray32s_pixel_t,
148 gil::gray32f_pixel_t,
166 gil::abgr16s_pixel_t,
168 gil::abgr32f_pixel_t,
169 gil::abgr32s_pixel_t,
173 gil::bgra16s_pixel_t,
175 gil::bgra32f_pixel_t,
176 gil::bgra32s_pixel_t,
180 gil::cmyk16s_pixel_t,
182 gil::cmyk32f_pixel_t,
183 gil::cmyk32s_pixel_t,
187 gil::rgba16s_pixel_t,
189 gil::rgba32f_pixel_t,
193 // List of all core pixel typedefs (i.e. with cv-qualifiers)
194 using pixel_typedefs = ::boost::mp11::mp_list
199 gil::gray8sc_pixel_t,
201 gil::gray16c_pixel_t,
202 gil::gray16s_pixel_t,
203 gil::gray16sc_pixel_t,
205 gil::gray32c_pixel_t,
206 gil::gray32f_pixel_t,
207 gil::gray32fc_pixel_t,
208 gil::gray32s_pixel_t,
209 gil::gray32sc_pixel_t,
217 gil::bgr16sc_pixel_t,
221 gil::bgr32fc_pixel_t,
223 gil::bgr32sc_pixel_t,
231 gil::rgb16sc_pixel_t,
235 gil::rgb32fc_pixel_t,
237 gil::rgb32sc_pixel_t,
241 gil::abgr8sc_pixel_t,
243 gil::abgr16c_pixel_t,
244 gil::abgr16s_pixel_t,
245 gil::abgr16sc_pixel_t,
247 gil::abgr32c_pixel_t,
248 gil::abgr32f_pixel_t,
249 gil::abgr32fc_pixel_t,
250 gil::abgr32s_pixel_t,
251 gil::abgr32sc_pixel_t,
255 gil::bgra8sc_pixel_t,
257 gil::bgra16c_pixel_t,
258 gil::bgra16s_pixel_t,
259 gil::bgra16sc_pixel_t,
261 gil::bgra32c_pixel_t,
262 gil::bgra32f_pixel_t,
263 gil::bgra32fc_pixel_t,
264 gil::bgra32s_pixel_t,
265 gil::bgra32sc_pixel_t,
269 gil::cmyk8sc_pixel_t,
271 gil::cmyk16c_pixel_t,
272 gil::cmyk16s_pixel_t,
273 gil::cmyk16sc_pixel_t,
275 gil::cmyk32c_pixel_t,
276 gil::cmyk32f_pixel_t,
277 gil::cmyk32fc_pixel_t,
278 gil::cmyk32s_pixel_t,
279 gil::cmyk32sc_pixel_t,
283 gil::rgba8sc_pixel_t,
285 gil::rgba16c_pixel_t,
286 gil::rgba16s_pixel_t,
287 gil::rgba16sc_pixel_t,
289 gil::rgba32c_pixel_t,
290 gil::rgba32f_pixel_t,
291 gil::rgba32fc_pixel_t,
292 gil::rgba32s_pixel_t,
293 gil::rgba32sc_pixel_t
296 struct not_a_pixel_type {};
298 using non_pixels = ::boost::mp11::mp_list
310 }}}} // namespace boost::gil::test::fixture