]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // |
2 | // Copyright 2019-2020 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 | #include <boost/gil.hpp> | |
9 | ||
10 | #include <boost/core/lightweight_test.hpp> | |
11 | ||
12 | #include "test_fixture.hpp" | |
13 | #include "test_utility_output_stream.hpp" | |
14 | #include "core/pixel/test_fixture.hpp" | |
15 | ||
16 | namespace gil = boost::gil; | |
17 | namespace fixture = boost::gil::test::fixture; | |
18 | ||
19 | struct test_constructor_with_dimensions_pixel | |
20 | { | |
21 | template <typename Image> | |
22 | void operator()(Image const &) | |
23 | { | |
24 | using image_t = Image; | |
25 | gil::point_t const dimensions{256, 128}; | |
26 | using pixel_t = typename image_t::view_t::value_type; | |
27 | pixel_t const rnd_pixel = fixture::pixel_generator<pixel_t>::random(); | |
28 | image_t image(dimensions, rnd_pixel); | |
29 | BOOST_TEST_EQ(image.width(), dimensions.x); | |
30 | BOOST_TEST_EQ(image.height(), dimensions.y); | |
31 | ||
32 | for (pixel_t const &p : gil::view(image)) | |
33 | BOOST_TEST_EQ(p, rnd_pixel); | |
34 | } | |
35 | static void run() | |
36 | { | |
37 | boost::mp11::mp_for_each<fixture::image_types>(test_constructor_with_dimensions_pixel{}); | |
38 | } | |
39 | }; | |
40 | ||
20effc67 TL |
41 | struct test_constructor_from_other_image |
42 | { | |
43 | template <typename Image> | |
44 | void operator()(Image const &) | |
45 | { | |
46 | using image_t = Image; | |
47 | gil::point_t const dimensions{256, 128}; | |
48 | using pixel_t = typename image_t::view_t::value_type; | |
49 | pixel_t const rnd_pixel = fixture::pixel_generator<pixel_t>::random(); | |
50 | { | |
51 | //constructor interleaved from planar | |
52 | gil::image<pixel_t, true> image1(dimensions, rnd_pixel); | |
53 | image_t image2(image1); | |
54 | BOOST_TEST_EQ(image2.dimensions(), dimensions); | |
55 | auto v1 = gil::const_view(image1); | |
56 | auto v2 = gil::const_view(image2); | |
57 | BOOST_TEST_ALL_EQ(v1.begin(), v1.end(), v2.begin(), v2.end()); | |
58 | } | |
59 | // { | |
60 | // //constructor planar from interleaved | |
61 | // image_t image1(dimensions, rnd_pixel); | |
62 | // gil::image<pixel_t, true> image2(image1); | |
63 | // BOOST_TEST_EQ(image2.dimensions(), dimensions); | |
64 | // auto v1 = gil::const_view(image1); | |
65 | // auto v2 = gil::const_view(image2); | |
66 | // BOOST_TEST_ALL_EQ(v1.begin(), v1.end(), v2.begin(), v2.end()); | |
67 | // } | |
68 | } | |
69 | static void run() | |
70 | { | |
71 | boost::mp11::mp_for_each<fixture::rgb_interleaved_image_types>(test_constructor_from_other_image{}); | |
72 | } | |
73 | }; | |
74 | ||
f67539c2 TL |
75 | struct test_move_constructor |
76 | { | |
77 | template <typename Image> | |
78 | void operator()(Image const&) | |
79 | { | |
80 | using image_t = Image; | |
81 | gil::point_t const dimensions{256, 128}; | |
82 | { | |
83 | image_t image(fixture::create_image<image_t>(dimensions.x, dimensions.y, 0)); | |
84 | ||
85 | image_t image2(std::move(image)); | |
86 | BOOST_TEST_EQ(image2.dimensions(), dimensions); | |
87 | BOOST_TEST_EQ(image.dimensions(), gil::point_t{}); | |
88 | } | |
89 | } | |
90 | static void run() | |
91 | { | |
92 | boost::mp11::mp_for_each<fixture::image_types>(test_move_constructor{}); | |
93 | } | |
94 | }; | |
95 | ||
96 | struct test_move_assignement | |
97 | { | |
98 | template <typename Image> | |
99 | void operator()(Image const&) | |
100 | { | |
101 | using image_t = Image; | |
102 | gil::point_t const dimensions{256, 128}; | |
103 | { | |
104 | image_t image = fixture::create_image<image_t>(dimensions.x, dimensions.y, 0); | |
105 | image_t image2 = fixture::create_image<image_t>(dimensions.x * 2, dimensions.y * 2, 1); | |
106 | image2 = std::move(image); | |
107 | BOOST_TEST_EQ(image2.dimensions(), dimensions); | |
108 | BOOST_TEST_EQ(image.dimensions(), gil::point_t{}); | |
109 | } | |
110 | } | |
111 | static void run() | |
112 | { | |
113 | boost::mp11::mp_for_each<fixture::image_types>(test_move_assignement{}); | |
114 | } | |
115 | }; | |
116 | ||
117 | int main() | |
118 | { | |
119 | test_constructor_with_dimensions_pixel::run(); | |
20effc67 | 120 | test_constructor_from_other_image::run(); |
f67539c2 TL |
121 | |
122 | test_move_constructor::run(); | |
123 | test_move_assignement::run(); | |
124 | ||
125 | return ::boost::report_errors(); | |
126 | } |