Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / core / image_view / view_type.cpp
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 #include <boost/gil.hpp>
9
10 #include <type_traits>
11
12 namespace gil = boost::gil;
13
14 struct Interleaved : std::false_type {};
15 struct Planar : std::true_type {};
16 struct NotStepX : std::false_type {};
17 struct StepX : std::true_type {};
18 struct Immutable : std::false_type {};
19 struct Mutable : std::true_type {};
20
21 template <typename ResultView, typename Layout, typename IsPlanar, typename IsStepX, typename IsMutable>
22 void test()
23 {
24     static_assert(std::is_same
25     <
26         typename gil::view_type
27         <
28             std::uint8_t,
29             Layout,
30             IsPlanar::value,
31             IsStepX::value,
32             IsMutable::value
33         >::type,
34         ResultView
35     >::value, "view_type yields unexpected view");
36 }
37
38 template <typename ResultView, typename Layout, typename IsPlanar, typename IsStepX, typename IsMutable>
39 void test_not()
40 {
41     static_assert(!std::is_same
42     <
43         typename gil::view_type
44         <
45             std::uint8_t,
46             Layout,
47             IsPlanar::value,
48             IsStepX::value,
49             IsMutable::value
50         >::type,
51         ResultView
52     >::value, "view_type yields unexpected view");
53 }
54
55 int main()
56 {
57     test<gil::gray8_view_t, gil::gray_layout_t, Interleaved, NotStepX, Mutable>();
58     test<gil::gray8c_view_t, gil::gray_layout_t, Interleaved, NotStepX, Immutable>();
59     test<gil::gray8_step_view_t, gil::gray_layout_t, Interleaved, StepX, Mutable>();
60     test<gil::gray8c_step_view_t, gil::gray_layout_t, Interleaved, StepX, Immutable>();
61     test_not<gil::gray8_view_t, gil::gray_layout_t, Planar, NotStepX, Mutable>();
62     test_not<gil::gray8_view_t, gil::rgb_layout_t, Planar, NotStepX, Mutable>();
63     test_not<gil::gray8_view_t, gil::gray_layout_t, Interleaved, StepX, Mutable>();
64     test_not<gil::gray8_view_t, gil::gray_layout_t, Interleaved, NotStepX, Immutable>();
65
66     test<gil::abgr8_view_t, gil::abgr_layout_t, Interleaved, NotStepX, Mutable>();
67     test<gil::abgr8c_view_t, gil::abgr_layout_t, Interleaved, NotStepX, Immutable>();
68     test<gil::abgr8_step_view_t, gil::abgr_layout_t, Interleaved, StepX, Mutable>();
69     test<gil::abgr8c_step_view_t, gil::abgr_layout_t, Interleaved, StepX, Immutable>();
70     test_not<gil::abgr8_view_t, gil::bgra_layout_t, Interleaved, NotStepX, Mutable>();
71     test_not<gil::abgr8_view_t, gil::rgba_layout_t, Interleaved, NotStepX, Mutable>();
72
73     test<gil::argb8_view_t, gil::argb_layout_t, Interleaved, NotStepX, Mutable>();
74     test<gil::argb8c_view_t, gil::argb_layout_t, Interleaved, NotStepX, Immutable>();
75     test<gil::argb8_step_view_t, gil::argb_layout_t, Interleaved, StepX, Mutable>();
76     test<gil::argb8c_step_view_t, gil::argb_layout_t, Interleaved, StepX, Immutable>();
77
78     test<gil::bgr8_view_t, gil::bgr_layout_t, Interleaved, NotStepX, Mutable>();
79     test<gil::bgr8c_view_t, gil::bgr_layout_t, Interleaved, NotStepX, Immutable>();
80     test<gil::bgr8_step_view_t, gil::bgr_layout_t, Interleaved, StepX, Mutable>();
81     test<gil::bgr8c_step_view_t, gil::bgr_layout_t, Interleaved, StepX, Immutable>();
82     test_not<gil::bgr8_view_t, gil::rgb_layout_t, Interleaved, NotStepX, Mutable>();
83
84     test<gil::bgra8_view_t, gil::bgra_layout_t, Interleaved, NotStepX, Mutable>();
85     test<gil::bgra8c_view_t, gil::bgra_layout_t, Interleaved, NotStepX, Immutable>();
86     test<gil::bgra8_step_view_t, gil::bgra_layout_t, Interleaved, StepX, Mutable>();
87     test<gil::bgra8c_step_view_t, gil::bgra_layout_t, Interleaved, StepX, Immutable>();
88     test_not<gil::bgra8_view_t, gil::abgr_layout_t, Interleaved, NotStepX, Mutable>();
89     test_not<gil::bgra8_view_t, gil::rgba_layout_t, Interleaved, NotStepX, Mutable>();
90
91     test<gil::rgb8_view_t, gil::rgb_layout_t, Interleaved, NotStepX, Mutable>();
92     test<gil::rgb8c_view_t, gil::rgb_layout_t, Interleaved, NotStepX, Immutable>();
93     test<gil::rgb8_step_view_t, gil::rgb_layout_t, Interleaved, StepX, Mutable>();
94     test<gil::rgb8c_step_view_t, gil::rgb_layout_t, Interleaved, StepX, Immutable>();
95     test_not<gil::rgb8_view_t, gil::rgb_layout_t, Planar, NotStepX, Mutable>();
96     test_not<gil::rgb8_view_t, gil::abgr_layout_t, Interleaved, NotStepX, Mutable>();
97     test_not<gil::rgb8_view_t, gil::bgra_layout_t, Interleaved, NotStepX, Mutable>();
98
99     test<gil::rgb8_planar_view_t, gil::rgb_layout_t, Planar, NotStepX, Mutable>();
100     test<gil::rgb8c_planar_view_t, gil::rgb_layout_t, Planar, NotStepX, Immutable>();
101     test<gil::rgb8_planar_step_view_t, gil::rgb_layout_t, Planar, StepX, Mutable>();
102     test<gil::rgb8c_planar_step_view_t, gil::rgb_layout_t, Planar, StepX, Immutable>();
103
104     test<gil::cmyk8_view_t, gil::cmyk_layout_t, Interleaved, NotStepX, Mutable>();
105     test<gil::cmyk8c_view_t, gil::cmyk_layout_t, Interleaved, NotStepX, Immutable>();
106     test<gil::cmyk8_step_view_t, gil::cmyk_layout_t, Interleaved, StepX, Mutable>();
107     test<gil::cmyk8c_step_view_t, gil::cmyk_layout_t, Interleaved, StepX, Immutable>();
108     test_not<gil::cmyk8_view_t, gil::rgba_layout_t, Interleaved, NotStepX, Mutable>();
109
110     test<gil::cmyk8_planar_view_t, gil::cmyk_layout_t, Planar, NotStepX, Mutable>();
111     test<gil::cmyk8c_planar_view_t, gil::cmyk_layout_t, Planar, NotStepX, Immutable>();
112     test<gil::cmyk8_planar_step_view_t, gil::cmyk_layout_t, Planar, StepX, Mutable>();
113     test<gil::cmyk8c_planar_step_view_t, gil::cmyk_layout_t, Planar, StepX, Immutable>();
114 }