]>
Commit | Line | Data |
---|---|---|
92f5a8d4 | 1 | // |
f67539c2 | 2 | // Copyright 2018-2020 Mateusz Loskot <mateusz at loskot dot net> |
92f5a8d4 TL |
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 | ||
f67539c2 TL |
14 | #include "test_utility_output_stream.hpp" |
15 | ||
16 | namespace boost { namespace gil { | |
17 | namespace test { namespace fixture { | |
18 | ||
19 | gil::point_t d{2, 2}; | |
20 | std::uint8_t r[] = { 1, 2, 3, 4 }; | |
21 | std::uint8_t g[] = { 10, 20, 30, 40 }; | |
22 | std::uint8_t b[] = { 110, 120, 130, 140 }; | |
23 | std::uint8_t a[] = { 251, 252, 253, 254 }; | |
24 | ||
25 | }}}} | |
26 | ||
92f5a8d4 | 27 | namespace gil = boost::gil; |
f67539c2 | 28 | namespace fixture = boost::gil::test::fixture; |
92f5a8d4 | 29 | |
f67539c2 | 30 | void test_dimensions() |
92f5a8d4 | 31 | { |
f67539c2 | 32 | auto v = gil::planar_rgba_view(fixture::d.x, fixture::d.y, fixture::r, fixture::g, fixture::b, fixture::a, sizeof(std::uint8_t) * 2); |
92f5a8d4 | 33 | BOOST_TEST(!v.empty()); |
f67539c2 TL |
34 | BOOST_TEST_EQ(v.dimensions(), fixture::d); |
35 | BOOST_TEST_EQ(v.num_channels(), 4u); | |
36 | BOOST_TEST_EQ(v.size(), static_cast<std::size_t>(fixture::d.x * fixture::d.y)); | |
37 | } | |
92f5a8d4 | 38 | |
f67539c2 TL |
39 | void test_front() |
40 | { | |
41 | auto v = gil::planar_rgba_view(fixture::d.x, fixture::d.y, fixture::r, fixture::g, fixture::b, fixture::a, sizeof(std::uint8_t) * 2); | |
92f5a8d4 | 42 | gil::rgba8_pixel_t const pf{1, 10, 110, 251}; |
f67539c2 TL |
43 | BOOST_TEST_EQ(v.front(), pf); |
44 | } | |
92f5a8d4 | 45 | |
f67539c2 TL |
46 | void test_back() |
47 | { | |
48 | auto v = gil::planar_rgba_view(fixture::d.x, fixture::d.y, fixture::r, fixture::g, fixture::b, fixture::a, sizeof(std::uint8_t) * 2); | |
92f5a8d4 | 49 | gil::rgba8_pixel_t const pb{4, 40, 140, 254}; |
f67539c2 TL |
50 | BOOST_TEST_EQ(v.back(), pb); |
51 | } | |
92f5a8d4 | 52 | |
f67539c2 TL |
53 | void test_pixel_equal_to_operator() |
54 | { | |
55 | auto v = gil::planar_rgba_view(fixture::d.x, fixture::d.y, fixture::r, fixture::g, fixture::b, fixture::a, sizeof(std::uint8_t) * 2); | |
56 | for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(v.size()); i++) | |
92f5a8d4 | 57 | { |
f67539c2 TL |
58 | gil::rgba8_pixel_t const p{fixture::r[i], fixture::g[i], fixture::b[i], fixture::a[i]}; |
59 | BOOST_TEST_EQ(v[i], p); | |
92f5a8d4 | 60 | } |
f67539c2 TL |
61 | } |
62 | ||
63 | int main() | |
64 | { | |
65 | test_dimensions(); | |
66 | test_front(); | |
67 | test_back(); | |
68 | test_pixel_equal_to_operator(); | |
92f5a8d4 | 69 | |
f67539c2 | 70 | return ::boost::report_errors(); |
92f5a8d4 | 71 | } |