Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / core / image_view / planar_rgba_view.cpp
1 //
2 // Copyright 2018 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 <cstdint>
13
14 namespace gil = boost::gil;
15
16 int main()
17 {
18     gil::point_t d{2, 2};
19     std::uint8_t r[] = { 1, 2, 3, 4 };
20     std::uint8_t g[] = { 10, 20, 30, 40 };
21     std::uint8_t b[] = { 110, 120, 130, 140 };
22     std::uint8_t a[] = { 251, 252, 253, 254 };
23
24     auto v = gil::planar_rgba_view(d.x, d.y, r, g, b, a, sizeof(std::uint8_t) * 2);
25     BOOST_TEST(!v.empty());
26     BOOST_TEST(v.dimensions() == d);
27     BOOST_TEST(v.num_channels() == 4u);
28     BOOST_TEST(v.size() == static_cast<std::size_t>(d.x * d.y));
29
30     gil::rgba8_pixel_t const pf{1, 10, 110, 251};
31     BOOST_TEST(v.front() == pf);
32
33     gil::rgba8_pixel_t const pb{4, 40, 140, 254};
34     BOOST_TEST(v.back() == pb);
35
36     for (std::ptrdiff_t i = 0; i < v.size(); i++)
37     {
38         gil::rgba8_pixel_t const p{r[i], g[i], b[i], a[i]};
39         BOOST_TEST(v[i] == p);
40     }
41
42     return boost::report_errors();
43 }