]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | // |
2 | // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net> | |
3 | // | |
4 | // Distributed under the Boost Software License, Version 1.0 | |
5 | // See accompanying file LICENSE_1_0.txt or copy at | |
6 | // http://www.boost.org/LICENSE_1_0.txt | |
7 | // | |
f67539c2 TL |
8 | #ifndef BOOST_GIL_TEST_CORE_IMAGE_TEST_FIXTURE_HPP |
9 | #define BOOST_GIL_TEST_CORE_IMAGE_TEST_FIXTURE_HPP | |
10 | ||
92f5a8d4 TL |
11 | #include <boost/gil.hpp> |
12 | #include <boost/assert.hpp> | |
13 | ||
14 | #include <cstdint> | |
15 | #include <initializer_list> | |
16 | #include <limits> | |
17 | #include <random> | |
18 | #include <tuple> | |
19 | #include <type_traits> | |
20 | ||
f67539c2 | 21 | #include "core/test_fixture.hpp" |
92f5a8d4 | 22 | |
f67539c2 | 23 | namespace boost { namespace gil { namespace test { namespace fixture { |
92f5a8d4 TL |
24 | |
25 | using image_types = std::tuple | |
26 | < | |
27 | gil::gray8_image_t, | |
28 | gil::gray16_image_t, | |
29 | gil::gray32_image_t, | |
30 | gil::bgr8_image_t, | |
31 | gil::bgr16_image_t, | |
32 | gil::bgr32_image_t, | |
33 | gil::rgb8_image_t, | |
34 | gil::rgb16_image_t, | |
35 | gil::rgb32_image_t, | |
36 | gil::rgba8_image_t, | |
20effc67 TL |
37 | gil::rgba16_image_t, |
38 | gil::rgba32_image_t | |
39 | >; | |
40 | ||
41 | using rgb_interleaved_image_types = std::tuple | |
42 | < | |
43 | gil::bgr8_image_t, | |
44 | gil::bgr16_image_t, | |
45 | gil::bgr32_image_t, | |
46 | gil::rgb8_image_t, | |
47 | gil::rgb16_image_t, | |
48 | gil::rgb32_image_t, | |
49 | gil::rgba8_image_t, | |
92f5a8d4 TL |
50 | gil::rgba16_image_t, |
51 | gil::rgba32_image_t | |
52 | >; | |
53 | ||
92f5a8d4 TL |
54 | template <typename Image, typename Generator> |
55 | auto generate_image(std::ptrdiff_t size_x, std::ptrdiff_t size_y, Generator&& generate) -> Image | |
56 | { | |
57 | using pixel_t = typename Image::value_type; | |
58 | ||
59 | Image out(size_x, size_y); | |
60 | gil::for_each_pixel(view(out), [&generate](pixel_t& p) { | |
61 | gil::static_generate(p, [&generate]() { return generate(); }); | |
62 | }); | |
63 | ||
64 | return out; | |
65 | } | |
66 | ||
67 | template <typename Image> | |
68 | auto create_image(std::ptrdiff_t size_x, std::ptrdiff_t size_y, int channel_value) -> Image | |
69 | { | |
70 | using pixel_t = typename Image::value_type; | |
71 | using channel_t = typename gil::channel_type<pixel_t>::type; | |
72 | static_assert(std::is_integral<channel_t>::value, "channel must be integral type"); | |
73 | ||
74 | Image out(size_x, size_y); | |
75 | gil::for_each_pixel(view(out), [&channel_value](pixel_t& p) { | |
76 | gil::static_fill(p, static_cast<channel_t>(channel_value)); | |
77 | }); | |
78 | ||
79 | return out; | |
80 | } | |
81 | ||
82 | }}}} // namespace boost::gil::test::fixture | |
f67539c2 TL |
83 | |
84 | #endif |