Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / core / image_processing / box_filter.cpp
1 //
2 // Copyright 2019 Miral Shah <miralshah2211@gmail.com>
3 //
4 // Use, modification and distribution are subject to the Boost Software License,
5 // Version 1.0. (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_image_processing_box_filter
10 #include "unit_test.hpp"
11
12 #include <boost/gil/image_view.hpp>
13 #include <boost/gil/algorithm.hpp>
14 #include <boost/gil/gray.hpp>
15 #include <boost/gil/image_processing/filter.hpp>
16
17
18 namespace gil = boost::gil;
19
20 std::uint8_t img[] =
21 {
22     0, 0, 0, 0, 0, 0, 0, 0, 0,
23     0, 0, 0, 0, 0, 0, 0, 0, 0,
24     0, 0, 255, 0, 0, 0, 255, 0, 0,
25     0, 0, 0, 255, 0, 255, 0, 0, 0,
26     0, 0, 0, 0, 255, 0, 0, 0, 0,
27     0, 0, 0, 255, 0, 255, 0, 0, 0,
28     0, 0, 255, 0, 0, 0, 255, 0, 0,
29     0, 0, 0, 0, 0, 0, 0, 0, 0,
30     0, 0, 0, 0, 0, 0, 0, 0, 0
31 };
32
33 std::uint8_t output[] =
34 {
35     0, 0, 0, 0, 0, 0, 0, 0, 0,
36     0, 28, 28, 28, 0, 28, 28, 28, 0,
37     0, 28, 56, 56, 56, 56, 56, 28, 0,
38     0, 28, 56, 85, 85, 85, 56, 28, 0,
39     0, 0, 56, 85, 141, 85, 56, 0, 0,
40     0, 28, 56, 85, 85, 85, 56, 28, 0,
41     0, 28, 56, 56, 56, 56, 56, 28, 0,
42     0, 28, 28, 28, 0, 28, 28, 28, 0,
43     0, 0, 0, 0, 0, 0, 0, 0, 0
44 };
45
46 BOOST_AUTO_TEST_SUITE(filter)
47
48 BOOST_AUTO_TEST_CASE(box_filter_with_default_parameters)
49 {
50     gil::gray8c_view_t src_view =
51         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t*>(img), 9);
52
53     gil::image<gil::gray8_pixel_t> temp_img(src_view.width(), src_view.height());
54     typename gil::image<gil::gray8_pixel_t>::view_t temp_view = view(temp_img);
55     gil::gray8_view_t dst_view(temp_view);
56
57     gil::box_filter(src_view, dst_view, 3);
58
59     gil::gray8c_view_t out_view =
60         gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t*>(output), 9);
61
62
63     BOOST_TEST(gil::equal_pixels(out_view, dst_view));
64 }
65
66 BOOST_AUTO_TEST_SUITE_END()