Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / extension / numeric / extend_boundary.cpp
1 //
2 // Copyright 2019 Pranam Lashkari <plashkari628@gmail.com>
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
9 #define BOOST_TEST_MODULE test_ext_numeric_extend_boundary
10 #include "unit_test.hpp"
11 #include "unit_test_utility.hpp"
12
13 #include <boost/gil.hpp>
14 #include <boost/gil/extension/numeric/algorithm.hpp>
15 #include <boost/gil/extension/numeric/convolve.hpp>
16
17 namespace gil = boost::gil;
18
19 std::uint8_t img[] =
20 {
21     1, 2, 3, 4, 5, 6, 7, 8, 9,
22     10, 0, 0, 0, 0, 0, 0, 0, 32,
23     11, 0, 255, 0, 0, 0, 255, 0, 31,
24     12, 0, 0, 255, 0, 255, 0, 0, 30,
25     13, 0, 0, 0, 255, 0, 0, 0, 29,
26     14, 0, 0, 255, 0, 255, 0, 0, 28,
27     15, 0, 255, 0, 0, 0, 255, 0, 27,
28     16, 0, 0, 0, 0, 0, 0, 0, 26,
29     17, 18, 19, 20, 21, 22, 23, 24, 25
30 };
31
32 std::uint8_t row_output_constant[] =
33 {
34     1, 2, 3, 4, 5, 6, 7, 8, 9,
35     1, 2, 3, 4, 5, 6, 7, 8, 9,
36     1, 2, 3, 4, 5, 6, 7, 8, 9,
37     10, 0, 0, 0, 0, 0, 0, 0, 32,
38     11, 0, 255, 0, 0, 0, 255, 0, 31,
39     12, 0, 0, 255, 0, 255, 0, 0, 30,
40     13, 0, 0, 0, 255, 0, 0, 0, 29,
41     14, 0, 0, 255, 0, 255, 0, 0, 28,
42     15, 0, 255, 0, 0, 0, 255, 0, 27,
43     16, 0, 0, 0, 0, 0, 0, 0, 26,
44     17, 18, 19, 20, 21, 22, 23, 24, 25,
45     17, 18, 19, 20, 21, 22, 23, 24, 25,
46     17, 18, 19, 20, 21, 22, 23, 24, 25
47 };
48
49 std::uint8_t row_output_zero[] = 
50 {
51     0, 0, 0, 0, 0, 0, 0, 0, 0,
52     0, 0, 0, 0, 0, 0, 0, 0, 0,
53     0, 0, 0, 0, 0, 0, 0, 0, 0,
54     1, 2, 3, 4, 5, 6, 7, 8, 9,
55     10, 0, 0, 0, 0, 0, 0, 0, 32,
56     11, 0, 255, 0, 0, 0, 255, 0, 31,
57     12, 0, 0, 255, 0, 255, 0, 0, 30,
58     13, 0, 0, 0, 255, 0, 0, 0, 29,
59     14, 0, 0, 255, 0, 255, 0, 0, 28,
60     15, 0, 255, 0, 0, 0, 255, 0, 27,
61     16, 0, 0, 0, 0, 0, 0, 0, 26,
62     17, 18, 19, 20, 21, 22, 23, 24, 25,
63     0, 0, 0, 0, 0, 0, 0, 0, 0,
64     0, 0, 0, 0, 0, 0, 0, 0, 0,
65     0, 0, 0, 0, 0, 0, 0, 0, 0,
66 };
67
68 std::uint8_t col_output_constant[] =
69 {
70     1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9,
71     10, 10, 0, 0, 0, 0, 0, 0, 0, 32, 32,
72     11, 11, 0, 255, 0, 0, 0, 255, 0, 31, 31,
73     12, 12, 0, 0, 255, 0, 255, 0, 0, 30, 30,
74     13, 13, 0, 0, 0, 255, 0, 0, 0, 29, 29,
75     14, 14, 0, 0, 255, 0, 255, 0, 0, 28, 28,
76     15, 15, 0, 255, 0, 0, 0, 255, 0, 27, 27,
77     16, 16, 0, 0, 0, 0, 0, 0, 0, 26, 26,
78     17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25
79 };
80
81 std::uint8_t col_output_zero[] = 
82 {
83     0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
84     0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0,
85     0, 0, 11, 0, 255, 0, 0, 0, 255, 0, 31, 0, 0,
86     0, 0, 12, 0, 0, 255, 0, 255, 0, 0, 30, 0, 0,
87     0, 0, 13, 0, 0, 0, 255, 0, 0, 0, 29, 0, 0,
88     0, 0, 14, 0, 0, 255, 0, 255, 0, 0, 28, 0, 0,
89     0, 0, 15, 0, 255, 0, 0, 0, 255, 0, 27, 0, 0,
90     0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0,
91     0, 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0
92 };
93
94 std::uint8_t boundary_output_constant[] =
95 {
96     1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9,
97     1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9,
98     1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9,
99     10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 32, 32, 32,
100     11, 11, 11, 0, 255, 0, 0, 0, 255, 0, 31, 31, 31,
101     12, 12, 12, 0, 0, 255, 0, 255, 0, 0, 30, 30, 30,
102     13, 13, 13, 0, 0, 0, 255, 0, 0, 0, 29, 29, 29,
103     14, 14, 14, 0, 0, 255, 0, 255, 0, 0, 28, 28, 28,
104     15, 15, 15, 0, 255, 0, 0, 0, 255, 0, 27, 27, 27,
105     16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 26, 26, 26,
106     17, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25,
107     17, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25,
108     17, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25
109 };
110
111 std::uint8_t boundary_output_zero[] =
112 {
113     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115     0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
116     0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0,
117     0, 0, 11, 0, 255, 0, 0, 0, 255, 0, 31, 0, 0,
118     0, 0, 12, 0, 0, 255, 0, 255, 0, 0, 30, 0, 0,
119     0, 0, 13, 0, 0, 0, 255, 0, 0, 0, 29, 0, 0,
120     0, 0, 14, 0, 0, 255, 0, 255, 0, 0, 28, 0, 0,
121     0, 0, 15, 0, 255, 0, 0, 0, 255, 0, 27, 0, 0,
122     0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0,
123     0, 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0,
124     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
126 };
127
128 BOOST_AUTO_TEST_SUITE(boundary_extension)
129
130 BOOST_AUTO_TEST_CASE(extend_row_with_constant)
131 {
132     gil::gray8c_view_t src_view =
133         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
134
135     gil::gray8c_view_t out_view =
136         gil::interleaved_view(9, 13, reinterpret_cast<const gil::gray8_pixel_t *>(row_output_constant), 9);
137
138     auto output = gil::extend_row(src_view, 2, gil::boundary_option::extend_constant);
139
140     BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
141 }
142
143 BOOST_AUTO_TEST_CASE(extend_row_with_zero)
144 {
145     gil::gray8c_view_t src_view =
146         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
147
148     gil::gray8c_view_t out_view =
149         gil::interleaved_view(9, 15, reinterpret_cast<const gil::gray8_pixel_t *>(row_output_zero), 9);
150
151     auto output = gil::extend_row(src_view, 3, gil::boundary_option::extend_zero);
152
153     BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
154 }
155
156 BOOST_AUTO_TEST_CASE(extend_row_with_padded)
157 {
158     gil::gray8c_view_t src_view =
159         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
160
161     auto src_sub_view = gil::subimage_view(src_view, 0, 1, 9, 7);
162
163     auto output = gil::extend_row(src_sub_view, 1, gil::boundary_option::extend_padded);
164
165     BOOST_TEST(gil::equal_pixels(src_view, gil::view(output)));
166 }
167
168 BOOST_AUTO_TEST_CASE(extend_col_with_constant)
169 {
170     gil::gray8c_view_t src_view =
171         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
172
173     gil::gray8c_view_t out_view =
174         gil::interleaved_view(11, 9, reinterpret_cast<const gil::gray8_pixel_t *>(col_output_constant), 11);
175
176     auto output = gil::extend_col(src_view, 1, gil::boundary_option::extend_constant);
177
178     BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
179 }
180
181 BOOST_AUTO_TEST_CASE(extend_col_with_zero)
182 {
183     gil::gray8c_view_t src_view =
184         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
185
186     gil::gray8c_view_t out_view =
187         gil::interleaved_view(13, 9, reinterpret_cast<const gil::gray8_pixel_t *>(col_output_zero), 13);
188
189     auto output = gil::extend_col(src_view, 2, gil::boundary_option::extend_zero);
190
191     BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
192 }
193
194 BOOST_AUTO_TEST_CASE(extend_col_with_padded)
195 {
196     gil::gray8c_view_t src_view =
197         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
198
199     auto src_sub_view = gil::subimage_view(src_view, 1, 0, 7, 9);
200
201     auto output = gil::extend_col(src_sub_view, 1, gil::boundary_option::extend_padded);
202
203     BOOST_TEST(gil::equal_pixels(src_view, gil::view(output)));
204 }
205
206 BOOST_AUTO_TEST_CASE(extend_img_with_constant)
207 {
208     gil::gray8c_view_t src_view =
209         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
210
211     gil::gray8c_view_t out_view =
212         gil::interleaved_view(13, 13, reinterpret_cast<const gil::gray8_pixel_t *>(boundary_output_constant), 13);
213
214     auto output = gil::extend_boundary(src_view, 2, gil::boundary_option::extend_constant);
215
216     BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
217 }
218
219 BOOST_AUTO_TEST_CASE(extend_img_with_zero)
220 {
221     gil::gray8c_view_t src_view =
222         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
223
224     gil::gray8c_view_t out_view =
225         gil::interleaved_view(13, 13, reinterpret_cast<const gil::gray8_pixel_t *>(boundary_output_zero), 13);
226
227     auto output = gil::extend_boundary(src_view, 2, gil::boundary_option::extend_zero);
228
229     BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
230 }
231
232 BOOST_AUTO_TEST_CASE(extend_img_with_padded)
233 {
234     gil::gray8c_view_t src_view =
235         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
236
237     auto src_sub_view = gil::subimage_view(src_view, 1, 1, 7, 7);
238
239     auto output = gil::extend_boundary(src_sub_view, 1, gil::boundary_option::extend_padded);
240
241     BOOST_TEST(gil::equal_pixels(src_view, gil::view(output)));
242 }
243
244 BOOST_AUTO_TEST_SUITE_END()