| 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 | // |
| 8 | #ifndef BOOST_GIL_TEST_CORE_IMAGE_TEST_FIXTURE_HPP |
| 9 | #define BOOST_GIL_TEST_CORE_IMAGE_TEST_FIXTURE_HPP |
| 10 | |
| 11 | #include <boost/gil.hpp> |
| 12 | |
| 13 | #include <cstdint> |
| 14 | #include <initializer_list> |
| 15 | #include <limits> |
| 16 | #include <random> |
| 17 | #include <tuple> |
| 18 | #include <type_traits> |
| 19 | |
| 20 | namespace boost { namespace gil { namespace test { namespace fixture { |
| 21 | |
| 22 | using image_types = std::tuple |
| 23 | < |
| 24 | gil::gray8_image_t, |
| 25 | gil::gray16_image_t, |
| 26 | gil::gray32_image_t, |
| 27 | gil::bgr8_image_t, |
| 28 | gil::bgr16_image_t, |
| 29 | gil::bgr32_image_t, |
| 30 | gil::rgb8_image_t, |
| 31 | gil::rgb16_image_t, |
| 32 | gil::rgb32_image_t, |
| 33 | gil::rgba8_image_t, |
| 34 | gil::rgba16_image_t, |
| 35 | gil::rgba32_image_t |
| 36 | >; |
| 37 | |
| 38 | #if defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE) |
| 39 | using pmr_image_types = std::tuple<>; |
| 40 | #else |
| 41 | using pmr_image_types = std::tuple |
| 42 | < |
| 43 | gil::pmr::gray8_image_t, |
| 44 | gil::pmr::gray16_image_t, |
| 45 | gil::pmr::gray32_image_t, |
| 46 | gil::pmr::bgr8_image_t, |
| 47 | gil::pmr::bgr16_image_t, |
| 48 | gil::pmr::bgr32_image_t, |
| 49 | gil::pmr::rgb8_image_t, |
| 50 | gil::pmr::rgb16_image_t, |
| 51 | gil::pmr::rgb32_image_t, |
| 52 | gil::pmr::rgba8_image_t, |
| 53 | gil::pmr::rgba16_image_t, |
| 54 | gil::pmr::rgba32_image_t |
| 55 | >; |
| 56 | #endif //defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE) |
| 57 | |
| 58 | using rgb_interleaved_image_types = std::tuple |
| 59 | < |
| 60 | gil::bgr8_image_t, |
| 61 | gil::bgr16_image_t, |
| 62 | gil::bgr32_image_t, |
| 63 | gil::rgb8_image_t, |
| 64 | gil::rgb16_image_t, |
| 65 | gil::rgb32_image_t, |
| 66 | gil::rgba8_image_t, |
| 67 | gil::rgba16_image_t, |
| 68 | gil::rgba32_image_t |
| 69 | >; |
| 70 | |
| 71 | using bit_aligned_image_types = std::tuple |
| 72 | < |
| 73 | gil::bit_aligned_image1_type<1, gil::gray_layout_t>::type, |
| 74 | gil::bit_aligned_image1_type<3, gil::gray_layout_t>::type, |
| 75 | gil::bit_aligned_image1_type<8, gil::gray_layout_t>::type, |
| 76 | gil::bit_aligned_image3_type<2, 2, 2, gil::rgb_layout_t>::type, |
| 77 | gil::bit_aligned_image3_type<5, 6, 5, gil::rgb_layout_t>::type, |
| 78 | gil::bit_aligned_image3_type<6, 6, 6, gil::rgb_layout_t>::type |
| 79 | >; |
| 80 | |
| 81 | template <typename Image, typename Generator> |
| 82 | auto generate_image(std::ptrdiff_t size_x, std::ptrdiff_t size_y, Generator&& generate) -> Image |
| 83 | { |
| 84 | using pixel_t = typename Image::value_type; |
| 85 | |
| 86 | Image out(size_x, size_y); |
| 87 | gil::for_each_pixel(view(out), [&generate](pixel_t& p) { |
| 88 | gil::static_generate(p, [&generate]() { return generate(); }); |
| 89 | }); |
| 90 | |
| 91 | return out; |
| 92 | } |
| 93 | |
| 94 | template <typename Image> |
| 95 | auto create_image(std::ptrdiff_t size_x, std::ptrdiff_t size_y, int channel_value) -> Image |
| 96 | { |
| 97 | using pixel_t = typename Image::value_type; |
| 98 | using channel_t = typename gil::channel_type<pixel_t>::type; |
| 99 | static_assert(std::is_integral<channel_t>::value, "channel must be integral type" ); |
| 100 | |
| 101 | Image out(size_x, size_y); |
| 102 | gil::for_each_pixel(view(out), [&channel_value](pixel_t& p) { |
| 103 | gil::static_fill(p, static_cast<channel_t>(channel_value)); |
| 104 | }); |
| 105 | |
| 106 | return out; |
| 107 | } |
| 108 | |
| 109 | }}}} // namespace boost::gil::test::fixture |
| 110 | |
| 111 | #endif |
| 112 | |