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