• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
3 // Copyright 2005-2007 Adobe Systems Incorporated
4 //
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
8 //
9 #ifndef BOOST_GIL_TEST_CORE_PIXEL_TEST_FIXTURE_HPP
10 #define BOOST_GIL_TEST_CORE_PIXEL_TEST_FIXTURE_HPP
11 
12 #include <boost/gil/channel.hpp>
13 #include <boost/gil/color_base_algorithm.hpp>
14 #include <boost/gil/concepts/pixel.hpp>
15 #include <boost/gil/packed_pixel.hpp>
16 #include <boost/gil/pixel.hpp>
17 #include <boost/gil/planar_pixel_reference.hpp>
18 #include <boost/gil/promote_integral.hpp>
19 #include <boost/gil/typedefs.hpp>
20 #include <boost/gil/extension/toolbox/metafunctions/channel_type.hpp> // channel_type for packed and bit-aligned pixels
21 
22 #include <boost/core/ignore_unused.hpp>
23 #include <boost/mp11.hpp>
24 #include <boost/mp11/mpl.hpp> // for compatibility with Boost.Test
25 
26 #include <cstdint>
27 #include <iterator>
28 #include <tuple>
29 #include <type_traits>
30 
31 #include "core/test_fixture.hpp" // random_value
32 #include "core/channel/test_fixture.hpp" // channel_minmax_value
33 
34 namespace boost { namespace gil { namespace test { namespace fixture {
35 
36 template <typename Pixel>
37 struct pixel_generator
38 {
39     using channel_t = typename gil::channel_type<Pixel>::type;
40 
maxboost::gil::test::fixture::pixel_generator41     static auto max() -> Pixel
42     {
43         channel_minmax_value<channel_t> channel;
44         Pixel pixel;
45         gil::static_fill(pixel, channel.max_v_);
46         return pixel;
47     }
48 
minboost::gil::test::fixture::pixel_generator49     static auto min()-> Pixel
50     {
51         channel_minmax_value<channel_t> channel;
52         Pixel pixel;
53         gil::static_fill(pixel, channel.min_v_);
54         return pixel;
55     }
56 
randomboost::gil::test::fixture::pixel_generator57     static auto random() -> Pixel
58     {
59         random_value<channel_t> generate;
60         Pixel pixel;
61         gil::static_generate(pixel, [&generate]() { return generate(); });
62         return pixel;
63     }
64 };
65 
66 template <typename Pixel, int Tag = 0>
67 class pixel_value
68 {
69 public:
70     using type = Pixel;
71     using pixel_t = type;
72     type pixel_{};
73 
74     pixel_value() = default;
pixel_value(pixel_t const & pixel)75     explicit pixel_value(pixel_t const& pixel)
76         : pixel_(pixel) // test copy constructor
77     {
78         type temp_pixel; // test default constructor
79         boost::ignore_unused(temp_pixel);
80         boost::function_requires<PixelValueConcept<pixel_t> >();
81     }
82 };
83 
84 // Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp
85 // The core suffix indicates `Pixel` is GIL core pixel type.
86 template <typename Pixel, int Tag = 0>
87 using value_core = pixel_value<Pixel, Tag>;
88 
89 template <typename PixelRef, int Tag = 0>
90 struct pixel_reference
91     : pixel_value
92     <
93         typename std::remove_reference<PixelRef>::type,
94         Tag
95     >
96 {
97     static_assert(
98         std::is_reference<PixelRef>::value ||
99         gil::is_planar<PixelRef>::value, // poor-man test for specialization of planar_pixel_reference
100         "PixelRef must be reference or gil::planar_pixel_reference");
101 
102     using type = PixelRef;
103     using pixel_t = typename std::remove_reference<PixelRef>::type;
104     using parent_t = pixel_value<typename pixel_t::value_type, Tag>;
105     using value_t = typename pixel_t::value_type;
106     type pixel_; // reference
107 
pixel_referenceboost::gil::test::fixture::pixel_reference108     pixel_reference() : parent_t{}, pixel_(parent_t::pixel_) {}
pixel_referenceboost::gil::test::fixture::pixel_reference109     explicit pixel_reference(value_t const& pixel) : parent_t(pixel), pixel_(parent_t::pixel_)
110     {
111         boost::function_requires<PixelConcept<pixel_t>>();
112     }
113 };
114 
115 // Alias compatible with naming of equivalent class in the test/legacy/pixel.cpp
116 // The core suffix indicates `Pixel` is GIL core pixel type.
117 template <typename Pixel, int Tag = 0>
118 using reference_core = pixel_reference<Pixel, Tag>;
119 
120 // Metafunction to yield nested type of a representative pixel type
121 template <typename PixelValueOrReference>
122 using nested_type = typename PixelValueOrReference::type;
123 
124 // Metafunction to yield nested type of a representative pixel_t type
125 template <typename PixelValueOrReference>
126 using nested_pixel_type = typename PixelValueOrReference::pixel_t;
127 
128 // Subset of pixel models that covers all color spaces, channel depths,
129 // reference/value, planar/interleaved, const/mutable.
130 // Operations like color conversion will be invoked on pairs of those.
131 using representative_pixel_types= ::boost::mp11::mp_list
132 <
133     value_core<gil::gray8_pixel_t>,
134     reference_core<gil::gray16_pixel_t&>,
135     value_core<gil::bgr8_pixel_t>,
136     reference_core<gil::rgb8_planar_ref_t>,
137     value_core<gil::argb32_pixel_t>,
138     reference_core<gil::cmyk32f_pixel_t&>,
139     reference_core<gil::abgr16c_ref_t>, // immutable reference
140     reference_core<gil::rgb32fc_planar_ref_t>
141 >;
142 
143 // List of all integer-based core pixel typedefs (i.e. with cv-qualifiers)
144 using pixel_integer_types = ::boost::mp11::mp_list
145 <
146     gil::gray8_pixel_t,
147     gil::gray8s_pixel_t,
148     gil::gray16_pixel_t,
149     gil::gray16s_pixel_t,
150     gil::gray32_pixel_t,
151     gil::gray32s_pixel_t,
152     gil::bgr8_pixel_t,
153     gil::bgr8s_pixel_t,
154     gil::bgr16_pixel_t,
155     gil::bgr16s_pixel_t,
156     gil::bgr32_pixel_t,
157     gil::bgr32s_pixel_t,
158     gil::rgb8_pixel_t,
159     gil::rgb8s_pixel_t,
160     gil::rgb16_pixel_t,
161     gil::rgb16s_pixel_t,
162     gil::rgb32_pixel_t,
163     gil::rgb32s_pixel_t,
164     gil::abgr8_pixel_t,
165     gil::abgr8s_pixel_t,
166     gil::abgr16_pixel_t,
167     gil::abgr16s_pixel_t,
168     gil::abgr32_pixel_t,
169     gil::abgr32s_pixel_t,
170     gil::bgra8_pixel_t,
171     gil::bgra8s_pixel_t,
172     gil::bgra16_pixel_t,
173     gil::bgra16s_pixel_t,
174     gil::bgra32_pixel_t,
175     gil::bgra32s_pixel_t,
176     gil::cmyk8_pixel_t,
177     gil::cmyk8s_pixel_t,
178     gil::cmyk16_pixel_t,
179     gil::cmyk16s_pixel_t,
180     gil::cmyk32_pixel_t,
181     gil::cmyk32s_pixel_t,
182     gil::rgba8_pixel_t,
183     gil::rgba8s_pixel_t,
184     gil::rgba16_pixel_t,
185     gil::rgba16s_pixel_t,
186     gil::rgba32_pixel_t,
187     gil::rgba32s_pixel_t
188 >;
189 
190 // List of all integer-based core pixel typedefs (i.e. with cv-qualifiers)
191 using pixel_float_types = ::boost::mp11::mp_list
192 <
193     gil::gray32f_pixel_t,
194     gil::bgr32f_pixel_t,
195     gil::rgb32f_pixel_t,
196     gil::abgr32f_pixel_t,
197     gil::bgra32f_pixel_t,
198     gil::cmyk32f_pixel_t,
199     gil::rgba32f_pixel_t
200 >;
201 
202 // List of all core pixel types (i.e. without cv-qualifiers)
203 using pixel_types = ::boost::mp11::mp_append
204 <
205     pixel_integer_types,
206     pixel_float_types
207 >;
208 
209 // List of all core pixel typedefs (i.e. with cv-qualifiers)
210 using pixel_typedefs = ::boost::mp11::mp_append
211 <
212     pixel_integer_types,
213     pixel_float_types,
214     ::boost::mp11::mp_list
215     <
216         gil::gray8c_pixel_t,
217         gil::gray8sc_pixel_t,
218         gil::gray16c_pixel_t,
219         gil::gray16sc_pixel_t,
220         gil::gray32c_pixel_t,
221         gil::gray32fc_pixel_t,
222         gil::gray32sc_pixel_t,
223         gil::bgr8c_pixel_t,
224         gil::bgr8sc_pixel_t,
225         gil::bgr16c_pixel_t,
226         gil::bgr16sc_pixel_t,
227         gil::bgr32c_pixel_t,
228         gil::bgr32fc_pixel_t,
229         gil::bgr32sc_pixel_t,
230         gil::rgb8c_pixel_t,
231         gil::rgb8sc_pixel_t,
232         gil::rgb16c_pixel_t,
233         gil::rgb16sc_pixel_t,
234         gil::rgb32c_pixel_t,
235         gil::rgb32fc_pixel_t,
236         gil::rgb32sc_pixel_t,
237         gil::abgr8c_pixel_t,
238         gil::abgr8sc_pixel_t,
239         gil::abgr16c_pixel_t,
240         gil::abgr16sc_pixel_t,
241         gil::abgr32c_pixel_t,
242         gil::abgr32fc_pixel_t,
243         gil::abgr32sc_pixel_t,
244         gil::bgra8c_pixel_t,
245         gil::bgra8sc_pixel_t,
246         gil::bgra16c_pixel_t,
247         gil::bgra16sc_pixel_t,
248         gil::bgra32c_pixel_t,
249         gil::bgra32fc_pixel_t,
250         gil::bgra32sc_pixel_t,
251         gil::cmyk8c_pixel_t,
252         gil::cmyk8sc_pixel_t,
253         gil::cmyk16c_pixel_t,
254         gil::cmyk16sc_pixel_t,
255         gil::cmyk32c_pixel_t,
256         gil::cmyk32fc_pixel_t,
257         gil::cmyk32sc_pixel_t,
258         gil::rgba8c_pixel_t,
259         gil::rgba8sc_pixel_t,
260         gil::rgba16c_pixel_t,
261         gil::rgba16sc_pixel_t,
262         gil::rgba32c_pixel_t,
263         gil::rgba32fc_pixel_t,
264         gil::rgba32sc_pixel_t
265     >
266 >;
267 
268 struct not_a_pixel_type {};
269 
270 using non_pixels = ::boost::mp11::mp_list
271 <
272     not_a_pixel_type,
273     char,
274     short, int, long,
275     double, float,
276     std::size_t,
277     std::true_type,
278     std::false_type
279 >;
280 
281 using packed_channel_references_3 = typename gil::detail::packed_channel_references_vector_type
282 <
283     std::uint8_t,
284     mp11::mp_list_c<int, 3>
285 >::type;
286 
287 using packed_pixel_gray3 = gil::packed_pixel
288 <
289     std::uint8_t,
290     packed_channel_references_3,
291     gil::gray_layout_t
292 >;
293 
294 using packed_channel_references_121 = typename gil::detail::packed_channel_references_vector_type
295 <
296     std::uint8_t,
297     mp11::mp_list_c<int, 1, 2, 1>
298 >::type;
299 
300 using packed_pixel_bgr121 = gil::packed_pixel
301 <
302     std::uint8_t,
303     packed_channel_references_121,
304     gil::bgr_layout_t
305 >;
306 
307 using packed_channel_references_535 = typename gil::detail::packed_channel_references_vector_type
308 <
309     std::uint16_t,
310     mp11::mp_list_c<int, 5, 3, 5>
311 >::type;
312 
313 using packed_pixel_rgb535 = gil::packed_pixel
314 <
315     std::uint16_t,
316     packed_channel_references_535,
317     gil::rgb_layout_t
318 >;
319 
320 using bit_aligned_pixel_bgr232_refefence = gil::bit_aligned_pixel_reference
321     <
322         std::uint8_t,
323         mp11::mp_list_c<int, 2, 3, 2>,
324         gil::bgr_layout_t,
325         true
326     > const;
327 
328 using bit_aligned_pixel_bgr232_iterator = bit_aligned_pixel_iterator<bit_aligned_pixel_bgr232_refefence>;
329 
330 using bit_aligned_pixel_bgr232 = std::iterator_traits<bit_aligned_pixel_bgr232_iterator>::value_type;
331 
332 using bit_aligned_pixel_rgb567_refefence = gil::bit_aligned_pixel_reference
333     <
334         std::uint32_t,
335         mp11::mp_list_c<int, 5, 6, 7>,
336         gil::rgb_layout_t,
337         true
338     > const;
339 
340 using bit_aligned_pixel_rgb567_iterator = bit_aligned_pixel_iterator<bit_aligned_pixel_rgb567_refefence>;
341 
342 using bit_aligned_pixel_rgb567 = std::iterator_traits<bit_aligned_pixel_rgb567_iterator>::value_type;
343 
344 }}}} // namespace boost::gil::test::fixture
345 
346 #endif
347